Advertisement
RecklessDarph

Mazub0.2

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