Advertisement
RedVinck

Entity

May 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.64 KB | None | 0 0
  1. package jumpingalien.model;
  2.  
  3. import be.kuleuven.cs.som.annotate.*;
  4. //import jdk.nashorn.internal.ir.SetSplitState;
  5. import jumpingalien.util.Sprite;
  6.  
  7.  
  8. /**
  9. * A class for making the Entity file.
  10. *
  11. * @version 1.0
  12. * @author Thierry Klougbo & Jordi De Pau
  13. *
  14. * @invar Each Mazub can have its time as time.
  15. * | canHaveAstime(this.gettime())
  16. */
  17. public class Entity {
  18. // Consttructor Settings
  19. /**
  20. * Constructor for all kinds of Plants and Sharks. //FIXME moet hier @Post bij?
  21. * @param pixelX
  22. * @param pixelY
  23. * @param sprites
  24. * @throws Exception
  25. */
  26. public Entity(int pixelX,int pixelY, Sprite...sprites) throws Exception {
  27. setActualPosition(calculateToActual(pixelX), calculateToActual(pixelY));
  28. setSprites(sprites);
  29. }
  30. /**
  31. * Constructor for Slimes
  32. * @param id
  33. * @param pixelX
  34. * @param pixelY
  35. * @param school
  36. * @param sprites
  37. * @throws Exception
  38. */
  39. public Entity(long id, int pixelX, int pixelY, School school, Sprite... sprites) throws Exception {
  40. setPixelPosition(pixelX, pixelY);
  41. setActualPosition(pixelX/100, pixelY/100);
  42. setSprites(sprites);
  43. }
  44.  
  45. //FIXME weet niet of object buiten weereld mag worden gezet.
  46. /*
  47. *************
  48. ** Position *
  49. *************/
  50. /**
  51. * The actual positon of Objects.
  52. */
  53. public double[] actualPosition=new double[2];
  54. /**
  55. *
  56. * @param newPosition
  57. * @post ...
  58. * |new.getActualPosition() == newPosition
  59. */
  60. public void changeActualPosition(double[] newPosition) throws Exception {actualPosition = newPosition;}
  61.  
  62. /**
  63. *
  64. * @param x
  65. * @param y
  66. * @post...
  67. * |new.getActualPotion()[0]==x && new.getActualPostion()[1]==y
  68. * |new.getPisxelPostione()[0]==(int)(getActualPosition()[0]*100) && new.getPisxelPostione()[1]== (int)(getActualPosition()[1]*100)
  69. */
  70. public void setActualPosition(double x, double y) {
  71. actualPosition[0]=x;actualPosition[1]=y;
  72. setPixelPosition(calculateToPixel(x),calculateToPixel(y));
  73. }
  74. /**
  75. *
  76. * @return..
  77. * |result == actualPosition
  78. */
  79. public double[] getActualPosition() {return actualPosition;}
  80.  
  81. /**
  82. * The pixel postion of the objects
  83. */
  84. public int[] pixelPosition=new int[2];
  85. /**
  86. *
  87. * @param newPosition
  88. * @post...
  89. * |new.getPixelPostion== newPositon
  90. */
  91. public void changePixelPosition(int[] newPosition) {
  92. pixelPosition = newPosition;
  93. }
  94.  
  95. /**
  96. *
  97. * @param pixelLeftX
  98. * @param pixelBottomY
  99. * @post...
  100. * |new.getPixelPostion[0]==pixleLeftX
  101. * |new.getPixelPostion[1]==pixelBottomY
  102. */
  103. public void setPixelPosition(int pixelLeftX, int pixelBottomY) {
  104. pixelPosition[0] = pixelLeftX; pixelPosition[1]=pixelBottomY;
  105. // pixelPosition[0] = (int)(getActualPosition()[0]*100); pixelPosition[1]= (int)(getActualPosition()[1]*100);
  106. }
  107. /**
  108. *
  109. * @return...
  110. * |result==pixelPostion
  111. */
  112. public int[] getPixelPosition() { return pixelPosition;}
  113.  
  114. /*
  115. ****************
  116. * Orientation *
  117. ****************
  118. */
  119. public int Orientation;
  120.  
  121. /**
  122. *
  123. * @param cURRENT_ORIENTATION
  124. * The current orientation of Mazub.
  125. * @pre cURRENT_ORIENTATION must be 1 or -1
  126. * |(cURRENT_ORIENTATION==-1)||(cURRENT_ORIENTATION==1)
  127. * @pre..
  128. * |Orientation==1 ||
  129. * |Orientation==-1
  130. * @post ..
  131. * |new.CURRENT_ORIENTATION = cURRENT_ORIENTATION
  132. */
  133. public void setOrientation(int cURRENT_ORIENTATION) {
  134. Orientation = cURRENT_ORIENTATION;}
  135.  
  136. /**
  137. *
  138. * @return
  139. * |result==CURRENT_ORIENTATION
  140. */
  141. public int getOrientation() {return Orientation;}
  142.  
  143. /*
  144. ************
  145. * Velocity *
  146. ************
  147. */
  148. /**
  149. * The Velocity of gameobjects.
  150. */
  151. public double[] Velocity= new double[2];
  152. /**
  153. * The acceleration of gameobjects.
  154. */
  155. public double[] Acceleration=new double[2];
  156. /**
  157. *
  158. * @param velocityx
  159. * @param velocityY
  160. * @post...
  161. * |new.getVelocity[0]
  162. */
  163. public void setVelocity(double velocityx, double velocityY){Velocity[0]=velocityx; Velocity[1]=velocityY;}
  164.  
  165. /**
  166. *
  167. * @return...
  168. * |result== Velocity
  169. */
  170. public double[] getVelocity() {return Velocity;}
  171. /**
  172. *
  173. * @param horzintel
  174. * @param vertical
  175. * @post...
  176. * |new.getAcceleration[0]==horizontal &&
  177. * |new.getAcceleration[1]==vertical
  178. */
  179. public void setAcceleration(double horzontal,double vertical) {
  180. Acceleration[0] = horzontal;
  181. Acceleration[1] = vertical;}
  182.  
  183. public double[] getAcceleration() {
  184. return Acceleration;
  185. }
  186.  
  187. /*
  188. ************
  189. * Movement *
  190. ************
  191. */
  192. /**
  193. * @post...
  194. * |new.getOrientation==-1
  195. */
  196. public void startMoveLeft(){setOrientation(-1);}
  197. /**
  198. * @post...
  199. * |new.getOrientation==-1
  200. */
  201. public void startMoveRight(){setOrientation(1);}
  202.  
  203. //FIXME zien of het in elke classe hetzelfde doet.
  204. public void startMovement2() { }
  205.  
  206. public void startMovement1() { }
  207. /**
  208. * @post...
  209. * |new.getOrientation==0
  210. */
  211. public void endMove() {setOrientation(0);}
  212.  
  213. /*
  214. **************
  215. * Terminated *
  216. **************
  217. */
  218. /**
  219. * Parameter storing the hitpoints of gameobjects
  220. */
  221. public int Hitpoint;
  222. /**
  223. *
  224. * @param hitpoint
  225. * @post...
  226. * |new.getHitpoint==hitpoint
  227. */
  228. public void setHitPoint(int hitpoint) {
  229. Hitpoint += hitpoint;
  230. }
  231. /**
  232. *
  233. * @return...
  234. * |result==Hitpoint
  235. */
  236. public int getHitpoint() {return Hitpoint;}
  237.  
  238. // AdvancedTime Settings
  239. public double deathTime=0;
  240. /**
  241. *
  242. * @param dt
  243. * @throws Exception
  244. * @post...
  245. * |if(isDeadGameObject()){isTerminatedGameObject()==true}//FIXME weet niet of het echt zo moet worden geschreven.
  246. */
  247. public void advanceTime(double dt) throws Exception {
  248. if(isDeadGameObject()) {
  249. deathTime=dt;
  250. if(dt==deathTime+0.6) {
  251. terminateGameObject();
  252. }
  253.  
  254. }
  255. }
  256.  
  257.  
  258. public void terminateGameObject() {
  259. removeWorld();
  260. }
  261.  
  262. /*
  263. *********************
  264. * Sprites of Entity*
  265. *********************
  266. */
  267. public Sprite[] Sprites;
  268. /**
  269. *
  270. * @param spritess
  271. * @throws Exception
  272. * |spritess.length <= 0
  273. * @post...
  274. * |new.getSprites==spritess
  275. */
  276. public void setSprites(Sprite[] spritess) throws Exception {
  277. if(spritess == null) {throw new Exception("Not effective Sprites");}
  278. for (int i = 0; i < spritess.length; i++) {
  279. if(spritess[i]==null) {throw new Exception("Invalid sprites we don't like sprites with null values.");}}
  280. if(spritess.length > 0) {this.Sprites = spritess;}
  281. else {throw new Exception("illegalArgument Sprites");}
  282. }
  283. /**
  284. *
  285. * @return...
  286. * |result==Sprites
  287. */
  288. public Sprite[] getSprites() {return Sprites;}
  289.  
  290. public Sprite currentSprite;
  291. /**
  292. *
  293. * @return...
  294. * |result==null
  295. */
  296. public Sprite getCurrentSprite() {
  297. return Sprites[0];
  298. }
  299.  
  300.  
  301. /*
  302. ************
  303. * Terminate*
  304. ************
  305. */
  306. /**FIXME SORRY
  307. * @post...
  308. * |getWorld==null
  309. * @post...
  310. * |!(world.hasAsGameObject)
  311. */
  312. public void terminateGameObject(Entity currentEntity){
  313. if(getWorld() !=null) {getWorld().removeGameObject(currentEntity);}
  314. removeWorld();}
  315.  
  316. public boolean Terminated=false;
  317. /** FIXME SORRY
  318. *
  319. * @param gameObject
  320. * @return...
  321. * |result==true ||
  322. * |result==false
  323. */
  324.  
  325. public boolean isTerminatedGameObject() {
  326. if(getWorld()==null) {return true;}
  327. else {return false; }}
  328.  
  329.  
  330. /**
  331. *
  332. * @return...
  333. * |result==true ||
  334. * |result==false
  335. */
  336. public boolean isDeadGameObject() {
  337. if(getHitpoint()<= 0) { return true;}
  338. else {return false;}
  339. }
  340. /*
  341. ************
  342. * Get World*
  343. ************
  344. *
  345. */
  346. World currentWorld;
  347. public void falling() {}
  348. /**
  349. *
  350. * @param world
  351. * @post...
  352. * |getWorld==world
  353. */
  354. public void setWorld(World world) {
  355. currentWorld = world;
  356. }
  357.  
  358. /**
  359. *
  360. * @return..
  361. * |result==currentWorld
  362. */
  363. public World getWorld() {
  364. return currentWorld;
  365. }
  366. /*
  367. ************
  368. * Collision*
  369. ************
  370. *
  371. */
  372.  
  373. public int calculateToPixel (double actual) {return ((int)(actual*100));}
  374. public double calculateToActual (int pixel) {return (((double)pixel)/100);}
  375. public void addHitPoint(int hitsChanged) {
  376. setHitPoint(getHitpoint()+hitsChanged);
  377.  
  378. }
  379. public void endJump() {
  380. // TODO Auto-generated method stub
  381.  
  382. }
  383. public void removeWorld() {
  384. currentWorld = null;
  385.  
  386. }
  387. public void stopDuckingIsEnabled() {
  388. // TODO Auto-generated method stub
  389.  
  390. }
  391.  
  392.  
  393. /*
  394. * TerminateGameObject
  395. * isTerminatedGameObject
  396. */
  397.  
  398. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement