Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jumpingalien.model;
- import be.kuleuven.cs.som.annotate.*;
- //import jdk.nashorn.internal.ir.SetSplitState;
- import jumpingalien.util.Sprite;
- /**
- * A class for making the Entity file.
- *
- * @version 1.0
- * @author Thierry Klougbo & Jordi De Pau
- *
- * @invar Each Mazub can have its time as time.
- * | canHaveAstime(this.gettime())
- */
- public class Entity {
- // Consttructor Settings
- /**
- * Constructor for all kinds of Plants and Sharks. //FIXME moet hier @Post bij?
- * @param pixelX
- * @param pixelY
- * @param sprites
- * @throws Exception
- */
- public Entity(int pixelX,int pixelY, Sprite...sprites) throws Exception {
- setActualPosition(calculateToActual(pixelX), calculateToActual(pixelY));
- setSprites(sprites);
- }
- /**
- * Constructor for Slimes
- * @param id
- * @param pixelX
- * @param pixelY
- * @param school
- * @param sprites
- * @throws Exception
- */
- public Entity(long id, int pixelX, int pixelY, School school, Sprite... sprites) throws Exception {
- setPixelPosition(pixelX, pixelY);
- setActualPosition(pixelX/100, pixelY/100);
- setSprites(sprites);
- }
- //FIXME weet niet of object buiten weereld mag worden gezet.
- /*
- *************
- ** Position *
- *************/
- /**
- * The actual positon of Objects.
- */
- public double[] actualPosition=new double[2];
- /**
- *
- * @param newPosition
- * @post ...
- * |new.getActualPosition() == newPosition
- */
- public void changeActualPosition(double[] newPosition) throws Exception {actualPosition = newPosition;}
- /**
- *
- * @param x
- * @param y
- * @post...
- * |new.getActualPotion()[0]==x && new.getActualPostion()[1]==y
- * |new.getPisxelPostione()[0]==(int)(getActualPosition()[0]*100) && new.getPisxelPostione()[1]== (int)(getActualPosition()[1]*100)
- */
- public void setActualPosition(double x, double y) {
- actualPosition[0]=x;actualPosition[1]=y;
- setPixelPosition(calculateToPixel(x),calculateToPixel(y));
- }
- /**
- *
- * @return..
- * |result == actualPosition
- */
- public double[] getActualPosition() {return actualPosition;}
- /**
- * The pixel postion of the objects
- */
- public int[] pixelPosition=new int[2];
- /**
- *
- * @param newPosition
- * @post...
- * |new.getPixelPostion== newPositon
- */
- public void changePixelPosition(int[] newPosition) {
- pixelPosition = newPosition;
- }
- /**
- *
- * @param pixelLeftX
- * @param pixelBottomY
- * @post...
- * |new.getPixelPostion[0]==pixleLeftX
- * |new.getPixelPostion[1]==pixelBottomY
- */
- public void setPixelPosition(int pixelLeftX, int pixelBottomY) {
- pixelPosition[0] = pixelLeftX; pixelPosition[1]=pixelBottomY;
- // pixelPosition[0] = (int)(getActualPosition()[0]*100); pixelPosition[1]= (int)(getActualPosition()[1]*100);
- }
- /**
- *
- * @return...
- * |result==pixelPostion
- */
- public int[] getPixelPosition() { return pixelPosition;}
- /*
- ****************
- * Orientation *
- ****************
- */
- public int Orientation;
- /**
- *
- * @param cURRENT_ORIENTATION
- * The current orientation of Mazub.
- * @pre cURRENT_ORIENTATION must be 1 or -1
- * |(cURRENT_ORIENTATION==-1)||(cURRENT_ORIENTATION==1)
- * @pre..
- * |Orientation==1 ||
- * |Orientation==-1
- * @post ..
- * |new.CURRENT_ORIENTATION = cURRENT_ORIENTATION
- */
- public void setOrientation(int cURRENT_ORIENTATION) {
- Orientation = cURRENT_ORIENTATION;}
- /**
- *
- * @return
- * |result==CURRENT_ORIENTATION
- */
- public int getOrientation() {return Orientation;}
- /*
- ************
- * Velocity *
- ************
- */
- /**
- * The Velocity of gameobjects.
- */
- public double[] Velocity= new double[2];
- /**
- * The acceleration of gameobjects.
- */
- public double[] Acceleration=new double[2];
- /**
- *
- * @param velocityx
- * @param velocityY
- * @post...
- * |new.getVelocity[0]
- */
- public void setVelocity(double velocityx, double velocityY){Velocity[0]=velocityx; Velocity[1]=velocityY;}
- /**
- *
- * @return...
- * |result== Velocity
- */
- public double[] getVelocity() {return Velocity;}
- /**
- *
- * @param horzintel
- * @param vertical
- * @post...
- * |new.getAcceleration[0]==horizontal &&
- * |new.getAcceleration[1]==vertical
- */
- public void setAcceleration(double horzontal,double vertical) {
- Acceleration[0] = horzontal;
- Acceleration[1] = vertical;}
- public double[] getAcceleration() {
- return Acceleration;
- }
- /*
- ************
- * Movement *
- ************
- */
- /**
- * @post...
- * |new.getOrientation==-1
- */
- public void startMoveLeft(){setOrientation(-1);}
- /**
- * @post...
- * |new.getOrientation==-1
- */
- public void startMoveRight(){setOrientation(1);}
- //FIXME zien of het in elke classe hetzelfde doet.
- public void startMovement2() { }
- public void startMovement1() { }
- /**
- * @post...
- * |new.getOrientation==0
- */
- public void endMove() {setOrientation(0);}
- /*
- **************
- * Terminated *
- **************
- */
- /**
- * Parameter storing the hitpoints of gameobjects
- */
- public int Hitpoint;
- /**
- *
- * @param hitpoint
- * @post...
- * |new.getHitpoint==hitpoint
- */
- public void setHitPoint(int hitpoint) {
- Hitpoint += hitpoint;
- }
- /**
- *
- * @return...
- * |result==Hitpoint
- */
- public int getHitpoint() {return Hitpoint;}
- // AdvancedTime Settings
- public double deathTime=0;
- /**
- *
- * @param dt
- * @throws Exception
- * @post...
- * |if(isDeadGameObject()){isTerminatedGameObject()==true}//FIXME weet niet of het echt zo moet worden geschreven.
- */
- public void advanceTime(double dt) throws Exception {
- if(isDeadGameObject()) {
- deathTime=dt;
- if(dt==deathTime+0.6) {
- terminateGameObject();
- }
- }
- }
- public void terminateGameObject() {
- removeWorld();
- }
- /*
- *********************
- * Sprites of Entity*
- *********************
- */
- public Sprite[] Sprites;
- /**
- *
- * @param spritess
- * @throws Exception
- * |spritess.length <= 0
- * @post...
- * |new.getSprites==spritess
- */
- public void setSprites(Sprite[] spritess) throws Exception {
- if(spritess == null) {throw new Exception("Not effective Sprites");}
- for (int i = 0; i < spritess.length; i++) {
- if(spritess[i]==null) {throw new Exception("Invalid sprites we don't like sprites with null values.");}}
- if(spritess.length > 0) {this.Sprites = spritess;}
- else {throw new Exception("illegalArgument Sprites");}
- }
- /**
- *
- * @return...
- * |result==Sprites
- */
- public Sprite[] getSprites() {return Sprites;}
- public Sprite currentSprite;
- /**
- *
- * @return...
- * |result==null
- */
- public Sprite getCurrentSprite() {
- return Sprites[0];
- }
- /*
- ************
- * Terminate*
- ************
- */
- /**FIXME SORRY
- * @post...
- * |getWorld==null
- * @post...
- * |!(world.hasAsGameObject)
- */
- public void terminateGameObject(Entity currentEntity){
- if(getWorld() !=null) {getWorld().removeGameObject(currentEntity);}
- removeWorld();}
- public boolean Terminated=false;
- /** FIXME SORRY
- *
- * @param gameObject
- * @return...
- * |result==true ||
- * |result==false
- */
- public boolean isTerminatedGameObject() {
- if(getWorld()==null) {return true;}
- else {return false; }}
- /**
- *
- * @return...
- * |result==true ||
- * |result==false
- */
- public boolean isDeadGameObject() {
- if(getHitpoint()<= 0) { return true;}
- else {return false;}
- }
- /*
- ************
- * Get World*
- ************
- *
- */
- World currentWorld;
- public void falling() {}
- /**
- *
- * @param world
- * @post...
- * |getWorld==world
- */
- public void setWorld(World world) {
- currentWorld = world;
- }
- /**
- *
- * @return..
- * |result==currentWorld
- */
- public World getWorld() {
- return currentWorld;
- }
- /*
- ************
- * Collision*
- ************
- *
- */
- public int calculateToPixel (double actual) {return ((int)(actual*100));}
- public double calculateToActual (int pixel) {return (((double)pixel)/100);}
- public void addHitPoint(int hitsChanged) {
- setHitPoint(getHitpoint()+hitsChanged);
- }
- public void endJump() {
- // TODO Auto-generated method stub
- }
- public void removeWorld() {
- currentWorld = null;
- }
- public void stopDuckingIsEnabled() {
- // TODO Auto-generated method stub
- }
- /*
- * TerminateGameObject
- * isTerminatedGameObject
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement