I want to add a shield into my game and when the z key is pressed that the shield image rotate to face upwards and be 2 y coordinate above the Warrior and when the c key is pressed that the shield is flipped and put -2 x coordinates to the side of the Warrior1. this is how it looks so far and i can't figure out the right way to code it.
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 36 37 38 39 40 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Shield here. * * @author (your name) * @version (a version number or a date) */ public class Shield extends Actor { int Warrior1X = getX(); int Warrior1Y = getY(); /** * Act - do whatever the Shield wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (Greenfoot.isKeyDown( "z" )) { setRotation( 90 ); addObject( new Shield(), setLocation(getX(Warrior1. class ), getY(Warrior1. class ))+ 2 ); } if (Greenfoot.isKeyDown( "x" )) { setRotation( 180 ); addObject( new Shield(), setLocation(getX(Warrior1. class ), getY(Warrior1. class ))+ 2 ); } if (Greenfoot.isKeyDown( "c" )) { setRotation( 270 ); addObject( new Shield(), setLocation(getX(Warrior1. class ), getY(Warrior1. class ))+ 2 ); } if (Greenfoot.isKeyDown( "v" )) { setRotation( 0 ); addObject( new Shield(), setLocation(getX(Warrior1. class ), getY(Warrior1. class ))+ 2 ); } } } |