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

2019/12/5

Fire class appears before BlueCar reaches X axis

suzbo suzbo

2019/12/5

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class BlueCar here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class BlueCar extends Actor
{
    /**
     * Act - do whatever the BlueCar wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        setImage("BlueCar!.png");

        if(Greenfoot.getRandomNumber(90)>60)
        {

            move(5); 

            if (isAtEdge())
            { 
                Greenfoot.playSound("Cheering.mp3");
                setImage("1stplaceA.png");
                Greenfoot.stop();
                FlagMan flagman = new FlagMan();
                getWorld().addObject(flagman,841,246);

            }
        }

        if (getX()==900);
        {
            Fire fire = new Fire();
            getWorld().addObject(fire,400,60);  
        }

    }

}
Fire class appears before the BlueCar reaches the location of the X axis
danpost danpost

2019/12/5

#
suzbo wrote...
Fire class appears before the BlueCar reaches the location of the X axis
Please show World subclass codes and list any and all classes that extend the BlueCar class.
suzbo suzbo

2019/12/5

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class MyWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MyWorld extends World
{

    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    public MyWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(942,275, 1); 
        prepare();
    }

    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {

        BlueCar blueCar = new BlueCar();
        addObject(blueCar,35,54);
        GreyCar greyCar = new GreyCar();
        addObject(greyCar,33,127);
        RedCar redCar = new RedCar();
        addObject(redCar,38,202);
        FlagMan flagMan = new FlagMan();
        addObject(flagMan,853,247);
        FlagMan flagMan2 = new FlagMan();
        addObject(flagMan2,852,10);
        flagMan2.setLocation(531,129);
        removeObject(flagMan2);
        removeObject(flagMan);
    }
}
Here is the World Class code. No Actor class extends the BlueCar class. I hope that helps.
suzbo suzbo

2019/12/5

#
Here is the World Class code. No Actor class extends the BlueCar class. I hope that helps.
danpost danpost

2019/12/5

#
suzbo wrote...
Fire class appears before the BlueCar reaches the location of the X axis
With what you have given, I cannot see any reason for what you say is happening. The only strange thing I see (which I cannot expect to be related to your issue) is the exclamation mark inside the filename of the image -- and that may be fine, as is.
You need to login to post a reply.