Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
sidescroller colldetect help
Author Message
JHDK

Posted: Fri Jan 23, 2004 1:20 pm   Post subject: sidescroller colldetect help

I have a problem with collision detection in a sidescroll game. player controls rocket trying to avoid enemy missile

Here is how i am drawing enemy:
 code: Pic.Draw (enemy (1), enemyX (1) - speed, enemyY (1), picMerge)

the speed isinitial value 100 and +=15 in a for loop contained in a loop, i think that is where the problem is.

anyhow, here is the code for the collision detection:
 code: if x < (enemyX (i) - speed) + 50*i and x > (enemyX (i) - speed) - 50*i and y < enemyY(1) +50 and y> enemyY(1) - 50 then                 dead := true                 quit             end if

Also, i made the background scroll and to draw enemy, make it start at say for example x=1000, if max x for screen is 800.
so the nemy will will go at 100+15+15+15...+15 until it passes past the x=0, but in the caluculations it cant detect it.

any sort of help is appreciated thankyou

ADDED: what i mean is that, it does work, but a crucial bug is that after the enemy passes, the player still dies if you go to coordinates that enemy missile had passed throuigh, even though enemy not there anymore.

Delos

Posted: Fri Jan 23, 2004 10:05 pm   Post subject: (No subject)

Try 2 things:

Reset "dead" to false once if the condition does not compute.

If that does not work, then attempt a Distance function:

You'll need the (x,y) of the Player, and the (x,y) of the object (Enemy).
This (x,y) would most likely refer to either the centre or the touching edge of the object in question.

Then use a simple Pythagorean:
 code: if round( sqrt ( abs (( PlayerX - EnemyX) ** 2) + abs((PlayerY - EnemyY)**2))) <= 0 then % Increase from 0 to account for variable pic radii. dead := true end if % At the end of the chech (if it is in a loop) do this: dead := false

If that does not work...then try resetting your Enemy Array Vars for those that are off the screen.

Edit: Just found this:
http://www.compsci.ca/v2/viewtopic.php?t=75
JHDK

Posted: Sat Jan 24, 2004 1:06 pm   Post subject: (No subject)

well thanks for your help, but i figured it out anyhow.
It was just that the range of detection for y was too great.

Hey I appreciate your trying to help Delos, heres a few bits.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 3 Posts ]
 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: