Advertisement
RedVinck

Mazub Jordi 4.0

May 22nd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.68 KB | None | 0 0
  1. package jumpingalien.model;
  2.  
  3. import jumpingalien.util.ModelException;
  4. import jumpingalien.util.Sprite;
  5.  
  6. import java.math.BigDecimal;
  7. import java.math.RoundingMode;
  8.  
  9. import com.sun.org.apache.bcel.internal.generic.RETURN;
  10.  
  11. import be.kuleuven.cs.som.annotate.*;
  12. //import javafx.geometry.HorizontalDirection;
  13.  
  14. /**
  15. * A class for making the Mazub alien move jump, duck and also get the imageSprites and coordinates.
  16. *
  17. * @version 3.0
  18. * @author Thierry Klougbo & Jordi De Pau
  19. *
  20. * @invar Each Mazub can have its time as time.
  21. * | canHaveAstime(this.gettime())
  22. */
  23. public class Mazub extends Entity{
  24.  
  25. /**
  26. * Initialise the object Mazub (player) with given coordinations of Pixel X and Pixel and given sprites = Images of the player
  27. *
  28. * @param BottomPixelX
  29. * The Bottom Pixel X for this player Mazub
  30. * @param BottomPixelY
  31. * The Bottom Pixel Y for this player Mazub
  32. * @param sprites
  33. * Sprites an array of at least 10 Images and are even for every animation for player mazub.
  34. * @throws IllegalArgumentException
  35. * The given BottomPixelX and BottomPixelY are no valid Bottom pixels for any Mazub.
  36. * ||if(BottomPixelX<0 || BottomPixelX>1024 || BottomPixelY <0 || BottomPixelY>768) {throw new IllegalArgumentException();}
  37. */
  38. public Mazub(int BottomPixelX,int BottomPixelY, Sprite... sprites) throws Exception{
  39. super(BottomPixelX, BottomPixelY, sprites);
  40. if(BottomPixelX<0 || BottomPixelY <0) {throw new Exception("Negative values for pixels");}
  41. if(sprites.length%2 == 1||sprites.length <10) {throw new Exception("Invalid sprites");}
  42. setActualPosition((double)BottomPixelX/100,(double)BottomPixelY/100);
  43. setPixelPosition(BottomPixelX, BottomPixelY);
  44. setHitPoint(100);
  45.  
  46. }
  47.  
  48.  
  49. /*
  50. ****************
  51. * Game World *
  52. ****************
  53. */
  54. public final double WORLD_WIGTH = 1024.00;
  55. public final double WORLD_HEIGHT = 768.00;
  56. public double[] dimentions=new double[2];
  57. /**
  58. * returns an array containing the wigth and the height of the game window.
  59. * @return
  60. * |result == dimentions
  61. */
  62. public double[] getDimentions() {dimentions[0]=WORLD_WIGTH; dimentions[1]=WORLD_HEIGHT; return dimentions;}
  63.  
  64. //Orientation => Nominal
  65.  
  66.  
  67. /*
  68. ****************
  69. * Orientation *
  70. ****************
  71. */
  72. //FIXME Need to make previous position for current sprite and stuff
  73. /*
  74.  
  75. /**
  76. * @pre second must be equal to 1
  77. * | if(second == 1)
  78. * @post the previous orientation is equal to the current orientation.
  79. * |new.PREVIOUS_ORIENTATION = CURRENT_ORIENTATION
  80. /
  81. public void setPREVIOUS_ORIENTATION() {if(second == 1)
  82. {PREVIOUS_ORIENTATION = Orientation;}}
  83.  
  84. /**
  85. * @return the previous orientation
  86. * |result==PREVIOUS_ORIENTATION
  87. /
  88. public int getOrientation() {return PREVIOUS_ORIENTATION;}
  89. */
  90.  
  91. /*
  92. ****************
  93. * Velocity *
  94. ****************
  95. */
  96. //Horizontal => Totally
  97. public double MINIMAL_HORIZONTAL_SPEED =1.0;
  98. public double MAXIMUM_HORIZONTAL_SPEED = 3.0;
  99. /**
  100. * @return ...
  101. * |result==MAXIMUM_HORIZONTAL_SPEED
  102. */
  103. public double getMAXIMUM_HORIZONTAL_SPEED() {return MAXIMUM_HORIZONTAL_SPEED;}
  104.  
  105. /**
  106. * @param mAXIMUM_HORIZONTAL_SPEED
  107. * @post ...
  108. * |MAXIMUM_HORIZONTAL_SPEED = mAXIMUM_HORIZONTAL_SPEED
  109. */
  110. public void setMAXIMUM_HORIZONTAL_SPEED(double mAXIMUM_HORIZONTAL_SPEED) {if(getOrientation()!=0) {MAXIMUM_HORIZONTAL_SPEED = mAXIMUM_HORIZONTAL_SPEED*getOrientation();}else {MAXIMUM_HORIZONTAL_SPEED = mAXIMUM_HORIZONTAL_SPEED*1;}}
  111.  
  112. /**
  113. *
  114. * @return ...
  115. * |result==MINIMAL_HORIZONTAL_SPEED
  116.  
  117. */
  118. public double getMINIMAL_HORIZONTAL_SPEED() {return MINIMAL_HORIZONTAL_SPEED;}
  119.  
  120. /**
  121. *
  122. * @param mINIMAL_HORIZONTAL_SPEED
  123. * @post ..
  124. * |MINIMAL_HORIZONTAL_SPEED = mINIMAL_HORIZONTAL_SPEED*getOrientation()
  125. */
  126. public void setMINIMAL_HORIZONTAL_SPEED(double mINIMAL_HORIZONTAL_SPEED) {if(getOrientation()!=0) {MINIMAL_HORIZONTAL_SPEED = mINIMAL_HORIZONTAL_SPEED*getOrientation();}else {MINIMAL_HORIZONTAL_SPEED = mINIMAL_HORIZONTAL_SPEED*1;}}
  127.  
  128.  
  129. /*
  130. ****************
  131. * Changing Max Horizontal*
  132. ****************
  133. */
  134.  
  135. public void horizontalMaxChanging(double dt) {
  136. BigDecimal time= BigDecimal.valueOf(dt),acceleration= BigDecimal.valueOf(getAcceleration()[0]),velocity= BigDecimal.valueOf(getVelocity()[0]);
  137.  
  138. int px=getPixelPosition()[0];
  139. int py=getPixelPosition()[1];
  140. // if(getWorld() != null && getWorld().getGeologicalFeatures(px=getPixelPosition()[0]+(getSpriteDimention()[0]-1), py=getPixelPosition()[1])!=1){
  141.  
  142. if(Math.abs(getVelocity()[0])<Math.abs(getMAXIMUM_HORIZONTAL_SPEED())){setVelocity( velocity.add(acceleration.multiply(time)).doubleValue(), getVelocity()[1]);}
  143. // if(isDucking() == true) {setMAXIMUM_HORIZONTAL_SPEED(1.0);}
  144. if(getVelocity()[0]!=0 && Math.abs(getVelocity()[0])> Math.abs(getMAXIMUM_HORIZONTAL_SPEED())) {setVelocity(getMAXIMUM_HORIZONTAL_SPEED(), getVelocity()[1]);}
  145. if(getVelocity()[0]!=0 && Math.abs(getVelocity()[0])<Math.abs(getMINIMAL_HORIZONTAL_SPEED())) {setVelocity(getMINIMAL_HORIZONTAL_SPEED(), getVelocity()[1]);}
  146.  
  147. }
  148.  
  149. public void verticalChanging(double dt) {
  150. BigDecimal time= BigDecimal.valueOf(dt),acceleration= BigDecimal.valueOf(getAcceleration()[1]),velocity= BigDecimal.valueOf(getVelocity()[1]);
  151. // else if(getActualPosition()[1] > 0 && world.getGeologicalFeatures(px, py)==1) {setAcceleration(getAcceleration()[0], 0);}
  152. if(getWorld() != null && getActualPosition()[1]<=0) {setAcceleration(getAcceleration()[0],0);}
  153. setVelocity(getVelocity()[0], velocity.add(acceleration.multiply(time)).doubleValue());
  154.  
  155. }
  156.  
  157. /*
  158. ****************
  159. * Running*
  160. ****************
  161. */
  162.  
  163. public void startMoveLeft() {
  164. // int px=getPixelPosition()[0]; int py=getPixelPosition()[1];
  165. // if(world.getGeologicalFeatures(px, py+(getSpriteDimention()[1]-2))!=1) {
  166. Moving = true;
  167. setOrientation(-1);
  168. setAcceleration(-0.9, getAcceleration()[1]);
  169. setVelocity(-1, getVelocity()[1]);
  170. setMAXIMUM_HORIZONTAL_SPEED(3.0);
  171. //
  172. }
  173.  
  174.  
  175.  
  176. public void startMoveRight() {
  177. int px=getPixelPosition()[0]; int py=getPixelPosition()[1];
  178. // if(world.getGeologicalFeatures(px+(getSpriteDimention()[0]-1), py+(getSpriteDimention()[1]-2))!=1) {
  179. Moving = true;
  180. setOrientation(1);
  181. setAcceleration(0.9, getAcceleration()[1]);
  182. setVelocity(1, getVelocity()[1]);
  183. setMAXIMUM_HORIZONTAL_SPEED(3.0);}
  184.  
  185.  
  186. public boolean Moving;
  187. /**
  188. * @post The current orientation is equal to 0
  189. * | new.getOrientation() == 0
  190. * @post The current horizontal accelereation is equal to 0
  191. * | new.getAcceleration()[0]=0
  192. * @post The horizontal velocity is equal to 0
  193. * | new.getVelocity()[0]=0
  194. */
  195. public void endMove() {
  196. Moving = false;
  197. setAcceleration(0, getAcceleration()[1]);
  198. setVelocity(0, getVelocity()[1]);
  199. }
  200.  
  201. public int currentOrientation;
  202. public void setCurrentOrientation(int i) {
  203. currentOrientation=i;
  204. }
  205. public int getCurrentOrientation() {
  206. return currentOrientation;
  207.  
  208. }
  209.  
  210. /**
  211. *
  212. * @return the value of the variable Moving
  213. * | result == if(Moving) {return true;}
  214. * else {return false;}
  215. */
  216. public boolean isMoving() {
  217. //assert(moving==true) ?
  218. if(Moving) {return true;}
  219. else {return false;}
  220. }
  221.  
  222. /**
  223. * Initialize this new Mazub with given time.
  224. *
  225. * @param time
  226. * The time for this new Mazub.
  227. * @pre This new Mazub can have the given time as its time.
  228. * | canHaveAstime(time)
  229. * @post The time of this new Mazub is equal to the given
  230. * time.
  231. * | new.gettime() == time
  232. */
  233. public void running(double time) {
  234. if(getActualPosition()[0] >= 0 && getActualPosition()[0] <= getDimentions()[0]) {
  235. double posx=
  236. BigDecimal.valueOf(actualPosition[0])
  237. .add (BigDecimal.valueOf(Velocity[0]).multiply(BigDecimal.valueOf(time)))
  238. .add(BigDecimal.valueOf(getAcceleration()[0]).multiply(BigDecimal.valueOf(0.5))
  239. .multiply(BigDecimal.valueOf(Math.pow(time, 2)))).doubleValue();
  240. setActualPosition(posx, getActualPosition()[1]);
  241. }
  242. if(getActualPosition()[0]>getDimentions()[0]) {setActualPosition(getDimentions()[0],getActualPosition()[1]);}
  243. if(getActualPosition()[0]< 0) {setHitPoint(0);}
  244. }
  245.  
  246.  
  247.  
  248.  
  249. /*
  250. ****************
  251. * Jumping & FAlling *
  252. ****************
  253. */
  254. public boolean jumping;
  255. public double ACCELERATION_WHILE_JUMPING = 8.0;
  256. public double ACCELERATION_WHILE_FALLING = -10.0;
  257.  
  258. /**
  259. * Set the vertical velocity of this object_name to the given vertical velocity.
  260. *
  261. * @pre The given vertical velocity must be a valid vertsiical velocity for any
  262. * Mazub.
  263. * | isValidVERTICAL_VELOCITY(setVetical_VELOCITY(ACCELERATION_WHILE_JUMPINT))
  264. *
  265. * @post The vertical velocity of this Mazub is equal to the given
  266. * vertical velocity.
  267. * | new.getVERTICAL_VELOCITY() == setVetical_VELOCITY(ACCELERATION_WHILE_JUMPINT)
  268. * @post The vertical acceleration of this Mazub is equal to -10.
  269. * | new.getAcceleration()[1] == setVetical_ACCELERATION(-10)
  270. *
  271. */
  272. public void startJump() {
  273.  
  274. // if(world.getGeologicalFeatures(px, py)!=1) {
  275. jumping = true;
  276. setVelocity(getVelocity()[0], ACCELERATION_WHILE_JUMPING);
  277. setAcceleration(getAcceleration()[0], ACCELERATION_WHILE_FALLING);
  278. // }
  279. }
  280.  
  281. /**
  282. * @post The vertical velocity of this Mazub is equal to 0.
  283. * | new.getVERTICAL_VELOCITY() == setVetical_VELOCITY(0)
  284. */
  285. public void endJump() {
  286. // if(jumping) {
  287. jumping = false;
  288. setAcceleration(getAcceleration()[0],0);
  289. if(getVelocity()[1]>0) {setVelocity(getVelocity()[0],0);}
  290. // }
  291. }
  292. public void falling() {
  293. setAcceleration(getAcceleration()[0], ACCELERATION_WHILE_FALLING);
  294. }
  295. /**
  296. *
  297. * @return if Mazub is jumping or not
  298. * |result == if(jumping) {return true;}
  299. | else{return false;}
  300. */
  301. public boolean isJumping() {
  302. if(jumping) {return true;}
  303. else{return false;}
  304. }
  305.  
  306. /**
  307. * Check whether the given time is a valid time for
  308. * any Mazub.
  309. *
  310. * @param time
  311. * The time to check.
  312. * @return
  313. * | result ==
  314. */
  315. public static boolean isValidtime(double time) {
  316. if (time == 0.2) {return true;}
  317. else {return false;}
  318. }
  319.  
  320. /**
  321. * Initialize this new Mazub with given time.
  322. *
  323. * @param time
  324. * The time for this new Mazub.
  325. * @throws ExceptionName_Java
  326. * The given time is not a valid time for any
  327. * Mazub.
  328. * | ! isValidtime(gettime())
  329. * @effect ...
  330. * |if(getActualPositionY() >= 0 && getActualPositionY() <= getWorldHeight()) {setActualPositionY(getActualPositionY()+ (getVERTICAl_VELOCITY()*time)+(0.5*getAcceleration()[1]*time*time)) ;}
  331. * |if(getActualPositionY()>getWorldHeight()) {setActualPositionY(getWorldHeight());}
  332. * |if(getActualPositionY()< 0) {setActualPositionY(0);}
  333. */
  334. public void jumping(double time) throws IllegalArgumentException{
  335.  
  336. if(getActualPosition()[1] >= 0 && getActualPosition()[1] <= getDimentions()[1]) {
  337. double posy=
  338. BigDecimal.valueOf(actualPosition[1])
  339. .add (BigDecimal.valueOf(Velocity[1]).multiply(BigDecimal.valueOf(time)))
  340. .add(BigDecimal.valueOf(getAcceleration()[1]).multiply(BigDecimal.valueOf(0.5))
  341. .multiply(BigDecimal.valueOf(Math.pow(time, 2)))).doubleValue();
  342. setActualPosition(getActualPosition()[0], posy);
  343. }
  344. if(getWorld()!=null) {if (getAcceleration()[0] >getWorld().getSizeInPixels()[0]) {setHitPoint(0);}}
  345. if(getActualPosition()[1]< 0) {setHitPoint(0);}
  346. }
  347.  
  348. /*
  349. * int[] pos =
  350. {(BigDecimal.valueOf(
  351. (BigDecimal.valueOf(currentEntity.actualPosition[0])
  352. .add (BigDecimal.valueOf(currentEntity.Velocity[0]).multiply(BigDecimal.valueOf(time)))
  353. .add(BigDecimal.valueOf(currentEntity.getAcceleration()[0]).multiply(BigDecimal.valueOf(0.5))
  354. .multiply(BigDecimal.valueOf(Math.pow(time, 2))))).doubleValue()).doubleValue()),
  355. mazub.calculateToPixel(BigDecimal.valueOf(
  356. (BigDecimal.valueOf(currentEntity.actualPosition[1])
  357. .add (BigDecimal.valueOf(currentEntity.Velocity[1]).multiply(BigDecimal.valueOf(time)))
  358. .add(BigDecimal.valueOf(currentEntity.getAcceleration()[1]).multiply(BigDecimal.valueOf(0.5))
  359. .multiply(BigDecimal.valueOf(Math.pow(time, 2))))).doubleValue()).doubleValue())};
  360. *
  361. */
  362.  
  363.  
  364.  
  365. /*
  366. ****************
  367. * Ducking *
  368. ****************
  369. */
  370.  
  371. //Fixme Check wheter if he stop with ducking it doesnt stop
  372. public boolean Ducking;
  373. public boolean ableToDuck=true;
  374. /**
  375. * @effect...
  376. * |if(getOrientation() != 0) {setMAXIMUM_HORIZONTAL_SPEED(1.0*getOrientation());}
  377. * |else {setMAXIMUM_HORIZONTAL_SPEED(1.0);}
  378. *@post ...
  379. * |Ducking = true
  380. */
  381. public void startDucking() {
  382. if(isDucking()==false) {setMAXIMUM_HORIZONTAL_SPEED(1.0);setAcceleration(0, getAcceleration()[1]);}
  383. else {setMAXIMUM_HORIZONTAL_SPEED(1.0);}
  384. Ducking = true;
  385. }
  386.  
  387. /**
  388. * @effect...
  389. * |if(getOrientation() != 0)setMAXIMUM_HORIZONTAL_SPEED(3.0*getOrientation());
  390. * |else {setMAXIMUM_HORIZONTAL_SPEED(3.0);} Ducking = false;
  391. */
  392. public void endDucking() {
  393. if (isDucking()) {
  394. setMAXIMUM_HORIZONTAL_SPEED(3.0);
  395. Ducking=false;}
  396.  
  397. }
  398.  
  399. /**
  400. *
  401. * @return...
  402. * |if(Ducking) {return true;}
  403. * |else {return false;}
  404. */
  405. public boolean isDucking() {
  406. if(Ducking) {return true;}
  407. else {return false;}
  408. }
  409.  
  410.  
  411. /*
  412. ****************
  413. * AdvancedTime *
  414. ****************
  415. */
  416. //Time
  417. public double aFitfhOFASecond = 0;
  418. public double milisecond= 0;
  419. public double HitTime=0;
  420.  
  421. /**
  422. * Changes the position of Mazub
  423. * @param time
  424. * @effect...
  425. * |horizontalChanging(time);
  426. * |verticalChanging(time);
  427. * |running(time);
  428. * |jumping(time);
  429. * |if(second >= 1.0) {setPREVIOUS_ORIENTATION(); second =0;}
  430. * |else{second =+time;}
  431. * |if (milisecond >= 0.075) {setImagCount(getImagCount()+ 1); milisecond = 0;}
  432. * |else {milisecond += time;}
  433. * |if(isMoving() == false) {setImagCount(0);}
  434. */
  435.  
  436. public double lessThenaSecond=0.000;
  437. public void advanceTime(double time) throws Exception {
  438.  
  439. if(overlapEarth(futureEarth(time, 0), getPixelPosition()[1])==false) {running(time);}
  440. if(overlapEarth(getPixelPosition()[0],futureEarth(time, 1))==false){jumping(time);}
  441. horizontalMaxChanging(time);
  442. verticalChanging(time);
  443.  
  444. if(lessThenaSecond>=1.00&&isMoving()==false) {setOrientation(0);lessThenaSecond =0;}
  445. else {lessThenaSecond +=time;}
  446.  
  447. if (isMoving() && milisecond >= 0.075) {setImagCount(getImagCount()+ 1); milisecond = 0;}
  448. else {milisecond += time;}
  449.  
  450. if(isMoving() == false) {setImagCount(0);}
  451.  
  452. }
  453. /*
  454. ****************
  455. * Collision *
  456. ****************
  457. */
  458. public BigDecimal timePerCm(double time,Entity currentEntity) {
  459.  
  460. //Calculation of time fragments with given acceleration, velocity and time.
  461. BigDecimal currentVelocityX= BigDecimal.valueOf(currentEntity.getVelocity()[0]), currentVelocityY= BigDecimal.valueOf(currentEntity.getVelocity()[1]), currentAccelerationX= BigDecimal.valueOf(currentEntity.getAcceleration()[0]),currentAccelerationY= BigDecimal.valueOf(currentEntity.getAcceleration()[1]);
  462. BigDecimal cm= BigDecimal.valueOf(0.01);
  463. BigDecimal timedt = BigDecimal.valueOf(time);
  464. BigDecimal mathsqr1=BigDecimal.valueOf(Math.sqrt((currentAccelerationX.pow(2).add(currentAccelerationY.pow(2))).doubleValue()));
  465. BigDecimal mathsqr2=BigDecimal.valueOf(Math.sqrt((currentVelocityX.pow(2).add(currentVelocityY.pow(2))).doubleValue()));
  466. BigDecimal divider = mathsqr1.add(mathsqr2.multiply(timedt));
  467. if(divider.compareTo(BigDecimal.valueOf(0.0))==0) {return BigDecimal.valueOf(time);}
  468. BigDecimal dt= BigDecimal.valueOf(cm.divide((divider), 16, RoundingMode.HALF_UP).doubleValue());
  469. return dt;
  470.  
  471. }
  472.  
  473.  
  474. /*
  475. ****************
  476. * Sprites *
  477. ****************
  478. */
  479.  
  480.  
  481.  
  482. public Sprite[] getSprites() {return Sprites;}
  483.  
  484. public int imagCount;
  485. /**
  486. * Sets the sprites for Mazub
  487. * @param sPRITES
  488. * @post ...
  489. * |SPRITES = sPRITES
  490. * @throws IllegalArgumentExecption if array of sprytes is empty.
  491. * |if(sPRITES==null) {throw new IllegalArgumentException();}
  492. */
  493.  
  494. /**
  495. * Sets the image Count of the sprites for Mazub
  496. * @param imagCount
  497. * @post ..
  498. * |this.imagCount = imagCount
  499. */
  500. public void setImagCount(int imagCount){
  501. this.imagCount = imagCount;}
  502.  
  503. /**
  504. * Gets the image Count of the sprites for Mazub
  505. * @return...
  506. * |result==imagCount
  507. */
  508. public int getImagCount() {return imagCount;}
  509.  
  510. /**
  511. * Gets the current sprite for Mazub while it is moving.
  512. * @effect...
  513. * |if((isDucking() == false)&&(getOrientation() ==0) && (getOrientation() == 0)) {return getSprites()[0];}
  514. * |else if((isDucking() == true) && (getOrientation()==0) &&(getOrientation() == 0)) {return getSprites()[1];
  515. * |else if((getOrientation() > 0) && (Moving == false) && (isDucking() == false)) {return getSprites()[2];}
  516. * |else if((getOrientation() < 0) && (Moving == false)&& (isDucking() == false)) {return getSprites()[3];}
  517. * |else if((getOrientation() == 1) && (isDucking() ==false) && (isJumping() == true)) {return getSprites()[4];}
  518. * |else if((getOrientation() ==-1) && (isDucking() == false)&& (isJumping() == true)) {return getSprites()[5];}
  519. * |else if((getOrientation() ==1||getOrientation() == 1) && (isDucking() == true)) {return getSprites()[6];}
  520. * |else if((getOrientation() == -1|| getOrientation() == -1) &&(isDucking() ==true)) {return getSprites()[7];}
  521. * |else if((getOrientation() == 1) && (isDucking() == false)&& (isJumping() == false)) {return getSprites()[8+setImages()];}
  522. * |else if((getOrientation() == -1) && (isDucking()== false)&& (isJumping() ==false)) {return getSprites()[((SPRITES.length-8)/2+8)+(setImages())];}
  523. * |else {return getSprites()[1];}
  524. * @return
  525. * |result==getSprites()
  526. */
  527. public Sprite getCurrentSprite() {
  528. //0 is not moving horizontally, has not moved horizontally within the last second of in-game time and is not ducking.
  529. if((isDucking() == false)&&(getVelocity()[0]==0)) {return getSprites()[0]; }
  530.  
  531. //1 is not moving horizontally, has not moved horizontally within the last second of in-game time and is ducking.
  532. else if ((isDucking() == true) && (getOrientation()==0) &&(getVelocity()[0])==0) {return getSprites()[1];}
  533.  
  534. //2 is not moving horizontally but its last horizontal movement was to the right (within 1s), and the character is not ducking.
  535. //Looking at right
  536. else if (getVelocity()[0] > 0&&getOrientation() >0 && Moving==false && (isDucking() == false)) {return getSprites()[2];}
  537. //3 is not moving horizontally but its last horizontal movement was to the left (within 1s), and the character is not ducking.
  538. //Looking at left
  539. else if (getVelocity()[0]<0 &&getOrientation()<0 && (Moving == false)&& (isDucking() == false)) {return getSprites()[3];}
  540.  
  541. //4 is moving to the right and jumping and not ducking.
  542. //Jumping right
  543. else if (getVelocity()[0]>0 && (isDucking() ==false) && (isJumping() == true)) {return getSprites()[4];}
  544. //5 is moving to the left and jumping and not ducking.
  545. else if (getVelocity()[0]<0 && (isDucking() == false)&& (isJumping() == true)) {return getSprites()[5];}
  546.  
  547. //6 is ducking and moving to the right or was moving to the right (within 1s)
  548. else if (getVelocity()[0]>0 && (isDucking() == true)) {return getSprites()[6];}
  549. //7 is ducking and moving to the left or was moving to the left (within 1s).
  550. else if (getVelocity()[0]<0 &&(isDucking() ==true)) {return getSprites()[7];}
  551.  
  552. //8..(8 + m) the character is neither ducking nor jumping and moving to the right
  553. else if (getVelocity()[0]>0 && (isDucking() == false)&& (isJumping() == false)) {return getSprites()[8+setImages()];}
  554.  
  555. //(9 + m)..(9 + 2m) the character is neither ducking nor jumping and moving to the left.
  556. else if (getVelocity()[0]<0 && (isDucking()== false)&& (isJumping() ==false)) {return getSprites()[((Sprites.length-8)/2+8)+(setImages())];}
  557. else {return getSprites()[0];}
  558. }
  559.  
  560. /**
  561. * Sets the images of Mazub
  562. * @post...
  563. * |int length=(getSprites().length-8)/2;
  564. * |int m1 = getImagCount();
  565. * @return ...
  566. * |result==m1
  567. * @effect...
  568. * |if(getImagCount() >= length) {setImagCount(0);
  569. */
  570. public int setImages() {
  571. int length=(getSprites().length-8)/2;
  572. if(getImagCount() >= length) {setImagCount(0);}
  573. int m1 = getImagCount();
  574. return m1;
  575. }
  576.  
  577. public boolean IllegalSprites;
  578.  
  579. /**
  580. * Gets illegal Sprites
  581. * @return
  582. * |result==if(IllegalSprites)
  583. * @effect...
  584. * |if( getSprites() == null || getSprites().length< 10 ||(getSprites().length%2) == 1) {
  585. * |return IllegalSprites = true;}
  586. * |for (Sprite sprite : SPRITES) {if(sprite == null) {return IllegalSprites = true;}}
  587. */
  588. public boolean getIllegalSprites() {
  589. if( getSprites() == null || getSprites().length< 10 ||(getSprites().length%2) == 1) {
  590. return IllegalSprites = true;}
  591. for (Sprite sprite : Sprites) {
  592. if(sprite == null) {return IllegalSprites = true;}}
  593. return IllegalSprites = false;
  594. }
  595.  
  596. int[] SpriteDimentions=new int[2];
  597. public int Width=0;int Heigth=0;
  598. public int[] getSpriteDimention() {
  599.  
  600. if(isJumping()|| isMoving()) {this.Width=70;this.Heigth=97;}
  601.  
  602.  
  603.  
  604.  
  605. if(!(isMoving()) && !(isDucking()) && !(isJumping())) {this.Width=70; this.Heigth=97;}
  606. if(isDucking()) {this.Width=70; this.Heigth=70;}
  607.  
  608. SpriteDimentions[0]=this.Width;
  609. SpriteDimentions[1]=this.Heigth;
  610. return SpriteDimentions;
  611. }
  612.  
  613. /*
  614. ****************
  615. * Hitpoints *
  616. ****************
  617. */
  618. /**
  619. *
  620. * @param newPosition
  621. * @post ...
  622. * |new.getActualPosition() == newPosition
  623. */
  624. public void changeActualPosition(double[] newPosition) throws Exception {
  625. if(newPosition == null) {throw new Exception("Invalid value of position's");}
  626. else if(newPosition.length != 2) {throw new Exception("Invalid value of position's");}
  627. else if(Double.isNaN(newPosition[0])==true|| Double.isNaN(newPosition[1])==true) {throw new Exception("Invalid value of an or both position's");}
  628. else {actualPosition =newPosition;}
  629. if(getWorld()!= null) {
  630. if(getWorld().OutsideWorldBorder(newPosition)) {getWorld().terminatedGameObject(getWorld().getMazub());terminateEntity();}}
  631. else if (newPosition[0]<0||newPosition[1]<0) {throw new Exception("Outside Universe");}
  632. // if(getWorld()!= null & getWorld().getGeologicalFeatures(getWorld().calculateInFeature(calculateToPixel(newPosition[0])+1),getWorld().calculateInFeature(calculateToPixel(newPosition[1])+1))==1) {throw new Exception("can't change to impassable terrain");}
  633. }
  634.  
  635. public void terminateEntity() {
  636. removeWorld();
  637. }
  638.  
  639. //FIXME do right values
  640. public void setHitPoint(int hitpoint) {if(Hitpoint<=500) {Hitpoint=hitpoint;}}
  641. public void addHitPoint(int hitpoint) {if(Hitpoint + hitpoint <= 500) {Hitpoint += hitpoint;}}
  642.  
  643. public int futureEarth(double time,int direction) throws Exception {
  644. int pos =
  645. calculateToPixel(BigDecimal.valueOf(
  646. (BigDecimal.valueOf(getActualPosition()[direction])
  647. .add (BigDecimal.valueOf(getVelocity()[direction]).multiply(BigDecimal.valueOf(time)))
  648. .add(BigDecimal.valueOf(getAcceleration()[direction]).multiply(BigDecimal.valueOf(0.5))
  649. .multiply(BigDecimal.valueOf(Math.pow(time, 2))))).doubleValue()).doubleValue());
  650. return pos;
  651. }
  652. public boolean overlapEarth(int X, int Y) {
  653. boolean touch=false;
  654. X+=1;Y = Y+=1;
  655. int SpriteX=getCurrentSprite().getWidth()-2,SpriteY=getCurrentSprite().getHeight()-2;
  656. if(getWorld().getGeologicalFeatures(X, Y)==1
  657. || getWorld().getGeologicalFeatures(X+SpriteX, Y )== 1
  658. || getWorld().getGeologicalFeatures(X, Y+SpriteX)==1
  659. || getWorld().getGeologicalFeatures(X+SpriteX, Y+SpriteY)==1
  660. ){touch=true;}
  661. return touch;
  662. }
  663. /**
  664. * Variable registering whether this person is terminated.
  665. */
  666. private boolean isTerminated = false;
  667.  
  668. public boolean OutsideWorldBorder(double[] newpos){
  669. if(newpos[0] < 0 || newpos[0] > getWorld().getSizeInPixels()[0]-1 || newpos[1] <0 || newpos[1] > getWorld().getSizeInPixels()[1]-1 ) {return true;}
  670. else {return false;}}
  671.  
  672.  
  673.  
  674. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement