Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jumpingalien.model;
- import jumpingalien.util.ModelException;
- import jumpingalien.util.Sprite;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import com.sun.org.apache.bcel.internal.generic.RETURN;
- import be.kuleuven.cs.som.annotate.*;
- //import javafx.geometry.HorizontalDirection;
- /**
- * A class for making the Mazub alien move jump, duck and also get the imageSprites and coordinates.
- *
- * @version 3.0
- * @author Thierry Klougbo & Jordi De Pau
- *
- * @invar Each Mazub can have its time as time.
- * | canHaveAstime(this.gettime())
- */
- public class Mazub extends Entity{
- /**
- * Initialise the object Mazub (player) with given coordinations of Pixel X and Pixel and given sprites = Images of the player
- *
- * @param BottomPixelX
- * The Bottom Pixel X for this player Mazub
- * @param BottomPixelY
- * The Bottom Pixel Y for this player Mazub
- * @param sprites
- * Sprites an array of at least 10 Images and are even for every animation for player mazub.
- * @throws IllegalArgumentException
- * The given BottomPixelX and BottomPixelY are no valid Bottom pixels for any Mazub.
- * ||if(BottomPixelX<0 || BottomPixelX>1024 || BottomPixelY <0 || BottomPixelY>768) {throw new IllegalArgumentException();}
- */
- public Mazub(int BottomPixelX,int BottomPixelY, Sprite... sprites) throws Exception{
- super(BottomPixelX, BottomPixelY, sprites);
- if(BottomPixelX<0 || BottomPixelY <0) {throw new Exception("Negative values for pixels");}
- if(sprites.length%2 == 1||sprites.length <10) {throw new Exception("Invalid sprites");}
- setActualPosition((double)BottomPixelX/100,(double)BottomPixelY/100);
- setPixelPosition(BottomPixelX, BottomPixelY);
- setHitPoint(100);
- }
- /*
- ****************
- * Game World *
- ****************
- */
- public final double WORLD_WIGTH = 1024.00;
- public final double WORLD_HEIGHT = 768.00;
- public double[] dimentions=new double[2];
- /**
- * returns an array containing the wigth and the height of the game window.
- * @return
- * |result == dimentions
- */
- public double[] getDimentions() {dimentions[0]=WORLD_WIGTH; dimentions[1]=WORLD_HEIGHT; return dimentions;}
- //Orientation => Nominal
- /*
- ****************
- * Orientation *
- ****************
- */
- //FIXME Need to make previous position for current sprite and stuff
- /*
- /**
- * @pre second must be equal to 1
- * | if(second == 1)
- * @post the previous orientation is equal to the current orientation.
- * |new.PREVIOUS_ORIENTATION = CURRENT_ORIENTATION
- /
- public void setPREVIOUS_ORIENTATION() {if(second == 1)
- {PREVIOUS_ORIENTATION = Orientation;}}
- /**
- * @return the previous orientation
- * |result==PREVIOUS_ORIENTATION
- /
- public int getOrientation() {return PREVIOUS_ORIENTATION;}
- */
- /*
- ****************
- * Velocity *
- ****************
- */
- //Horizontal => Totally
- public double MINIMAL_HORIZONTAL_SPEED =1.0;
- public double MAXIMUM_HORIZONTAL_SPEED = 3.0;
- /**
- * @return ...
- * |result==MAXIMUM_HORIZONTAL_SPEED
- */
- public double getMAXIMUM_HORIZONTAL_SPEED() {return MAXIMUM_HORIZONTAL_SPEED;}
- /**
- * @param mAXIMUM_HORIZONTAL_SPEED
- * @post ...
- * |MAXIMUM_HORIZONTAL_SPEED = mAXIMUM_HORIZONTAL_SPEED
- */
- public void setMAXIMUM_HORIZONTAL_SPEED(double mAXIMUM_HORIZONTAL_SPEED) {if(getOrientation()!=0) {MAXIMUM_HORIZONTAL_SPEED = mAXIMUM_HORIZONTAL_SPEED*getOrientation();}else {MAXIMUM_HORIZONTAL_SPEED = mAXIMUM_HORIZONTAL_SPEED*1;}}
- /**
- *
- * @return ...
- * |result==MINIMAL_HORIZONTAL_SPEED
- */
- public double getMINIMAL_HORIZONTAL_SPEED() {return MINIMAL_HORIZONTAL_SPEED;}
- /**
- *
- * @param mINIMAL_HORIZONTAL_SPEED
- * @post ..
- * |MINIMAL_HORIZONTAL_SPEED = mINIMAL_HORIZONTAL_SPEED*getOrientation()
- */
- public void setMINIMAL_HORIZONTAL_SPEED(double mINIMAL_HORIZONTAL_SPEED) {if(getOrientation()!=0) {MINIMAL_HORIZONTAL_SPEED = mINIMAL_HORIZONTAL_SPEED*getOrientation();}else {MINIMAL_HORIZONTAL_SPEED = mINIMAL_HORIZONTAL_SPEED*1;}}
- /*
- ****************
- * Changing Max Horizontal*
- ****************
- */
- public void horizontalMaxChanging(double dt) {
- BigDecimal time= BigDecimal.valueOf(dt),acceleration= BigDecimal.valueOf(getAcceleration()[0]),velocity= BigDecimal.valueOf(getVelocity()[0]);
- int px=getPixelPosition()[0];
- int py=getPixelPosition()[1];
- // if(getWorld() != null && getWorld().getGeologicalFeatures(px=getPixelPosition()[0]+(getSpriteDimention()[0]-1), py=getPixelPosition()[1])!=1){
- if(Math.abs(getVelocity()[0])<Math.abs(getMAXIMUM_HORIZONTAL_SPEED())){setVelocity( velocity.add(acceleration.multiply(time)).doubleValue(), getVelocity()[1]);}
- // if(isDucking() == true) {setMAXIMUM_HORIZONTAL_SPEED(1.0);}
- if(getVelocity()[0]!=0 && Math.abs(getVelocity()[0])> Math.abs(getMAXIMUM_HORIZONTAL_SPEED())) {setVelocity(getMAXIMUM_HORIZONTAL_SPEED(), getVelocity()[1]);}
- if(getVelocity()[0]!=0 && Math.abs(getVelocity()[0])<Math.abs(getMINIMAL_HORIZONTAL_SPEED())) {setVelocity(getMINIMAL_HORIZONTAL_SPEED(), getVelocity()[1]);}
- }
- public void verticalChanging(double dt) {
- BigDecimal time= BigDecimal.valueOf(dt),acceleration= BigDecimal.valueOf(getAcceleration()[1]),velocity= BigDecimal.valueOf(getVelocity()[1]);
- // else if(getActualPosition()[1] > 0 && world.getGeologicalFeatures(px, py)==1) {setAcceleration(getAcceleration()[0], 0);}
- if(getWorld() != null && getActualPosition()[1]<=0) {setAcceleration(getAcceleration()[0],0);}
- setVelocity(getVelocity()[0], velocity.add(acceleration.multiply(time)).doubleValue());
- }
- /*
- ****************
- * Running*
- ****************
- */
- public void startMoveLeft() {
- // int px=getPixelPosition()[0]; int py=getPixelPosition()[1];
- // if(world.getGeologicalFeatures(px, py+(getSpriteDimention()[1]-2))!=1) {
- Moving = true;
- setOrientation(-1);
- setAcceleration(-0.9, getAcceleration()[1]);
- setVelocity(-1, getVelocity()[1]);
- setMAXIMUM_HORIZONTAL_SPEED(3.0);
- //
- }
- public void startMoveRight() {
- int px=getPixelPosition()[0]; int py=getPixelPosition()[1];
- // if(world.getGeologicalFeatures(px+(getSpriteDimention()[0]-1), py+(getSpriteDimention()[1]-2))!=1) {
- Moving = true;
- setOrientation(1);
- setAcceleration(0.9, getAcceleration()[1]);
- setVelocity(1, getVelocity()[1]);
- setMAXIMUM_HORIZONTAL_SPEED(3.0);}
- public boolean Moving;
- /**
- * @post The current orientation is equal to 0
- * | new.getOrientation() == 0
- * @post The current horizontal accelereation is equal to 0
- * | new.getAcceleration()[0]=0
- * @post The horizontal velocity is equal to 0
- * | new.getVelocity()[0]=0
- */
- public void endMove() {
- Moving = false;
- setAcceleration(0, getAcceleration()[1]);
- setVelocity(0, getVelocity()[1]);
- }
- public int currentOrientation;
- public void setCurrentOrientation(int i) {
- currentOrientation=i;
- }
- public int getCurrentOrientation() {
- return currentOrientation;
- }
- /**
- *
- * @return the value of the variable Moving
- * | result == if(Moving) {return true;}
- * else {return false;}
- */
- public boolean isMoving() {
- //assert(moving==true) ?
- if(Moving) {return true;}
- else {return false;}
- }
- /**
- * Initialize this new Mazub with given time.
- *
- * @param time
- * The time for this new Mazub.
- * @pre This new Mazub can have the given time as its time.
- * | canHaveAstime(time)
- * @post The time of this new Mazub is equal to the given
- * time.
- * | new.gettime() == time
- */
- public void running(double time) {
- if(getActualPosition()[0] >= 0 && getActualPosition()[0] <= getDimentions()[0]) {
- double posx=
- BigDecimal.valueOf(actualPosition[0])
- .add (BigDecimal.valueOf(Velocity[0]).multiply(BigDecimal.valueOf(time)))
- .add(BigDecimal.valueOf(getAcceleration()[0]).multiply(BigDecimal.valueOf(0.5))
- .multiply(BigDecimal.valueOf(Math.pow(time, 2)))).doubleValue();
- setActualPosition(posx, getActualPosition()[1]);
- }
- if(getActualPosition()[0]>getDimentions()[0]) {setActualPosition(getDimentions()[0],getActualPosition()[1]);}
- if(getActualPosition()[0]< 0) {setHitPoint(0);}
- }
- /*
- ****************
- * Jumping & FAlling *
- ****************
- */
- public boolean jumping;
- public double ACCELERATION_WHILE_JUMPING = 8.0;
- public double ACCELERATION_WHILE_FALLING = -10.0;
- /**
- * Set the vertical velocity of this object_name to the given vertical velocity.
- *
- * @pre The given vertical velocity must be a valid vertsiical velocity for any
- * Mazub.
- * | isValidVERTICAL_VELOCITY(setVetical_VELOCITY(ACCELERATION_WHILE_JUMPINT))
- *
- * @post The vertical velocity of this Mazub is equal to the given
- * vertical velocity.
- * | new.getVERTICAL_VELOCITY() == setVetical_VELOCITY(ACCELERATION_WHILE_JUMPINT)
- * @post The vertical acceleration of this Mazub is equal to -10.
- * | new.getAcceleration()[1] == setVetical_ACCELERATION(-10)
- *
- */
- public void startJump() {
- // if(world.getGeologicalFeatures(px, py)!=1) {
- jumping = true;
- setVelocity(getVelocity()[0], ACCELERATION_WHILE_JUMPING);
- setAcceleration(getAcceleration()[0], ACCELERATION_WHILE_FALLING);
- // }
- }
- /**
- * @post The vertical velocity of this Mazub is equal to 0.
- * | new.getVERTICAL_VELOCITY() == setVetical_VELOCITY(0)
- */
- public void endJump() {
- // if(jumping) {
- jumping = false;
- setAcceleration(getAcceleration()[0],0);
- if(getVelocity()[1]>0) {setVelocity(getVelocity()[0],0);}
- // }
- }
- public void falling() {
- setAcceleration(getAcceleration()[0], ACCELERATION_WHILE_FALLING);
- }
- /**
- *
- * @return if Mazub is jumping or not
- * |result == if(jumping) {return true;}
- | else{return false;}
- */
- public boolean isJumping() {
- if(jumping) {return true;}
- else{return false;}
- }
- /**
- * Check whether the given time is a valid time for
- * any Mazub.
- *
- * @param time
- * The time to check.
- * @return
- * | result ==
- */
- public static boolean isValidtime(double time) {
- if (time == 0.2) {return true;}
- else {return false;}
- }
- /**
- * Initialize this new Mazub with given time.
- *
- * @param time
- * The time for this new Mazub.
- * @throws ExceptionName_Java
- * The given time is not a valid time for any
- * Mazub.
- * | ! isValidtime(gettime())
- * @effect ...
- * |if(getActualPositionY() >= 0 && getActualPositionY() <= getWorldHeight()) {setActualPositionY(getActualPositionY()+ (getVERTICAl_VELOCITY()*time)+(0.5*getAcceleration()[1]*time*time)) ;}
- * |if(getActualPositionY()>getWorldHeight()) {setActualPositionY(getWorldHeight());}
- * |if(getActualPositionY()< 0) {setActualPositionY(0);}
- */
- public void jumping(double time) throws IllegalArgumentException{
- if(getActualPosition()[1] >= 0 && getActualPosition()[1] <= getDimentions()[1]) {
- double posy=
- BigDecimal.valueOf(actualPosition[1])
- .add (BigDecimal.valueOf(Velocity[1]).multiply(BigDecimal.valueOf(time)))
- .add(BigDecimal.valueOf(getAcceleration()[1]).multiply(BigDecimal.valueOf(0.5))
- .multiply(BigDecimal.valueOf(Math.pow(time, 2)))).doubleValue();
- setActualPosition(getActualPosition()[0], posy);
- }
- if(getWorld()!=null) {if (getAcceleration()[0] >getWorld().getSizeInPixels()[0]) {setHitPoint(0);}}
- if(getActualPosition()[1]< 0) {setHitPoint(0);}
- }
- /*
- * int[] pos =
- {(BigDecimal.valueOf(
- (BigDecimal.valueOf(currentEntity.actualPosition[0])
- .add (BigDecimal.valueOf(currentEntity.Velocity[0]).multiply(BigDecimal.valueOf(time)))
- .add(BigDecimal.valueOf(currentEntity.getAcceleration()[0]).multiply(BigDecimal.valueOf(0.5))
- .multiply(BigDecimal.valueOf(Math.pow(time, 2))))).doubleValue()).doubleValue()),
- mazub.calculateToPixel(BigDecimal.valueOf(
- (BigDecimal.valueOf(currentEntity.actualPosition[1])
- .add (BigDecimal.valueOf(currentEntity.Velocity[1]).multiply(BigDecimal.valueOf(time)))
- .add(BigDecimal.valueOf(currentEntity.getAcceleration()[1]).multiply(BigDecimal.valueOf(0.5))
- .multiply(BigDecimal.valueOf(Math.pow(time, 2))))).doubleValue()).doubleValue())};
- *
- */
- /*
- ****************
- * Ducking *
- ****************
- */
- //Fixme Check wheter if he stop with ducking it doesnt stop
- public boolean Ducking;
- public boolean ableToDuck=true;
- /**
- * @effect...
- * |if(getOrientation() != 0) {setMAXIMUM_HORIZONTAL_SPEED(1.0*getOrientation());}
- * |else {setMAXIMUM_HORIZONTAL_SPEED(1.0);}
- *@post ...
- * |Ducking = true
- */
- public void startDucking() {
- if(isDucking()==false) {setMAXIMUM_HORIZONTAL_SPEED(1.0);setAcceleration(0, getAcceleration()[1]);}
- else {setMAXIMUM_HORIZONTAL_SPEED(1.0);}
- Ducking = true;
- }
- /**
- * @effect...
- * |if(getOrientation() != 0)setMAXIMUM_HORIZONTAL_SPEED(3.0*getOrientation());
- * |else {setMAXIMUM_HORIZONTAL_SPEED(3.0);} Ducking = false;
- */
- public void endDucking() {
- if (isDucking()) {
- setMAXIMUM_HORIZONTAL_SPEED(3.0);
- Ducking=false;}
- }
- /**
- *
- * @return...
- * |if(Ducking) {return true;}
- * |else {return false;}
- */
- public boolean isDucking() {
- if(Ducking) {return true;}
- else {return false;}
- }
- /*
- ****************
- * AdvancedTime *
- ****************
- */
- //Time
- public double aFitfhOFASecond = 0;
- public double milisecond= 0;
- public double HitTime=0;
- /**
- * Changes the position of Mazub
- * @param time
- * @effect...
- * |horizontalChanging(time);
- * |verticalChanging(time);
- * |running(time);
- * |jumping(time);
- * |if(second >= 1.0) {setPREVIOUS_ORIENTATION(); second =0;}
- * |else{second =+time;}
- * |if (milisecond >= 0.075) {setImagCount(getImagCount()+ 1); milisecond = 0;}
- * |else {milisecond += time;}
- * |if(isMoving() == false) {setImagCount(0);}
- */
- public double lessThenaSecond=0.000;
- public void advanceTime(double time) throws Exception {
- if(overlapEarth(futureEarth(time, 0), getPixelPosition()[1])==false) {running(time);}
- if(overlapEarth(getPixelPosition()[0],futureEarth(time, 1))==false){jumping(time);}
- horizontalMaxChanging(time);
- verticalChanging(time);
- if(lessThenaSecond>=1.00&&isMoving()==false) {setOrientation(0);lessThenaSecond =0;}
- else {lessThenaSecond +=time;}
- if (isMoving() && milisecond >= 0.075) {setImagCount(getImagCount()+ 1); milisecond = 0;}
- else {milisecond += time;}
- if(isMoving() == false) {setImagCount(0);}
- }
- /*
- ****************
- * Collision *
- ****************
- */
- public BigDecimal timePerCm(double time,Entity currentEntity) {
- //Calculation of time fragments with given acceleration, velocity and time.
- BigDecimal currentVelocityX= BigDecimal.valueOf(currentEntity.getVelocity()[0]), currentVelocityY= BigDecimal.valueOf(currentEntity.getVelocity()[1]), currentAccelerationX= BigDecimal.valueOf(currentEntity.getAcceleration()[0]),currentAccelerationY= BigDecimal.valueOf(currentEntity.getAcceleration()[1]);
- BigDecimal cm= BigDecimal.valueOf(0.01);
- BigDecimal timedt = BigDecimal.valueOf(time);
- BigDecimal mathsqr1=BigDecimal.valueOf(Math.sqrt((currentAccelerationX.pow(2).add(currentAccelerationY.pow(2))).doubleValue()));
- BigDecimal mathsqr2=BigDecimal.valueOf(Math.sqrt((currentVelocityX.pow(2).add(currentVelocityY.pow(2))).doubleValue()));
- BigDecimal divider = mathsqr1.add(mathsqr2.multiply(timedt));
- if(divider.compareTo(BigDecimal.valueOf(0.0))==0) {return BigDecimal.valueOf(time);}
- BigDecimal dt= BigDecimal.valueOf(cm.divide((divider), 16, RoundingMode.HALF_UP).doubleValue());
- return dt;
- }
- /*
- ****************
- * Sprites *
- ****************
- */
- public Sprite[] getSprites() {return Sprites;}
- public int imagCount;
- /**
- * Sets the sprites for Mazub
- * @param sPRITES
- * @post ...
- * |SPRITES = sPRITES
- * @throws IllegalArgumentExecption if array of sprytes is empty.
- * |if(sPRITES==null) {throw new IllegalArgumentException();}
- */
- /**
- * Sets the image Count of the sprites for Mazub
- * @param imagCount
- * @post ..
- * |this.imagCount = imagCount
- */
- public void setImagCount(int imagCount){
- this.imagCount = imagCount;}
- /**
- * Gets the image Count of the sprites for Mazub
- * @return...
- * |result==imagCount
- */
- public int getImagCount() {return imagCount;}
- /**
- * Gets the current sprite for Mazub while it is moving.
- * @effect...
- * |if((isDucking() == false)&&(getOrientation() ==0) && (getOrientation() == 0)) {return getSprites()[0];}
- * |else if((isDucking() == true) && (getOrientation()==0) &&(getOrientation() == 0)) {return getSprites()[1];
- * |else if((getOrientation() > 0) && (Moving == false) && (isDucking() == false)) {return getSprites()[2];}
- * |else if((getOrientation() < 0) && (Moving == false)&& (isDucking() == false)) {return getSprites()[3];}
- * |else if((getOrientation() == 1) && (isDucking() ==false) && (isJumping() == true)) {return getSprites()[4];}
- * |else if((getOrientation() ==-1) && (isDucking() == false)&& (isJumping() == true)) {return getSprites()[5];}
- * |else if((getOrientation() ==1||getOrientation() == 1) && (isDucking() == true)) {return getSprites()[6];}
- * |else if((getOrientation() == -1|| getOrientation() == -1) &&(isDucking() ==true)) {return getSprites()[7];}
- * |else if((getOrientation() == 1) && (isDucking() == false)&& (isJumping() == false)) {return getSprites()[8+setImages()];}
- * |else if((getOrientation() == -1) && (isDucking()== false)&& (isJumping() ==false)) {return getSprites()[((SPRITES.length-8)/2+8)+(setImages())];}
- * |else {return getSprites()[1];}
- * @return
- * |result==getSprites()
- */
- public Sprite getCurrentSprite() {
- //0 is not moving horizontally, has not moved horizontally within the last second of in-game time and is not ducking.
- if((isDucking() == false)&&(getVelocity()[0]==0)) {return getSprites()[0]; }
- //1 is not moving horizontally, has not moved horizontally within the last second of in-game time and is ducking.
- else if ((isDucking() == true) && (getOrientation()==0) &&(getVelocity()[0])==0) {return getSprites()[1];}
- //2 is not moving horizontally but its last horizontal movement was to the right (within 1s), and the character is not ducking.
- //Looking at right
- else if (getVelocity()[0] > 0&&getOrientation() >0 && Moving==false && (isDucking() == false)) {return getSprites()[2];}
- //3 is not moving horizontally but its last horizontal movement was to the left (within 1s), and the character is not ducking.
- //Looking at left
- else if (getVelocity()[0]<0 &&getOrientation()<0 && (Moving == false)&& (isDucking() == false)) {return getSprites()[3];}
- //4 is moving to the right and jumping and not ducking.
- //Jumping right
- else if (getVelocity()[0]>0 && (isDucking() ==false) && (isJumping() == true)) {return getSprites()[4];}
- //5 is moving to the left and jumping and not ducking.
- else if (getVelocity()[0]<0 && (isDucking() == false)&& (isJumping() == true)) {return getSprites()[5];}
- //6 is ducking and moving to the right or was moving to the right (within 1s)
- else if (getVelocity()[0]>0 && (isDucking() == true)) {return getSprites()[6];}
- //7 is ducking and moving to the left or was moving to the left (within 1s).
- else if (getVelocity()[0]<0 &&(isDucking() ==true)) {return getSprites()[7];}
- //8..(8 + m) the character is neither ducking nor jumping and moving to the right
- else if (getVelocity()[0]>0 && (isDucking() == false)&& (isJumping() == false)) {return getSprites()[8+setImages()];}
- //(9 + m)..(9 + 2m) the character is neither ducking nor jumping and moving to the left.
- else if (getVelocity()[0]<0 && (isDucking()== false)&& (isJumping() ==false)) {return getSprites()[((Sprites.length-8)/2+8)+(setImages())];}
- else {return getSprites()[0];}
- }
- /**
- * Sets the images of Mazub
- * @post...
- * |int length=(getSprites().length-8)/2;
- * |int m1 = getImagCount();
- * @return ...
- * |result==m1
- * @effect...
- * |if(getImagCount() >= length) {setImagCount(0);
- */
- public int setImages() {
- int length=(getSprites().length-8)/2;
- if(getImagCount() >= length) {setImagCount(0);}
- int m1 = getImagCount();
- return m1;
- }
- public boolean IllegalSprites;
- /**
- * Gets illegal Sprites
- * @return
- * |result==if(IllegalSprites)
- * @effect...
- * |if( getSprites() == null || getSprites().length< 10 ||(getSprites().length%2) == 1) {
- * |return IllegalSprites = true;}
- * |for (Sprite sprite : SPRITES) {if(sprite == null) {return IllegalSprites = true;}}
- */
- public boolean getIllegalSprites() {
- if( getSprites() == null || getSprites().length< 10 ||(getSprites().length%2) == 1) {
- return IllegalSprites = true;}
- for (Sprite sprite : Sprites) {
- if(sprite == null) {return IllegalSprites = true;}}
- return IllegalSprites = false;
- }
- int[] SpriteDimentions=new int[2];
- public int Width=0;int Heigth=0;
- public int[] getSpriteDimention() {
- if(isJumping()|| isMoving()) {this.Width=70;this.Heigth=97;}
- if(!(isMoving()) && !(isDucking()) && !(isJumping())) {this.Width=70; this.Heigth=97;}
- if(isDucking()) {this.Width=70; this.Heigth=70;}
- SpriteDimentions[0]=this.Width;
- SpriteDimentions[1]=this.Heigth;
- return SpriteDimentions;
- }
- /*
- ****************
- * Hitpoints *
- ****************
- */
- /**
- *
- * @param newPosition
- * @post ...
- * |new.getActualPosition() == newPosition
- */
- public void changeActualPosition(double[] newPosition) throws Exception {
- if(newPosition == null) {throw new Exception("Invalid value of position's");}
- else if(newPosition.length != 2) {throw new Exception("Invalid value of position's");}
- else if(Double.isNaN(newPosition[0])==true|| Double.isNaN(newPosition[1])==true) {throw new Exception("Invalid value of an or both position's");}
- else {actualPosition =newPosition;}
- if(getWorld()!= null) {
- if(getWorld().OutsideWorldBorder(newPosition)) {getWorld().terminatedGameObject(getWorld().getMazub());terminateEntity();}}
- else if (newPosition[0]<0||newPosition[1]<0) {throw new Exception("Outside Universe");}
- // if(getWorld()!= null & getWorld().getGeologicalFeatures(getWorld().calculateInFeature(calculateToPixel(newPosition[0])+1),getWorld().calculateInFeature(calculateToPixel(newPosition[1])+1))==1) {throw new Exception("can't change to impassable terrain");}
- }
- public void terminateEntity() {
- removeWorld();
- }
- //FIXME do right values
- public void setHitPoint(int hitpoint) {if(Hitpoint<=500) {Hitpoint=hitpoint;}}
- public void addHitPoint(int hitpoint) {if(Hitpoint + hitpoint <= 500) {Hitpoint += hitpoint;}}
- public int futureEarth(double time,int direction) throws Exception {
- int pos =
- calculateToPixel(BigDecimal.valueOf(
- (BigDecimal.valueOf(getActualPosition()[direction])
- .add (BigDecimal.valueOf(getVelocity()[direction]).multiply(BigDecimal.valueOf(time)))
- .add(BigDecimal.valueOf(getAcceleration()[direction]).multiply(BigDecimal.valueOf(0.5))
- .multiply(BigDecimal.valueOf(Math.pow(time, 2))))).doubleValue()).doubleValue());
- return pos;
- }
- public boolean overlapEarth(int X, int Y) {
- boolean touch=false;
- X+=1;Y = Y+=1;
- int SpriteX=getCurrentSprite().getWidth()-2,SpriteY=getCurrentSprite().getHeight()-2;
- if(getWorld().getGeologicalFeatures(X, Y)==1
- || getWorld().getGeologicalFeatures(X+SpriteX, Y )== 1
- || getWorld().getGeologicalFeatures(X, Y+SpriteX)==1
- || getWorld().getGeologicalFeatures(X+SpriteX, Y+SpriteY)==1
- ){touch=true;}
- return touch;
- }
- /**
- * Variable registering whether this person is terminated.
- */
- private boolean isTerminated = false;
- public boolean OutsideWorldBorder(double[] newpos){
- if(newpos[0] < 0 || newpos[0] > getWorld().getSizeInPixels()[0]-1 || newpos[1] <0 || newpos[1] > getWorld().getSizeInPixels()[1]-1 ) {return true;}
- else {return false;}}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement