Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package inf112.skeleton.app.GUI.player;
- import com.badlogic.gdx.Input;
- import com.badlogic.gdx.math.Interpolation;
- import com.badlogic.gdx.scenes.scene2d.InputEvent;
- import com.badlogic.gdx.scenes.scene2d.InputListener;
- import com.badlogic.gdx.scenes.scene2d.actions.MoveByAction;
- import com.badlogic.gdx.scenes.scene2d.actions.RotateByAction;
- import inf112.skeleton.app.GUI.pieces.Robot;
- import inf112.skeleton.app.gameLogic.ProgramCard;
- import inf112.skeleton.app.gameLogic.enums.Direction;
- import java.util.List;
- import java.util.Stack;
- public class MovableRobot extends Robot {
- private int health;
- private final int maxHealth;
- private int damageTokens;
- private Direction dir;
- private Position pos;
- private Stack<ProgramCard> playerDeck;
- private List<ProgramCard> playerRegister;
- private MoveByAction moveAction = new MoveByAction();
- public MovableRobot(int robotnr, Position pos, Direction dir, int health){
- super(robotnr);
- this.pos = pos;
- this.dir = dir;
- this.health = health;
- this.maxHealth = health;
- this.damageTokens = 0;
- setBounds(getX(), getY(), getWidth(), getHeight());
- addListener(new InputListener() {
- @Override
- public boolean keyDown(InputEvent event, int keycode) {
- setOrigin(getWidth() / 2, getHeight() / 2);
- moveAction.setDuration(0.3f);
- RotateByAction rotateByAction = new RotateByAction();
- moveAction.setAmount(-getWidth(), 0f);
- moveAction.setInterpolation(Interpolation.pow3);
- switch (keycode) {
- case Input.Keys.RIGHT:
- moveAction.setAmount(getWidth(), 0f);
- break;
- case Input.Keys.LEFT:
- moveAction.setAmount(-getWidth(), 0);
- break;
- case Input.Keys.DOWN:
- moveAction.setAmount(0f, -getHeight());
- break;
- case Input.Keys.UP:
- moveAction.setAmount(0f, getHeight());
- break;
- }
- MovableRobot.this.addAction(moveAction);
- return true;
- }
- });
- }
- public void move() {
- moveAction.setAmount(0f, getHeight());
- MovableRobot.this.addAction(moveAction);
- }
- /**
- * Player gets one damageToken
- */
- public void takeDamage(int amountOfDamage) {
- if(damageTokens + amountOfDamage < 10){
- damageTokens+=amountOfDamage;
- } else {
- damageTokens = 0;
- health--;
- }
- }
- /**
- * Player loses a damageToken
- */
- public void repair() {
- if(damageTokens > 0){
- damageTokens--;
- }
- }
- /**
- * @return This piece's current health
- */
- public int getHealth() {
- return this.health;
- }
- /**
- * @return This piece's current amount of damageTokens
- */
- public int getDamageTokens() {
- return damageTokens;
- }
- /**
- * @return The direction this piece currently is facing
- */
- public Direction getDirection() {
- return this.dir;
- }
- public Position getPos() {
- return this.pos;
- }
- /**
- * @return true if piece's health is above 0, otherwise false
- */
- public boolean isAlive() {
- return this.health > 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement