import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class survivor here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Surviver extends Mover
{
private GreenfootImage image1;
private GreenfootImage image2;
/**
* Act - do whatever the survivor wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
checkKeypress();
switchImage();
image1 = new GreenfootImage("Soldat.png");
image2 = new GreenfootImage("Soldat2.png");
if (touch(Zombie1.class))
{AllgCode.Leben--;
destroy(Zombie1.class);
}
if (touch(Zombie2.class))
{AllgCode.Leben--;
destroy(Zombie2.class);
}
}
public void checkKeypress()
{
if (Greenfoot.isKeyDown("a"))
{
move(-10);
}
if (Greenfoot.isKeyDown("d"))
{
move(10);
}
if(Greenfoot.isKeyDown("w"))
{
setLocation(getX(),getY()-10);
}
if(Greenfoot.isKeyDown("s"))
{
setLocation(getX(),getY()+10);
}
if ("space".equals(Greenfoot.getKey()))
{
fire();
}
}
private void fire()
{
Projectile projectile = new Projectile();
getWorld().addObject(projectile, getX(), getY());
projectile.setRotation(getRotation());
}
public void switchImage()
{
if (Greenfoot.isKeyDown("a"))
{
setImage(image1);
}
if (Greenfoot.isKeyDown("d"))
{
setImage(image2);
}
}
}
I want that the survivor shoots in the way , where he is looking.
So if hegoes to the right, he also should shoot to the right. If he goes to the left, he also should shoot to the left.
