colision with walls
Author |
Message |
magicman
![](http://clanff7.cl.funpic.org/modules/Forums/images/avatars/5066862484383ad4eaf5d5.jpg)
|
Posted: Tue Apr 06, 2004 9:40 am Post subject: colision with walls |
|
|
i'm making pong and i need to make the ball go off the wall. How can i do that?
here's my code:
[code]
View.Set ("graphics")
drawfill (0, 0, 17, 17)
var x : int := 15 %Player 1
var y : int := 160 %Player 1
var x1 : int := 630 %Player 2
var y1 : int := 160 %Player 2
var z : int := maxx div 2 %Ball
var a : int := maxy div 2 %Ball
var changex := 5
var changey := 5
var chars : array char of boolean
loop
View.Set ("offscreenonly")
View.Update
cls
%player 1
Draw.ThickLine (x, y, 15, y + 100, 3, 0)
delay (10)
%Player 2
Draw.ThickLine (x1, y1, 630, y1 + 100, 3, 0)
Input.KeyDown (chars)
%Player 1
if chars ('w') then
y := y + 10
end if
if chars ('s') then
y := y - 10
end if
%Player 2
if chars (KEY_UP_ARROW) then
y1 := y1 + 10
end if
if chars (KEY_DOWN_ARROW) then
y1 := y1 - 10
end if
%Ball
drawfilloval (z, a, 10, 10, 0)
drawfill (z, a, 0, 0)
delay(10)
drawfilloval (z, a, 10, 10, 0)
drawfill (z, a, 0, 0)
%Side Lines
drawline (0, 3, maxx, 3, 0)
drawline (0, maxy - 3, maxx, maxy - 3, 0)
end loop
thanks. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
TheFerret
![](http://compsci.ca/v3/uploads/user_avatars/1203353290461453ed4f045.jpg)
|
Posted: Tue Apr 06, 2004 2:01 pm Post subject: (No subject) |
|
|
You would need this before the part where x and y change...
code: | if x<=maxx then
changex*=-1
elsif x>=0 then
changex*=-1
|
You would do the same for y... |
|
|
|
|
![](images/spacer.gif) |
|
|