I'm trying to make simple collision detection using the switch statement. The statement takes the y position of a certain object and then it detects if the object's x is the same as another object. The problem is that I have if statements inside of the cases it goes through the whole if statement, even if the condition isn't met. The object is supposed to be sent back to the starting point after it gets hit by an enemy (enemies are moving through the screen) and moves in increments of 19 so the case is met. The problem is I can't seem to move it up because it keeps getting sent back to the starting spot whenever I meet the case (y = 221). When I remove deadObject() from the switch statement, it works fine and only prints "dead" when it's running into an enemy. How can I go about to fixing this?
I've been looking around on the internet about this but I can't find anything AS3 related to if statements in switch statements. Thanks for any help
public function enterFrame(me:Event)
{
position = objectA.y
switch(position)
{
case 221:
if (objectA.x == enemy1.x || objectA.x == enemy1.x + 10)
trace("dead1");
deadObject()
if (objectA.x == enemy2.x || objectA.x == enemy2.x + 10)
trace("dead1");
deadObject()
if (objectA.x == enemy3.x || objectA.x == enemy3.x + 10)
trace("dead1");
deadObject()
break;
}
}
public function deadObject()
{
objectA.x = 133;
objectA = 240;
}