Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jumpingalien.model;
- import be.kuleuven.cs.som.annotate.*;
- 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
- * @post...
- * |new.getActuaPosition()[0]==calculateToActual(pixelX) &&
- * |new.getgetActuaPosition()[1]==calculateToActual(pixelY)
- */
- 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
- *
- * @post...
- * |new.getActualPosition()[0]== (double)pixelX/100 &&
- * |new.getActualPosition()[1]== (double)pixelY/100
- */
- public Entity(long id, int pixelX, int pixelY, School school, Sprite... sprites) throws Exception {
- setPixelPosition(pixelX, pixelY);
- setActualPosition((double)pixelX/100, (double)pixelY/100);
- setSprites(sprites);
- }
- //FIXME weet niet of object buiten weereld mag worden gezet.
- /*
- *************
- ** Position *
- *************/
- 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
- * @post...
- * |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;}
- 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
- * @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 *
- ************
- */
- public double[] Velocity= new double[2];
- public double[] Acceleration=new double[2];
- /**
- *
- * @param velocityx
- * @param velocityY
- * @post...
- * |new.getVelocity[0]=velocityX &&
- * |new.getVelocity[1]=velocityY
- */
- 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
- * @throws Exception
- */
- public void startMoveLeft() throws Exception {setOrientation(-1);}
- /**
- * @post...
- * |new.getOrientation==-1
- * @throws Exception
- */
- public void startMoveRight() throws Exception{setOrientation(1);}
- public void startMovement2() { }
- public void startMovement1() { }
- /**
- * @post...
- * |new.getOrientation==0
- */
- public void endMove() {setOrientation(0);}
- /*
- **************
- * Terminated *
- **************
- */
- /**FIXME SORRY
- * @post...
- * |getWorld==null
- * @post...
- * |!(world.hasAsGameObject)
- */
- public void terminateGameObject(){
- if(getWorld() !=null) {removeWorld();}
- }
- public int Hitpoint;
- /**
- *
- * @param hitpoint
- * @post...
- * |new.getHitpoint+=hitpoint
- */
- public void setHitPoint(int hitpoint) {Hitpoint += hitpoint;}
- /**
- *
- * @return...
- * |result==Hitpoint
- */
- public int getHitpoint() {return Hitpoint;}
- public double deathTime=0;
- public void advanceTime(double dt) throws Exception {
- if(isDeadGameObject()) {
- deathTime=dt;
- // if(dt==deathTime+0.6) {terminateGameObject();}
- }
- }
- /*
- *********************
- * Sprites of Entity*
- *********************
- */
- public Sprite[] Sprites;
- 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");}
- }
- public Sprite[] getSprites() {return Sprites;}
- public Sprite currentSprite;
- public Sprite getCurrentSprite() {
- return Sprites[0];
- }
- public boolean Terminated=false;
- /** FIXME SORRY
- *
- * @param gameObject
- * @return...
- * |if(getWorld()==null)
- * |then (result==true)
- * |else (result==false)
- */
- public boolean isTerminatedGameObject() {
- if(getWorld()==null) {return true;}
- else {return false; }}
- /**
- *
- * @return...
- * |if(getHitpoint()<= 0)
- * |then (result==true)
- * |else (result==false)
- */
- public boolean isDeadGameObject() {
- if(getHitpoint()<= 0) { return true;}
- else {return false;}
- }
- /*
- ************
- * Get World*
- ************
- *
- */
- World currentWorld;
- public double timerElement=0;
- public boolean ableTogetDamaged=false;
- public void falling() {}
- /**
- *
- * @param world
- * @post...
- * |new.getWorld==world
- */
- public void setWorld(World world) {currentWorld = world;
- }
- /**
- *
- * @return..
- * |result==currentWorld
- */
- public World getWorld() {return currentWorld;}
- /*
- ************
- * Collision*
- ************
- *
- */
- /**
- *
- * @param actual
- * @return...
- * |result==((int)(actual*100))
- */
- public int calculateToPixel (double actual) {return ((int)(actual*100));}
- /**
- *
- * @param pixel
- * @return...
- * |result==(((double)pixel)/100)
- */
- public double calculateToActual (int pixel) {return (((double)pixel)/100);}
- /**
- *
- * @param hitsChanged
- * @post...
- * |new.getHitpoint()==Hitpoint+hitsChanged
- */
- public void addHitPoint(int hitsChanged) {setHitPoint(hitsChanged);}
- public void endJump() { }
- /**
- * new.getWorld()==null
- */
- public void removeWorld() {currentWorld = null;}
- public void stopDuckingIsEnabled() { }
- public double lessThenTwo = 0.0;
- public boolean canBeDamaged=true;
- public int hitsChanged = 0;
- public int totalChanged = 0;
- /**
- *
- * @param currentEntity
- * @effect...
- * |if(getWorld().Element(currentEntity,3)==true)
- * |then (hitsChanged+=-50;totalChanged+=-50)
- * |else if(getWorld().Element(currentEntity,5)==true)
- * |then (hitsChanged+=-4;totalChanged+=-4)
- * |else if(getWorld().Element(currentEntity,2)==true)
- * |then (hitsChanged+=-2;totalChanged+=-2)
- * @return...
- * |result==hitsChanged
- */
- public int ElementCollison(Entity currentEntity) {
- if(getWorld().Element(currentEntity,3)==true){hitsChanged+=-50;totalChanged+=-50;}// 3=Magma
- else if(getWorld().Element(currentEntity,5)==true){hitsChanged+=-4;totalChanged+=-4;}
- else if(getWorld().Element(currentEntity,2)==true){hitsChanged+=-2;totalChanged+=-2;} // 2=Water
- return hitsChanged;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement