/** * Projectile with ballistic attributes and physics * @author vanitas,lil * */ public class Ammunition extends MovingObject { private float durability, //Lifetime in seconds lifetime; //"Age" of the projectile in seconds /** * Constructor * @param direction * @param x location * @param y * @param pearcing can this penetrate other Objects? */ public Ammunition(float rotation, float x, float y, boolean pearcing) { //this.direction = (float) Math.toRadians(direction+90); //Set the direction of the projectile this.setRotation(rotation); this.x = x; this.y = y; this.durability = 0; //Set variables this.setShape(new Shape(Shape.S_BULLET)); this.getShape().setSize(1f); this.durability = 2; //Lifetime in seconds } /** * moves the object one frame */ @Override public void move(float delta, boolean keepOnScreen) { float xNeu = (float) (x+Math.cos((float) Math.toRadians(90-this.getRotation()))*0.35f*delta); float yNeu = (float) (y+Math.sin((float) Math.toRadians(90-this.getRotation()))*0.35f*delta); this.lifetime += (delta/1000); //Let the projectile "age" if(this.lifetime>this.durability) //If "too old" do something { SpaceSpiel.getMunition().remove(this); } x = xNeu; y = yNeu; if(keepOnScreen) keepOnScreen(); } /** * modifies the speedvector (In this case it doesnt, cause a bullet in space doesn't * change direction and speed */ @Override public void accelerate() { //Keep this empty, Munition doesn't accelerate (Except for rockets maybe) } //Getters and setters public float getDurability() { return durability; } public void setDurability(float durability) { this.durability = durability; } public float getX() { return x; } public void setX(float x) { this.x = x; } public float getY() { return y; } public void setY(float y) { this.y = y; } public float getLifetime() { return lifetime; } public void setLifetime(float lifetime) { this.lifetime = lifetime; } }