Here is the P1 button
Here is the P2 button
Here is the menu
Here is the InfoStore
Here is the level 1 code
And here is the level base code (Where level1 gets the methods)
Please help thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public class P1but extends Actor{ private GreenfootImage P1img; public InfoStore y; public P1but(){ P1img = new GreenfootImage( "P1Button.png" ); P1img.scale( 240 , 80 ); setImage(P1img); } /** * Act - do whatever the P1but wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act(){ if (Greenfoot.mouseClicked( this )){ Level1 t = new Level1(); Greenfoot.setWorld(t); InfoStore.setPnum( 1 ); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public class P2but extends Actor{ private GreenfootImage P2img; public InfoStore y; public P2but(){ P2img = new GreenfootImage( "P2Button.png" ); P2img.scale( 240 , 80 ); setImage(P2img); } /** * Act - do whatever the P2but wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act(){ if (Greenfoot.mouseClicked( this )){ Level1 e = new Level1(); Greenfoot.setWorld(e); InfoStore.setPnum( 2 ); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public class Menu2 extends World{ private GreenfootImage BG; /** * Constructor for objects of class Menu2. * */ public Menu2(){ super ( 960 , 720 , 1 ); BG = new GreenfootImage( "MenuFile.png" ); BG.scale(getWidth(), getHeight()); setBackground(BG); addObject( new P1but(), 480 , 400 ); addObject( new P2but(), 480 , 525 ); } } |
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 | public class InfoStore{ private static int Pnum; private static int LvlNum; /** * Constructor for objects of class InfoStore */ public InfoStore(){ Pnum = 0 ; LvlNum = 0 ; } public static int getPnum(){ return Pnum; } public static void setPnum( int newPnum){ Pnum = newPnum; } public static int getLvlNum(){ return LvlNum; } public void setLvlNum( int newLvlNum){ LvlNum = newLvlNum; } public void act(){ } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public class Level1 extends LevelBase { /** * Constructor for objects of class Level1. * */ public Level1(){ setBG(); spawnObj(); spawnPlyrs(); } public void act() { } } |
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 | public class LevelBase extends World { protected GreenfootImage img; /** * Constructor for objects of class LevelBase. * */ public LevelBase() { super ( 960 , 720 , 1 ); } public void setBG(){ img = new GreenfootImage( "LevelBG1.png" ); img.scale(getWidth(), getHeight()); setBackground(img); } public void spawnPlyrs(){ if (InfoStore.getPnum()== 1 ){ addObject( new Player1(), 107 , 625 ); return ; } if (InfoStore.getPnum()== 2 ){ addObject( new Player1(), 100 , 625 ); addObject( new Player2(), 110 , 625 ); } } public void spawnObj(){ addObject( new SpawnArea(), 107 , 625 ); } } |