Coverage Summary for Class: ControlsScreen (com.mozarellabytes.kroy.Screens)

Class Class, % Method, % Line, %
ControlsScreen 0% (0/ 1) 0% (0/ 11) 0% (0/ 112)


1 package com.mozarellabytes.kroy.Screens; 2  3 import com.badlogic.gdx.Gdx; 4 import com.badlogic.gdx.Screen; 5 import com.badlogic.gdx.graphics.Color; 6 import com.badlogic.gdx.graphics.OrthographicCamera; 7 import com.badlogic.gdx.graphics.Texture; 8 import com.badlogic.gdx.graphics.glutils.ShapeRenderer; 9 import com.mozarellabytes.kroy.Kroy; 10 import com.mozarellabytes.kroy.Utilities.*; 11  12 import java.awt.*; 13  14 /** This screen shows the games controls including dragging the 15  * fire truck to move it and pressing 'A' to attack the fortresses */ 16  17 public class ControlsScreen implements Screen { 18  19  private final Kroy game; 20  21  /** The image displayed as the background behind the control screen */ 22  private Texture backgroundImage; 23  24  /** The tile that shows the truck's path */ 25  private final Texture trailImage; 26  27  /** The tile that shows the end of the truck's path */ 28  private final Texture trailEndImage; 29  30  /** Sprite of a truck facing to the right */ 31  private final Texture truckRight; 32  33  /** Sprite of a truck facing to the left */ 34  private final Texture truckLeft; 35  36  /** Sprite of a fortress */ 37  private final Texture fortress; 38  39  /** Camera to set the projection for the screen */ 40  public final OrthographicCamera camera; 41  42  /** Rectangle containing the exit buttons coordinates */ 43  private final Rectangle exitButton; 44  45  /** The HP of the fortress, helps animate the fortress */ 46  private int HP; 47  48  /** Counter to reset the fortresses health bar */ 49  private int count; 50  51  /** The name of the screen that called the control screen, 52  * used to determine the background image */ 53  private final String screen; 54  55  /** Width of the screen */ 56  private final float screenWidth; 57  58  /** Height of the screen */ 59  private final float screenHeight; 60  61  /** Screen that called the control screen - the screen 62  * to return to after the control screen has been exited */ 63  private final Screen parent; 64  65  66  /** Constructor for the Control screen 67  * @param game LibGdx game 68  * @param parent the screen that called the control screen 69  * @param screen the name of the screen that called the control screen*/ 70  public ControlsScreen(Kroy game, Screen parent, String screen) { 71  this.game = game; 72  this.parent = parent; 73  this.screen = screen; 74  75  camera = new OrthographicCamera(); 76  camera.setToOrtho(false, Gdx.graphics.getDisplayMode().width, Gdx.graphics.getDisplayMode().height); 77  78  screenWidth = camera.viewportWidth; 79  screenHeight = camera.viewportHeight; 80  81  Gdx.input.setInputProcessor(new ControlScreenInputHandler(this)); 82  if (screen.equals("menu")) { 83  backgroundImage = new Texture(Gdx.files.internal("menuscreen_blank_2.png"), true); 84  } else if (screen.equals("game")) { 85  backgroundImage = new Texture(Gdx.files.internal("images/YorkMapEdit.png"), true); 86  } 87  88  backgroundImage.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.MipMapLinearNearest); 89  90  trailImage = new Texture(Gdx.files.internal("sprites/firetruck/trail.png"), true); 91  trailEndImage = new Texture(Gdx.files.internal("sprites/firetruck/trailEnd.png"), true); 92  93  truckRight = new Texture(Gdx.files.internal("sprites/firetruck/right.png"), true); 94  truckLeft = new Texture(Gdx.files.internal("sprites/firetruck/left.png"), true); 95  96  fortress = new Texture(Gdx.files.internal("sprites/fortress/fortress.png"), true); 97  98  HP = 200; 99  count = 0; 100  101  exitButton = new Rectangle(); 102  exitButton.x = 1185; 103  exitButton.y = (int) (camera.viewportHeight - 90); 104  exitButton.width = (int)(screenWidth / 1.08f); 105  exitButton.height = (int)(screenHeight / 1.126f); 106  } 107  108  @Override 109  public void show() { 110  111  } 112  113  /** Renders the control screen including explaining how to move 114  * the firetrucks and attack the fortresses 115  * 116  * @param delta The time in seconds since the last render. */ 117  @Override 118  public void render(float delta) { 119  120  camera.update(); 121  game.batch.setProjectionMatrix(camera.combined); 122  123  camera.update(); 124  game.batch.setProjectionMatrix(camera.combined); 125  126  drawBackgroundImage(); 127  drawFilledBackgroundBox(); 128  129  game.batch.begin(); 130  131  game.font50.draw(game.batch, "Control screen", screenWidth / 2.8f, screenHeight / 1.1678f); 132  game.font25.draw(game.batch, "Flood the fortresses before the fortresses destroy your fire trucks to win", (screenWidth / 2) - (36 * 15),screenHeight / 1.29f); 133  game.font33.draw(game.batch, "Moving the Fire Trucks", screenWidth / 8.33f, screenHeight * 0.6875f); 134  game.font25.draw(game.batch, "Click on a truck and drag it", screenWidth / 7.692f,screenHeight * 0.6125f); 135  game.font25.draw(game.batch, "This gives the truck a path:", screenWidth / 7.692f,screenHeight * 0.56875f); 136  game.font25.draw(game.batch, "Unclick and the truck will", screenWidth / 7.692f,screenHeight * 0.3815f); 137  game.font25.draw(game.batch, "follow the path", screenWidth / 7.692f,screenHeight * 0.34375f); 138  139  game.batch.setColor(Color.CYAN); 140  float startPos = screenWidth / 7.11f; 141  float height = screenHeight / 2.2857f; 142  game.batch.draw(trailImage, startPos,screenHeight / 2.2857f); 143  game.batch.draw(trailImage, startPos + trailImage.getWidth() + 2, height); 144  game.batch.draw(trailImage, startPos + trailImage.getWidth() * 2 + 4, height); 145  game.batch.draw(trailImage, startPos + trailImage.getWidth() * 3 + 6, height); 146  game.batch.draw(trailImage, startPos + trailImage.getWidth() * 4 + 8, height); 147  game.batch.draw(trailImage, startPos + trailImage.getWidth() * 5 + 10, height); 148  game.batch.draw(trailImage, startPos + trailImage.getWidth() * 6 + 12, height); 149  game.batch.draw(trailEndImage, startPos + trailImage.getWidth() * 6 + 12, height); 150  151  game.font25.draw(game.batch, "Or click and drag from the", screenWidth / 7.76f,screenHeight / 3.81f); 152  game.font25.draw(game.batch, "end of the trucks path", screenWidth / 7.76f,screenHeight / 4.57f); 153  154  game.batch.draw(trailImage, screenWidth / 3.37f, screenHeight / 8.89f); 155  game.batch.draw(trailEndImage, screenWidth / 3.37f, screenHeight / 8.89f); 156  157  game.batch.setColor(Color.RED); 158  game.batch.draw(trailImage, screenWidth / 4.74f, screenHeight / 8.89f); 159  game.batch.draw(trailEndImage, screenWidth / 4.74f, screenHeight / 8.89f); 160  161  game.font33.draw(game.batch, "Attacking the fortresses", screenWidth / 1.88f, screenHeight * 0.6875f); 162  game.font25.draw(game.batch, "When a firetruck is within range ", screenWidth / 1.87f,screenHeight * 0.6125f); 163  game.font25.draw(game.batch, "of a fortress press A to attack", screenWidth / 1.87f,screenHeight * 0.56875f); 164  165  game.batch.setColor(Color.WHITE); 166  game.batch.draw(truckRight, screenWidth / 7.44f, screenHeight / 2.33f); 167  game.batch.draw(fortress,screenWidth / 1.62f, screenHeight / 6.15f); 168  game.batch.draw(truckLeft,screenWidth / 1.23f, screenHeight / 4.21f); 169  170  game.batch.end(); 171  172  damageFortressHP(); 173  drawFortressHealthBar(); 174  175  renderExitButton(); 176  177  } 178  179  @Override 180  public void resize(int width, int height) { 181  182  } 183  184  @Override 185  public void pause() { 186  187  } 188  189  @Override 190  public void resume() { 191  192  } 193  194  @Override 195  public void hide() { 196  197  } 198  199  /** Called when this screen should release all resources. */ 200  @Override 201  public void dispose() { 202  fortress.dispose(); 203  trailImage.dispose(); 204  trailEndImage.dispose(); 205  truckRight.dispose(); 206  truckLeft.dispose(); 207  } 208  209  210  /** Changes the screen back to the screen that called the 211  * control screen */ 212  public void changeScreen() { 213  if (this.screen.equals("game")) { 214  GUI gui = new GUI(game, (GameScreen) parent); 215  Gdx.input.setInputProcessor(new GameInputHandler((GameScreen) parent, gui)); 216  gui.idleInfoButton(); 217  this.game.setScreen(parent); 218  } else if (this.screen.equals("menu")){ 219  Gdx.input.setInputProcessor(new MenuInputHandler((MenuScreen)parent)); 220  this.game.setScreen(parent); 221  } 222  } 223  224  /** Draws the image being shown behind the controls panel */ 225  private void drawBackgroundImage(){ 226  game.batch.begin(); 227  game.batch.draw(backgroundImage, 0, 0, camera.viewportWidth, camera.viewportHeight); 228  game.batch.end(); 229  } 230  231  /** Draws the black rectangle over which the controls are shown */ 232  private void drawFilledBackgroundBox(){ 233  game.shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); 234  game.shapeRenderer.rect(screenWidth / 25.6f,screenHeight / 16, screenWidth / 1.085f , screenHeight / 1.14f, Color.BLACK, Color.BLACK,Color.BLACK, Color.BLACK); 235  game.shapeRenderer.end(); 236  } 237  238  /** Function causing damage to the fortress to deplete 239  * it's health bar */ 240  private void damageFortressHP() { 241  if (HP == 0) { 242  HP = 200; 243  } else { 244  HP--; 245  } 246  } 247  248  /** This draws the fortresses health bar */ 249  private void drawFortressHealthBar(){ 250  251  game.shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); 252  game.shapeRenderer.rect(screenWidth / 1.4713f, screenHeight / 2.58f, 35, 60); 253  game.shapeRenderer.rect(screenWidth / 1.4629f, screenHeight / 2.5297f, 24, 50, Color.FIREBRICK, Color.FIREBRICK, Color.FIREBRICK, Color.FIREBRICK); 254  game.shapeRenderer.rect(screenWidth / 1.4629f, screenHeight / 2.5297f, 24, HP / 4f, Color.RED, Color.RED, Color.RED, Color.RED); 255  game.shapeRenderer.end(); 256  257  if (count <= 30) { 258  drawFireTruckAttacking(); 259  } else if (count == 60){ 260  count = 0; 261  } 262  count++; 263  } 264  265  /** This draws the 'A' above the fire truck */ 266  private void drawFireTruckAttacking(){ 267  game.batch.begin(); 268  game.font33.draw(game.batch, "A", screenWidth / 1.205f, screenHeight /2.81f); 269  game.batch.end(); 270  } 271  272  273  /** Renders the exit button */ 274  private void renderExitButton(){ 275  game.shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); 276  game.shapeRenderer.rect(screenWidth / 1.08f, screenHeight / 1.126f, 30, 30, Color.FIREBRICK, Color.FIREBRICK, Color.FIREBRICK, Color.FIREBRICK); 277  game.shapeRenderer.rect(screenWidth / 1.078f, screenHeight / 1.123f, 26, 26, Color.RED, Color.RED, Color.RED, Color.RED); 278  game.shapeRenderer.end(); 279  280  game.batch.begin(); 281  game.font33Red.draw(game.batch, "X", screenWidth / 1.074f, screenHeight / 1.09f); 282  game.batch.end(); 283  } 284  285  public Rectangle getExitButton() { 286  return this.exitButton; 287  } 288  289 }