package model_pkg.gameobject_pkg;
import model_pkg.GfxState;
import def_classes.Box;
import def_classes.Point;
import def_classes.Vector2D;
import display_pkg.SpriteSheet;
/**
* A linear cloud which the player might stand upon.
* @author Alving J., Kullman K.
*/
public class CloudLinear extends Cloud {
// The current position of the cloud
// Extreme positions are determined by the velocity.
private Point cyclePosition1, cyclePosition2;
/**
* Creates a linear cloud
* @param x x-position of the first extreme point
* @param y y-position of the first extreme point
* @param x2 x-position of the second extreme point
* @param y2 y-position of the second extreme point
* @param velocity angular velocity of the motion
* @param bbox the clouds bounding box
* @param sprSheet the spritesheet of the cloud
* @param cloudSize the animation index to use
*/
public CloudLinear(
int x, int y, int x2 , int y2,
int velocity, Box bbox, SpriteSheet sprSheet, int cloudSize) {
setWorldPosition(new Point(
x+(x2-x)/2 - (bbox.getLeft() + bbox.getWidth()/2),
y+(y2-y)/2 - (bbox.getTop() + bbox.getHeight()/2)));
setBoundingBox(bbox);
cyclePosition1 = new Point(x, y);
cyclePosition2 = new Point(x2, y2);
cycleDegree = 0;
cycleStep = velocity/10.0;
setSolidSurface(true);
currentAnim = new GfxState(sprSheet, cloudSize);
}
public void updateMovement() {
int dx = (cyclePosition2.getIntX() - cyclePosition1.getIntX())/2;
int dy = (cyclePosition2.getIntY() - cyclePosition1.getIntY())/2;
double speedX = dx*(Math.cos(cycleDegree*Math.PI/180))*cycleStep*Math.PI/180;
double speedY = dy*(Math.cos(cycleDegree*Math.PI/180))*cycleStep*Math.PI/180;
Vector2D newVelocity = new Vector2D(speedX,speedY);
//velocity.setX(speedX);
//velocity.setY(speedY);
setVelocity(newVelocity);
cycleDegree += cycleStep;
setMovement(getVelocity());
}
}