Hi. How can I create several different levels and create a counter that continues to count in several different worlds. Also i am brand new to coding and greenfoot so I would appreciate it if you told me where I have to add it.
that is my title screen.
that is level 1.
That is my counter code.
That is my bee code (the enemy)
That is my turtle (the character the player controls)
That is my strawberry code (the thing the counter is counting and what the turtle eats.)
My code for Title Screen Text (theres nothing there.)
If you have any advice for the game in general that would be much appreciated. Im also trying to add a You Win pop up on a level (Ive only made 1 level so far but on like level 5 I hope to make a You Win and stuff.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | public StartScreen() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 800 , 600 , 1 ); prepare(); } public void act() { if (Greenfoot.isKeyDown( "enter" )) Greenfoot.setWorld( new MyWorld()); } /** * Prepare the world for the start of the program. * That is: create the initial objects and add them to the world. */ private void prepare() { TitleScreen titleScreen = new TitleScreen(); addObject(titleScreen, 377 , 313 ); } |
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 | Counter counter = new Counter(); //1.5.5 brings cleaner movement coding for the Turtle and a Score Counter that will function in next update. //This new update features radical changes to the whole code such as GameOver and new class. /** * Constructor for objects of class MyWorld. * */ public MyWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 800 , 600 , 1 ); prepare(); } public Counter getCounter() { return counter; } /** * Prepare the world for the start of the program. * That is: create the initial objects and add them to the world. */ private void prepare() { addObject(counter, 100 , 40 ); Strawberry strawberry = new Strawberry(); addObject(strawberry, 263 , 204 ); Strawberry strawberry2 = new Strawberry(); addObject(strawberry2, 441 , 153 ); Strawberry strawberry3 = new Strawberry(); addObject(strawberry3, 451 , 321 ); Strawberry strawberry4 = new Strawberry(); addObject(strawberry4, 197 , 306 ); Strawberry strawberry5 = new Strawberry(); addObject(strawberry5, 87 , 139 ); Strawberry strawberry6 = new Strawberry(); addObject(strawberry6, 275 , 78 ); Bee bee = new Bee(); addObject(bee, 331 , 92 ); Bee bee2 = new Bee(); addObject(bee2, 273 , 311 ); Bee bee3 = new Bee(); addObject(bee3, 57 , 52 ); Turtle turtle = new Turtle(); addObject(turtle, 561 , 41 ); Strawberry strawberry7 = new Strawberry(); addObject(strawberry7, 451 , 470 ); Strawberry strawberry8 = new Strawberry(); addObject(strawberry8, 669 , 481 ); Strawberry strawberry9 = new Strawberry(); addObject(strawberry9, 667 , 302 ); Strawberry strawberry10 = new Strawberry(); addObject(strawberry10, 125 , 510 ); Strawberry strawberry11 = new Strawberry(); addObject(strawberry11, 304 , 508 ); Bee bee4 = new Bee(); addObject(bee4, 566 , 478 ); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 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 | public void act() { move(Greenfoot.getRandomNumber( 10 )); if (isAtEdge()) { if (Greenfoot.getRandomNumber( 100 ) < 100 ) { turn( 180 ); } } if (Greenfoot.getRandomNumber( 100 ) < 20 ) { turn(Greenfoot.getRandomNumber( 20 )); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public void act() { HitEnemy(); if (Greenfoot.isKeyDown ( "a" )) { turn (- 3 ); } if (Greenfoot.isKeyDown ( "d" )) { turn ( 3 ); } if (Greenfoot.isKeyDown ( "s" )) { move (- 3 ); } if (Greenfoot.isKeyDown ( "w" )) { move ( 3 ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | public void act() { HitEnemy(); } public void HitEnemy() { if (isTouching (Turtle. class )) { World myWorld = getWorld(); MyWorld space = (MyWorld)myWorld; Counter counter = space.getCounter(); counter.addScore(); getWorld().removeObject ( this ); } } |
1 2 3 4 | public void act() { // Add your action code here. } |