Hey guys I was wondering if I could change worlds when reached a certain score but I don't know how. Any tips? I'll paste the code if you want to, just don't know what code is needed to solve this haha


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class world here. * * @author (your name) * @version (a version number or a date) */ public class ZombieWorld extends World { /** * Constructor for objects of class world. * */ Counter counter = new Counter(); HealthBar healthbar = new HealthBar(); public ZombieWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 1200 , 800 , 1 , false ); prepare(); } public Counter getCounter() { return counter; } public HealthBar getHealthBar() { return healthbar; } private void prepare() { ZombieSpawner spawner = new ZombieSpawner(); addObject(spawner, 0 , 0 ); Survivor survivor = new Survivor(); addObject(survivor, 600 , 600 ); addObject(counter, 61 , 26 ); addObject(healthbar, 174 , 26 ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * Write a description of class Counter here. * * @author (your name) * @version (a version number or a date) */ public class Counter extends Actor { int score = 0 ; /** * Act - do whatever the Counter wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { setImage( new GreenfootImage( "Score : " + score, 24 , Color.GREEN, Color.BLACK)); } public void addScore() { score ++; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class zombie here. * * @author (your name) * @version (a version number or a date) */ public class Zombie extends WorldActors { GreenfootImage zombie1 = new GreenfootImage( "zombie1.png" ); GreenfootImage zombie2 = new GreenfootImage( "zombie2.png" ); GreenfootImage zombie3 = new GreenfootImage( "zombie3.png" ); public int frame = 1 ; public int animationCounter = 0 ; public int speed = 1 ; /** * Act - do whatever the zombie wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { animationCounter ++; if (animationCounter % 6 == 0 ) animate(); chaseSurvivor(); die(); } public void chaseSurvivor() { turnTowards(Survivor.survivorX, Survivor.survivorY); move(speed); } public void animate() { if (frame == 1 ) { setImage(zombie1); frame = 2 ; } else if (frame == 2 ) { setImage(zombie2); frame = 3 ; } else if (frame == 3 ) { setImage(zombie3); frame = 1 ; } } public void die() { Actor bullet = getOneIntersectingObject(Bullet. class ); Actor explosion = getOneIntersectingObject(Explosion. class ); if (bullet!= null ) { World myWorld = getWorld(); getWorld().removeObject(bullet); ZombieWorld zombieworld = (ZombieWorld)myWorld; Counter counter = zombieworld.getCounter(); counter.addScore(); getWorld().addObject( new Splat(), getX(), getY()); getWorld().removeObject( this ); } else if (explosion != null ) { World myWorld = getWorld(); ZombieWorld zombieworld = (ZombieWorld)myWorld; Counter counter = zombieworld.getCounter(); counter.addScore(); getWorld().addObject( new Splat(), getX(), getY()); getWorld().removeObject( this ); } } } |
1 | if (score == someValue) Greenfoot.setWorld( new NextWorld()); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class zombie here. * * @author (your name) * @version (a version number or a date) */ public class Zombie extends WorldActors { GreenfootImage zombie1 = new GreenfootImage( "zombie1.png" ); GreenfootImage zombie2 = new GreenfootImage( "zombie2.png" ); GreenfootImage zombie3 = new GreenfootImage( "zombie3.png" ); public int frame = 1 ; public int animationCounter = 0 ; public int speed = 1 ; /** * Act - do whatever the zombie wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { animationCounter ++; if (animationCounter % 6 == 0 ) animate(); chaseSurvivor(); die(); } public void chaseSurvivor() { turnTowards(Survivor.survivorX, Survivor.survivorY); move(speed); } public void animate() { if (frame == 1 ) { setImage(zombie1); frame = 2 ; } else if (frame == 2 ) { setImage(zombie2); frame = 3 ; } else if (frame == 3 ) { setImage(zombie3); frame = 1 ; } } public void die() { Actor bullet = getOneIntersectingObject(Bullet. class ); Actor explosion = getOneIntersectingObject(Explosion. class ); if (bullet!= null ) { World myWorld = getWorld(); getWorld().removeObject(bullet); ZombieWorld zombieworld = (ZombieWorld)myWorld; Counter counter = zombieworld.getCounter(); counter.addScore(); getWorld().addObject( new Splat(), getX(), getY()); getWorld().removeObject( this ); } else if (explosion != null ) { World myWorld = getWorld(); ZombieWorld zombieworld = (ZombieWorld)myWorld; Counter counter = zombieworld.getCounter(); counter.addScore(); getWorld().addObject( new Splat(), getX(), getY()); getWorld().removeObject( this ); } } } |
1 2 3 | Counter counter = null ; if (myWorld instanceof ZombieWorld) counter = ((ZombieWorld)myWorld).getCounter(); else if (myWorld instanceof ZombieWorld2) counter = ((ZombieWorld2)myWorld).getCounter(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * Write a description of class Counter here. * * @author (your name) * @version (a version number or a date) */ public class Counter extends Actor { int score = 0 ; /** * Act - do whatever the Counter wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { setImage( new GreenfootImage( "Score : " + score, 24 , Color.GREEN, Color.BLACK)); if (score == 30 ) Greenfoot.setWorld( new ScreenInbetween()); } public void addScore() { score ++; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * Write a description of class Counter here. * * @author (your name) * @version (a version number or a date) */ public class Counter extends Actor { int score = 0 ; /** * Act - do whatever the Counter wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { setImage( new GreenfootImage( "Score : " + score, 24 , Color.GREEN, Color.BLACK)); World myWorld = getWorld(); if (score == 30 && myWorld instanceof ZombieWorld) Greenfoot.setWorld( new ScreenInbetween()); else if (score == 30 && myWorld instanceof ZombieWorld2) Greenfoot.setWorld( new ScreenInbetween2()); else if (score == 30 && myWorld instanceof ZombieWorld3) Greenfoot.setWorld( new EndScreen()); } public void addScore() { score ++; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class StartScreen here. * * @author (your name) * @version (a version number or a date) */ public class StartScreen extends World { /** * Constructor for objects of class StartScreen. * */ public StartScreen() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 1200 , 800 , 1 ); GreenfootSound backgroundMusic = new GreenfootSound( "GameMusic.mp3" ); backgroundMusic.playLoop(); prepare(); } private void prepare() { TitleLetters titleletters = new TitleLetters(); addObject(titleletters, 600 , 400 ); } public void act() { if (Greenfoot.isKeyDown( "enter" )) Greenfoot.setWorld( new ZombieWorld()); else if (Greenfoot.isKeyDown( "c" )) Greenfoot.setWorld( new Controls()); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class world here. * * @author (your name) * @version (a version number or a date) */ public class ZombieWorld extends World { /** * Constructor for objects of class world. * */ Counter counter = new Counter(); HealthBar healthbar = new HealthBar(); public ZombieWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 1200 , 800 , 1 , false ); prepare(); } public Counter getCounter() { return counter; } public HealthBar getHealthBar() { return healthbar; } private void prepare() { ZombieSpawner spawner = new ZombieSpawner(); addObject(spawner, 0 , 0 ); Survivor survivor = new Survivor(); addObject(survivor, 600 , 600 ); addObject(counter, 61 , 26 ); addObject(healthbar, 174 , 26 ); } } |