why doesn't my actor move? how do i fix it?
sorry if its messy i did my best to clean it up for you guys
i was also wondering how to change my image after cell dies. the last void doesn't seem to be working so maybe I've just been putting it in the wrong spot. thanks in advance!
import greenfoot.*;
/**
* Write a description of class Gohan here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Gohan extends Actor
{
private int health = 900000; //its over 9000
public void setHealth(int points) {
health += points;
}
public int getHealth() {
return health;
}
private GreenfootImage image1;
private GreenfootImage image2;
private GreenfootImage image3;
private GreenfootImage image4;
private GreenfootImage image5;
private GreenfootImage image6;
private GreenfootImage image7;
private GreenfootImage image8;
public Gohan()
{
image1 = new GreenfootImage("gohan.png");
image2 = new GreenfootImage("gohanstep.png");
image3 = new GreenfootImage("gohanstep2.png");
image4 = new GreenfootImage("powerattack.png");
image5 = new GreenfootImage("gohanpunch.png");
image6 = new GreenfootImage("Gohankick1.png");
image7 = new GreenfootImage("HealthBar.png");
image8 = new GreenfootImage("Gpowerup.png");
setImage(image1);
}/**
* Act - do whatever the Gohan wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
checkKeypress ();
}
public void checkKeypress()
{
if (Greenfoot.isKeyDown("left"))
{
if ( getImage() == image1 )
{ setImage(image2);
}
else
{if ( getImage() == image8 ){}
else{ setImage(image1);
}
move(-30);
}
if (Greenfoot.isKeyDown("right"))
{ if ( getImage() == image1 )
{ setImage(image2);
}
else{ setImage(image1);
}
move (30);
}
if (Greenfoot.isKeyDown("s"))
{
setImage(image3);
hitEnemy();
}
else if ( getImage() == image3)
{
setImage(image1);}
if (Greenfoot.isKeyDown("z"))
{
setImage(image3);
hitEnemy();
}
if (Greenfoot.isKeyDown("x"))
{
setImage(image6);
hitEnemy();
}
else if ( getImage()== image6)
{setImage(image1);}
if (Greenfoot.isKeyDown("a"))
{
setImage(image5);
hitEnemy();
}
else if ( getImage()== image5)
{setImage(image1);}
if (Greenfoot.isKeyDown("space"))
{
setImage(image4);
hittingEnemy();
}
else if ( getImage() == image4 )
{setImage(image1);}
if (health<=0)
{getWorld().removeObject(this);
}
}
}
private void hitEnemy() {
Cell cell = (Cell) getOneObjectAtOffset(0, 0, Cell.class);
if (cell != null) {
cell.setHealth(-1001);
cell.move(30);
}
}
private void hittingEnemy() {
Cell cell = (Cell) getOneObjectAtOffset(0, 0, Cell.class);
if (cell != null) {
cell.setHealth(-4000);
cell.move(200);
}
}
private void celldies() {
Cell cell = (Cell) getOneObjectAtOffset(0, 0, Cell.class);
if (cell != null) {
if (cell.health <=0){ setImage(image8);}
}
}
}

