Coverage Summary for Class: MenuInputHandler (com.mozarellabytes.kroy.Utilities)

Class Class, % Method, % Line, %
MenuInputHandler 0% (0/ 1) 0% (0/ 9) 0% (0/ 40)


1 package com.mozarellabytes.kroy.Utilities; 2  3 import com.badlogic.gdx.Gdx; 4 import com.badlogic.gdx.Input; 5 import com.badlogic.gdx.InputProcessor; 6 import com.badlogic.gdx.math.Vector2; 7 import com.badlogic.gdx.math.Vector3; 8 import com.mozarellabytes.kroy.Screens.MenuScreen; 9  10 public class MenuInputHandler implements InputProcessor { 11  12  private final MenuScreen menu; 13  14  /** Constructs the MenuInputHandler 15  * 16  * @param menu the menu screen that this input handler is controlling 17  */ 18  public MenuInputHandler(MenuScreen menu) { 19  this.menu = menu; 20  } 21  22  /** Exits the game if 'ESCAPE' key is pressed, goes to control 23  * screen if 'C' is pressed, toggles the sound if 'S' is pressed 24  * 25  * @param keycode one of the constants in {@link Input.Keys} 26  * @return whether the input was processed */ 27  @Override 28  public boolean keyDown(int keycode) { 29  switch (keycode) { 30  case Input.Keys.ESCAPE: 31  Gdx.app.exit(); 32  System.exit(1); 33  break; 34  case Input.Keys.C: 35  menu.clickedControlsButton(); 36  menu.toControlScreen(); 37  break; 38  case Input.Keys.S: 39  menu.clickedSoundButton(); 40  menu.changeSound(); 41  } 42  return true; 43  } 44  45  @Override 46  public boolean keyUp(int keycode) { 47  if (keycode == Input.Keys.A) { 48  SoundFX.sfx_truck_attack.stop(); 49  } 50  return true; 51  } 52  53  @Override 54  public boolean keyTyped(char character) { 55  return false; 56  } 57  58  /** Checks if the user clicks on the start, controls or sound button. 59  * It starts the game, shows the controls screen or toggles the sound 60  * respectively. 61  * @param screenX The x coordinate, origin is in the upper left corner 62  * @param screenY The y coordinate, origin is in the upper left corner 63  * @param pointer the pointer for the event. 64  * @param button the button 65  * @return the input was processed */ 66  @Override 67  public boolean touchDown(int screenX, int screenY, int pointer, int button) { 68  Vector2 clickCoordinates = new Vector2(screenX, screenY); 69  Vector3 position = menu.camera.unproject(new Vector3(clickCoordinates.x, clickCoordinates.y, 0)); 70  if (menu.getStartButton().contains(position.x, position.y)) { 71  menu.clickedStartButton(); 72  } else if (menu.getControlsButton().contains(position.x, position.y)) { 73  menu.clickedControlsButton(); 74  } else if (menu.getSoundButton().contains(position.x, position.y)) { 75  menu.clickedSoundButton(); 76  } 77  return true; 78  } 79  80  /** Executes the action according to the button clicked by the user. 81  * i.e. if the user clicks down on the Start button but lifts their 82  * click somewhere else, the game will not start. 83  * @param screenX The x coordinate, origin is in the upper left corner 84  * @param screenY The y coordinate, origin is in the upper left corner 85  * @param pointer the pointer for the event. 86  * @param button the button 87  * @return the input was processed */ 88  @Override 89  public boolean touchUp(int screenX, int screenY, int pointer, int button) { 90  Vector2 clickCoordinates = new Vector2(screenX, screenY); 91  Vector3 position = menu.camera.unproject(new Vector3(clickCoordinates.x, clickCoordinates.y, 0)); 92  if (menu.getStartButton().contains(position.x, position.y)) { 93  menu.toGameScreen(); 94  } else if (menu.getControlsButton().contains(position.x, position.y)) { 95  menu.toControlScreen(); 96  } else if (menu.getSoundButton().contains(position.x, position.y)){ 97  menu.changeSound(); 98  } else { 99  menu.idleStartButton(); 100  menu.idleControlsButton(); 101  menu.idleSoundButton(); 102  } 103  return true; 104  } 105  106  @Override 107  public boolean touchDragged(int screenX, int screenY, int pointer) { 108  return false; 109  } 110  111  @Override 112  public boolean mouseMoved(int screenX, int screenY) { 113  return false; 114  } 115  116  117  @Override 118  public boolean scrolled(int amount) { 119  return false; 120  } 121 }