I added bullet code to my character but I don't know how to make my character shoot in the direction of which my character is facing. I have tried about anything on the internet but nothing seems to work. this is my code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | public class Soldaat extends Actor { public void act() { { if (Greenfoot.isKeyDown( "up" )) { setLocation(getX(),getY()- 3 ); this .setImage( "characters1Up.png" ); } if (Greenfoot.isKeyDown( "down" )) { setLocation(getX(), getY()+ 3 ); this .setImage( "characters1Down.png" ); } if (Greenfoot.isKeyDown( "left" )) { setLocation(getX()- 3 , getY()); this .setImage( "characters1Left.png" ); } if (Greenfoot.isKeyDown( "right" )) { setLocation(getX()+ 3 , getY()); this .setImage( "characters1Right.png" ); } { checkFire(); } } } public void checkFire() { if (Greenfoot.isKeyDown( "space" )) { getWorld().addObject( new Bullet(), getX(), getY()); Bullet.setRotation(getRotation()); } } } |