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

2013/5/19

Level problem...

Miikku Miikku

2013/5/19

#
Problem is in the levels here my code:
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 = 200;
    private int level = 0;

    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 == 0)
        {
            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)
        {
            getWorld().removeObject(this);
            level = level += 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();
        }
    }
}
GreenGoo GreenGoo

2013/5/19

#
You need to change the getWorld().removeObject(this); level = level += 1; to level = level + 1; getWorld().removeObject(this);
Miikku Miikku

2013/5/19

#
It doesent act.
Miikku Miikku

2013/5/19

#
Help?
GreenGoo GreenGoo

2013/5/19

#
What does 'It does not act' mean? Can you be specific about the problem?
danpost danpost

2013/5/19

#
The value of level is at zero to start; so, of course, your level does not work.
Miikku Miikku

2013/5/19

#
Aah ya :D
Miikku Miikku

2013/5/19

#
But why this didn't raise level?
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 = 200;
    private 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);
        }  
    }
    
    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();
        }
    }
}
Miikku Miikku

2013/5/19

#
Help?
danpost danpost

2013/5/19

#
If you want all your zombies to share the 'level field, then it will have to be made 'static' also.
Miikku Miikku

2013/5/20

#
Code?
danpost danpost

2013/5/20

#
change line 11 to 'private static int level = 1;'.
Miikku Miikku

2013/5/20

#
Ok
You need to login to post a reply.