helo,
i am trying to see if my enemy (the wolf) is intersecting my player in my game. i am trying to reset my player. right now he is set to display an atacking animation if a wolf intersect him so i understand this part; but if he run away i need to stop his atacking animation and put his moving animation so i would need to check the thing is i have multiple enemy (or want to) so i was thinking i could say something like "if wolf !intersecting(player.rectangle) && player.atacking then player.atacking = false (runign away) but the thing is what if their was another wolf intersecting him. i gues the way i am making the game this is imposible because the run speed is all the same and the enemy all spawn from the left but i feel like i might need to know this to be a good coder and maybe put something like that in the video game.
i was thinking about what if their was a way to say if (mywholelist.isintersecting(player)) i have the list in a while loop and i can set a boolean to say true if any of the element in the list are intersecting then when i run away from the wolf with my player what if one wolf is not intersecting but one is how do i check if all are not intersecting
in lamen term my code kinda look like:
// iterate through wolf list to move wolf and animate wolfiterator = wolf.values().iterator(); while(wolfiterator.hasNext()) { unit wolfobject = wolfiterator.next(); g.setColor(new Color(255, 0, 0, 255)); g.fillRect((int)wolfobject.agrovationrectangle.getX(), (int)wolfobject.agrovationrectangle.getY(), (int)wolfobject.agrovationrectangle.getWidth(), (int)wolfobject.agrovationrectangle.getHeight()); g.setColor(new Color(0, 255, 0, 255)); g.fillRect((int)wolfobject.unitrectangle.getX(), (int)wolfobject.unitrectangle.getY(), (int)wolfobject.unitrectangle.getWidth(), (int)wolfobject.unitrectangle.getHeight()); // wolf run toward wooyl; agrovated if (!wolfobject.unitrectangle.intersects(wooyl.unitrectangle) && wolfobject.agrovated) { wolfobject = detectquadrent(null, wolfobject); } // wolf start atacking if (wolfobject.unitrectangle.intersects(wooyl.colisionrectangle)) { if (!wooyl.atacking) { wooyl.atacking = true; } wolfobject.moving = false; wolfobject.agrovated = false; if (!wolfobject.atacking) { wolfobject.atacking = true; wooylatacking = true; } handleunitmovement(g, wolfobject); } // stop wolf atacking if player ran if (!wolfobject.unitrectangle.intersects(wooyl.colisionrectangle) && wolfobject.atacking) { wolfobject.atacking = false; } // wolf run toward wooyl; agrovate if (wolfobject.agrovationrectangle.intersects(wooyl.colisionrectangle)) { if (!wolfobject.agrovated) { wolfobject.agrovated = true; } if (!wolfobject.atacking) { handleunitmovement(g, wolfobject); } } if (wooyl.moving || wolfobject.agrovated) { wolfobject.unitrectangle.setRect(wolfobject.x.intValue(), wolfobject.y.intValue(), wolfobject.curentanimated.getIconWidth(), wolfobject.curentanimated.getIconHeight()); }
maybe my while loop is confusing me anyone know of a method to check the entire list if these guy are or are not intersecting?
i was looking online at "containall()" method or am right now