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

2021/4/27

Help needed!:

amit3118 amit3118

2021/4/27

#
]Hi, I'm trying to make a centipede game, and right now I've got it so that it will shoot a laser from a player and now I need it to shoot mushrooms down. So the first time it hits a mushroom I need it to change images from the original image ( "Arcade - Centipede - General Sprites_0008.png") to "Arcade - Centipede - General Sprites_0009.png" this was my code in laser
        move();
        if(this.getWorld()!=null) {
            Mushroom m = (Mushroom)getOneIntersectingObject(Mushroom.class);
            if(m != null) {
                m.onHit();
                
                
              
            }
        }
and this was my code in mushroom actor :
    int height = getImage().getHeight();
    int width = getImage().getWidth();
    public GreenfootImage hit0 = new GreenfootImage("Arcade - Centipede - General Sprites_0008.png");
    public GreenfootImage hit1 = new GreenfootImage("Arcade - Centipede - General Sprites_0009.png");
        
        
        
    
    public void onHit() {
        
        if(getImage().equals(hit0)) {
            setImage("Arcade - Centipede - General Sprites_0009.png");
        }
        
why doesnt it change, and can someone provide a solution?
Risen Risen

2021/4/27

#
Something wrong with line 11 in mushroom. The only thing that I can recommed you is to use this
    boolean isTouched;
public void onHit() {
     
    if(!isTouched) {
        setImage("Arcade - Centipede - General Sprites_0009.png");
    }
    isTouched = true;
};
danpost danpost

2021/4/28

#
Change line 11 to:
if (!getImage().equals(hit1))
and line 12 to:
setImage(hit1);
You need to login to post a reply.