2016-02-27 20:45:32 +00:00
|
|
|
package com.sagi.dayan.Games.Elements;
|
|
|
|
|
|
|
|
|
2016-03-20 19:16:01 +00:00
|
|
|
import com.sagi.dayan.Games.Utils.Utils;
|
2016-02-27 20:45:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by sagi on 2/20/16.
|
|
|
|
*/
|
|
|
|
public class EnemyShip extends AnimatedSprite {
|
2016-03-18 22:33:29 +00:00
|
|
|
protected int currentStep;
|
|
|
|
protected double stepDelay, fireDelay;
|
2016-03-12 10:24:42 +00:00
|
|
|
protected long lastFireTime, lastStepTime;
|
|
|
|
protected int[] moveVector;
|
|
|
|
protected Wave wave;
|
|
|
|
protected int hitsToDestroy;
|
|
|
|
protected boolean isDone;
|
|
|
|
protected long startExploded;
|
2016-03-18 22:33:29 +00:00
|
|
|
public EnemyShip(int x, int y, int w, int h, int acc, String imgName, double angle, int sWidth, int sHeight,double fireDelay, double stepDelay, Wave wave, int[] moveVector,int numOfFirstFrames, int hitsToDestroy) {
|
2016-03-12 10:24:42 +00:00
|
|
|
super(x, y, w, h, acc, imgName, angle, sWidth, sHeight, numOfFirstFrames);
|
|
|
|
this.fireDelay = fireDelay;
|
|
|
|
this.stepDelay = stepDelay;
|
|
|
|
this.currentStep = 0;
|
|
|
|
this.lastFireTime = System.currentTimeMillis();
|
|
|
|
this.lastStepTime = System.currentTimeMillis();
|
|
|
|
this.moveVector = moveVector;
|
|
|
|
this.wave = wave;
|
|
|
|
this.hitsToDestroy = hitsToDestroy;
|
2016-02-27 20:45:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-12 10:24:42 +00:00
|
|
|
protected void initFirstAnimation(String spriteSheet, int numOfFirstFrames) {
|
2016-03-20 18:28:33 +00:00
|
|
|
if(imageName == "L1-ES2.png"){
|
|
|
|
animations.add(new Animation(imageName, numOfFirstFrames, 100));
|
|
|
|
}else {
|
|
|
|
animations.add(new Animation(imageName, numOfFirstFrames, 300));
|
|
|
|
}
|
2016-02-27 20:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update() {
|
2016-03-12 10:24:42 +00:00
|
|
|
long now = System.currentTimeMillis();
|
|
|
|
if(currentAnimation == 1){
|
|
|
|
if(now - startExploded >= 500){
|
|
|
|
isDone = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(now - lastFireTime >= fireDelay*1000){
|
|
|
|
wave.fireFromEnemy(this);
|
|
|
|
lastFireTime = now;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(now - lastStepTime >= stepDelay*1000 && currentStep < moveVector.length - 1){
|
|
|
|
currentStep++;
|
|
|
|
lastStepTime = now;
|
|
|
|
}
|
|
|
|
|
|
|
|
locX += acceleration * Math.cos(Math.toRadians(moveVector[currentStep]));
|
|
|
|
locY -= acceleration * -1* Math.sin(Math.toRadians(moveVector[currentStep]));
|
|
|
|
}
|
|
|
|
public void gotHit() {
|
|
|
|
hitsToDestroy--;
|
|
|
|
if(hitsToDestroy == 0){
|
|
|
|
startExploded = System.currentTimeMillis();
|
|
|
|
animations.add(new Animation("explosion.png", 16, 500));
|
|
|
|
currentAnimation++;
|
2016-03-20 19:16:01 +00:00
|
|
|
Utils.playSound("enemy_exp.wav");
|
2016-03-12 10:24:42 +00:00
|
|
|
}
|
|
|
|
System.out.println("GOT HIT " + hitsToDestroy);
|
|
|
|
}
|
2016-03-19 00:01:49 +00:00
|
|
|
public boolean isDead() {
|
2016-03-19 01:40:07 +00:00
|
|
|
return hitsToDestroy <= 0;
|
2016-03-12 10:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isDone(){
|
|
|
|
return isDone;
|
2016-02-27 20:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|