Here Pong
Just Add Scoring & Sound
Rem Project: PONG
Rem Created: 11/2/2003 7:13:43 AM
Rem ***** Main Source File *****
Remstart
The game of pong using sprites
Remend
SET DISPLAY MODE 640,400,32
Sync OFF
Sync rate 0
#CONSTANT TopWall 1
#CONSTANT BottomWall 2
#CONSTANT LeftWall 3
#CONSTANT RightWall 4
#CONSTANT Paddle 5
#CONSTANT Ball 6
#CONSTANT BallSize 20
#CONSTANT SCRWD Screen Width()
#CONSTANT SCRHT Screen Height()
#CONSTANT WALLTH 25
#CONSTANT RED RGB(255,0,0)
#CONSTANT WHITE RGB(255,255,255)
#CONSTANT BLUE RGB(0,0,255)
#CONSTANT GREEN RGB(0,255,0)
#CONSTANT PDLWD 20
#CONSTANT PDLHT 60
#CONSTANT PDLX SCRWD-(WALLTH+PDLWD+5)
#CONSTANT PDLY MouseY()-(PDLHT/2)
#CONSTANT MinAngle 20
Global StartSpeed : StartSpeed = 3
Global BallSpeed : BallSpeed = StartSpeed
Global TimeChange : TimeChange = 5000
Global MyTimer : MyTimer = Timer() + TimeChange
Randomize Timer()
MakeTable()
MakePaddle()
MakeBall()
Hide Mouse
do
MoveBall()
CheckLimits()
MovePaddle()
CheckCollision()
CheckSpeed()
Sync
loop
Function CheckLimits()
If Sprite x(Ball) > SCRWD-WALLTH
MakeBall()
Endif
If Sprite x(Ball) < WALLTH
Move Sprite Ball, -BallSpeed
Rotate Sprite Ball, Bounce(0, Sprite Angle(Ball))
Endif
If Sprite Y(Ball) > SCRHT-WALLTH
Move Sprite Ball, -BallSpeed
Rotate Sprite Ball, Bounce(180, Sprite Angle(Ball))
Endif
If Sprite Y(Ball) < WALLTH
Move Sprite Ball, -BallSpeed
Rotate Sprite Ball, Bounce(180,Sprite Angle(Ball))
Endif
EndFunction
Function Bounce(WallAng,N)
ExitAngle = (WallAng-N) Mod 360
EndFunction ExitAngle
Function CheckSpeed()
If MyTimer < Timer()
inc BallSpeed
MyTimer = Timer() + TimeChange
EndIf
EndFunction
Function CheckCollision()
Select Sprite hit(Ball,0)
CASE Paddle : Rotate Sprite Ball,270-(Sprite Y(Ball)- (Sprite Y(Paddle)+PDLHT/2)) :ENDCASE
EndSelect
EndFunction
Function MoveBall()
Move Sprite Ball, BallSpeed
EndFunction
Function MakeTable()
MakeSprite(TopWall,SCRWD,WALLTH,RED): Sprite TopWall,0,0,TopWall
MakeSprite(BottomWall,SCRWD,WALLTH,RED):Sprite BottomWall,0,SCRHT-WALLTH,BottomWall
MakeSprite(LeftWall,WALLTH,SCRHT,RED):Sprite LeftWall,0,0,LeftWall
MakeSprite(RightWall,WALLTH,SCRHT,RED): Sprite RightWall,SCRWD-WALLTH,0,RightWall
EndFunction
Function MakePaddle()
MakeSprite(Paddle,PDLWD,PDLHT,BLUE)
EndFunction
Function MakeBall():
If Sprite Exist (Ball) Then Delete Sprite Ball
MakeSprite(Ball,BallSize,BallSize,GREEN)
Sprite Ball,50,50,Ball
Offset Sprite Ball, BallSize/2,BallSize/2
rotate sprite ball, rnd(60)+90
BallSpeed = StartSpeed
EndFunction
Function MovePaddle()
Sprite Paddle,SCRWD-(WALLTH+PDLWD+1),MouseY()-(PDLHT/2),Paddle
EndFunction
Function MakeSprite(SP,WD,HT,CL)
If Bitmap Exist (1) then Delete Bitmap 1
create Bitmap 1, WD,HT
INK CL,0
BOX 0,0,WD,HT
Get Image SP,0,0,WD,HT
Sprite SP,0,0,SP
Delete Bitmap 1
Set Current Bitmap 0
EndFunction
System
PIII 650 MZ H.P. Pavillion
394 Mem GeForce 4 400MX