Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
collision detection
Author Message
jonos

Posted: Sun Feb 01, 2004 4:47 pm   Post subject: collision detection

im trying to make a game, but i didn't understand the collision detection tony, dan, and some other people are talking about in tutorials, so i decided to try to make my own. im not sure if this is the right way to go about it, or if this way will cause problems with trying to do some things in the game. it works, but im not sure if it the right way to do it...

 code: var chars : array char of boolean var circlex, circley : int := 100 var radius : int := 20 colorback (black) cls loop     setscreen ("offscreenonly")     View.Update     drawfillbox (20, 20, maxx - 20, maxy - 20, brightred)     drawfilloval (circlex, circley, radius, radius, black)     Input.KeyDown (chars)     if chars (KEY_UP_ARROW) then         if circley + radius > maxy - 20 then             circley := circley - 1         else             circley := circley + 1         end if     elsif chars (KEY_DOWN_ARROW) then         if circley + radius < 60 then             circley := circley + 1         else             circley := circley - 1         end if     elsif chars (KEY_LEFT_ARROW) then         if circlex + radius < 60 then             circlex := circlex + 1         else             circlex := circlex - 1         end if     elsif chars (KEY_RIGHT_ARROW) then         if circlex + radius > maxx - 20 then             circlex := circlex - 1         else             circlex := circlex + 1         end if     end if end loop

if the brevity of the code is not very good, oh well.

Paul

Posted: Sun Feb 01, 2004 4:49 pm   Post subject: (No subject)

oh, so you used the size of the walls? I was just thinking about how to do it with whatdotcolor, you know, the only thing I've thought up of is if a color drawn over that doesnt belong there, then change the coords.
recneps

Posted: Sun Feb 01, 2004 4:50 pm   Post subject: (No subject)

that works. thats basically the "rectangle" because you've made an invisible rectangle around the whole screen area, eg i show as a drawbox ;p

drawbox(0,0,maxx,maxy,7)

thats basically your box. and when it hits the edge of that box, its gonna go back one rather than forward, according to your code.
Paul

Posted: Sun Feb 01, 2004 4:55 pm   Post subject: (No subject)

Jonos, you won't mind if I leech off your post right? It has to do with the same thing. Can anyone tell me how to do collision detection with whatdotcolor?
jonos

Posted: Sun Feb 01, 2004 4:57 pm   Post subject: (No subject)

ill try it with whatdotcolor right now, hold on ten mins. i don't care if you leach off mine, i leached off your title colors
recneps

Posted: Sun Feb 01, 2004 5:00 pm   Post subject: (No subject)

drawbox(x,y,x2,y2,black)

and
collision=true
end if
jonos

Posted: Sun Feb 01, 2004 5:06 pm   Post subject: (No subject)

 code: var chars : array char of boolean var circlex, circley : int := 100 var radius : int := 20 colorback (black) cls loop     setscreen ("offscreenonly")     View.Update     drawfillbox (20, 20, maxx - 20, maxy - 20, 12)     drawfilloval (circlex, circley, radius, radius, white)     Input.KeyDown (chars)     if chars (KEY_UP_ARROW) then         if whatdotcolor (circlex, circley + radius + 2) = 12 then             circley := circley + 1         else             circley := circley - 1         end if     elsif chars (KEY_DOWN_ARROW) then         if whatdotcolor (circlex, circley + radius + 2) = 12 then             circley := circley - 1         else             circley := circley + 1         end if     elsif chars (KEY_LEFT_ARROW) then         if whatdotcolor (circley, circlex + radius + 2) = 12 then             circlex := circlex - 1         else             circlex := circlex + 1         end if     elsif chars (KEY_RIGHT_ARROW) then         if whatdotcolor (circley, circlex + radius + 2) = 12 then             circlex := circlex + 1         else             circlex := circlex - 1         end if     end if end loop

this is what i got, but it still doesn't work perfectly, i hope no one beat me to it. play around with it paulbian and maybe you can get it to work.,
Andy

Posted: Sun Feb 01, 2004 5:08 pm   Post subject: (No subject)

your approach only works for mono colored things... what u should do is check to the direction of movement...

Paul

Posted: Sun Feb 01, 2004 5:10 pm   Post subject: (No subject)

Im thinking of doing one of those obstacle courses where you have to manuver the ball, which the size you can change, but the the smaller it is the faster it gets, through a tube that has different sized sections. Just to get familiar with collision detection. To me that's where whatdotcolor could be useful.
jonos

Posted: Sun Feb 01, 2004 5:10 pm   Post subject: (No subject)

can you help us please, cause what i gave doesn't even work, it stops in a place where it shouldn't.
jonos

Posted: Sun Feb 01, 2004 5:17 pm   Post subject: (No subject)

just one small thing to fix cause the circle stops in this one place on the y axis all the time
Paul

Posted: Sun Feb 01, 2004 5:21 pm   Post subject: (No subject)

I just made a minor change to the if structure, cause you used elsif, it doesnt move diagonally.
jonos

Posted: Sun Feb 01, 2004 5:24 pm   Post subject: (No subject)

yeah, i was trying some stuff to make it go diagonal, thanks. i got it working, i just had to make the window smaller, which probably isn't the best way to do it, but whatever

maybe someone will know how to do it better.
TheXploder

Posted: Sun Feb 01, 2004 5:32 pm   Post subject: (No subject)

it's still wierd somethimes the up button make it move through the wall or the up button makes it move down.. really weird, and I've never see anyone do collisions with whatdotcolour...
jonos

Posted: Sun Feb 01, 2004 5:35 pm   Post subject: (No subject)

yeah, i see what you mean, i think it's just turing though, because i don't see how it could be wrong. ive thought it over pretty hard
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 4  [ 49 Posts ]
Goto page 1, 2, 3, 4  Next
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: