Yes, another pong game.
Author |
Message |
Jekate
|
Posted: Fri Sep 29, 2006 7:43 pm Post subject: Yes, another pong game. |
|
|
Ok, I'm working on a basic pong game for now. Not for class, just for fun. Anyways, this is what I got so far, with NO processes:
code: | var ballx, bally, vx, vy, y1, y2 : int
var chars : array char of boolean
y2 := maxy div 2 - 25
y1 := maxy div 2 - 25
ballx := maxx div 2
bally := maxy div 2
vx := 3
vy := 3
View.Set ("offscreenonly")
loop
cls
Input.KeyDown (chars)
if chars ('w') then
y1 += 3
elsif chars ('s') then
y1 -= 3
end if
if chars (KEY_UP_ARROW) then
y2 += 3
elsif chars (KEY_DOWN_ARROW) then
y2 -= 3
end if
ballx += vx
bally += vy
if (ballx + 10) >= maxx or (ballx - 10) <= 0 then
vx *= -1
elsif (bally + 10) >= maxy or (bally - 10) <= 0 then
vy *= -1
elsif whatdotcolor (ballx + 10, bally) = 4 or whatdotcolor (ballx - 10, bally) = 4 then
vx *= -1
end if
if y1 + 50 >= maxy then
y1 := maxy - 51
elsif y1 <= 0 then
y1 := 1
end if
if y2 + 50 >= maxy then
y2 := maxy - 51
elsif y2 <= 0 then
y2 := 1
end if
drawfillbox (20, y1, 30, y1 + 50, 4)
drawfillbox (maxx - 20, y2, maxx - 30, y2 + 50, 4)
drawfilloval (ballx, bally, 10, 10, 4)
delay (10)
View.Update
end loop
|
Ok, now I can't get my collision detection to work. It just passes through the paddle. Now I haven't looked at it for too long, so I may just end up finding my error, but for now I cannot. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TokenHerbz
|
Posted: Sat Sep 30, 2006 12:02 am Post subject: (No subject) |
|
|
well, first its all about where your paddle is, if you can make it bounce off the wall, then you can make it bounce off the paddle.
your paddle is "x" amount more then 0, and "x" amount less then maxx, i think you can make it work. |
|
|
|
|
|
Jekate
|
Posted: Sat Sep 30, 2006 8:20 am Post subject: (No subject) |
|
|
Ty for the help. I knew I could do it that way, but I guess I never realy tried it. Here is the altered code:
code: | var ballx, bally, vx, vy, y1, y2 : int
var chars : array char of boolean
y2 := maxy div 2 - 25
y1 := maxy div 2 - 25
ballx := maxx div 2
bally := maxy div 2
vx := 3
vy := 3
View.Set ("offscreenonly")
loop
cls
Input.KeyDown (chars)
if chars ('w') then
y1 += 3
elsif chars ('s') then
y1 -= 3
end if
if chars (KEY_UP_ARROW) then
y2 += 3
elsif chars (KEY_DOWN_ARROW) then
y2 -= 3
end if
ballx += vx
bally += vy
if (ballx + 10) >= maxx or (ballx - 10) <= 0 then
vx *= -1
elsif (bally + 10) >= maxy or (bally - 10) <= 0 then
vy *= -1
elsif bally >= y2 and bally <= y2 + 50 and ballx + 10 >= maxx - 20 then
vx *= -1
elsif bally >= y1 and bally <= y1 + 50 and ballx - 10 <= 30 then
vx *= -1
end if
if y1 + 50 >= maxy then
y1 := maxy - 51
elsif y1 <= 0 then
y1 := 1
end if
if y2 + 50 >= maxy then
y2 := maxy - 51
elsif y2 <= 0 then
y2 := 1
end if
drawfillbox (20, y1, 30, y1 + 50, 4)
drawfillbox (maxx - 20, y2, maxx - 30, y2 + 50, 4)
drawfilloval (ballx, bally, 10, 10, 4)
delay (10)
View.Update
end loop
|
+bits (only a few cuz I got little of them lol) |
|
|
|
|
|
Jekate
|
Posted: Sat Sep 30, 2006 11:18 am Post subject: (No subject) |
|
|
I can't edit my post above ^^ so I guess I have to post another one.
Ok, now I got it to bounce of the paddles, somewhat correctly. If the ball comes in at exactly the right points, the ball bounces back and forth, on the paddle. Anyway to fix this? |
|
|
|
|
|
TokenHerbz
|
Posted: Sat Sep 30, 2006 2:54 pm Post subject: (No subject) |
|
|
Yes, you must take in all the dimentions of the paddle.
the paddle is taller then just "y" point, even though you draw your paddle 20 pix higher then the pady var, you need to use that in your collition code. |
|
|
|
|
|
Clayton
|
Posted: Mon Oct 02, 2006 9:16 am Post subject: (No subject) |
|
|
look into the tutorial in the Turing Walkthrough about collision detection, you should find all you need there
PS Tokenherbz, your avatar is too big |
|
|
|
|
|
|
|