Hi there!
I'm new to Greenfoot and Java in general, but i'd love to learn more about programming.
I think this question has probably been asked before (maybe not in this exact way,), but this seems like an awesome forum for e beginner like me.
You guys seem pretty helpful. :)
My problem is this:
I'm writing a Bomberman clone at school, and i have a problem with my main Actor.
The idea is that he's supposed to look up when going up, down when going down, and left when going left. Nothing is supposed to happen when he goes right, as the "sprite" (or image) is already turned right.
I first tried to just rotate him (with setRotation in a method (it's a method, and not a function, right?)), but then he walks upside down when going left (as the rotation is set to 180 degrees here).
I've then gotten this far:
which in my head should give the following result:
Do nothing when going right, mirror the actor when going left, and rotate him +/- 90 degrees when going up and down.
I have a setDirection() method which you can see here. It is called whenever one of the arrow keys are pressed.
Can anyone help me get an idea of what's wrong?
I thought I could do the rotation like this, just like I could with mirrorHorizontally().
GreenfootImage jacobRight; GreenfootImage jacobLeft; GreenfootImage jacobUp; GreenfootImage jacobDown; public Bomberman() { jacobRight=getImage(); jacobLeft=new GreenfootImage(getImage()); jacobLeft.mirrorHorizontally(); jacobUp=new GreenfootImage(getImage()); jacobUp.setRotation(-90); jacobDown=new GreenfootImage(getImage()); jacobDown.setRotation(90); }
public void setDirection() { if (direction==UP) { setImage(jacobUp); } else if (direction==DOWN) { setImage(jacobDown); } else if (direction==LEFT) { setImage(jacobLeft); } else if (direction==RIGHT) { setImage(jacobRight); } }