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

2012/1/16

um... My World isn't getting seen by the program?

1
2
NJoson NJoson

2012/1/16

#
So I was just reading through the code so I could understand what was going on and now no world is seen and when I tried to share it Greenfoot told me that no world class could be found. The code of the world() class is: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Desert here. * * @author (your name) * @version (a version number or a date) */ public class Road extends World { // instance variables private int counter = 0; private int spawnRate; private int spawnY; private int vehicleSpeed; private int lives = 3; private int level; private int autoCount; private Level currentLevel; private boolean levelLoaded = false; private boolean spawning; private boolean actionPaused = false; private boolean showScore = false; private boolean deathSequenceActive = false; // Not implemented yet: private int chanceOfDouble; private int chanceOfTriple; // Sounds and Graphics loading private GreenfootImage frogImage = new GreenfootImage ("frog.png"); private GreenfootImage splat = new GreenfootImage ("splat.png"); private GreenfootImage rivalImage = new GreenfootImage ("rival.gif"); // For some reason sounds work better if initialized in the constructor private GreenfootSound smush; private GreenfootSound levelUpSound; private GreenfootSound gameOverSound; // owned instance objects private LifeCounter lifeCounter = new LifeCounter (); private LevelCounter levelCounter = new LevelCounter (); private Frogger myFrog = new Frogger(); private Rival redRival = new Rival(); //heart object private Actor heart; /** * Constructor for objects of class Desert. */ public Road() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); // Ensure that Frogs and Blood occur over top of everything else setPaintOrder(Frogger.class, BloodPool.class, ScoreBoard.class, Enemy.class); // Add the life counter to the World addObject (lifeCounter, 67, 25); addObject (levelCounter, 530, 24); // Initialize sound within the constructor to avoid wierd sound lag smush = new GreenfootSound("smush.wav"); levelUpSound = new GreenfootSound("mariocoin.mp3"); gameOverSound = new GreenfootSound("GameOver.wav"); // Set level to 1 level = 1; autoCount = 0; } public void act () { // Load level if necessary if (levelLoaded == false) { // Load level if player has lives left if (lives > 0) { levelLoader(); levelLoaded = true; } else { ScoreBoard s = new ScoreBoard (level, "Game Over", "On Level "); addObject (s, 300,200); gameOverSound.play(); // End program Greenfoot.stop(); } } // If appropriate, spawn cars if (actionPaused == false && spawning == true) { spawnCars(); } // Control sequence to ensure that after death, program waits until // all cars are off-screen before spawning the next Frogger if (deathSequenceActive) { if (autoCount == 0) { deathSequenceActive = false; levelLoaded = false; } } // Create hearts at specified rate---------------------------------------------------------- if (Greenfoot.getRandomNumber(300)==0) { //creates a random number at every frame and if it is equal to 0... heart=new Heart(); //create a new heart addObject(heart,Greenfoot.getRandomNumber(451)+50,Greenfoot.getRandomNumber(226)+150); //add the heart to the world with random coordinates between (50,150) and (450,225) //note: increasing the 300 in the if statement will create less hearts, and vice versa for decreasing } //------------------------------------------------------------------------------------------ } // Method to set necessary values to change level private void levelLoader () { // Add a fresh Frogger object addObject(myFrog, 300, 370); // Update the info stored in currentLevel currentLevel = new Level (level); levelCounter.setLevel(level); // Set image to frog (in case "splat" was being displayed) myFrog.setImage(frogImage); // change appropriate booleans for game flow actionPaused = false; spawning = true; // load instance variables from Level spawnRate = currentLevel.getSpawnRate(); vehicleSpeed = currentLevel.getVehicleSpeed(); chanceOfDouble = currentLevel.getChanceOfDouble(); chanceOfTriple = currentLevel.getChanceOfTriple(); myFrog.setSpeed(currentLevel.getFroggerSpeed()); // Ensure that level is not loaded again until necessary levelLoaded = true; } /** * Controlled spawning of new cars */ private void spawnCars() { int randVal = Greenfoot.getRandomNumber(3)+1; int spawnChance = Greenfoot.getRandomNumber(100) + 1; // spawn single if (counter % spawnRate == 0) { if (randVal == 1) spawnY = 127; else if (randVal == 2) spawnY = 223; else spawnY = 320; addObject(new EastboundAuto(vehicleSpeed), 20, spawnY); autoCount++; } else if (counter % spawnRate == spawnRate / 2) { if (randVal == 1) spawnY = 78; else if (randVal == 2) spawnY = 173; else spawnY = 270; addObject(new WestboundAuto(vehicleSpeed), 578, spawnY); autoCount++; } counter++; } /** * */ private void spawn (int num, int y, boolean east) { } /** * This method gets called when the player dies or finishes a level * * True = player completed level * False = player died */ public void endLevel(boolean win) { ScoreBoard s = null; actionPaused = true; spawning = false; if (win == true) { level++; levelUpSound.play(); removeObject (myFrog); levelLoaded = false; Greenfoot.delay(50); } else { // Change the Frogger's image to the bloody frog myFrog.setImage(splat); // Play a smush sound smush.play(); BloodPool b = new BloodPool(); addObject (b, myFrog.getX(), myFrog.getY()); lives -= 1; lifeCounter.subtractLife(); actionPaused = false; deathSequenceActive = true; removeObject (myFrog); } } //create a method for adding a life------------------------------------------------------------ public void collectHeart() { lives++; lifeCounter.addLife(); } //--------------------------------------------------------------------------------------------- public boolean isActionPaused () { return actionPaused; } public void reduceAutoCount (int byHowMany) { autoCount -= byHowMany; } } The only other thing I did was create an Actor. In case it is the problem, the code for the new Actor is: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Rival here. * * @author (your name) * @version (a version number or a date) */ public class Rival extends Actor { /** * Act - do whatever the Rival wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ private int speed; private boolean active; public Rival() { active= true; speed=2; } public void act() { if (checkWin() ) { endGame(true); } else if(checkDeath() && active == true) { active = false; endGame(false); } } public void addedToWorld (World w) { active = true; } public void advance() { if (active == true) { setLocation(getWorld().getWidth()-Greenfoot.getRandomNumber(100), getY()); move(4); if (Greenfoot.getRandomNumber(150) < 10) { turn(Greenfoot.getRandomNumber(90) - 45); } if (getX() >= getWorld().getWidth()) turn(180); } } private boolean checkDeath() { Enemy e = (Enemy)getOneIntersectingObject(Enemy.class); if (e != null) // if an enemy is detected colliding with Frogger, then death = true :( return true; return false; } private boolean checkWin() { if (getY() <= 32) { active = false; return true; } else return false; } private void endGame (boolean win) { // Return a message declaring win or lose to the Road (World) Road d = (Road)getWorld(); d.endLevel (win); } public void setSpeed (int speed) { this.speed = speed; } }
davmac davmac

2012/1/16

#
Have you tried restarting Greenfoot? Are you using the latest version of Greenfoot?
NJoson NJoson

2012/1/16

#
I restarted the software and my greenfoot is 2.1.1. Still not working. The world doesn't get displayed and the run and pause buttons are gray.
davmac davmac

2012/1/16

#
Can you try with Greenfoot 2.1.2?
Akuhano Akuhano

2012/1/16

#
Did you try compiling first? (I understand this might be a stupid question)
NJoson NJoson

2012/1/16

#
Compiling didn't do anything. Would it make a difference even though it was written in 2.1.1? I currently downloading 2.1.2
NJoson NJoson

2012/1/16

#
so I just finished updating and the problem persists. Any other suggestions?
Akuhano Akuhano

2012/1/16

#
What I've tried once was to open a new scenario, copy everything over, and try there.
davmac davmac

2012/1/16

#
If you zip up the scenario and send it to support@greenfoot.org we can have a look at it.
NJoson NJoson

2012/1/16

#
okay I sent the compressed file.
kiarocks kiarocks

2012/1/16

#
Is there any compile errors?
NJoson NJoson

2012/1/16

#
None. All my classes pass.
NJoson NJoson

2012/1/16

#
would it help if I posted the other classes also?
danpost danpost

2012/1/16

#
The problem stems from the fact that you re-named your world class. You may have to create a new scenario and copy/paste everything over. Wait, I see you have tried that -- When you open the scenario, does Greenfoot show your sub-class of the World to be 'Road' or 'Desert', and does the code in the world class match this name?
davmac davmac

2012/1/16

#
The scenario you sent doesn't completely compile. The source for "WestboundAuto" is missing - the .java file is empty. I could construct a new world by right-clicking the world class (Road) and choosing "new Road()". After that the world is displayed properly.
There are more replies on the next page.
1
2