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

2022/4/4

timer doesnt change value

Aaron-aid Aaron-aid

2022/4/4

#
help, i coded a basic countdown timer but it just sits there doing nothing ;c
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class boss here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class boss extends Actor
{
    int health = 100;
    int timer = 10;
    int timer_real = timer;
    /**
     * Act - do whatever the boss wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        attack();
        getWorld().showText(""+timer, 300, 300);
        //bullet bullet = new bullet();
    }    
    void attack()
    {
        timer_real--;
        if (timer_real<= 0)
        {
            bullet bullet = new bullet();
            timer_real=timer;
        }
    }
}
Aaron-aid Aaron-aid

2022/4/4

#
heres the bullet code if yall need it
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class code here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class bullet extends boss
{
    int PlayerLastX;
    int PlayerLastY;
    boolean runonce = false;
    /**
     * Act - do whatever the code wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        runonce();
        
        move(1);
        if(isAtEdge())
        {
        getWorld().removeObject(this);
        }
    }   
    void runonce()
    {
        if(runonce == false){
        PlayerLastX=getWorld().getObjects(Player.class).get(0).getX();
        PlayerLastY=getWorld().getObjects(Player.class).get(0).getY();
        turnTowards(PlayerLastX, PlayerLastY);
        runonce = true;
       }
    }
}
Super_Hippo Super_Hippo

2022/4/4

#
The only variable which is ever changed is timer_real and that one isn’t shown. The variable timer isn’t set to anything else than 10 anywhere.
Aaron-aid Aaron-aid

2022/4/13

#
nah i figured it out, it ran i just forgot to add the bullet to the world
You need to login to post a reply.