Advertisement
Guest User

Player.java

a guest
Jul 6th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. public class Player {
  2. private static String tex;
  3. private static float x;
  4. private static float y;
  5. private static float width;
  6. private static float height;
  7. private static float speed;
  8. private static ArrayList<Player> Players;
  9.  
  10.  
  11.  
  12.  
  13. public Player (String tex, float speed, float x, float y, float width, float height){
  14.  
  15. Player.tex = tex;
  16. Player.x = x;
  17. Player.y = y;
  18. Player.width = width;
  19. Player.height = height;
  20. Player.speed = speed;
  21. this.setPlayers(new ArrayList<Player>());
  22. Players.add(this);
  23.  
  24.  
  25. }
  26.  
  27.  
  28. public static int Direction = 2;
  29. public static boolean Moving = false;
  30. public static boolean start = false;
  31.  
  32. public static void handlePlayer(){
  33. for(Player p: Players){
  34. Player.Update();
  35. Player.draw();
  36. }
  37. }
  38.  
  39. public static void Walk(){
  40. if(start == false){
  41. start = true;
  42. Moving = false;
  43. }
  44. if(Direction == 0 && Moving == true ){
  45. System.out.println("Walking North");
  46. getPlayers().get(0).setY(y -= speed * Time.Delta());
  47. }
  48. if(Direction == 1 && Moving == true ){
  49. System.out.println("Walking East");
  50. getPlayers().get(0).setX(x += speed * Time.Delta());
  51.  
  52. }
  53. if(Direction == 2 && Moving == true ){
  54. System.out.println("Walking South");
  55. getPlayers().get(0).setY(y += speed * Time.Delta());
  56. }
  57. if(Direction == 3 && Moving == true ){
  58. System.out.println("Walking West");
  59. getPlayers().get(0).setX(x -= speed * Time.Delta());
  60. }
  61. if(Direction == 0 && Moving == false ){
  62. System.out.println("Standing North");
  63. }
  64. if(Direction == 1 && Moving == false ){
  65. System.out.println("Standing East");
  66. }
  67. if(Direction == 2 && Moving == false ){
  68. System.out.println("Standing South");
  69. }
  70. if(Direction == 3 && Moving == false ){
  71. System.out.println("Standing West");
  72. }
  73. }
  74. public static void Inputs(){
  75. if(Keyboard.isKeyDown(Keyboard.KEY_W)){
  76. Direction = 0;
  77. Moving = true;
  78. }
  79. if(Keyboard.isKeyDown(Keyboard.KEY_D)){
  80. Direction = 1;
  81. Moving = true;
  82. }
  83. if(Keyboard.isKeyDown(Keyboard.KEY_S)){
  84. Direction = 2;
  85. Moving = true;
  86. }
  87. if(Keyboard.isKeyDown(Keyboard.KEY_A)){
  88. Direction = 3;
  89. Moving = true;
  90. }
  91. if(!Keyboard.isKeyDown(Keyboard.KEY_W) && !Keyboard.isKeyDown(Keyboard.KEY_D) && !Keyboard.isKeyDown(Keyboard.KEY_S) && !Keyboard.isKeyDown(Keyboard.KEY_A)){
  92. Moving = false;
  93. }
  94. }
  95.  
  96. public static void draw(){
  97. Draw.DrawQuadTex(Draw.QuickLoadTexture(tex), x, y, width, height);
  98. }
  99.  
  100.  
  101.  
  102. public static void Update(){
  103. System.out.println(getPlayers().get(0).getX() + "x" + getPlayers().get(0).getY() + "y");
  104. Inputs();
  105. Walk();
  106. }
  107. public String getTex() {
  108. return tex;
  109. }
  110. public void setTex(String tex) {
  111. Player.tex = tex;
  112. }
  113. public float getX() {
  114. return x;
  115. }
  116. public void setX(float x) {
  117. Player.x = x;
  118. }
  119. public float getY() {
  120. return y;
  121. }
  122. public void setY(float y) {
  123. Player.y = y;
  124. }
  125. public float getWidth() {
  126. return width;
  127. }
  128. public void setWidth(float width) {
  129. Player.width = width;
  130. }
  131. public float getHeight() {
  132. return height;
  133. }
  134. public void setHeight(float height) {
  135. Player.height = height;
  136. }
  137. public static ArrayList<Player> getPlayers() {
  138. return Players;
  139. }
  140. public void setPlayers(ArrayList<Player> players) {
  141. Players = players;
  142. }
  143.  
  144.  
  145.  
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement