Advertisement
RecklessDarph

Backup Mazub

Jul 9th, 2019
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 23.60 KB | None | 0 0
  1. package jumpingalien.model;
  2.  
  3. import jumpingalien.util.ModelException;
  4. import jumpingalien.util.Sprite;
  5.  
  6. import static org.junit.Assert.assertNotEquals;
  7.  
  8. import java.math.BigDecimal;
  9. import java.math.RoundingMode;
  10. import be.kuleuven.cs.som.annotate.*;
  11.  
  12.  
  13.  
  14. public class Mazub{
  15. /*
  16. **************
  17. * Game World *
  18. **************
  19. */
  20.     private double World_Width= 10.24;
  21.     private double World_Height= 7.68;
  22.  
  23. /*
  24. ************
  25. * Position *
  26. ************
  27. */
  28.     //Variables
  29.     private double[] ActualPositon;
  30.     private int[] PixelPosition;
  31.     //facade
  32.     /**
  33.      * A method to get the Actual position
  34.      * @return
  35.      *      |result==ActualPosition
  36.      */
  37.     public double[] getActualPosition() {
  38.         return ActualPositon;
  39.     }
  40.    
  41.     /**
  42.      * A method to change the actual position
  43.      * @param newPosition
  44.      * @throws Exception
  45.      *      if the new positions are negative .
  46.      *          |if(newPosition[1] <0 || newPosition[0] <0)
  47.      *              |then (throw new Exception("A or both positions are negative"))
  48.      * @throws Exception
  49.      *      if the new positions are bigger than the world width or height
  50.      *          |if(newPosition[0]>World_Width || newPosition[1]> World_Height)
  51.      *              | then(throw new Exception("A or both positions is bigger than world dimentions"))
  52.      * @throws Exception
  53.      *      if the new positions are not numbers.
  54.      *          |if(Double.isNaN(newPosition[0]) ||Double.isNaN(newPosition[0]))
  55.      *                  |then (throw new Exception("Invalid input type"))
  56.      * @throws Exception
  57.      *      if the array given as parameter does not have two elements.
  58.      *          |if(newPosition.length != 2)
  59.      *              |then (throw new Exception("Invalid size of Position"))
  60.      * @post the new actual position is equal to newPosition
  61.      *      new.getActualPosition=newPosition
  62.      */
  63.     public void changeActualPosition(double[] newPosition) throws Exception {
  64.         if(newPosition[1] <0 || newPosition[0] <0) {throw new Exception("A or both positions are negative");}
  65.         if(newPosition[0]>World_Width || newPosition[1]> World_Height) {throw new Exception("A or both positions is bigger than world dimentions");}
  66.         else if(Double.isNaN(newPosition[0]) ||Double.isNaN(newPosition[0])) {throw new Exception("Invalid input type");}
  67.         else if(newPosition.length != 2) {throw new Exception("Invalid size of Position");}
  68.         else{this.ActualPositon = newPosition;}
  69.     }
  70.    
  71.    
  72.     // Helper classes
  73.     /**
  74.      * A method to get the pixel positions
  75.      * @return
  76.      *      |newPixelPosition
  77.      *     
  78.      */
  79.     public int[] getPixelPosition() {
  80.         int[] newPixelPosition= {(int) (getActualPosition()[0]*100),(int) (getActualPosition()[1]*100)};
  81.         return newPixelPosition ;}
  82.    
  83.     /**
  84.      * Method to set the actual position
  85.      * @param x
  86.      * @param y
  87.      * @throws Exception
  88.      *      if the new position values are less than zero
  89.      *          |if(x <0 || y <0)
  90.      *              |then(throw new Exception("A or both positions are negative"))
  91.      * @throws Exception
  92.      *      if the new positin values are no numbers
  93.      *          |if(Double.isNaN(x) ||Double.isNaN(y))
  94.      *              |then(throw new Exception("Invalid input type"))
  95.      */
  96.     public void setActualPositon(double x, double y) throws Exception {
  97.     if(x <0 || y <0) {throw new Exception("A or both positions are negative");}
  98.         else if(Double.isNaN(x) ||Double.isNaN(y)) {throw new Exception("Invalid input type");}
  99.         else{
  100.             double[] actualPositon= {x,y};
  101.             ActualPositon = actualPositon;}
  102.        
  103.     }
  104.    
  105.     /**
  106.      * Method to set pixselPosition
  107.      * @param x
  108.      * @param y
  109.      * @throws Exception
  110.      *      if the new position values are less than zero
  111.      *          |if(x <0 || y <0)
  112.      *              |then(throw new Exception("A or both positions are negative"))
  113.      * @post the new pixel position is set
  114.      *      |new.getPixelPosition=newPosition
  115.      *     
  116.      */
  117.     public void setPixelPosition(int x, int y) throws Exception {
  118.         if(x <0 || y <0) {throw new Exception("A or both positions are negative");}
  119.         else{
  120.         int[] newPositon= {x,y};
  121.         PixelPosition = newPositon;}
  122.     }
  123.     //helper methods
  124.    
  125. /*
  126. ***********
  127. * Mazub   *
  128. ***********
  129.         */
  130.     public Mazub(int pixelLeftX, int pixelBottomY, Sprite... sprites) throws Exception {
  131.         setActualPositon((double)pixelLeftX/100, (double)pixelBottomY/100);
  132.         setAllSprites(sprites);
  133.     }
  134.  
  135.     /*
  136. **************
  137. * Orientation*
  138. **************
  139. */  
  140.     //variable
  141.     private int Orientation=0;
  142.     //facade
  143.     /**
  144.      * Returns the orientation
  145.      * @return the orientation
  146.      *      |result==Orientation
  147.      */
  148.     public int getOrientation() {
  149.         return Orientation;
  150.     }      
  151.     //helper methods
  152.     /**
  153.      * Sets the orientation
  154.      * @post
  155.      *      the new orientation is set
  156.      *          |new.getOrientation==currentOrientation
  157.      * @param currentOrientation
  158.      */
  159.     public void setOrientation(int currentOrientation) {
  160.         this.Orientation = currentOrientation;
  161.     }
  162.  
  163. /*
  164. ************
  165. * Velocity *
  166. ************
  167. */
  168.    
  169.     //variable
  170.         public double[] Velocity = {0,0};
  171.         //variables
  172.         private double Max_Horizontal = 3.0;
  173.         private double Min_Horizontal = 1.0;
  174.         //facade
  175.         /**
  176.          * returns the velocity
  177.          * @return
  178.          *      |result==Velocity
  179.          */
  180.         public double[] getVelocity() {
  181.             return this.Velocity;
  182.         }
  183.        
  184.         // helpermethodes
  185.         /**
  186.          * Sets the velocity
  187.          * @param x
  188.          * @param y
  189.          * @post
  190.          *      the new velocity is set
  191.          *          |new.getVelocity==velocity
  192.          */
  193.         public void setVelocity(double x, double y) {
  194.             double[] velocity= {x,y};
  195.             Velocity = velocity;
  196.         }
  197.        
  198.         //helper methods
  199.         /**
  200.          * return the maximal horizontal velocity
  201.          * @effect
  202.          *      if the velocity is positive
  203.          *          |if(getVelocity()[0]>0)
  204.          *              |then(result==Max_Horizontal)
  205.          * @effect
  206.          *      if the velocity is negative
  207.          *          |if(getVelocity()[0]<0)
  208.          *              |then(result==Max_Horizontal*-1)
  209.          * @return
  210.          *      |result==Max_Horizontal
  211.          */
  212.         public double getMax_Horizontal() {
  213.             if(getVelocity()[0]>0) {return Max_Horizontal;}
  214.             if(getVelocity()[0]<0) {return Max_Horizontal*-1;}
  215.             else {return Max_Horizontal;}
  216.         }
  217.        
  218.         public void setMax_Horizontal(double max_Horizontal) {
  219.             Max_Horizontal = max_Horizontal;
  220.         }
  221.        
  222. /*
  223. ****************
  224. * Acceleration *
  225. ****************
  226. */
  227.         /* Acceleration *//* not sure*/
  228.         //variable
  229.         public double[] Acceleration = {0,0};
  230.         //facade
  231.         /**
  232.          * Return the Acceleration
  233.          * @return
  234.          *      |result==Acceleration
  235.          */
  236.         public double[] getAcceleration() {
  237.             return this.Acceleration;
  238.         }
  239.         //not in facade
  240.         /**
  241.          * Sets the acceleration
  242.          * @param x
  243.          * @param y
  244.          * @post
  245.          *      the new acceleration is set
  246.          *          |new.getAcceleration==acceleration
  247.          */
  248.         public void setAcceleration(double x, double y) {
  249.             double[] acceleration= {x,y};
  250.             Acceleration = acceleration;
  251.         }
  252.    
  253. /*
  254. **********************
  255. * Horizontal Vertical*
  256. **********************
  257.      */
  258.     /**
  259.      * Method that sets the right velocity and acceleration for moving mazub.
  260.      * @param dt
  261.      *      Time to be used when changing the position of mazub.
  262.      * @effect if mazub is ducking and moving
  263.      *      |if(isDucking()&&isMoving())
  264.      *          |then (setVelocity(getMax_Horizontal(), getVelocity()[1]))
  265.      * @effect if the horizontal velocity and the absolute value of the horizontal velocity is less than the absolute value of the minimal horizontal speed
  266.      *      |if(Math.abs(getVelocity()[0])<Math.abs(getMax_Horizontal()))
  267.      *          |then (setVelocity( getVelocity()[0]+getAcceleration()[0]*dt, getVelocity()[1]))
  268.      * @effect if the horizontal velocity not is equal to zero and the absolute value of the horizontal velocity is more than the absolute value of the minimal horizontal speed
  269.      *      |if(getVelocity()[0]!=0 && Math.abs(getVelocity()[0])
  270.      *          |then (setVelocity(getMax_Horizontal(), getVelocity()[1]))
  271.      *
  272.      */
  273.     public void horizontalMaxChanging(double dt) {
  274.     if(isDucking()&&isMoving()) {setVelocity(getMax_Horizontal(), getVelocity()[1]);}
  275.     else if(Math.abs(getVelocity()[0])<Math.abs(getMax_Horizontal())){setVelocity( getVelocity()[0]+getAcceleration()[0]*dt, getVelocity()[1]);}
  276.     if(getVelocity()[0]!=0 && Math.abs(getVelocity()[0])> Math.abs(getMax_Horizontal())) {setVelocity(getMax_Horizontal(), getVelocity()[1]);}
  277.        
  278.         }
  279.    
  280.    
  281.      
  282. /*
  283. **********************
  284. * Vertical Velocity*
  285. **********************
  286. */
  287.     /**
  288.      * Sets the new actual position of mazub.
  289.      * @param dt
  290.      *      Time to be used when changing the position of mazub.
  291.      * @effect if the actual position is less than zero
  292.      *      |if(getActualPosition()[1]<0)
  293.      *      |then (falling())
  294.      * @post the new vertical acceleration of mazub is set to 0
  295.      *      |if(getActualPosition()[1]>0)
  296.      *      |then(new.getAcceleration()[1]==-10)
  297.      * @post The new vertical velocity of mazub is set
  298.      *      |new.getVelocity()[1]==getVelocity()[1]+getAcceleration[1]*dt
  299.      */
  300.     public void verticalChanging(double dt) {
  301.        
  302.         if(getActualPosition()[1]<0) {falling();}
  303.         else if(getActualPosition()[1]>0) {setAcceleration(getAcceleration()[0],-10);}
  304.         setVelocity(getVelocity()[0], getVelocity()[1]+getAcceleration()[1]*dt);
  305.        
  306.     }
  307.    
  308. /*
  309. **********
  310. * Running*
  311. **********
  312. */
  313.     /**
  314.      * Sets the right orientation, acceleration and velocity of mazub to move to the left.
  315.      * @throws Exception
  316.      *          if mazub is moving
  317.      *              |if(isMoving())
  318.      *                  |then(throw new Exception("Already moving"))
  319.      * @post new orientation is set to -1
  320.      *      |new.getOrientation==-1
  321.      * @post new horizontal acceleration is set to -0.9
  322.      *      |new.getAcceleration()[0]==-0.9
  323.      * @post new horizontal velocity is set to -1
  324.      *      |new.getVelocity()[0]==-1
  325.      * @post Moving is set to true
  326.      *      |new.IsMoving()==true
  327.      */
  328.     public void startMoveLeft() throws Exception {
  329.         if(isMoving()==false) {
  330.           setOrientation(-1);
  331.           setAcceleration(-0.9, getAcceleration()[1]);
  332.           setVelocity(-1, getVelocity()[1]);
  333.           if(isDucking()==false) {setMax_Horizontal(3.0);}
  334.    
  335.         }
  336.         else {
  337.             throw new Exception("Already moving");
  338.         }
  339.     }
  340.    
  341.     /**
  342.      *
  343.      * @throws Exception
  344.      *      if mazub is moving
  345.      *              |if(isMoving())
  346.      *                  |then(throw new Exception("Already moving"))
  347.      * @post new orientation is set to 1
  348.      *      |new.getOrientation==1
  349.      * @post new horizontal acceleration is set to 0.9
  350.      *      |new.getAcceleration()[0]==0.9
  351.      * @post new horizontal velocity is set to 1
  352.      *      |new.getVelocity()[0]==1
  353.      * @post Moving is set to true
  354.      *      |new.IsMoving()==true
  355.      */
  356.     public void startMoveRight() throws Exception {
  357.         if(isMoving()==false) {
  358.           setOrientation(1);
  359.           setAcceleration(0.9, getAcceleration()[1]);
  360.           setVelocity(1, getVelocity()[1]);
  361.           if(isDucking()==false) {setMax_Horizontal(3.0);}
  362.         }
  363.         else {throw new Exception("Already moving");}
  364.     }
  365.    
  366.     /**
  367.      * End the horizontal movement of mazub.
  368.      * @throws Exception
  369.      *      if mazub is alreadi moving
  370.      *          |if(!isMoving())
  371.      *              the(throw new Exception("Not moving"))
  372.      * @post The current horizontal acceleration is equal to 0
  373.      *      | new.getAcceleration()[0]==0
  374.      * @post The horizontal velocity is equal to 0
  375.      *      | new.getVelocity()[0]==0
  376.      */
  377.     public void endMove() throws Exception {
  378.         if(isMoving()==true) {setAcceleration(0, getAcceleration()[1]);setVelocity(0, getVelocity()[1]);}
  379.         else {throw new Exception("Not moving");}
  380.         }
  381.  
  382.  
  383.     /**
  384.      *
  385.      * @return the value of the variable Moving
  386.      * if mazub is moving
  387.      *      | if(getVelocity()[0]!=0)
  388.      *          |then (return==true;)
  389.      *      |else (return false;)
  390.      *                  
  391.      */
  392.     public boolean isMoving() {
  393.         if(getVelocity()[0]!=0) {return true;}
  394.         else {return false;}
  395.     }
  396.    
  397.    
  398.     /**
  399.      * Sets the new actual position of mazub
  400.      * @param time
  401.      *      time to us to calculate the new position
  402.      * @throws Exception
  403.      * @effect if the horizontal actual position is bigger tha zero but less than the world width
  404.      *      | if(getActualPosition()[0] >= 0 && getActualPosition()[0] <= World_Width)
  405.      *          |then(double posx=getActualPosition()[0]+getVelocity()[0]*time+getAcceleration()[0]*0.5*time*time;
  406.      *              |if(posx <0)
  407.      *                  |then(posx=0)
  408.      *              |if(posx >World_Width)
  409.      *                  |then(posx=World_Width)
  410.      *              |new.getActualPosition[0]==posx)
  411.      *     
  412.      */
  413.     public void running(double time) throws Exception {
  414.         if(getActualPosition()[0] >= 0 && getActualPosition()[0] <= World_Width) {
  415.             double posx=getActualPosition()[0]+getVelocity()[0]*time+getAcceleration()[0]*0.5*time*time;
  416.              if(posx <0) {posx=0;}
  417.              if(posx >World_Width) {posx=World_Width;}
  418.             setActualPositon(posx, getActualPosition()[1]);
  419.             }
  420.         }
  421.        
  422.        
  423.      
  424.    
  425.     /*
  426.     *********************
  427.     * Jumping & Falling *
  428.     *********************
  429.     */
  430.    
  431.     /**
  432.      * Is true if mazub is jumping. Else is false
  433.      */
  434.     public boolean jumping;
  435.     /**
  436.      * The acceleration of mazub while jumping
  437.      */
  438.     public double VELOCITY_WHILE_JUMPING = 8.0;
  439.     /**
  440.      * The acceleration of mazub while falling
  441.      */
  442.     public double ACCELERATION_WHILE_FALLING = -10.0;
  443.  
  444.     /**
  445.      * Innitiates jumping
  446.      * @throws Exception
  447.      *      if mazub is already jumping
  448.      *          |if(isJumping())
  449.      *              | then(throw new Exception("Already Jumping"))
  450.      * @post
  451.      *  new vertical velocity and acceleration are set
  452.      *      |new.getVelocity[1]==VELOCITY_WHILE_JUMPING
  453.      *      |new.getAcceleration[1]==ACCELERATION_WHILE_FALLING
  454.      */
  455.     public void startJump() throws Exception {
  456.         if(isJumping()==false) {
  457.             setVelocity(getVelocity()[0], VELOCITY_WHILE_JUMPING);
  458.             setAcceleration(getAcceleration()[0], ACCELERATION_WHILE_FALLING);
  459.         }
  460.         else {
  461.             throw new Exception("Already Jumping");
  462.         }
  463.     }
  464.    
  465.     /**
  466.      * ends the jump
  467.      * @throws Exception
  468.      * @effect
  469.      *      if the vertical velocity is over 0
  470.      *          |if(getVelocity()[1]>0.0)
  471.      *              |then(setVelocity(getVelocity()[0], 0);falling())
  472.      */
  473.     public void endJump() throws Exception {
  474.         if(getVelocity()[1]==0) {throw new Exception("");}
  475.         if(getVelocity()[1]>0.0) {setVelocity(getVelocity()[0], 0);falling();}
  476.     }
  477.  
  478.    /**
  479.     * @post the vertical acceleration is set
  480.     *       |new.getAcceleration[1]==ACCELERATION_WHILE_FALLING
  481.     */
  482.    public void falling() {  
  483.        setAcceleration(getAcceleration()[0], ACCELERATION_WHILE_FALLING);
  484.    }
  485.    
  486.     /**
  487.      * Return is mazub is jumping or not
  488.      * @return
  489.      *      | if(getVelocity()[1]>0)
  490.      *          |result==true
  491.      *      |else
  492.      *          |result==false
  493.      */
  494.     public boolean isJumping() {
  495.         if(getVelocity()[1]>0) {return true;}
  496.         else{return false;}
  497.     }
  498.  
  499.     /**
  500.      * Checks whether the given time is a valid time for any Mazub.
  501.      * @param  time
  502.      *         The time to check.
  503.      * @return
  504.      *       | if (time == 0.2)
  505.      *              |then (return true)
  506.      *       |else (result== false)
  507.     */
  508.     public static boolean isValidtime(double time) {
  509.         if (time == 0.2) {return true;}
  510.         else {return false;}
  511.     }
  512.    
  513.    /**
  514.     * Innitiates Jumping
  515.     * @param time
  516.     * @throws Exception
  517.     * @effect
  518.     *   |if(getActualPosition()[1] >= 0 && getActualPosition()[1] <=World_Height)
  519.     *       |then( double posy= getActualPosition()[1]+getVelocity()[1]*time+getAcceleration()[1]*0.5*time*time;
  520.     *       | if(posy <0) {posy=0;}if(posy >World_Height)
  521.     *           |then(posy=World_Height)
  522.     *       |new.getActualPosition[1]==posy)
  523.     *
  524.     */
  525.     public void jumping(double time) throws Exception{
  526.                 if(getActualPosition()[1] >= 0 && getActualPosition()[1] <=World_Height) {
  527.                     double posy= getActualPosition()[1]+getVelocity()[1]*time+getAcceleration()[1]*0.5*time*time;
  528.                  if(posy <0) {posy=0;}if(posy >World_Height) {posy=World_Height;}
  529.                     setActualPositon(getActualPosition()[0], posy);
  530.                     }
  531.             }
  532.                
  533.        
  534.     /*
  535.     ***********
  536.     * Ducking *
  537.     ***********
  538.     */
  539.  
  540.     /**
  541.      * Innitiates ducking
  542.      * @throws Exception
  543.      * @post
  544.      *      |new.getMax_Horizontal==1.0
  545.      * @effect is mazub is moving
  546.      *      |if(isMoving())
  547.      *          |then(setVelocity(getMax_Horizontal(), getVelocity()[1]))
  548.      */
  549.     public void startDuck() throws Exception {
  550.         setMax_Horizontal(1.0);
  551.         if(isMoving()) {setVelocity(getMax_Horizontal(), getVelocity()[1]);}
  552.  
  553.     }
  554.    
  555.     /**
  556.      * ends ducking
  557.      * @throws Exception
  558.      * @post
  559.      *      |new.getMax_Horizontal==3.0
  560.      */
  561.     public void endDuck() throws Exception {setMax_Horizontal(3.0);}
  562.    
  563.     /**
  564.      *
  565.      * @return true is mazub is ducking. False if not
  566.      *      |if(Ducking)
  567.      *          |(result==true)
  568.      *      |else (result == false)
  569.      */
  570.     public boolean isDucking() {
  571.         if(Math.abs(getMax_Horizontal())==1.0) {return true;}
  572.         else {return false;}
  573.     }
  574.    
  575.        
  576.     /*
  577.      ****************
  578.      * AdvancedTime *
  579.      ****************
  580.      */
  581.    
  582.     //Time
  583.     public double aFitfhOFASecond = 0;
  584.     public double milisecond= 0;
  585.     public double HitTime=0;
  586.     public boolean test;
  587.     public double lessThenaSecond=0.000;
  588.    
  589.     public void advanceTime(double time) throws Exception {
  590.         if(Double.isNaN(time)) {time=0;}
  591.             if(getActualPosition()[1]>0) {falling();}
  592.            
  593.            running(time);
  594.            jumping(time);
  595.             horizontalMaxChanging(time);
  596.             verticalChanging(time);
  597.            
  598.         if(lessThenaSecond>=1.00 && isMoving()==false) {setOrientation(0);lessThenaSecond =0;}
  599.         if(isMoving()==false) {lessThenaSecond +=time;}
  600.        
  601.         if (isMoving() && milisecond >= 0.075) {setImagCount(getImagCount()+ 1); milisecond -= 0.075;}
  602.         else {milisecond += time;}
  603.        
  604.         if(isMoving() == false) {setImagCount(0);}
  605.        
  606.        
  607.        }
  608.        
  609.  
  610.     /*
  611.      ****************
  612.      * Sprites *
  613.      ****************
  614.      */
  615.  
  616.    
  617.  
  618.    
  619.     /**
  620.      * Used to know what index of Sprites to use next while mazub is running
  621.      */
  622.     public int imagCount;
  623.     private Sprite[] Allsprites;
  624.    
  625.     /**
  626.      * Sets the image Count of the sprites for Mazub
  627.      * @param imagCount
  628.      * @post ..
  629.      *      |new.imagCount = imagCount
  630.      */
  631.     public void setImagCount(int imagCount){
  632.         this.imagCount = imagCount;}
  633.    
  634.     /**
  635.      * Gets the image Count of the sprites for Mazub
  636.      * @return...
  637.      *      |result==imagCount
  638.      */
  639.     public int getImagCount() {return imagCount;}
  640.    
  641.     public Sprite sprites;
  642.     /**
  643.      * Gets the current sprite for Mazub while it is moving.
  644.      * @effect...
  645.      *      |if((isDucking() == false)&&(getOrientation()  ==0)    && (getOrientation() == 0)) {return getSprites()[0];}
  646.      *      |else if((isDucking() == true) && (getOrientation()==0) &&(getOrientation() == 0)) {return getSprites()[1];
  647.      *      |else if((getOrientation() > 0) &&  (Moving == false)  && (isDucking() == false)) {return getSprites()[2];}
  648.      *      |else if((getOrientation() < 0)    &&  (Moving == false)&& (isDucking() == false)) {return getSprites()[3];}
  649.      *      |else if((getOrientation() == 1)    &&  (isDucking() ==false) && (isJumping() == true)) {return getSprites()[4];}
  650.      *      |else if((getOrientation() ==-1)    && (isDucking() == false)&& (isJumping() == true)) {return getSprites()[5];}
  651.      *      |else if((getOrientation() ==1|| getOrientation() == 1) &&  (isDucking() == true)) {return getSprites()[6];}
  652.      *      |else if((getOrientation() == -1|| getOrientation() == -1) &&(isDucking() ==true)) {return getSprites()[7];}
  653.      *      |else if((getOrientation() == 1)    &&  (isDucking() == false)&& (isJumping() == false)) {return getSprites()[8+setImages()];}
  654.      *      |else if((getOrientation() == -1)   && (isDucking()== false)&& (isJumping() ==false)) {return getSprites()[((SPRITES.length-8)/2+8)+(setImages())];}
  655.      *      |else {return getSprites()[1];}
  656.      * @return
  657.      *      |result==getSprites()
  658.      */
  659.     public  Sprite getCurrentSprite() {
  660.         //0  is not moving horizontally, has not moved horizontally within the last second of in-game time and is not ducking.
  661.         if(getOrientation()==0 && (isDucking() == false) && (getVelocity()[0]==0)) {sprites= getSprites()[0];}
  662.        
  663.         //1 is not moving horizontally, has not moved horizontally within the last second of in-game time and is ducking.
  664.         else if ((isDucking() == true) && (getOrientation()==0) && (getVelocity()[0])==0) {sprites =getSprites()[1];}
  665.        
  666.         //2 is not moving horizontally but its last horizontal movement was to the right (within 1s), and the character is not ducking.
  667.         //Looking at right
  668.         else if (getOrientation()==1 &&  isMoving()==false  && (isDucking() == false)) {sprites= getSprites()[2];}
  669.        
  670.         //3 is not moving horizontally but its last horizontal movement was to the left (within 1s), and the character is not ducking.
  671.         //Looking at left
  672.         else if (getOrientation()==-1 && (isMoving()==false) && (isDucking() == false)) {sprites= getSprites()[3];}
  673.        
  674.         //4 is moving to the right and jumping and not ducking.
  675.         //Jumping right
  676.         else if (getVelocity()[0]>0 && (isDucking() == false) && (isJumping() == true)) {sprites= getSprites()[4];}
  677.        
  678.         //5 is moving to the left and jumping and not ducking.
  679.         else if (getVelocity()[0]<0 && (isDucking() == false) && (isJumping() == true)) {sprites= getSprites()[5];}
  680.        
  681.         //8..(8 + m) the character is neither ducking nor jumping and moving to the right
  682.         else if (getVelocity()[0]>0 && (isDucking() == false) && (isJumping() == false)) {sprites= getSprites()[8+setImages()];}
  683.        
  684.         //(9 + m)..(9 + 2m) the character is neither ducking nor jumping and moving to the left.
  685.         else if (getVelocity()[0]<0 && (isDucking()== false) && (isJumping() ==false)) {sprites= getSprites()[((getSprites().length-8)/2+8)+(setImages())];}
  686.        
  687.         //6 is ducking and moving to the right or was moving to the right (within 1s)
  688.         else if ((isDucking() == true) && getVelocity()[0]>0||getOrientation()>0) {sprites= getSprites()[6];}
  689.        
  690.         //7 is ducking and moving to the left or was moving to the left (within 1s).
  691.         else if (getVelocity()[0]<0||getOrientation()<0 &&(isDucking() ==true)) {sprites= getSprites()[7];}
  692.        
  693.         return sprites;
  694. //        else {return getSprites()[0];}
  695.         }
  696.    
  697.     /**
  698.      * Sets the images of Mazub
  699.      * @post...
  700.      *      |new.length=(getSprites().length-8)/2;
  701.      *      |new.m1 = getImagCount();
  702.      * @return ...
  703.      *      |result==m1
  704.      * @effect if the imagecount exceeds the length of the sprites array
  705.      *      |if(getImagCount() >= length)
  706.      *          |then (setImagCount(0))
  707.      */
  708.     public int setImages() {
  709.         int length=(getSprites().length-8)/2;
  710.         if(getImagCount() >= length) {setImagCount(0);}
  711.         int m1 = getImagCount();
  712.         return m1;
  713.     }
  714.    
  715.     private void setAllSprites(Sprite[] sprites) throws Exception {
  716.         if(sprites.length <10 ||sprites.length%2 ==1) {throw new Exception("Invalid sprites");}
  717.         for (int i = 0; i < sprites.length; i++) {
  718.             if(sprites[i]==null || sprites[i] instanceof Sprite==false) {
  719.                 throw new Exception("Illegal type sprites");}
  720.         }
  721.        
  722.         this.Allsprites = sprites.clone(); 
  723.     }
  724.    
  725.     /**
  726.      * return the sprites
  727.      * @return
  728.      *      |result==Allsprites.clone()
  729.      */
  730.     public Sprite[] getSprites() {
  731.         return this.Allsprites.clone();
  732.     }
  733.  
  734.  
  735. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement