Allegro.cc Forums » Programming Questions » Enemies disappear with out any collision

 Enemies disappear with out any collision
 someone972 Member #7,719 August 2006 I believe part of the problem is in your collideArrow function: ```if((arrow.x > enemy.x + enemy.width) || (arrow.y > enemy.y + enemy.height) || (enemy.x > arrow.x + arrow.height) || (enemy.y > arrow.y + arrow.height) && (enemy.live) && (arrow.live)) ``` What you probably want it to be is: ```if((arrow.x > enemy.x + enemy.width) || (arrow.y > enemy.y + enemy.height) || (enemy.x > arrow.x + arrow.height) || (enemy.y > arrow.y + arrow.height) || !(enemy.live) || !(arrow.live)) ``` ______________________________________As long as it remains classified how long it took me to make I'll be deemed a computer game genius. - William LabbettTheory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why. -UnknownI have recklessly set in motion a chain of events with the potential to so-drastically change the path of my life that I can only find it to be beautifully frightening.
 Dizzy Egg Member #10,824 March 2009 I think that's very wrong....your basically saying "if the arrow is further right or higher than the enemy or the enemy is further right or higher than the arrow"...doesn't make sense.Also someone's advice is terrible! ----------------------------------------------------Please check out my songs:https://soundcloud.com/dont-rob-the-machina
 DJLad16 Member #14,857 January 2013 Thanks, someone, got it working What do you mean dizzy? The collision works fine, simple bounding box collision.
 Thomas Fjellstrom Member #476 June 2000 It seems like you're just checking each corner in isolation when you should be checking to see if the arrow is inside the bounding rectangle. -- Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]"If you can't think of a better solution, don't try to make a better solution." -- weapon_S"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730
 Dizzy Egg Member #10,824 March 2009 No, that ain't no bounding box collision! That's exactly what I said in my post. If you made bounding box collision with that code in someones post, I'll fry myself. ----------------------------------------------------Please check out my songs:https://soundcloud.com/dont-rob-the-machina
 Schyfis Member #9,752 May 2008 I think what you want to be doing for collision detection is something like the first line of the function I posted over here.What you have is slightly similar, but wrong in the end.You should also separate the enemy.live and arrow.live checks from the actual collision detection itself to make things clearer. ```if(!enemy.live || !arrow.live) return; //now, check for collision ``` ________________________________________________________________________________________________________[freedwill.us][unTied Games]
 Dizzy Egg Member #10,824 March 2009 I have no idea what any of you are talking about any more. Since when has it ever been possible to do a bounding box collision just using OR's....none of the code you're posting works!?!? ----------------------------------------------------Please check out my songs:https://soundcloud.com/dont-rob-the-machina
 Karadoc ~~ Member #2,749 September 2002 Dizzy Egg is right. -----------
 Audric Member #907 January 2001 The two forms are logically the same: ```if((arrow.x > enemy.x + enemy.width) || (arrow.y > enemy.y + enemy.height) || (enemy.x > arrow.x + arrow.height) || (enemy.y > arrow.y + arrow.height) || !(enemy.live) || !(arrow.live)) return false; return true // or: if((arrow.x <= enemy.x + enemy.width) && (arrow.y <= enemy.y + enemy.height) && (enemy.x <= arrow.x + arrow.height) && (enemy.y <= arrow.y + arrow.height) && (enemy.live) && (arrow.live)) return true; return false ```
 Dizzy Egg Member #10,824 March 2009 So it turns out the only Allegroid left with an IQ is Karadoc, because the rest of you are missing the point....bounding box would imply checking within a box! ----------------------------------------------------Please check out my songs:https://soundcloud.com/dont-rob-the-machina
 pkrcel Member #14,001 February 2012 To me also does not look like a bounding box collision. EDIT: ah OK, the expression is NEGATED by the return values so the logic AND is susbstituted by the equivalent negated logic *N*OR.....haven't checked deeply but MAY be ok. It is unlikely that Google shares your distaste for capitalism. - DerezoIf one had the eternity of time, one would do things later. - Johan Halmén
 EWClay Member #14,750 December 2012 Apparently with all the fuss over logic no one's noticed that it should be arrow.width on the second line.
 Audric Member #907 January 2001 Dizzy, I'm sorry but this code is ok... there's a little bug that uses height instead of width once (he couldn't notice it if they are equal), but otherwise it's intended to check if two rectangles overlap :One rectangle goes- horizontally from (arrow.x) to (arrow.x + arrow.width)- vertically from (arrow.y) to (arrow.y + arrow.height)The other rectangle goes- horizontally from (enemy.x) to (enemy.x + enemy.width)- vertically from (enemy.y) to (enemy.y + enemy.height)
 Dizzy Egg Member #10,824 March 2009 Nope. According to his logic, if my arrow is farther right OR higher than the enemy, there's a collision. No box involved. ----------------------------------------------------Please check out my songs:https://soundcloud.com/dont-rob-the-machina
 J-Gamer Member #12,491 January 2011 Dizzy Egg said:Nope. According to his logic, if my arrow is farther right OR higher than the enemy, there's a collision. No box involved. You seem to fail to see that the return statement reached when the condition is true returns false. That code checks for all cases where there is no collision, and returns true otherwise. " There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates
 pkrcel Member #14,001 February 2012 AABBCollision can be carried out checking if the two boxes overlap, or if the DO NOT overlap, but in that case you have to return negated values of course.That is what I failed to see as well (the xchange between return false and return true ) It is unlikely that Google shares your distaste for capitalism. - DerezoIf one had the eternity of time, one would do things later. - Johan Halmén
 Dizzy Egg Member #10,824 March 2009 ...ooooh....tits. My bad. ----------------------------------------------------Please check out my songs:https://soundcloud.com/dont-rob-the-machina
 Karadoc ~~ Member #2,749 September 2002 I guess Dizzy Egg and I were wrong all along. I had only looked at the snippet someone972 posted, and I wrongly assumed the condition was to test for a collision rather than for a miss. -----------
 someone972 Member #7,719 August 2006 Ha, I just came back to this thread to see if it got resolved and I got a good chuckle from the stream of posts .EDIT: If all that is needed is to check whether two bounding boxes collide, the negated method works fine and is actually a little more optimized since it bails early if one of the checks fails. Of course it's a nearly worthless optimization. ______________________________________As long as it remains classified how long it took me to make I'll be deemed a computer game genius. - William LabbettTheory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why. -UnknownI have recklessly set in motion a chain of events with the potential to so-drastically change the path of my life that I can only find it to be beautifully frightening.
 Karadoc ~~ Member #2,749 September 2002 Both methods 'bail early' if one of the checks fails. -----------
 someone972 Member #7,719 August 2006 Whoops, that's true. Looks like I'm not thinking strait today either . ______________________________________As long as it remains classified how long it took me to make I'll be deemed a computer game genius. - William LabbettTheory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why. -UnknownI have recklessly set in motion a chain of events with the potential to so-drastically change the path of my life that I can only find it to be beautifully frightening.
 Schyfis Member #9,752 May 2008 I dunno why, but I just like the "opposite way" of checking for bounding box collision. My brain wraps around it easier.Either way, were you able to figure it out, DJLad16? ________________________________________________________________________________________________________[freedwill.us][unTied Games]
 Go to: Allegro Development Installation, Setup & Configuration Allegro.cc Comments Off-Topic Ordeals The Depot Game Design & Concepts Programming Questions Recent Threads