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

2022/3/25

My cooldown timer won't work

li66m li66m

2022/3/25

#
private int shootTimer = 0;
    boolean invincible = false;
    private int invincibleTimer = 0;
    private int cooldownTimer = 0;
    /**
     * Act - do whatever the Player_1 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        //The Planes actions
        move();        
        shootTimer++;
        shoot();
        hit();
        invincible();
        invincibleTimer++;
        cooldownTimer ++;
    }   


public void invincible()
    {
        if (Greenfoot.isKeyDown("i") && cooldownTimer >= 120)
        {
            invincible = true;
            this.setImage(new GreenfootImage("Player 1 Inv.png"));
            invincibleTimer = 0;
        }
        if (invincibleTimer >=90)
        {
            invincible = false;
            this. setImage(new GreenfootImage("Player 1.png"));
            //cooldownTimer = 0; <-- as soon as bring it in it disables the powerup
        }
    }
Super_Hippo Super_Hippo

2022/3/25

#
The invincibleTimer should only increase if invincible equals true.
li66m li66m

2022/3/25

#
Super_Hippo wrote...
The invincibleTimer should only increase if invincible equals true.
should I replace the = 0 to ++?
Super_Hippo Super_Hippo

2022/3/25

#
No. Start by commenting out line 17.
li66m li66m

2022/3/26

#
Super_Hippo wrote...
No. Start by commenting out line 17.
nevermind I was able to figure out the problem myself. Thanks for the help though!
You need to login to post a reply.