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.
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); } } }