Advertisement
RecklessDarph

BackUp Entity

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