In my game, I have a Spike actor. When the player runs into the dull side, they should stop as if there was a wall ahead of them. And they should be able to walk on it (but by being damaged) as well. Currently, I'm working on making the player act like it's a wall. But for some reason, my code doesn't work. I just copied my method to find a wall, and changed it to work for Spikes, but it doesn't work.
Here's the code:
Here's what my wall method looks like:
Also, I feel I should mention that the Spike object is a subclass of DamageActor. (basically an actor that can damage other actors)
I also have code that stops the player when wall() is true. wall() is false becuase spike() is false, and I don't know why.
Thanks for the help.
/** * Checks to see if a Upward facing Spike is ahead * @return true if there's a spike ahead */ public boolean spike() { int height = getImage().getHeight(); int width = getImage().getHeight(); Actor spike = null; if (flipped) spike = getOneObjectAtOffset(width/2 + 2, -height/2, Spike.class); else spike = getOneObjectAtOffset(-width/2 - 2, -height/2, Spike.class); return spike != null; }
/** * Checks if there is a wall ahead * @return true if there's a wall ahead */ public boolean wall() { int height = getImage().getHeight(); int width = getImage().getWidth(); Actor ground = null; if (flipped) ground = getOneObjectAtOffset(width/2 + 2, -height/2, Ground.class); else ground = getOneObjectAtOffset(-width/2 - 2, -height/2, Ground.class); return ground != null || spike(); }