I am using an array list to display instructions before the game starts on the start screen. The array list work through the fact that it flips through the list displaying the text, however, it stops the entire game to display the text. Where would be a good place to place the instructions() method....Help!
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.*; /** * Write a description of class doodleWorld here. * * @author (your name) * @version (a version number or a date) */ public class DoodleWorld extends World { private boolean gameStarted, started = false ; private int enemySpawnTimeMax= 240 * 4 , enemySpawnTimer=enemySpawnTimeMax; private int enemy1SpawnTimeMax= 472 * 3 , enemy1SpawnTimer=enemy1SpawnTimeMax; private int enemy2SpawnTimeMax= 369 * 2 , enemy2SpawnTimer=enemy2SpawnTimeMax; private boolean began; private int transparency = 0 ; public int scrollSpeed; public boolean scroll; public boolean fall; private boolean hitEnemy; public boolean ended; private int restart; public int height = 0 ; public int doodleX; /** * Constructor for objects of class doodleWorld. * */ public DoodleWorld() { super ( 300 , 400 , 1 , false ); //sets the world size and pixel space addObject( new StaticEnemy(), 200 , 250 ); addObject( new StaticEnemy2(), 250 , 150 ); addObject( new Ground(), 56 , 317 ); addObject( new doodler( false ), 56 , 200 ); setPaintOrder(ScoreKeeper. class , doodler. class ,Enemy. class ,enemy1. class ,Enemy2. class , Ground. class , Ammo. class ); //the order of which the object appear in world setBackground( "title.png" ); getBackground().setTransparency( 255 ); began = true ; started = false ; height = 0 ; fall = false ; hitEnemy = false ; ended = false ; } public void act() { if (gameStarted== false ) { instructions(); } if (gameStarted== false & Greenfoot.mouseMoved( this )) { gameStarted = true ; } if (started== false & gameStarted== true ) { MouseInfo mouse = Greenfoot.getMouseInfo(); if (Greenfoot.mouseClicked( this )) //if the mouse clicks in the given range the game will start { if (mouse.getX()>= 45 && mouse.getX()<= 148 && mouse.getY()>= 104 && mouse.getY()<= 138 ) { started = true ; } } } if (started== true & began== true ) //if both or true it clears all object on start screan and begins game on level one { setBackground( "paper.png" ); cleanup(); began = false ; setLevel( 1 ); } if (fall) //fall below the Ground platforms { end(); } if (hitEnemy) { end(); } if (--enemySpawnTimer == 0 ) //one the enemy timer hits zero it will spawn an enemy at a random X coordinate and 0 y coordinate { enemySpawnTimer = enemySpawnTimeMax; addObject( new Enemy(), Greenfoot.getRandomNumber( 290 ), - 50 ); } if (--enemy1SpawnTimer == 0 ) //same as before with different location (new enemy) { enemy1SpawnTimer = enemy1SpawnTimeMax; addObject( new enemy1(), Greenfoot.getRandomNumber( 35 )+ 2 , - 70 ); } if (--enemy2SpawnTimer == 0 ) //same as before with different location (new enemy) { enemy2SpawnTimer = enemy2SpawnTimeMax; addObject( new Enemy2(), Greenfoot.getRandomNumber( 240 ), - 30 ); } } public void cleanup() //will remove all objects from screen in any loose condition { removeObjects(getObjects(doodler. class )); removeObjects(getObjects(MovingGround. class )); removeObjects(getObjects(Ground. class )); removeObjects(getObjects(Enemy. class )); removeObjects(getObjects(StaticEnemy. class )); removeObjects(getObjects(StaticEnemy2. class )); } public void setLevel( int level) //sets the intial level to one { //LevelList levelList = new LevelList(); switch (level) { case 1 : gamePlay(); // first level gameplay break ; } } public void gamePlay() //puts all the Grounds below doodle so he won't fall then has randomly appearing Grounds for doodle to jump on { addObject( new doodler(), getWidth()/ 2 , 300 ); addObject( new Ground( false ), 28 , 391 ); addObject( new Ground( false ), 83 , 391 ); addObject( new Ground( false ), 83 + 55 , 391 ); addObject( new Ground( false ), 83 + 55 + 55 , 391 ); addObject( new Ground( false ), 83 + 55 + 55 + 55 , 391 ); addObject( new Ground( false ), 83 + 55 + 55 + 55 + 55 , 391 ); addObject( new Ground(), Greenfoot.getRandomNumber( 300 ), 260 ); addObject( new Ground(), Greenfoot.getRandomNumber( 300 ), 150 ); addObject( new Ground(), Greenfoot.getRandomNumber( 300 ), 50 ); //addObject(new MovingGround(), Greenfoot.getRandomNumber(300), -9); addObject( new ScoreKeeper(), 253 , 385 ); } public void instructions() { ArrayList<String> instructions = new ArrayList<String>(); instructions.add( "Avoid enemies" ); instructions.add( "Use Arrow Keys to Move" ); instructions.add( "Press spacebar to shoot" ); instructions.add( "" ); instructions.add( "" ); Integer i = 0 ; while (i< 3 ) { showText(instructions.get(i), 130 , 390 ); i++; Greenfoot.delay( 100 ); } } public void end() //clears all object from screen and displays a game over screen { cleanup(); addObject( new GameOver(),getWidth()/ 2 ,getHeight()/ 2 ); } } |