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

2021/10/26

copys of objects get affected when one is triggered

Aaron-aid Aaron-aid

2021/10/26

#
i have aproblem, when u run over a bad guy he turns into a pile of blood, but when you. run one over they all turn into blood puddles
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
 * Write a description of class npc here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class npc extends player
{
    static boolean dead = false;
    static int cash;
    int once = 0;
    
    /**
     * Act - do whatever the npc wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        
        
        if (dead == true)
        {
            cash = Greenfoot.getRandomNumber(10);
            spawncash(cash);
        }
        if(isTouching(player.class))
        {
            if(driving() == true)
            {
                setImage("button-red.png");
                dead = true;
                getWorld().setPaintOrder(player.class,npc.class,cash.class);
            }
            if(driving() == false)
            {
                if(dead == false){
                 setLocation(getX()-4,getY());
            }
            if(dead == true){
                //nothing
            }
            }
        }
    }  
    void spawncash(int ammount)
    {
        if (once == 0){
        for (int i = 0; i <= ammount; i++)
        {
           getWorld().addObject(new cash(), getX(), getY());
        }
        once = 1;
       }
    }
    public static boolean isdead()
    {
        return dead;
    }
}
danpost danpost

2021/10/27

#
The class should not (at least, not yet, from what I can see) have anything that is static. The state of being dead is for that of an instance, not for the class.
Aaron-aid Aaron-aid

2021/10/27

#
yeah removing it fixed it
You need to login to post a reply.