Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 colision with walls
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
magicman




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
TheFerret




PostPosted: 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...
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: