I'm trying to make a pong game. This is my first game. I have made little madlib programs and stuff before this so I think I'm ready. The only problem is that I have no idea which type of collision detection to use for the ball and paddles.
Here's the code:
[You can Paste this code into your editor since it has no dependencies]
`Start up
Sync On
Sync Rate 60
`declare variables
Player1Y = 0
Player2Y = 0
ballx= 309
bally= 219
Start=1
ballhit=0
`get image from box and circle
BOX 0,0,30,110
GET IMAGE 1,0,0,30,110
CLS
CIRCLE 10,10,10
GET IMAGE 2,0,0,21,21
CLS
`Core Program
DO
`determine whether or not the ball has hit a paddle
IF UPKEY()=1 THEN Player1Y= Player1Y - 4
IF DOWNKEY()=1 THEN PLAYER1Y = PLAYER1Y + 4
SPRITE 1,0,PLAYER1Y,1
IF KEYSTATE(72)=1 THEN Player2Y= Player2Y - 4
IF KEYSTATE(80)=1 THEN PLAYER2Y = PLAYER2Y + 4
SPRITE 2,610,PLAYER2Y,1
`ball collisions
gosub ballhit_detection
gosub collisions
SYNC
LOOP
ballhit_detection:
IF Start=1
BallX=BallX+4
ELSE
IF BALLHIT2=1 THEN BALLX=BALLX-4 : BallY=RND(20)
IF BallHIT1=1 THEN BALLX=BALLX+4 : Bally=RND(50)
ENDIF
SPRITE 3,ballx,bally,2
return
Collisions:
IF SPRITE COLLISION(2,3)
BALLHIT2=1
BALLHIT1=0
ELSE
BALLHIT2=0
BALLHIT1=1
ENDIF
IF SPRITE COLLISION(1,3)
BALLHIT1=1
BALLHIT2=0
ELSE
BALLHIT1=0
BALLHIT2=1
ENDIF
return
Maybe I should make the collision simple, like this:
collision:
IF SPRITE COLLISION (3,2)
BALLX=BALLX*1
BALLY=(BALLY+ RND (20))*-1
Stan: OH MY GOD! THEY KILLED KENNY
Stan's Grandpa: You Bastards!
Kyle: HEY! ><