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

Username:   Password: 
 RegisterRegister   
 Collision Help Please
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
StrikerZ




PostPosted: Mon Dec 11, 2006 12:42 pm   Post subject: Collision Help Please

i am making a game where two circles draw paths and when one of them collide into the other players path, that player loses, but i am having trouble making the collision detection so that it tells you what player won if you hit the other players path. im also having trouble with the boundaries...every time the circles hit the boundaries they get stuck...could someone help please...heres my code
code:
var window : int := Window.Open ("graphics:1000;668")
View.Set ("offscreenonly")
var chars : array char of boolean
var x1, y1 : int
var x2, y2 : int
x1 := 800
y1 := 668 div 2
x2 := 200
y2 := 668 div 2

loop
    Input.KeyDown (chars)
    %Player 1
    if chars (KEY_UP_ARROW) then
        y1 := y1 + 1
    end if
    if chars (KEY_DOWN_ARROW) then
        y1 := y1 - 1
    end if
    if chars (KEY_LEFT_ARROW) then
        x1 := x1 - 1
    end if
    if chars (KEY_RIGHT_ARROW) then
        x1 := x1 + 1
    end if
    if (x1 + 10) >= maxx or (x1 - 10) <= -1 then
        x1 *= -1
    elsif (y1 + 10) >= maxy or (y1 - 10) <= -1 then
        y1 *= -1
    end if

    %Player 2
    if chars ('w') then
        y2 := y2 + 1
    end if
    if chars ('s') then
        y2 := y2 - 1
    end if
    if chars ('a') then
        x2 := x2 - 1
    end if
    if chars ('d') then
        x2 := x2 + 1
    end if
    if (x2 + 10) >= maxx or (x2 - 10) <= -1 then
        x2 *= -1
    elsif (y2 + 10) >= maxy or (y2 - 10) <= -1 then
        y2 *= -1
    end if
    Draw.FillOval (x1, y1, 10, 10, brightgreen)
    Draw.FillOval (x2, y2, 10, 10, brightblue)
    View.Update
Sponsor
Sponsor
Sponsor
sponsor
NikG




PostPosted: Mon Dec 11, 2006 1:09 pm   Post subject: Re: Collision Help Please

StrikerZ wrote:
code:
    if (x1 + 10) >= maxx or (x1 - 10) <= -1 then
        x1 *= -1
    elsif (y1 + 10) >= maxy or (y1 - 10) <= -1 then
        y1 *= -1
    end if
This will not work because all you are doing is changing the player's x/y positions to negative, so it'll keep changing back and forth. Instead, just set the x/y values to just outside the boundary.

As for collission detection, you haven't even attempted it, so I can't give you the answer. But I will tell you that you will not be able to do it without whatdotcolor if you want the players to lose when they hit the path of the other player.
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: