This site requires JavaScript, please enable it in your browser!
Greenfoot back
Miikku
Miikku wrote ...

2013/5/26

Counter doesen't act.

Miikku Miikku

2013/5/26

#
Yes counter doesen't act...
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

public class Zombie extends Actor
{
    private GreenfootImage zombieAnim1 = new GreenfootImage("Zombieanim.png");
    private GreenfootImage zombieAnim2 = new GreenfootImage("Zombieanim2.png");
    private GreenfootImage zombieAnim3 = new GreenfootImage("Zombieanim3.png");
    private int frame = 1;
    private int animationCount = 0;
    private int health = 10;
    private static int level = 1;

    private Counter counter;
    
    public Zombie(Counter pointCounter)
    {
       counter = pointCounter; 
    }    
    
    public void act() 
    {
        AI();
        
        if(animationCount % 12 == 0)
        animationWalk();
        
        animationCount ++;
        
        eat();
        death();
        level();
    }    
    
    public void level()
    {
        if(level >= 1)
        {
            move(1);
        }
        else if(level >= 10)
        {
            move(2);
        }
        else if(level >= 20)
        {
            move(3);
        }
        else if(level >= 40)
        {
            move(5);
        }
        else if(level >= 80)
        {
            move(8);
        }
        else if(level >= 120)
        {
            move(12);
        }
          
    }
    
    
    public void AI()
    {
        turnTowards(Soldier.currentX, Soldier.currentY);
    }
    
    public void animationWalk()
    {
        if(frame == 1)
        {
        setImage(zombieAnim1);
        frame = 2;
        }
        else if(frame == 2)
        {
        setImage(zombieAnim2);
        frame = 3;
        }
        else if(frame == 3)
        {
        setImage(zombieAnim3);
        frame = 1;
        }
    }
    
    public void death()
    {
        Actor bullet = getOneIntersectingObject(Bullet.class);
    
        if (bullet != null)
        {
            health = health - 10;
            getWorld().removeObject(bullet);
        }
        if (health <= 0)
        {
            level = level += 1;
            getWorld().removeObject(this);
            ((Counter)getWorld().getObjects(Counter.class).get(0)).add(1);
        }  
    }
    
    public void eat()
    {
        Actor soldier;
        soldier = getOneObjectAtOffset(0, 0, Soldier.class);
        if (soldier != null)
        {
            World ZombieWorld;
            ZombieWorld = getWorld();
            ZombieWorld.removeObject(soldier);
            setImage("gameoverr.png");
            Greenfoot.stop();
            Greenfoot.stop();
        }
    }
}
Gevater_Tod4711 Gevater_Tod4711

2013/5/26

#
You probably get a NullPointerException in line 101. If you change the order of lines 100 and 101 it should work.
Miikku Miikku

2013/5/26

#
Ya it work, THANKS
You need to login to post a reply.