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

2019/7/15

Finish line

Mia@2703 Mia@2703

2019/7/15

#
I need help making a finish line for my game. I want it to move it down like all my other actors are doing except at a certain time and then when the car passes through the finish line, it moves into the next level.
danpost danpost

2019/7/15

#
First, work on adding the finish line "at a certain time". What have you tried?
Mia@2703 Mia@2703

2019/7/15

#
So far I have only written this in the finish line clas:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class FinishLine here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class FinishLine extends Actor
{
    /**
     * Act - do whatever the FinishLine wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
       if (isTouching(FinishLine.class))
       {
          Greenfoot.setWorld(new Level2());
       }
   }
   
}
danpost danpost

2019/7/15

#
I doubt a FinishLine object touching another FinishLine object is the trigger you want to level up.
Mia@2703 Mia@2703

2019/7/15

#
What should I do then?
danpost danpost

2019/7/15

#
Mia@2703 wrote...
What should I do then?
Maybe -- check for touching a Car object.
Mia@2703 Mia@2703

2019/7/15

#
I need help on my game!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! please give an example or code.
Mia@2703 Mia@2703

2019/7/15

#
I figured out how to make the finish line
        if (Greenfoot.getRandomNumber(100) < 1)
        {
            addObject(new FinishLine(), Greenfoot.getRandomNumber(1)+300, 0);
        }
appear but more than one appears
danpost danpost

2019/7/15

#
Mia@2703 wrote...
I figured out how to make the finish line << Code Omitted >> appear but more than one appears
You just need another condition in spawning one:
if (Greenfoot.getRandomNumber(100) < 1 && getObjects(FinishLine.class).isEmpty())
Mia@2703 Mia@2703

2019/7/15

#
what does spawning mean where do i put it in the code please help
Super_Hippo Super_Hippo

2019/7/15

#
spawning = adding an object to the world You have to replace line 1 of your last shown code with the line given.
Mia@2703 Mia@2703

2019/7/16

#
How do you move an object at a certain time?
danpost danpost

2019/7/16

#
Mia@2703 wrote...
How do you move an object at a certain time?
With what is given, all that can be provided is a bit of pseudo-code: if (timeToMove) move(); Obviously, this is insufficient. Please provide more details and some attempted code.
You need to login to post a reply.