Added a new enemy sprite + player shooting sounds
This commit is contained in:
parent
babeb3e370
commit
fa440c16a4
4 changed files with 23 additions and 6 deletions
|
@ -29,8 +29,11 @@ public class EnemyShip extends AnimatedSprite {
|
|||
|
||||
@Override
|
||||
protected void initFirstAnimation(String spriteSheet, int numOfFirstFrames) {
|
||||
animations.add(new Animation(imageName, 8, 500));
|
||||
|
||||
if(imageName == "L1-ES2.png"){
|
||||
animations.add(new Animation(imageName, numOfFirstFrames, 100));
|
||||
}else {
|
||||
animations.add(new Animation(imageName, numOfFirstFrames, 300));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.sagi.dayan.Games.Elements;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
@ -21,6 +22,8 @@ public class Wave {
|
|||
protected long lastLaunchTime;
|
||||
protected String imageName;
|
||||
protected int hitsToDestroy;
|
||||
protected Random r;
|
||||
protected boolean isShipOfTypeOne;
|
||||
|
||||
public Wave(int enemyMaxAmount, int[] moveVector, double fireDelay, double stepDelay, double launchDelay, int acc, String imageName, int startX, int startY, Level stage, int hitsToDestroy){
|
||||
this.enemies = new Vector<>();
|
||||
|
@ -38,14 +41,21 @@ public class Wave {
|
|||
this.moveVector = moveVector;
|
||||
this.lastLaunchTime = System.currentTimeMillis();
|
||||
this.hitsToDestroy = hitsToDestroy;
|
||||
this.r = new Random();
|
||||
int odds = r.nextInt(100);
|
||||
isShipOfTypeOne = (odds > 60) ? true : false;
|
||||
}
|
||||
|
||||
public void update(){
|
||||
long now = System.currentTimeMillis();
|
||||
Vector <EnemyShip> enemiesToRemove = new Vector<>();
|
||||
if(now - lastLaunchTime >= launchDelay * 1000 && currentAmount <= enemyMaxAmount){
|
||||
// Create new enemy
|
||||
enemies.add(new EnemyShip(startX, startY, level.getStageHeight(), level.getStageHeight(), acc, imageName, 0, 15, 15, fireDelay, stepDelay, this, moveVector, 7, hitsToDestroy));
|
||||
// Create (RANDOM) new enemy
|
||||
if(isShipOfTypeOne){
|
||||
enemies.add(new EnemyShip(startX, startY, level.getStageHeight(), level.getStageHeight(), acc, imageName, 0, 15, 15, fireDelay, stepDelay, this, moveVector, 8, hitsToDestroy));
|
||||
}else{
|
||||
enemies.add(new EnemyShip(startX, startY, level.getStageHeight(), level.getStageHeight(), acc, "L1-ES2.png", 0, 15, 15, fireDelay, stepDelay, this, moveVector, 2, hitsToDestroy));
|
||||
}
|
||||
lastLaunchTime = now;
|
||||
currentAmount++;
|
||||
}
|
||||
|
|
BIN
src/com/sagi/dayan/Games/Sounds/player_laser.wav
Normal file
BIN
src/com/sagi/dayan/Games/Sounds/player_laser.wav
Normal file
Binary file not shown.
|
@ -217,7 +217,9 @@ public abstract class Level extends Scene {
|
|||
players.get(0).setvDirection(0);
|
||||
}
|
||||
if(keys.get(engine.getP1Controlles()[GameEngine.FIRE]) ){
|
||||
if(players.get(0).isAbleToFire() && !players.get(0).isGameOver()) {
|
||||
if(players.get(0).isAbleToFire() && engine.getP1Health() > 0) {
|
||||
//SOUND
|
||||
Utils.playSound("player_laser.wav");
|
||||
p1Missiles.add(new Missile(players.get(0).getCenterX() - 15, (int) players.get(0).getLocY(), getStageWidth(), getStageHeight(), players.get(0).getAcceleration() + 3, "P1Laser.png", 4));
|
||||
players.get(0).updateFireTime();
|
||||
}
|
||||
|
@ -253,7 +255,9 @@ public abstract class Level extends Scene {
|
|||
players.get(1).setvDirection(0);
|
||||
}
|
||||
if(keys.get(engine.getP2Controlles()[GameEngine.FIRE]) ){
|
||||
if(players.get(1).isAbleToFire() && !players.get(1).isGameOver()){
|
||||
if(players.get(1).isAbleToFire() && engine.getP1Health() > 0){
|
||||
//SOUND
|
||||
Utils.playSound("player_laser.wav");
|
||||
p2Missiles.add(new Missile(players.get(1).getCenterX() - 15, (int)players.get(1).getLocY(),getStageWidth(),getStageHeight(),players.get(1).getAcceleration() + 3, "P1Laser.png", 4));
|
||||
players.get(1).updateFireTime();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue