RecklessDarph

Entity

Apr 29th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.14 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. setPixelPosition(pixelX, pixelY);
  28. setActualPosition((double)(pixelX/100), (double) (pixelY/100));
  29. setSprites(sprites);
  30. }
  31. /**
  32. * Constructor for Slimes
  33. * @param id
  34. * @param pixelX
  35. * @param pixelY
  36. * @param school
  37. * @param sprites
  38. * @throws Exception
  39. */
  40. public Entity(long id, int pixelX, int pixelY, School school, Sprite... sprites) throws Exception {
  41. setPixelPosition(pixelX, pixelY);
  42. setActualPosition((double)(pixelX/100), (double) (pixelY/100));
  43. setSprites(sprites);
  44. }
  45.  
  46. //FIXME weet niet of object buiten weereld mag worden gezet.
  47. /*
  48. *************
  49. ** Position *
  50. *************/
  51. /**
  52. * The actual positon of Objects.
  53. */
  54. public double[] actualPosition=new double[2];
  55. /**
  56. *
  57. * @param newPosition
  58. * @post ...
  59. * |new.getActualPosition() == newPosition
  60. */
  61. public void changeActualPosition(double[] newPosition) throws Exception {
  62. if(currentWorld.getGeologicalFeatures((int)(newPosition[0]*100), (int)(newPosition[1]*100))==1
  63. ||currentWorld.getGeologicalFeatures((int)(newPosition[0]*100), (int)(newPosition[1]*100))==5) {throw new Exception();}
  64. actualPosition = newPosition;}
  65.  
  66. /**
  67. *
  68. * @param x
  69. * @param y
  70. * @post...
  71. * |new.getActualPotion()[0]==x && new.getActualPostion()[1]==y
  72. * |new.getPisxelPostione()[0]==(int)(getActualPosition()[0]*100) && new.getPisxelPostione()[1]== (int)(getActualPosition()[1]*100)
  73. */
  74. public void setActualPosition(double x, double y) {
  75. actualPosition[0]=x; actualPosition[1]=y;
  76. // setPixelPosition((int)(x*100),(int)(y*100));
  77. pixelPosition[0]=(int)(getActualPosition()[0]*100); pixelPosition[1]=(int)(getActualPosition()[1]*100);
  78. }
  79. /**
  80. *
  81. * @return..
  82. * |result == actualPosition
  83. */
  84. public double[] getActualPosition() {return actualPosition;}
  85.  
  86. /**
  87. * The pixel postion of the objects
  88. */
  89. public int[] pixelPosition=new int[2];
  90. /**
  91. *
  92. * @param newPosition
  93. * @post...
  94. * |new.getPixelPostion== newPositon
  95. */
  96. public void changePixelPosition(int[] newPosition) throws Exception {
  97. pixelPosition = newPosition;
  98. setActualPosition((double)(newPosition[0]/100), (double)(newPosition[1]/100));
  99. }
  100.  
  101. /**
  102. *
  103. * @param pixelLeftX
  104. * @param pixelBottomY
  105. * @post...
  106. * |new.getPixelPostion[0]==pixleLeftX
  107. * |new.getPixelPostion[1]==pixelBottomY
  108. */
  109. public void setPixelPosition(int pixelLeftX, int pixelBottomY) {
  110. pixelPosition[0] = pixelLeftX; pixelPosition[1]=pixelBottomY;
  111. }
  112. /**
  113. *
  114. * @return...
  115. * |result==pixelPostion
  116. */
  117. public int[] getPixelPosition() { return pixelPosition;}
  118.  
  119. /*
  120. ****************
  121. * Orientation *
  122. ****************
  123. */
  124. public int Orientation;
  125.  
  126. /**
  127. *
  128. * @param cURRENT_ORIENTATION
  129. * The current orientation of Mazub.
  130. * @pre cURRENT_ORIENTATION must be 1 or -1
  131. * |(cURRENT_ORIENTATION==-1)||(cURRENT_ORIENTATION==1)
  132. * @pre..
  133. * |Orientation==1 ||
  134. * |Orientation==-1
  135. * @post ..
  136. * |new.CURRENT_ORIENTATION = cURRENT_ORIENTATION
  137. */
  138. public void setOrientation(int cURRENT_ORIENTATION) {
  139. assert(cURRENT_ORIENTATION==-1)||(cURRENT_ORIENTATION==1);
  140. Orientation = cURRENT_ORIENTATION;}
  141.  
  142. /**
  143. *
  144. * @return
  145. * |result==CURRENT_ORIENTATION
  146. */
  147. public int getOrientation() {return Orientation;}
  148.  
  149. /*
  150. ************
  151. * Velocity *
  152. ************
  153. */
  154. /**
  155. * The Velocity of gameobjects.
  156. */
  157. public double[] Velocity= new double[2];
  158. /**
  159. * The acceleration of gameobjects.
  160. */
  161. public double[] Acceleration=new double[2];
  162. /**
  163. *
  164. * @param velocityx
  165. * @param velocityY
  166. * @post...
  167. * |new.getVelocity[0]
  168. */
  169. public void setVelocity(double velocityx, double velocityY){Velocity[0]=velocityx; Velocity[1]=velocityY;}
  170.  
  171. /**
  172. *
  173. * @return...
  174. * |result== Velocity
  175. */
  176. public double[] getVelocity() {return Velocity;}
  177. /**
  178. *
  179. * @param horzintel
  180. * @param vertical
  181. * @post...
  182. * |new.getAcceleration[0]==horizontal &&
  183. * |new.getAcceleration[1]==vertical
  184. */
  185. public void setAcceleration(double horzontal,double vertical) {
  186. Acceleration[0] = horzontal;
  187. Acceleration[1] = vertical;}
  188.  
  189. public double[] getAcceleration() {
  190. return Acceleration;
  191. }
  192.  
  193. /*
  194. ************
  195. * Movement *
  196. ************
  197. */
  198. /**
  199. * @post...
  200. * |new.getOrientation==-1
  201. */
  202. public void startMoveLeft(){setOrientation(-1);}
  203. /**
  204. * @post...
  205. * |new.getOrientation==-1
  206. */
  207. public void startMoveRight(){setOrientation(1);}
  208.  
  209. //FIXME zien of het in elke classe hetzelfde doet.
  210. public void startMovement2() { }
  211.  
  212. public void startMovement1() { }
  213. /**
  214. * @post...
  215. * |new.getOrientation==0
  216. */
  217. public void endMove() {setOrientation(0);}
  218.  
  219. /*
  220. **************
  221. * Terminated *
  222. **************
  223. */
  224. /**
  225. * Parameter storing the hitpoints of gameobjects
  226. */
  227. public int Hitpoint;
  228. /**
  229. *
  230. * @param hitpoint
  231. * @post...
  232. * |new.getHitpoint==hitpoint
  233. */
  234. public void setHitPoint(int hitpoint) {
  235. if(hitpoint==0) {Hitpoint=hitpoint;}
  236. else{Hitpoint += hitpoint;}
  237.  
  238. }
  239. /**
  240. *
  241. * @return...
  242. * |result==Hitpoint
  243. */
  244. public int getHitpoint() {return Hitpoint;}
  245.  
  246. // AdvancedTime Settings
  247. public double deathTime=0;
  248. /**
  249. *
  250. * @param dt
  251. * @throws Exception
  252. * @post...
  253. * |if(isDeadGameObject()){isTerminatedGameObject()==true}//FIXME weet niet of het echt zo moet worden geschreven.
  254. */
  255. public void advanceTime(double dt) throws Exception {
  256. if(isDeadGameObject()) {
  257. deathTime=dt;
  258. if(dt==deathTime+0.6) {
  259. terminateGameObject();
  260. }
  261.  
  262. }
  263. }
  264.  
  265.  
  266. private void terminateGameObject() {
  267.  
  268.  
  269. }
  270.  
  271. /*
  272. *********************
  273. * Sprites of Entity*
  274. *********************
  275. */
  276. public Sprite[] Sprites;
  277. /**
  278. *
  279. * @param spritess
  280. * @throws Exception
  281. * |spritess.length <= 0
  282. * @post...
  283. * |new.getSprites==spritess
  284. */
  285. public void setSprites(Sprite[] spritess) throws Exception {
  286. if(spritess.length > 0) {this.Sprites = spritess;}
  287. else {throw new Exception("illegalArgument Sprites");}
  288. }
  289. /**
  290. *
  291. * @return...
  292. * |result==Sprites
  293. */
  294. public Sprite[] getSprites() {return Sprites;}
  295.  
  296. public Sprite currentSprite;
  297. /**
  298. *
  299. * @return...
  300. * |result==null
  301. */
  302. public Sprite getCurrentSprite() {
  303. return null;
  304. }
  305.  
  306.  
  307. /*
  308. ************
  309. * Terminate*
  310. ************
  311. */
  312. /**FIXME SORRY
  313. * @post...
  314. * |getWorld==null
  315. * @post...
  316. * |!(world.hasAsGameObject)
  317. */
  318. public void terminateGameObject(Entity currentEntity){
  319. if(getWorld() !=null) {getWorld().removeGameObject(currentEntity);}
  320. removeWorld();}
  321.  
  322. public boolean Terminated=false;
  323. /** FIXME SORRY
  324. *
  325. * @param gameObject
  326. * @return...
  327. * |result==true ||
  328. * |result==false
  329. */
  330.  
  331. public boolean isTerminatedGameObject() {
  332. if(isDeadGameObject()) {}
  333. return isDeadGameObject();}
  334.  
  335. /**
  336. *
  337. * @return...
  338. * |result==true ||
  339. * |result==false
  340. */
  341. public boolean isDeadGameObject() {
  342. if(getHitpoint()== 0) { return true;}
  343. else {return false;}
  344. }
  345. /*
  346. ************
  347. * Get World*
  348. ************
  349. *
  350. */
  351. World currentWorld;
  352. /**
  353. *
  354. * @param world
  355. * @post...
  356. * |getWorld==world
  357. */
  358. public void setWorld(World world) {
  359. currentWorld = world;
  360. }
  361.  
  362. /**
  363. *
  364. * @return..
  365. * |result==currentWorld
  366. */
  367. public World getWorld() {
  368. return currentWorld;
  369. }
  370. /*
  371. ************
  372. * Collision*
  373. ************
  374. *
  375. */
  376. /*
  377. public boolean isEntityGoingAgainstAWall(int[] geologicalFeaturesCorners) {
  378. if (geologicalFeaturesCorners[0] == 1) {return true;}
  379. else if (geologicalFeaturesCorners[1]== 1) {return true;}
  380. else if (geologicalFeaturesCorners[2] == 1) {return true;}
  381. else if (geologicalFeaturesCorners[3] == 1) {return true;}
  382. else {return false;}
  383. }
  384. public boolean isEntityGoingAgainstAWater(int[] geologicalFeaturesCorners) {
  385. if (geologicalFeaturesCorners[0] == 1) {return true;}
  386. else if (geologicalFeaturesCorners[1]== 1) {return true;}
  387. else if (geologicalFeaturesCorners[2] == 1) {return true;}
  388. else if (geologicalFeaturesCorners[3] == 1) {return true;}
  389. else {return false;}
  390. }
  391. public boolean isEntityGoingAgainstAMagma(int[] geologicalFeaturesCorners) {
  392. if (geologicalFeaturesCorners[0] == 1) {return true;}
  393. else if (geologicalFeaturesCorners[1]== 1) {return true;}
  394. else if (geologicalFeaturesCorners[2] == 1) {return true;}
  395. else if (geologicalFeaturesCorners[3] == 1) {return true;}
  396. else {return false;}
  397. }
  398. public boolean isEntityGoingAgainstASlime(int[] geologicalFeaturesCorners) {
  399. if (geologicalFeaturesCorners[0] == 1) {return true;}
  400. else if (geologicalFeaturesCorners[1]== 1) {return true;}
  401. else if (geologicalFeaturesCorners[2] == 1) {return true;}
  402. else if (geologicalFeaturesCorners[3] == 1) {return true;}
  403. else {return false;}
  404. }
  405. public boolean isEntityGoingAgainstAIce(int[] geologicalFeaturesCorners) {
  406. if (geologicalFeaturesCorners[0] == 1) {return true;}
  407. else if (geologicalFeaturesCorners[1]== 1) {return true;}
  408. else if (geologicalFeaturesCorners[2] == 1) {return true;}
  409. else if (geologicalFeaturesCorners[3] == 1) {return true;}
  410. else {return false;}
  411. }
  412. public boolean isEntityGoingAgainstAGas(int[] geologicalFeaturesCorners) {
  413. if (geologicalFeaturesCorners[0] == 1) {return true;}
  414. else if (geologicalFeaturesCorners[1]== 1) {return true;}
  415. else if (geologicalFeaturesCorners[2] == 1) {return true;}
  416. else if (geologicalFeaturesCorners[3] == 1) {return true;}
  417. else {return false;}
  418. }
  419.  
  420.  
  421. public int[] currentCornersFeatures(double[] position) {
  422. int[] geologicalFeaturesCorners=new int[4];
  423. double[] leftBottom=actualPosition,
  424. rightBottom= {actualPosition[0]+calculateToActual(getCurrentSprite().getWidth()),actualPosition[1]},
  425. leftUp= {actualPosition[0],actualPosition[1]+currentSprite.getHeight()},
  426. RightUp= {actualPosition[0]+calculateToActual(getCurrentSprite().getWidth()),actualPosition[1]+currentSprite.getHeight()};
  427. geologicalFeaturesCorners[0] = getWorld().getGeologicalFeatures(calculateToPixel(leftBottom[0]), calculateToPixel(leftBottom[1]));
  428. geologicalFeaturesCorners[1] = getWorld().getGeologicalFeatures(calculateToPixel(rightBottom[0]), calculateToPixel(rightBottom[1]));
  429. geologicalFeaturesCorners[2] = getWorld().getGeologicalFeatures(calculateToPixel(leftUp[0]), calculateToPixel(leftUp[1]));
  430. geologicalFeaturesCorners[3] = getWorld().getGeologicalFeatures(calculateToPixel(RightUp[0]), calculateToPixel(RightUp[1]));
  431. return geologicalFeaturesCorners;
  432. }
  433. */
  434. public int calculateToPixel (double actual) {return ((int)(actual*100));}
  435. public double calculateToActual (int pixel) {return ((double)(pixel/100));}
  436. public void addHitPoint(int hitsChanged) {
  437. setHitPoint(getHitpoint()+hitsChanged);
  438.  
  439. }
  440. public void endJump() {
  441. // TODO Auto-generated method stub
  442.  
  443. }
  444. public void removeWorld() {
  445. currentWorld = null;
  446.  
  447. }
  448.  
  449.  
  450. /*
  451. * TerminateGameObject
  452. * isTerminatedGameObject
  453. */
  454.  
  455. }
Advertisement
Add Comment
Please, Sign In to add comment