• Welcome to Jose's Read Only Forum 2023.
 

Pong in o2

Started by Zlatko Vid, March 03, 2023, 09:03:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zlatko Vid

I am looking for old o2 programs and and found one good old
PONG by Peter Wirbelauer
I don't have this wav files maybe there are in A041, so i just commented them
:)

' pong game in o2
$ filename "Pong.exe"
include "rtl32.inc"
include "window.inc"

Window "Pong in o2 by Peter Wirbelauer",320, 240, 1

'SetFPS 10

x = 50
y = 50
x2 = 130
y2 = 160
pspeed = 1
xadj = 1
yadj = 1
delay = 1
score = 0

'haha = "wav/haha.wav"
'pong = "wav/pong.wav"

WHILE Key(27) = 0
  ClsColor (200, 200, 247)
  Circle   (x, y, 8, 0, 0, 255)
  FillBox  (x2, y2, 30, 4, 255, 255, 255)
  Box      (20, 20, 280, 160, 4,255, 255, 0)
  Text     (10, 0, "SCORE:" & score, 255, 0, 0)
  IF y <= 20
    yadj = 1
    'PlayWav pong
  END IF
  IF y >= 180
    yadj = -1
   ' PlayWav pong
  END IF
  IF x >= 300
    xadj = -1
   ' PlayWav pong
  END IF
  IF x <= 20
    xadj = 1
   ' PlayWav pong
  END IF
  IF Key(37) AND x2 > 18  :  x2 = x2 - pspeed : end if
  IF Key(39) AND x2 < 270 :  x2 = x2 + pspeed : end if
  x = x + xadj
  y = y + yadj
  IF y > y2 - 7 AND y2 < y2 + 2 AND x < x2 + 30 AND x > x2
    yadj = -1
    score = score + 1
  END IF
  IF y > y2 + 10
    'Text( sys x, y, string txt, sys r,g,b)
    Text (100, 200, "GAME OVER!", 0, 160, 55)
    'Playwav haha
    Waitkey(27)
    score = 0
    x = 5
    y = 5
    x2 = 130
    y2 = 150
  END IF
  FlipBuffer()
  SetFps 40
WEND
WinEnd


Nicola_Piano

#1
Hi Zlatko,
have you tried it with the 050P14?
window.inc does not have all the necessary functions.

Nicola_Piano

Ok,
to make it go I put the SetFps function in Window.inc under projA and I managed to find the two wav.

Other changes made:

include "..\demos\!ProjA\GdiWindow\Window.inc"
PlayWav pong,0,1
Playwav haha,0,1

Cheers


Sub SetFps(sys frame)   
QueryPerformanceFrequency sys_freq                                                                                         
sys_Interval = sys_freq/frame 
While (1)                                                                       
QueryPerformanceCounter sys_ct2                                                 
iF sys_ct2 >= sys_ct1 + sys_interval                                             
QueryPerformanceCounter sys_ct1                                             
Exit Sub           
End iF
Wend
End Sub



' pong game in o2
$ filename "Pong.exe"
include "rtl32.inc"
include "..\demos\!ProjA\GdiWindow\Window.inc"

Window "Pong in o2 by Peter Wirbelauer",320, 240, 1

SetFPS 10

int x = 50
int y = 50
int x2 = 130
int y2 = 160
int pspeed = 3
int xadj = 1
int yadj = 1
int delay = 1
int score = 0

string haha = "wav/haha.wav"
string pong = "wav/pong.wav"

WHILE Key(27) = 0
  ClsColor (200, 200, 247)
  Circle   (x, y, 8, 0, 0, 255)
  FillBox  (x2, y2, 30, 4, 255, 255, 255)
  Box      (20, 20, 280, 160, 4,255, 255, 0)
  Text     (10, 0, "SCORE:" & score, 255, 0, 0)
  IF y <= 20
    yadj = 1
    PlayWav pong,0,1
  END IF
  IF y >= 180
    yadj = -1
    PlayWav pong,0,1
  END IF
  IF x >= 300
    xadj = -1
    PlayWav pong,0,1
  END IF
  IF x <= 20
    xadj = 1
    PlayWav pong,0,1
  END IF
  IF Key(37) AND x2 > 18  :  x2 = x2 - pspeed : end if
  IF Key(39) AND x2 < 270 :  x2 = x2 + pspeed : end if
  x = x + xadj
  y = y + yadj
  IF y > y2 - 7 AND y2 < y2 + 2 AND x < x2 + 30 AND x > x2
    yadj = -1
    score = score + 1
  END IF
  IF y > y2 + 10
    'Text( sys x, y, string txt, sys r,g,b)
    Text (100, 200, "GAME OVER!", 0, 160, 55)
    Playwav haha,0,1
    Waitkey(27)
    score = 0
    x = 5
    y = 5
    x2 = 130
    y2 = 150
  END IF
  FlipBuffer()
  SetFps 40
WEND
WinEnd