48 lines
1.1 KiB
Java
48 lines
1.1 KiB
Java
|
/**
|
||
|
* A Spaceship that can fly and shoot
|
||
|
* @author vanitas
|
||
|
*
|
||
|
*/
|
||
|
public class Ship extends MovingObject
|
||
|
{
|
||
|
|
||
|
float firerate;
|
||
|
float burnout = 1000;
|
||
|
public Ship()
|
||
|
{
|
||
|
super();
|
||
|
this.setShape(new Shape(Shape.S_SHIP));
|
||
|
this.getShape().setSize(1f);
|
||
|
this.setMaxSpeed(1);
|
||
|
this.setFirerate(10);
|
||
|
}
|
||
|
public void fire(float delta)
|
||
|
{
|
||
|
while(burnout >= firerate){
|
||
|
float xOfBullet = (float) (this.getX()+Math.sin(Math.toRadians(this.getRotation()))*(this.getShape().getY(0)+7.5f));
|
||
|
float yOfBullet = (float) (this.getY()+Math.cos(Math.toRadians(this.getRotation()))*(this.getShape().getY(0)+7.5f));
|
||
|
Ammunition shot = new Ammunition(this.getRotation(), xOfBullet, yOfBullet, false); //TODO: Place bullet in front of the ship when fired
|
||
|
SpaceSpiel.getMunition().add(shot);
|
||
|
burnout = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void setFirerate(float firerateSec){
|
||
|
this.firerate = 60/firerateSec;
|
||
|
}
|
||
|
@Override
|
||
|
public void accelerate()
|
||
|
{
|
||
|
super.accelerate();
|
||
|
burnout++;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void processCollision(MovingObject o)
|
||
|
{
|
||
|
System.out.println("Verloren du Lappen");
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|