Metroids/Game/src/Metroid.java

109 lines
2.4 KiB
Java

import java.util.ArrayList;
/**
* A floating, gliding metroid TODO: Maybe add lifepoints, so that multiple hits are needed to destroy this
* @author vanitas
*
*/
public class Metroid extends MovingObject
{
private int level, //Size of the Metroid (default 3-1)
countBabies; //How many new Metroids spawn, when THIS gets killed?
private float spin;
public Metroid(int level)
{
this.level = level;
this.spin = (float) Math.random();
this.shape = new Shape(Shape.S_METROID);
this.getShape().setSize(level);
this.x = 400f;
this.y = 150f;
this.speedX = (float) (Math.random()*2f);
this.speedY = (float) (Math.random()*2f);
}
/**
* Creates a Metroid with
* @param level
* @param x
* @param y
* @param speedX
* @param speedY
*/
public Metroid(int level, float x, float y, float speedX, float speedY, float spin)
{
this.level = level;
this.spin = (float) Math.random();
this.shape = new Shape(Shape.S_METROID);
this.getShape().setSize(level*1.5f);
this.x = x;
this.y = y;
this.speedX = speedX;
this.speedY = speedY;
}
/**
* This method moves the Metroid according to its speedVector
* @param delta
* @param keepOnScreen if true the method calls keepOnScreen()
*/
@Override
public void move(float delta, boolean keepOnScreen)
{
this.x += delta*0.1f*this.speedX;
this.y += delta*0.1f*this.speedY;
this.rotation += delta*this.spin*0.2f;
if(keepOnScreen) this.keepOnScreen();
}
/**
* this method handles the case that THIS Metroid gets hit by an Object (Normally Ammunition)
* @param o The object that hit the Metroid
*/
@SuppressWarnings("unchecked")
@Override
public void processCollision(MovingObject o)
{
ArrayList<Metroid> m = SpaceSpiel.getMetroids();
if(this.level>1)
{
for(int i = 0; i<4; i++)
{
m.add(new Metroid(this.level-1, this.getX(),this.getY(),(float) (Math.random()*2f),(float) (Math.random()*2f),(float) Math.random()));
}
}
else
{
//TODO: By chance of 5% or so add some random Items or PowerUps to the game.
//
}
m.remove(this);
}
/**
* An empty method (A Metroid shouldn't accelerate)
* Only here to overwrite the parents method
*/
@Override
public void accelerate()
{
//Has to be empty
}
//Getters and setters
public int getLevel()
{
return this.level;
}
public void setLevel(int level)
{
this.level = level;
}
public float getSpin()
{
return this.spin;
}
public void setSpin(float spin)
{
this.spin = spin;
}
}