Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. package sk.tuke.oop.game.actors;
  2.  
  3. import sk.tuke.oop.framework.Actor;
  4. import sk.tuke.oop.framework.Animation;
  5. import sk.tuke.oop.framework.Input;
  6. import sk.tuke.oop.framework.World;
  7. import sk.tuke.oop.game.commands.MoveDown;
  8. import sk.tuke.oop.game.commands.MoveLeft;
  9. import sk.tuke.oop.game.commands.MoveRight;
  10. import sk.tuke.oop.game.commands.MoveUp;
  11. import sk.tuke.oop.game.items.Energy;
  12.  
  13. public class Ripley implements Actor, Movable {
  14. private int x;
  15. private int y;
  16. private int width;
  17. private int height;
  18. private Animation playerAnimation;
  19. private World world;
  20. private String name;
  21. private MoveUp moveUp = new MoveUp(1);
  22. private MoveDown moveDown = new MoveDown(1);
  23. private MoveRight moveRight = new MoveRight(1);
  24. private MoveLeft moveLeft = new MoveLeft(1);
  25.  
  26. public Ripley() {
  27. this.x = 100;
  28. this.y = 100;
  29. this.playerAnimation = new Animation("resources/sprites/player.png", 32, 32, 100);
  30. this.playerAnimation.setPingPong(true);
  31. }
  32.  
  33. @Override
  34. public int getX() {
  35. return this.x;
  36. }
  37.  
  38. @Override
  39. public int getY() {
  40. return this.y;
  41. }
  42.  
  43. @Override
  44. public int getWidth() {
  45. return this.width;
  46. }
  47.  
  48. @Override
  49. public int getHeight() {
  50. return this.height;
  51. }
  52.  
  53. @Override
  54. public void setPosition(int x, int y) {
  55. this.x = x;
  56. this.y = y;
  57. }
  58.  
  59. @Override
  60. public Animation getAnimation() {
  61. return this.playerAnimation;
  62. }
  63.  
  64. @Override
  65. public void setAnimation(Animation animation) {
  66. this.playerAnimation = animation;
  67. }
  68.  
  69. @Override
  70. public void act() {
  71. for(Actor actor : getWorld())
  72. if(this.intersects(actor))
  73. System.out.println("haha");
  74. Input input = Input.getInstance();
  75. if(input.isKeyPressed(Input.Key.ESCAPE))
  76. System.exit(0);
  77. else if(input.isKeyDown(Input.Key.UP)) {
  78. this.moveUp.execute(this);
  79. }
  80. else if(input.isKeyDown(Input.Key.LEFT)) {
  81. this.moveLeft.execute(this);
  82. }
  83. else if(input.isKeyDown(Input.Key.RIGHT)) {
  84. this.moveRight.execute(this);
  85. }
  86. else if(input.isKeyDown(Input.Key.DOWN)) {
  87. this.moveDown.execute(this);
  88. }
  89. else
  90. this.playerAnimation.stop();
  91. }
  92.  
  93. @Override
  94. public boolean intersects(Actor actor) {
  95. if(Math.abs(this.x - actor.getX()) < this.getWidth() && Math.abs(this.y - actor.getY()) < this.getHeight())
  96. return true;
  97. else
  98. return false;
  99. }
  100.  
  101. @Override
  102. public void addedToWorld(World world) {
  103. this.world = world;
  104. }
  105.  
  106. @Override
  107. public World getWorld() {
  108. return this.world;
  109. }
  110.  
  111. @Override
  112. public String getName() {
  113. return this.name;
  114. }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement