118 lines
3 KiB
Java
118 lines
3 KiB
Java
package ei.game.scene.units;
|
|
|
|
import ei.engine.math.Vector2f;
|
|
import ei.engine.math.Vector2i;
|
|
import ei.engine.scene.Sprite;
|
|
import ei.engine.sound.Sound;
|
|
import ei.game.gamestate.InGameState;
|
|
import ei.game.network.entities.NetworkUnit;
|
|
import ei.game.player.Player;
|
|
import ei.game.scene.SelectBox;
|
|
import ei.game.scene.weapons.Explotion;
|
|
import ei.game.scene.weapons.MachineGun;
|
|
import ei.game.scene.weapons.Weapon;
|
|
|
|
/**
|
|
*
|
|
* @author Jesper Lundin
|
|
*
|
|
*/
|
|
public class APU extends NetworkUnit{
|
|
private SelectBox selectionBox;
|
|
private Sprite sprite;
|
|
|
|
private Sound gunSound;
|
|
private Sound[] moveSound;
|
|
private Sound attackSound;
|
|
private Sound selectSound;
|
|
|
|
public APU(Player p, InGameState inGameState) {
|
|
super(70, p, inGameState);
|
|
}
|
|
|
|
public APU(int x, int y, Player p, InGameState inGameState){
|
|
super(70, new Vector2i(x,y), p, inGameState);
|
|
}
|
|
|
|
public void init(){
|
|
setBuildTime(200);
|
|
setPrice(200);
|
|
}
|
|
|
|
public void initGraphics(){
|
|
sprite = new Sprite("APU", "data/units/apu/apu0000.png");
|
|
sprite.setSize(new Vector2f(40,40));
|
|
getNode().add(sprite);
|
|
|
|
gunSound = new Sound("gunSound", "data/sounds/machinegun.wav");
|
|
moveSound = new Sound[2];
|
|
moveSound[0] = new Sound("moveSound", "data/sounds/APUmove1.wav");
|
|
moveSound[1] = new Sound("moveSound", "data/sounds/APUmove2.wav");
|
|
selectSound = new Sound("selectSound", "data/sounds/APUselect.wav");
|
|
attackSound = new Sound("attackSound", "data/sounds/APUattack.wav");
|
|
|
|
gunSound.setLocation(getNode().getLocation());
|
|
moveSound[0].setLocation(getNode().getLocation());
|
|
moveSound[1].setLocation(getNode().getLocation());
|
|
selectSound.setLocation(getNode().getLocation());
|
|
attackSound.setLocation(getNode().getLocation());
|
|
|
|
selectionBox = new SelectBox(0,40,40,getMaxLife());
|
|
}
|
|
|
|
protected SelectBox getSelection() {
|
|
return selectionBox;
|
|
}
|
|
/**
|
|
* Returns the weapon connected to this type
|
|
* of unit.
|
|
*/
|
|
public Weapon getWeapon(Vector2f startPos) {
|
|
return new MachineGun(startPos, getInGameState());
|
|
}
|
|
/**
|
|
* This unit type is now destroyed.
|
|
*/
|
|
public void destroyed(){
|
|
getInGameState().getWeaponHandler().addWeapon(new Explotion(new Vector2f(getNode().getLocation().getX(), getNode().getLocation().getY()), getInGameState()));
|
|
}
|
|
public Sound getGunSound() {
|
|
return gunSound;
|
|
}
|
|
public Sound getMoveSound() {
|
|
return moveSound[(int)(Math.random()*2)];
|
|
}
|
|
public Sound getSelectSound() {
|
|
return selectSound;
|
|
}
|
|
public Sound getAttackSound() {
|
|
return attackSound;
|
|
}
|
|
/**
|
|
* returns the velocity of the unit type.
|
|
* @return
|
|
*/
|
|
public float getVelocity() {
|
|
return 2;
|
|
}
|
|
/**
|
|
* Manages the sprite connected to this unit.
|
|
* @param s
|
|
*/
|
|
public void setSprite(Sprite s) {
|
|
this.sprite = s;
|
|
}
|
|
/**
|
|
* returns the sprite connected to this type
|
|
* of unit.
|
|
* @return
|
|
*/
|
|
public Sprite getSprite() {
|
|
return this.sprite;
|
|
}
|
|
|
|
@Override
|
|
public int getMaintenanceCost() {
|
|
return 50;
|
|
}
|
|
}
|