Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jumpingalien.model;
- import jumpingalien.util.Sprite;
- /**
- * A class for creating the plants in the game and getting the imageSprites and coordinates.
- * Plants can move from left to right, or from right to left.
- * After leaving the visible game world, the plants will be terminated.
- * Plants are food to be eaten by Mazub.
- *
- * @version 2.0
- * @author Thierry Klougbo & Jordi De Pau
- */
- public class Plant extends Entity{
- /**
- *Create an instance of Plant with given pixel position and given sprites.
- *The actual position of the new plant will correspond with the coordinates
- *of the left-bottom corner of the left-bottom pixel occupied by the new plant.
- *
- * @param pixelLeftX
- * @param pixelBottomY
- * @param sprites
- */
- public Plant(int pixelLeftX, int pixelBottomY, Sprite... sprites) {
- super(pixelLeftX, pixelBottomY, sprites);
- setSPRITES(sprites);
- setActualPosition(pixelLeftX, pixelBottomY);
- setPixelPosition(pixelLeftX, pixelBottomY);
- setHitPoint(1);
- }
- /*
- ************
- * Position *
- ************
- */
- public double[] actualPosition=new double[2];
- @Override
- public void setActualPosition(double X, double Y) {
- actualPosition[0]=(X/100); actualPosition[1]= (Y/100);
- // actualPosition[0]=getPixelPosition()[0]/100; actualPosition[1]=getPixelPosition()[0]/100;
- }
- /**
- * Returns the actual position of the given game object.
- * Returns an array of 2 doubles {x, y} that represents the coordinates of the
- * bottom-left corner of the given game object.
- * Coordinates are expressed in meters.
- *
- */
- @Override
- public double[] getActualPosition() {
- return actualPosition;
- }
- public int[] pixelPosition=new int[2];
- @Override
- 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);
- }
- @Override
- public int[] getPixelPosition() {return pixelPosition;}
- /*
- ****************
- * Orientation *
- ****************
- */
- public int Orientation;
- @Override
- public void setOrientation(int OrientationPlant) {Orientation = OrientationPlant;}
- public int getOrientation() {return Orientation;}
- /*
- ************
- * Movement *
- ************
- */
- @Override
- public void startMovingLeft(){
- setOrientation(-1);
- setVelocity(0.5, 0);}
- @Override
- public void startMovingRight() {
- setOrientation(1);
- setVelocity(0.5, 0);}
- /**
- *
- * @return boolean for if plant is moving left or not.
- * |if (getPlantVelocity()[0]< 0) {return true;} else {return false;}
- */
- public boolean IsMovingLeftPlant() {
- if (getVelocity()[0]< 0 || getVelocity()[0]==0) {return true;} else {return false;}}
- /**
- *
- * @return a boolean for if plant is moving right or not.
- * | if(getPlantVelocity()>0) {return true;} else {return false;}
- */
- public boolean IsMovingRightPlant() {
- if(getVelocity()[0]>0 || getVelocity()[0]==0) {return true;} else {return false;}}
- public void HorizontalMovement(double dt) {
- double posx=getActualPosition()[0]+(getVelocity()[0]*dt);
- setActualPosition(posx, getActualPosition()[1]);
- }
- /*
- ************
- * Velocity *
- ************
- */
- public double[] Velocity=new double[2];
- @Override
- public void setVelocity(double velocityX, double velocityY) {Velocity[0] = velocityX*getOrientation(); Velocity[1]=velocityY;}
- @Override
- public double[] getVelocity() {return Velocity;}
- /*
- *********************
- * Sprites of plants *
- *********************
- */
- public Sprite[] SpriteS;
- public void setSPRITES(Sprite[] sPrites) {SpriteS=sPrites;}
- public Sprite[] getSPRITES() {return SpriteS;}
- public Sprite SPRITES=null;
- /**
- * @return the current sprite of the plant.
- * |result=SPRITES
- * @post...
- * | if(IsMovingLeftPlant()==true){SPRITES[0]=currentSpritePlant[0];}
- * @post...
- * | if(IsMovingRightPlant()==true){SPRITES[0]=currentSpritePlant[1];}
- */
- public Sprite getCurrentSpritePlant() {
- if(IsMovingLeftPlant()==true){SPRITES=getSPRITES()[0];}
- if(IsMovingRightPlant()==true){SPRITES=getSPRITES()[1];}
- return SPRITES;
- }
- /*
- ***************
- *AdvencedTime *
- ***************
- */
- /*
- * Advance the state of the given game object by the given time period.
- */
- @Override
- public void advanceTime(double time) {
- double Time=time;
- double LeftTime=0;
- if (Time%0.5==0) {LeftTime=Time; startMovingLeft();HorizontalMovement(time);}
- if (Time==LeftTime+0.5 ) {startMovingRight();HorizontalMovement(time);}
- if(Time==10) {setHitPoint(0);isDeadGameObject();}
- }
- /*
- **************
- * Terminated *
- **************
- */
- public void terminateGameObject() {
- }
- @Override
- public boolean isDeadGameObject() {
- if(getHitpoint()== 0) {return true;}
- else {return false;}
- }
- /*
- ************
- * Hitpoints*
- ************
- *
- */
- public int Hitpoint=0;
- /**
- * Sets the hitpoint of the plant
- */
- @Override
- public void setHitPoint(int hitpoint) {
- if(Hitpoint==0) {isDeadGameObject();}
- Hitpoint=hitpoint;
- }
- /**
- *
- * @param Hitpoint
- * @return
- */
- @Override
- public int getHitpoint() {
- return Hitpoint;
- }
- /*
- **************
- * Get World
- **************
- *
- */
- World thisWorld;
- @Override
- public void setWorld(World world) {
- thisWorld = world;
- }
- @Override
- public World getWorld() {
- return thisWorld;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement