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

2022/11/11

trying to make a game over screen

RHMU RHMU

2022/11/11

#
I have a game over text bu6t I am trying to make it so when a timer gets to 90 seconds it appears. this is my code that i am using it is in the my world editor
if (timeCount == 90)
         {
             GameOver gameover = new GameOver();
             myWorld. addObject(gameover, myWorld, getWidth()/2, getHeight()/2);
         }
it says that the addObject "int cannot be differenced and the (timeCount == 90) is says bad oprands types for binary oporator this is the whole code
import greenfoot.Actor;

  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
{
    int cookieSpawnTimer = 50;
    public static int score = 0;
    int resetscore = 0;
    SimpleTimer tim =   new SimpleTimer();
    Counter timeCount = new Counter();
    private Actor gameover;
    int myWorld;
    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    public MyWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(873, 479, 1); 
        prepare();
        addObject(timeCount, 809,21);
        tim.mark();
            }
    
    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {
        score = resetscore;
        grany grany = new grany();
        addObject(grany,432,399);
    }
    
    
    public void act()
    {
        cookieSpawnTimer --;
        showText("Cookies : " + score, 75, 25);
        if (cookieSpawnTimer == 0)
        {
            Actor coookie;
            coookie Coookie = new coookie();
            addObject(new coookie(),(Greenfoot.getRandomNumber(873)),0);
            cookieSpawnTimer = 30;
        }
         timeCount.setValue(tim.millisElapsed()/1000);
         if (timeCount == 90)
         {
             GameOver gameover = new GameOver();
             myWorld. addObject(gameover, myWorld, getWidth()/2, getHeight()/2);
         }
    }
}   
danpost danpost

2022/11/12

#
RHMU wrote...
I have a game over text but I am trying to make it so when a timer gets to 90 seconds it appears. << Code Omitted >> it says that the addObject "int cannot be differenced and the (timeCount == 90) is says bad operand types for binary operator << Code Omitted >>
Line 19 declares myWorld as type int, yet line 60 uses it as a non-primitive type (not int, as used at the beginning of the line, at least). Plus, there are too many parameters used in the addObject command on line 60.
You need to login to post a reply.