Pong Collision Detection
Author |
Message |
remember_987
|
Posted: Sun Jan 11, 2009 12:55 pm Post subject: Pong Collision Detection |
|
|
I figured that an easy first game to make would be pong, so far all I have is a paddle that moves. I've been working to implement a ball into the game using collision detection. After reading the rectangular and circular collision tutorials I have a few questions:
1. Is it possible to use circular collision detection in conjunction with rectangular collision detection? (i.e. ball and paddle)
2. What is the best way to start collision detection in my code?
Also since I have never used collision detection before any advice/tips and examples would be greatly appreciated.
Paddle Code:
Turing: | var x: int:= 10
var y: int:= 100
var key: array char of boolean
setscreen ("graphics:1000,600,offscreenonly,position:center;center")
procedure draw
drawfillbox (x,y,x+ 10,y+ 50, white)
end draw
procedure blacky
drawfillbox (x,y,x+ 10,y+ 50, black)
end blacky
drawfillbox (maxx, maxy, 0, 0, black)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
Input.KeyDown (key )
if key (KEY_UP_ARROW) and y+ 50<= 600 then blacky y+= 1 draw View.Update
elsif key (KEY_DOWN_ARROW) and y+ 50>= 50 then blacky y-= 1 draw View.Update
end if
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Sun Jan 11, 2009 4:00 pm Post subject: RE:Pong Collision Detection |
|
|
1 -- Yes. Though it makes things a lot easier, if you think of it as a collision (where "collision" is the distance) between a point and a line.
2 -- think of how to implement it; what kind of effect it will have on the game; and when (in respect to the rest of the game loop) the effect will take place. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
|
|