Computer Science Canada
|Author:||Hurtful [ Mon Jun 02, 2003 9:09 pm ]|
|Post subject:||Pong ball|
I'm working on a basic pong game but i'm having difficulty with getting the ball (moving and colliding). I got the paddles working but thats about it. How do I make it so that the ball starts it the center, begin moving on a key stroke, and collide off walls and paddles? (I couldn't find what I was looking for in previous threads, maybe I missed something?) Any help would be appreciated.
|Author:||nate [ Mon Jun 02, 2003 9:10 pm ]|
READ THE COLLISION DETECTING TUTORIAL!!!
|Author:||Tony [ Mon Jun 02, 2003 9:48 pm ]|
thats under tutorials
|Author:||Hurtful [ Mon Jun 02, 2003 10:27 pm ]|
well, I read the tutorial, and managed to get it in to my program. Only details that I'm having still is the ball bouncing off the paddles and the graphics are a little choppy.
Here is what I have so far:
var winID : int := Window.Open ("offscreenonly")
Window.Set (winID, "nocursor")
var x, y : int
x := 0
y := maxy div 2
var x2, y2 : int
x2 := maxx
y2 := maxy div 2
var chars, chars2 : array char of boolean
var ballx, bally : int
var nx, ny : int := 1
var s : int := 10
ballx := Rand.Int (10, 100)
bally := Rand.Int (10, 100)
Draw.FillOval (ballx, bally, s, s, brightgreen)
Draw.FillOval (ballx, bally, s, s, black)
if ballx <= 0 then
nx := 1
elsif bally <= 0 then
ny := 1
if ballx >= maxx then
nx := -1
elsif bally >= maxy then
ny := -1
ballx += nx
bally += ny
if chars (KEY_SHIFT) then
y := y + 5
if chars (KEY_CTRL) then
y := y - 5
if chars (KEY_UP_ARROW) then
y2 := y2 + 5
if chars (KEY_DOWN_ARROW) then
y2 := y2 - 5
drawfillbox (x, y, 10 + x, 100 + y, brightgreen)
drawfillbox (x, y, 10 + x, 100 + y, black)
drawfillbox (x2, y2, x2 - 10, y2 - 100, brightgreen)
drawfillbox (x2, y2, x2 - 10, y2 - 100, black)
I couldn't figure out how to apply what was in the Collision Detection tutorial to this game.
|Author:||Tony [ Tue Jun 03, 2003 10:17 am ]|
well do you see how you use
to revese the direction when hiting floor and ceiling? Do the same, but replace the if statment with one from the collision detection tutorial.
Also, why do you keep on setting screen to "offscreenonly" throughout the program? 1 time is enough
|Author:||Blade [ Tue Jun 03, 2003 11:11 am ]|
ok. first off i read the collision tutorial tony wrote, but it blew my mind too. maybe it was because it looked a hella lot harder than what it really was. all you do is check to see if the ball is touching either sides. and for the paddles check to see if its in the range of the paddle.
as an example
that is something like what i would use to check the sides..
as for the paddles. i'm only gonna help you with the one. if you can figure it out for yourself to do the other... then godspeed son
|Author:||Muhammad Sheraly [ Thu Jun 05, 2003 4:42 pm ]|
|Post subject:||ping pong|
i have the pong game....but just the ball moving around the screen colliding....i need to put some paddles in...im havin trouble with that...