
-----------------------------------
Hurtful
Mon Jun 02, 2003 9:09 pm

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.

-----------------------------------
nate
Mon Jun 02, 2003 9:10 pm

m
-----------------------------------
READ THE COLLISION DETECTING TUTORIAL!!!

-----------------------------------
Tony
Mon Jun 02, 2003 9:48 pm


-----------------------------------
thats under tutorials  :wink:

-----------------------------------
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")
colorback (black)
color (green)
cls

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)     
loop
    View.Set ("offscreenonly")
    Draw.FillOval (ballx, bally, s, s, brightgreen) 
    View.Update
    delay (50)
    Draw.FillOval (ballx, bally, s, s, black) 

    if ballx = maxy then 
        ny := -1  
    end if
        ballx += nx
    bally += ny


    Input.KeyDown (chars)

    if chars (KEY_SHIFT) then
        y := y + 5
    end if
    if chars (KEY_CTRL) then
        y := y - 5
    end if

    Input.KeyDown (chars2)

    if chars (KEY_UP_ARROW) then
        y2 := y2 + 5
    end if

    if chars (KEY_DOWN_ARROW) then
        y2 := y2 - 5
    end if



    View.Set ("offscreenonly")
    drawfillbox (x, y, 10 + x, 100 + y, brightgreen)
    View.Update
    delay (25)
    drawfillbox (x, y, 10 + x, 100 + y, black)

    View.Set ("offscreenonly")
    drawfillbox (x2, y2, x2 - 10, y2 - 100, brightgreen)
    View.Update
    delay (25)
    drawfillbox (x2, y2, x2 - 10, y2 - 100, black)



end loop


I couldn't figure out how to apply what was in the Collision Detection tutorial to this game.

-----------------------------------
Tony
Tue Jun 03, 2003 10:17 am


-----------------------------------
well do you see how you use

if ballx >= maxx then 
nx := -1 
elsif bally >= maxy then 
ny := -1 
end if 
ballx += nx 
bally += ny 


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

-----------------------------------
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
if ballx >= maxx or ballx = maxy or bally 