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

Username:   Password: 
 RegisterRegister   
 Whatdotcolour collision detection problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Badsniper




PostPosted: Fri May 06, 2011 10:00 pm   Post subject: Whatdotcolour collision detection problem

code:

    if key ('w') and whatdotcolour (x, y - 4) = 7 then
        for decreasing a : 10 .. 1
            Input.KeyDown (key)
            y += a
            if key ('d') and whatdotcolour (x + 3, y) ~= 7 then
                x += 1
            end if
            if key ('a') and whatdotcolour (x + 3, y) ~= 7 then
                x -= 1
            end if
            Pic.Draw (back, 0, 0, 1)
            drawfilloval (x, y, 3, 3, 3)
            View.UpdateArea (0, 0, maxx, maxy)
            delay (16)
            cls
        end for


This is an exert from a program I am writing, I need it to move a small circle around the screen. This is the code when the circle "jumps". For some reason, the collision detection doesn't work when the circle is in the jump. for example, it will come to a stop when it hits a verticle black line, but when it "jumps" it can go through it. I've tried many things, from changing the x and y values the computer checks for black and I've redrawn the background (variable "back") in many different positions, but I can't get it to work. Can someone at least explain why?
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Fri May 06, 2011 11:02 pm   Post subject: RE:Whatdotcolour collision detection problem

That's because your CD is probably outside this for loop in the main game loop. You're not checking CD inside this loop. The typical way to do loops is to not freeze everything else (going into a subloop) but to keep with the ...

loop
input
logic
render frame (draw)
end loop

... program flow. The wrong way would be to make the CD a procedure and call that within the for loop. The right way would be to remember the state of the player (jumping/not jumping) that'd be toggled during input stage. Then move the player during the logic (which is when you check the CD).

There's bound to be a tutorial or source code for this like somewhere. If you can't find an example I'll write one up later.
mirhagk




PostPosted: Sat May 07, 2011 1:15 pm   Post subject: RE:Whatdotcolour collision detection problem

A trick is to use the movement as a velocity variable. That way the jump increases the velocity, and each turn the velocity gets added to the position, then the velocity gets smaller and smaller till it goes negative and the player falls back down.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: