RecklessDarph

Slime

May 14th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. package jumpingalien.model;
  2.  
  3. import java.util.HashSet;
  4. import java.util.Set;
  5. import jumpingalien.util.Sprite;
  6.  
  7. public class Slime extends Entity {
  8. public Slime(long id, int pixelLeftX, int pixelBottomY, School school, Sprite... sprites) throws Exception {
  9. super(pixelLeftX, pixelBottomY, sprites);
  10. setID(id);
  11. setSchool(school);
  12. setHitPoint(100);
  13. setOrientation(1);
  14. }
  15. public int walkX1=51;
  16. public int walkX2=50;
  17. public int walkY1=26;
  18. public int walkY2=28;
  19.  
  20. //Movement
  21. /**
  22. *
  23. * @param dt //FIXME zorg eerst dat het helemaal werkt
  24. *
  25. */
  26. public void Movement(double dt) {
  27.  
  28. //CollitionDetect
  29. //Bottom
  30. if(currentWorld.getGeologicalFeatures(super.getPixelPosition()[0]+(walkX1-1), super.getPixelPosition()[1])==1
  31. ||currentWorld.getGeologicalFeatures(super.getPixelPosition()[0]+(walkX2-1), super.getPixelPosition()[1])==1
  32. ){super.setActualPosition(super.getActualPosition()[0]+(super.getOrientation()*getVelocity()[0]*dt)+(getAcceleration()[0]*dt*dt), super.getActualPosition()[1]);}
  33. else {super.setActualPosition(super.getActualPosition()[0], (super.getActualPosition()[1]*getVelocity()[1]*dt)+((-10)*dt*dt));}
  34.  
  35. //Top
  36. if(currentWorld.getGeologicalFeatures(super.getPixelPosition()[0]+(walkX1-1), super.getPixelPosition()[1]+(walkY1-1))==1
  37. ||currentWorld.getGeologicalFeatures(super.getPixelPosition()[0]+(walkX2-1), super.getPixelPosition()[1]+(walkY2-1))==1
  38. ) {super.setActualPosition(super.getActualPosition()[0], super.getActualPosition()[1]+0.01);}
  39.  
  40. //RightSide
  41. if(currentWorld.getGeologicalFeatures(super.getPixelPosition()[0]+(walkX1-1), super.getPixelPosition()[1]+(walkY1-25))==1
  42. ||currentWorld.getGeologicalFeatures(super.getPixelPosition()[0]+(walkX2-1), super.getPixelPosition()[1]+(walkY2-26))==1
  43. ) {super.setActualPosition(super.getActualPosition()[0], super.getActualPosition()[1]+0.01);}
  44.  
  45. //LeftSide
  46. if(currentWorld.getGeologicalFeatures(super.getPixelPosition()[0], super.getPixelPosition()[1]+(walkY1-25))==1
  47. ||currentWorld.getGeologicalFeatures(super.getPixelPosition()[0], super.getPixelPosition()[1]+(walkY2-26))==1
  48. ) {super.setActualPosition(super.getActualPosition()[0], super.getActualPosition()[1]+0.01);}
  49. }
  50.  
  51. @Override
  52. /**
  53. * @param velocityx
  54. * @param velocityy
  55. * @post
  56. * |new.getVelocity()[0]==2.5
  57. * |new.getVelocity()[1]==0
  58. */
  59. public void setVelocity(double velocityx, double velocityY) {
  60. super.setVelocity(2.5, 0);
  61. }
  62.  
  63. //Velocity
  64. @Override
  65. /**
  66. *@return
  67. * |result==Velocity
  68. */
  69. public double[] getVelocity() {
  70. return Velocity; }
  71.  
  72. @Override
  73. /**
  74. * @param horizontal
  75. * @param vertical
  76. * @post..
  77. * |new.getAcceleration()[0]=0.7
  78. * |new.getAcceleration()[1]=veritical
  79. */
  80. public void setAcceleration(double horzontal, double vertical) {
  81. super.setAcceleration(0.7, vertical);
  82. }
  83.  
  84. /**
  85. *
  86. * @return..
  87. * |result==Acceleration
  88. */
  89. public double[] getAcceleration() {
  90. return Acceleration;}
  91.  
  92. //AdvancedTime//FIXME
  93. public void advanceTime(double time) {
  94. Movement(time);
  95. super.setActualPosition(super.getActualPosition()[0]+(super.getOrientation()*getVelocity()[0]*time)+(getAcceleration()[0]*time*time), super.getActualPosition()[1]);
  96.  
  97.  
  98.  
  99. }
  100.  
  101.  
  102. //Sprite
  103. /**
  104. *
  105. * @effect..
  106. * |if(super.getOrientation()==1) {return currentSprite=super.getSprites()[0];}
  107. * |else if(super.getOrientation()==-1) {return currentSprite=super.getSprites()[1];}
  108. * |else {return super.getSprites()[0];}
  109. */
  110. public Sprite getCurrentSprite() {
  111. if(super.getOrientation()==1) {return currentSprite=super.getSprites()[0];}
  112. else if(super.getOrientation()==-1) {return currentSprite=super.getSprites()[1];}
  113. else {return super.getSprites()[0];}
  114. }
  115.  
  116. public long ID;
  117. public static Set<Long> IdSet=new HashSet<Long>();
  118. /**
  119. *
  120. * @param id
  121. * @effect..
  122. * |ID=id
  123. */
  124. public void setID(long id) {
  125. ID=id;
  126. // IdSet.add(id);
  127. }
  128. /**
  129. * @post
  130. * |IdSet.size()==0
  131. */
  132. public static void CleanIdSet() {IdSet.clear();}
  133. /**
  134. *
  135. * @return
  136. * |result==ID
  137. */
  138. public long getID() {return ID;}
  139.  
  140. public School SCHOOL;
  141. /**
  142. *
  143. * @param school
  144. * @post
  145. * |new.getSchool()==school
  146. */
  147. public void setSchool(School school) {SCHOOL=school;}
  148. /**
  149. *
  150. * @return
  151. * |result==SCHOOOL
  152. */
  153. public School getSchool() {return SCHOOL;}
  154.  
  155.  
  156.  
  157. public void switchSchool(School newSchool) {
  158. // TODO Auto-generated method stub
  159.  
  160. }
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171. }
Advertisement
Add Comment
Please, Sign In to add comment