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

2019/11/26

Score in GameOver World

1
2
SemDeBakkero SemDeBakkero

2019/11/28

#
I fixed it but now there is the following underlined red text: "cannot find symbol - variable CounterM" and: "cannot find symbol - variable score" With the following code:
if(getObjects(Dodge_Speler.class).isEmpty()) //als er geen Spelers zijn (speler is dus dood)
        {
            GameOverDodge go = new GameOverDodge();
            go.CounterM.score = CounterM.score;
            Greenfoot.setWorld(go);
        }
danpost danpost

2019/11/28

#
SemDeBakkero wrote...
I fixed it but now there is the following underlined red text: "cannot find symbol - variable CounterM" and: "cannot find symbol - variable score" With the following code: << Code Omitted >>
In what World subclass is this code located?
SemDeBakkero SemDeBakkero

2019/11/28

#
In the following world:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Dodge Meteor
 * 
 * @author (Sem de Bakkker) 
 */

public class Dodge_Meteor extends World
{
    public Dodge_Speler mainSpeler = new Dodge_Speler(); //speler standaard toevoegen
    int MeteorCounter; //variable MeteorCounter maken
    int timer = 0; //timer instellen
    int starAmount = 200; //aantal sterren als variable instellen
    int i; //i als variable instellen
    int s; //s als variable instellen
    int x = Greenfoot.getRandomNumber(getWidth()); //variable x instellen op random breedte
    int y = Greenfoot.getRandomNumber(getHeight()); //variable y instellen op random hoogte
    private Star[] stars;
    CounterM CounterM = new CounterM(); //counter betekent nu nieuwe Counter
    public Dodge_Meteor()
    {    
        super(1150, 610, 1); //groote wereld instellen
        addObject(mainSpeler, getWidth()/2, getHeight()/2); //Speler toevoegen
        addObject(CounterM, 100, 40); //CounterM standaard toevoegen aan wereld
    }
    public CounterM getCounterM()
    {
        return CounterM; //het terugkeren van CounterM
    }
    public void act()
    {
        timer++;
        if (timer == 200 || timer == 500 || timer == 700 || timer == 1000 || timer == 1100)
        {
            addObject(new meteor(), getWidth(), getHeight()/2); //nog een rechtsmidden een meteor toevoegen
            //dit doe ik om het spel moeilijker te maken
        }
        
        
        for (Object obj : getObjects(Star.class)) ((Star) obj).move(); //alle objecten (Star.class) -> beweeg
        makeStars(); //voer makeStars uit
        
        if(getObjects(Dodge_Speler.class).isEmpty()) //als er geen Spelers zijn (speler is dus dood) dan...
        {
            Greenfoot.setWorld(new GameOverDodge()); //openen game over wereld
            Greenfoot.playSound("dood.mp3"); //geluid toe voegen dat het spel over is
        }
        
        MeteorCounter++; //meteorcounter laten oplopen
        if(getObjects(meteor.class).size() < 7 && MeteorCounter%100 == 0) //als er minder dan 7 meteors zijn dan...
        {                                                               
            SpawnMeteor(); //Voer SpawnMeteor uit
        }
    }


    private void makeStars()
    {
        stars = new Star[starAmount];  //stars instellen op nieuw star met een bepaalde hoeveelheid
        while (i < starAmount) 
        {
            int x = Greenfoot.getRandomNumber(getWidth()); //variable x instellen op random breedte 
            int y = Greenfoot.getRandomNumber(getHeight());//variable y instellen op random hoogte
            Star s = new Star();  //s betkent nu new Star
            addObject(s, x, y);  //niewe object s (new Star) met de variable x & y als de coördinaten
            stars[i] = s;
            i++; //i laten lopen
        }
    }  
    public void SpawnMeteor()
    {
        addObject(new meteor(), getWidth(), 0); //helemaal rechtsboven een meteor toevoegen
        addObject(new meteor(), getWidth(), getHeight()); //rechtsonder een meteor toevoegen
        addObject(new meteor(), getWidth(), getHeight()/2); //rechtsmidden een meteor toevoegen
        addObject(new meteor(), getWidth(), getHeight()/2); //nog een rechtsmidden een meteor toevoegen
        addObject(new meteor(), getWidth(), getHeight()/2); //en nog een rechtsmidden een meteor toevoegen
        addObject(new meteor(), getWidth(), getHeight()/4); //rechts kwart naar beneden (van bovenaan gezien) een meteor toevoegen
        addObject(new meteor(), getWidth(), getHeight()*3/4); //rechts kwart naar boven (van onderaan gezien) een meteor toevoegen
        addObject(new meteor(), getWidth(), getHeight()/8); //rechts een achtste naar beneden (van bovenaan gezien) een meteor toevoegen
        addObject(new meteor(), getWidth(), getHeight()*7/8); //rechts een achtste naar boven (van onderaan gezien) een meteor toevoegen
        addObject(new meteor(), getWidth(), getHeight()/16); //rechts een zestiende naar beneden (van bovenaan gezien) een meteor toevoegen
        addObject(new meteor(), getWidth(), getHeight()*15/16); //rechts een zestiende naar boven (van onderaan gezien) een meteor toevoegen
    }
}


And the following gameover world:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * GameOverDodge
 * 
 * @author (Sem de Bakker) 
 */
public class GameOverDodge extends World
{
    public GameOverDodge()
     {    
       super(1150, 610, 1); //grootte van wereld instellen
       showText("GAME OVER", getWidth()/2, 100); //tekst game over invoegen
       addObject(new CounterM(), getWidth()/2, 200); //counter standaard toevoegen aan wereld
       showText("PRESS R TO RESTART THE GAME", getWidth()/2, 400); //tekst invoegen
       showText("PRESS ENTER GO BACK TO HOME", getWidth()/2, 450); // tekst invoegen
    }
    public void act()
    {
        if(Greenfoot.isKeyDown("r")) //als r wordt ingedrukt
        {
            Greenfoot.setWorld(new Dodge_Meteor()); //open dan nieuwe wereld: Dodge Meteor
        }
        if(Greenfoot.isKeyDown("enter")) //als enter wordt ingedrukt
        {
            Greenfoot.setWorld(new Home()); //open dan niet wereld: Home
        }
    }
}
danpost danpost

2019/11/28

#
SemDeBakkero wrote...
In the following world: << Code Omitted >> And the following gameover world: << Code Omitted >>
Okay -- so you do not have a field for the counter in your GameOverDodge class. Replace line 4 (where the errors are) with the following:
CounterM cm = (CounterM)go.getObjects(CounterM.class).get(0);
cm.score = CounterM.score;
SemDeBakkero SemDeBakkero

2019/11/28

#
Thanks but now i get this error: "cannot find symbol - variable go" and "cannot find symbol - variable score"
SemDeBakkero SemDeBakkero

2019/11/28

#
Should I int them?
danpost danpost

2019/11/28

#
SemDeBakkero wrote...
Thanks but now i get this error: "cannot find symbol - variable go"
That would not be possible with line 3 (the line previous to that being replaced).
and "cannot find symbol - variable score"
Change both score to scoreM.
SemDeBakkero SemDeBakkero

2019/11/28

#
Ohh I get it, thanks man. But if I die (so go to gameover screen) the time is still going. How can I prevent that?
danpost danpost

2019/11/28

#
SemDeBakkero wrote...
if I die (so go to gameover screen) the time is still going.
Are you sure about that? The act in Dodge_Meteor world is not called when it is not the current world.
SemDeBakkero SemDeBakkero

2019/11/30

#
Yes it is, in the public Dodge_Meteor is the addObject
danpost danpost

2019/11/30

#
SemDeBakkero wrote...
Yes it is, in the public Dodge_Meteor is the addObject
Oh wait, your CounterM class actually creates timers -- not counters. In its act method:
// change
addScore(); // line 16
// to
if (getWorld() instanceof Dodge_Meteor) addScore();
SemDeBakkero SemDeBakkero

2019/12/1

#
THANKS it worked
You need to login to post a reply.
1
2