Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. package inf112.skeleton.app.GUI.player;
  2.  
  3. import com.badlogic.gdx.Input;
  4. import com.badlogic.gdx.math.Interpolation;
  5. import com.badlogic.gdx.scenes.scene2d.InputEvent;
  6. import com.badlogic.gdx.scenes.scene2d.InputListener;
  7. import com.badlogic.gdx.scenes.scene2d.actions.MoveByAction;
  8. import com.badlogic.gdx.scenes.scene2d.actions.RotateByAction;
  9. import inf112.skeleton.app.GUI.pieces.Robot;
  10. import inf112.skeleton.app.gameLogic.ProgramCard;
  11. import inf112.skeleton.app.gameLogic.enums.Direction;
  12.  
  13. import java.util.List;
  14. import java.util.Stack;
  15.  
  16. public class MovableRobot extends Robot {
  17.  
  18. private int health;
  19. private final int maxHealth;
  20. private int damageTokens;
  21. private Direction dir;
  22. private Position pos;
  23. private Stack<ProgramCard> playerDeck;
  24. private List<ProgramCard> playerRegister;
  25.  
  26. private MoveByAction moveAction = new MoveByAction();
  27.  
  28. public MovableRobot(int robotnr, Position pos, Direction dir, int health){
  29. super(robotnr);
  30. this.pos = pos;
  31. this.dir = dir;
  32. this.health = health;
  33. this.maxHealth = health;
  34. this.damageTokens = 0;
  35.  
  36. setBounds(getX(), getY(), getWidth(), getHeight());
  37.  
  38. addListener(new InputListener() {
  39. @Override
  40. public boolean keyDown(InputEvent event, int keycode) {
  41.  
  42.  
  43.  
  44.  
  45. setOrigin(getWidth() / 2, getHeight() / 2);
  46. moveAction.setDuration(0.3f);
  47.  
  48. RotateByAction rotateByAction = new RotateByAction();
  49.  
  50.  
  51. moveAction.setAmount(-getWidth(), 0f);
  52. moveAction.setInterpolation(Interpolation.pow3);
  53.  
  54.  
  55. switch (keycode) {
  56. case Input.Keys.RIGHT:
  57. moveAction.setAmount(getWidth(), 0f);
  58.  
  59. break;
  60. case Input.Keys.LEFT:
  61. moveAction.setAmount(-getWidth(), 0);
  62.  
  63. break;
  64. case Input.Keys.DOWN:
  65. moveAction.setAmount(0f, -getHeight());
  66.  
  67.  
  68. break;
  69. case Input.Keys.UP:
  70. moveAction.setAmount(0f, getHeight());
  71.  
  72.  
  73. break;
  74.  
  75.  
  76. }
  77. MovableRobot.this.addAction(moveAction);
  78.  
  79. return true;
  80. }
  81. });
  82. }
  83. public void move() {
  84. moveAction.setAmount(0f, getHeight());
  85. MovableRobot.this.addAction(moveAction);
  86. }
  87.  
  88.  
  89. /**
  90. * Player gets one damageToken
  91. */
  92. public void takeDamage(int amountOfDamage) {
  93. if(damageTokens + amountOfDamage < 10){
  94. damageTokens+=amountOfDamage;
  95. } else {
  96. damageTokens = 0;
  97. health--;
  98. }
  99. }
  100.  
  101. /**
  102. * Player loses a damageToken
  103. */
  104. public void repair() {
  105. if(damageTokens > 0){
  106. damageTokens--;
  107. }
  108. }
  109.  
  110.  
  111. /**
  112. * @return This piece's current health
  113. */
  114. public int getHealth() {
  115. return this.health;
  116. }
  117.  
  118.  
  119. /**
  120. * @return This piece's current amount of damageTokens
  121. */
  122. public int getDamageTokens() {
  123. return damageTokens;
  124. }
  125.  
  126. /**
  127. * @return The direction this piece currently is facing
  128. */
  129. public Direction getDirection() {
  130. return this.dir;
  131. }
  132.  
  133. public Position getPos() {
  134. return this.pos;
  135. }
  136.  
  137. /**
  138. * @return true if piece's health is above 0, otherwise false
  139. */
  140. public boolean isAlive() {
  141. return this.health > 0;
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement