Merge pull request #5 from sagidayan/master

before doc
This commit is contained in:
Aran Zaiger 2016-03-20 21:28:11 +02:00
commit cad78de800
19 changed files with 362 additions and 84 deletions

View file

@ -1,6 +1,7 @@
package com.sagi.dayan.Games.Elements;
import com.sagi.dayan.Games.Utils.Utils;
/**
* Created by sagi on 2/20/16.
@ -29,8 +30,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
@ -60,6 +64,7 @@ public class EnemyShip extends AnimatedSprite {
startExploded = System.currentTimeMillis();
animations.add(new Animation("explosion.png", 16, 500));
currentAnimation++;
Utils.playSound("enemy_exp.wav");
}
System.out.println("GOT HIT " + hitsToDestroy);
}

View file

@ -1,11 +1,14 @@
package com.sagi.dayan.Games.Elements;
import java.awt.Graphics;
import java.util.Random;
import java.util.Vector;
import javax.rmi.CORBA.Util;
import javax.swing.JPanel;
import com.sagi.dayan.Games.Stage.Level;
import com.sagi.dayan.Games.Utils.Utils;
/**
* Created by sagi on 3/11/16.
@ -21,6 +24,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 +43,22 @@ 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));
}
Utils.playSound("enemy_enter.wav");
lastLaunchTime = now;
currentAmount++;
}
@ -73,8 +86,10 @@ public class Wave {
}
public void fireFromEnemy(EnemyShip e){
if(!e.isDead())
level.enemyFire(e.getCenterX(), (int)(e.getLocY() + e.getsHeight()), -(e.getAcceleration() + 2));
if(!e.isDead()) {
level.enemyFire(e.getCenterX(), (int) (e.getLocY() + e.getsHeight()), -(e.getAcceleration() + 2));
Utils.playSound("enemy_relese.wav");
}
}
public Vector <EnemyShip> getEnemies() {

View file

@ -173,16 +173,25 @@ public class GameEngine {
stage.removeKeyListener(scene);
switch (currentLevel){
case 0:
scene = new FirstStage(pWidth, pHeight, numOfPlayers, this, "-= STAGE 1.0 =-", new int[]{5, 1,1,1});
scene = new FirstStage(pWidth, pHeight, numOfPlayers, this, "-= STAGE 1.0 =-", new int[]{5, 5});
break;
case 1:
scene = new SecondStage(pWidth, pHeight, numOfPlayers, this, "-= STAGE 2.0 =-", new int[]{5, 5,5,5});
scene = new SecondStage(pWidth, pHeight, numOfPlayers, this, "-= STAGE 2.0 =-", new int[]{5, 5,5});
break;
case 2:
scene = new ThirdStage(pWidth, pHeight, numOfPlayers, this, "-= STAGE 3.0 =-", new int[]{5, 0,0,8});
scene = new ThirdStage(pWidth, pHeight, numOfPlayers, this, "-= STAGE 3.0 =-", new int[]{5, 0,2,8});
break;
case 3:
scene = new FourthStage(pWidth, pHeight, numOfPlayers, this, "-= STAGE 4.0 =-", new int[]{5, 0,0,8});
scene = new FourthStage(pWidth, pHeight, numOfPlayers, this, "-= STAGE 4.0 =-", new int[]{5, 0,0,7});
break;
case 4:
scene = new FifthStage(pWidth, pHeight, numOfPlayers, this, "-= STAGE 5.0 =-", new int[]{5, 1,3,8, 10, 10});
break;
case 5:
scene = new SixthStage(pWidth, pHeight, numOfPlayers, this, "-= STAGE 6.0 =-", new int[]{5, 0,0,0, 0, 0, 10, 20});
break;
case 6:
scene = new BlitzStage(pWidth, pHeight, numOfPlayers, this, "-= BLITZ STAGE =-", new int[]{5, 0,0,0, 0, 0, 0, 0, 0, 0, 0});
break;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,91 @@
package com.sagi.dayan.Games.Stage;
import com.sagi.dayan.Games.Elements.Wave;
import com.sagi.dayan.Games.Engine.GameEngine;
import com.sagi.dayan.Games.Utils.WaveConfig;
import com.sagi.dayan.Games.Utils.WaveConfigs;
/**
* Created by sagi on 3/19/16.
*/
public class BlitzStage extends Level{
protected final int NUM_OF_WAVES = 4;
public BlitzStage(int width, int height, int numOfPlayers, GameEngine engine, String stageTitle, int[] waveDelay) {
super(width, height, numOfPlayers, engine, stageTitle, waveDelay);
numOfWaves = NUM_OF_WAVES;
}
@Override
protected void launchWave(long now) {
lastWaveTime = now;
System.out.println("New Wave!! " + currentWave + ", Time: " + now);
WaveConfig wc;
int numOfEnemies = 5, numOfHits = 1;
double launchDelay = 0.5, fireDelay = 5;
switch (currentWave){
case 0:
numOfEnemies = 35;
fireDelay = 0.5;
launchDelay = 0.5;
numOfHits = 1;
wc = engine.getWaveConfigs().getWaveConfig(0);
break;
case 1:
numOfEnemies = 35;
fireDelay = 0.3;
launchDelay = 0.5;
numOfHits = 10;
wc = engine.getWaveConfigs().getWaveConfig(1);
break;
case 2:
numOfEnemies = 45;
fireDelay = 0.3;
launchDelay = 0.5;
numOfHits = 10;
wc = engine.getWaveConfigs().getWaveConfig(2);
break;
case 3:
numOfEnemies = 45;
fireDelay = 0.2;
launchDelay = 0.4;
numOfHits = 10;
wc = engine.getWaveConfigs().getWaveConfig(3);
break;
case 4:
numOfEnemies = 55;
fireDelay = 0.2;
launchDelay = 0.4;
numOfHits = 10;
wc = engine.getWaveConfigs().getWaveConfig(4);
break;
case 5:
numOfEnemies = 55;
fireDelay = 0.2;
launchDelay = 0.4;
numOfHits = 10;
wc = engine.getWaveConfigs().getWaveConfig(5);
break;
case 6:
numOfEnemies = 65;
fireDelay = 0.2;
launchDelay = 0.4;
numOfHits = 10;
wc = engine.getWaveConfigs().getWaveConfig(6);
break;
case 7:
numOfEnemies = 65;
fireDelay = 0.2;
launchDelay = 0.4;
numOfHits = 10;
wc = engine.getWaveConfigs().getWaveConfig(7);
break;
default:
wc = engine.getWaveConfigs().getWaveConfig(WaveConfigs.DEMO);
break;
}
waves.add(new Wave(numOfEnemies, wc.getMoveVector(), fireDelay, wc.getStepDelay(), launchDelay, wc.getAcc(), "L1-ES1.png", wc.getStartX(), wc.getStartY(), this, numOfHits));
currentWave++;
}
}

View file

@ -0,0 +1,77 @@
package com.sagi.dayan.Games.Stage;
import com.sagi.dayan.Games.Elements.Wave;
import com.sagi.dayan.Games.Engine.GameEngine;
import com.sagi.dayan.Games.Utils.WaveConfig;
import com.sagi.dayan.Games.Utils.WaveConfigs;
/**
* Created by sagi on 3/19/16.
*/
public class FifthStage extends Level{
protected final int NUM_OF_WAVES = 4;
public FifthStage(int width, int height, int numOfPlayers, GameEngine engine, String stageTitle, int[] waveDelay) {
super(width, height, numOfPlayers, engine, stageTitle, waveDelay);
numOfWaves = NUM_OF_WAVES;
}
@Override
protected void launchWave(long now) {
lastWaveTime = now;
System.out.println("New Wave!! " + currentWave + ", Time: " + now);
WaveConfig wc;
int numOfEnemies = 5, numOfHits = 1;
double launchDelay = 0.5, fireDelay = 5;
switch (currentWave){
case 0:
numOfEnemies = 15;
fireDelay = 0.3;
launchDelay = 0.7;
numOfHits = 1;
wc = engine.getWaveConfigs().getWaveConfig(1);
break;
case 1:
numOfEnemies = 15;
fireDelay = 0.3;
launchDelay = 0.7;
numOfHits = 2;
wc = engine.getWaveConfigs().getWaveConfig(4);
break;
case 2:
numOfEnemies = 20;
fireDelay = 0.3;
launchDelay = 0.7;
numOfHits = 3;
wc = engine.getWaveConfigs().getWaveConfig(5);
break;
case 3:
numOfEnemies = 25;
fireDelay = 0.3;
launchDelay = 0.7;
numOfHits = 3;
wc = engine.getWaveConfigs().getWaveConfig(0);
break;
case 4:
numOfEnemies = 35;
fireDelay = 0.2;
launchDelay = 0.5;
numOfHits = 3;
wc = engine.getWaveConfigs().getWaveConfig(3);
break;
case 5:
numOfEnemies = 35;
fireDelay = 0.1;
launchDelay = 0.3;
numOfHits = 5;
wc = engine.getWaveConfigs().getWaveConfig(2);
break;
default:
wc = engine.getWaveConfigs().getWaveConfig(WaveConfigs.DEMO);
break;
}
waves.add(new Wave(numOfEnemies, wc.getMoveVector(), fireDelay, wc.getStepDelay(), launchDelay, wc.getAcc(), "L1-ES1.png", wc.getStartX(), wc.getStartY(), this, numOfHits));
currentWave++;
}
}

View file

@ -10,7 +10,7 @@ import com.sagi.dayan.Games.Utils.WaveConfigs;
*/
public class FirstStage extends Level{
protected final int NUM_OF_WAVES = 4;
protected final int NUM_OF_WAVES = 2;
public FirstStage(int width, int height, int numOfPlayers, GameEngine engine, String stageTitle, int[] waveDelay) {
super(width, height, numOfPlayers, engine, stageTitle, waveDelay);
@ -27,31 +27,24 @@ public class FirstStage extends Level{
switch (currentWave){
case 0:
numOfEnemies = 5;
fireDelay = 0.1;
launchDelay = 0.5;
fireDelay = 1.1;
launchDelay = 2;
numOfHits = 1;
wc = engine.getWaveConfigs().getWaveConfig(6);
wc = engine.getWaveConfigs().getWaveConfig(0);
break;
case 1:
numOfEnemies = 5;
fireDelay = 1;
launchDelay = 1;
numOfHits = 2;
wc = engine.getWaveConfigs().getWaveConfig(3);
fireDelay = 0.8;
launchDelay = 2;
numOfHits = 1;
wc = engine.getWaveConfigs().getWaveConfig(1);
break;
case 2:
numOfEnemies = 10;
fireDelay = 0.8;
launchDelay = 1;
numOfHits = 3;
wc = engine.getWaveConfigs().getWaveConfig(2);
break;
case 3:
numOfEnemies = 15;
fireDelay = 1.5;
launchDelay = 1;
numOfHits = 5;
wc = engine.getWaveConfigs().getWaveConfig(7);
fireDelay = 0.7;
launchDelay = 1.5;
numOfHits = 1;
wc = engine.getWaveConfigs().getWaveConfig(2);
break;
default:
wc = engine.getWaveConfigs().getWaveConfig(WaveConfigs.DEMO);

View file

@ -26,30 +26,30 @@ public class FourthStage extends Level{
double launchDelay = 0.5, fireDelay = 5;
switch (currentWave){
case 0:
numOfEnemies = 5;
numOfEnemies = 10;
fireDelay = 0.5;
launchDelay = 0.5;
launchDelay = 1;
numOfHits = 1;
wc = engine.getWaveConfigs().getWaveConfig(6);
wc = engine.getWaveConfigs().getWaveConfig(3);
break;
case 1:
numOfEnemies = 5;
numOfEnemies = 15;
fireDelay = 0.3;
launchDelay = 1;
numOfHits = 2;
wc = engine.getWaveConfigs().getWaveConfig(3);
launchDelay = 0.8;
numOfHits = 1;
wc = engine.getWaveConfigs().getWaveConfig(6);
break;
case 2:
numOfEnemies = 10;
fireDelay = 0.3;
launchDelay = 1;
numOfHits = 3;
wc = engine.getWaveConfigs().getWaveConfig(2);
launchDelay = 0.7;
numOfHits = 1;
wc = engine.getWaveConfigs().getWaveConfig(0);
break;
case 3:
numOfEnemies = 15;
numOfEnemies = 5;
fireDelay = 0.2;
launchDelay = 1;
launchDelay = 0.7;
numOfHits = 5;
wc = engine.getWaveConfigs().getWaveConfig(7);
break;

View file

@ -217,8 +217,10 @@ 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()) {
p1Missiles.add(new Missile(players.get(0).getCenterX() - 15, (int) players.get(0).getLocY(), getStageWidth(), getStageHeight(), players.get(0).getAcceleration() + 3, "P1Laser.png", 4));
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.getP2Health() > 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();
}
@ -457,7 +461,7 @@ public abstract class Level extends Scene {
eMTR.add(enemyMissiles.get(j));
}else{
blasts.add(new Blast((int)players.get(i).getLocX(),(int)players.get(i).getLocY(),"explosion.png",15));
Utils.playSound("player_exp.wav");
}
}
}
@ -536,6 +540,7 @@ public abstract class Level extends Scene {
protected void playerHit(int i){
if(players.get(i).isMortal()){
Utils.playSound((i == 0) ? "player_1_hit.wav" : "player_2_hit.wav");
engine.setPlayerHealth(i, -10);
if(i == 0){
if(engine.getP1Health() == 100){

View file

@ -10,7 +10,7 @@ import com.sagi.dayan.Games.Utils.WaveConfigs;
*/
public class SecondStage extends Level{
protected final int NUM_OF_WAVES = 4;
protected final int NUM_OF_WAVES = 3;
public SecondStage(int width, int height, int numOfPlayers, GameEngine engine, String stageTitle, int[] waveDelay) {
super(width, height, numOfPlayers, engine, stageTitle, waveDelay);
@ -27,31 +27,31 @@ public class SecondStage extends Level{
switch (currentWave){
case 0:
numOfEnemies = 5;
fireDelay = 0.5;
launchDelay = 0.5;
fireDelay = 1;
launchDelay = 2;
numOfHits = 1;
wc = engine.getWaveConfigs().getWaveConfig(6);
break;
case 1:
numOfEnemies = 5;
fireDelay = 0.3;
launchDelay = 1;
numOfHits = 2;
wc = engine.getWaveConfigs().getWaveConfig(3);
break;
case 2:
case 1:
numOfEnemies = 10;
fireDelay = 0.3;
launchDelay = 1;
numOfHits = 3;
wc = engine.getWaveConfigs().getWaveConfig(2);
fireDelay = 0.8;
launchDelay = 1.5;
numOfHits = 1;
wc = engine.getWaveConfigs().getWaveConfig(4);
break;
case 2:
numOfEnemies = 15;
fireDelay = 0.7;
launchDelay = 1.3;
numOfHits = 1;
wc = engine.getWaveConfigs().getWaveConfig(5);
break;
case 3:
numOfEnemies = 15;
fireDelay = 0.2;
numOfEnemies = 20;
fireDelay = 0.6;
launchDelay = 1;
numOfHits = 5;
wc = engine.getWaveConfigs().getWaveConfig(7);
numOfHits = 2;
wc = engine.getWaveConfigs().getWaveConfig(6);
break;
default:
wc = engine.getWaveConfigs().getWaveConfig(WaveConfigs.DEMO);

View file

@ -0,0 +1,84 @@
package com.sagi.dayan.Games.Stage;
import com.sagi.dayan.Games.Elements.Wave;
import com.sagi.dayan.Games.Engine.GameEngine;
import com.sagi.dayan.Games.Utils.WaveConfig;
import com.sagi.dayan.Games.Utils.WaveConfigs;
/**
* Created by sagi on 3/19/16.
*/
public class SixthStage extends Level{
protected final int NUM_OF_WAVES = 4;
public SixthStage(int width, int height, int numOfPlayers, GameEngine engine, String stageTitle, int[] waveDelay) {
super(width, height, numOfPlayers, engine, stageTitle, waveDelay);
numOfWaves = NUM_OF_WAVES;
}
@Override
protected void launchWave(long now) {
lastWaveTime = now;
System.out.println("New Wave!! " + currentWave + ", Time: " + now);
WaveConfig wc;
int numOfEnemies = 5, numOfHits = 1;
double launchDelay = 0.5, fireDelay = 5;
switch (currentWave){
case 0:
numOfEnemies = 25;
fireDelay = 0.5;
launchDelay = 0.5;
numOfHits = 1;
wc = engine.getWaveConfigs().getWaveConfig(2);
break;
case 1:
numOfEnemies = 25;
fireDelay = 0.3;
launchDelay = 0.5;
numOfHits = 2;
wc = engine.getWaveConfigs().getWaveConfig(1);
break;
case 2:
numOfEnemies = 30;
fireDelay = 0.3;
launchDelay = 0.5;
numOfHits = 3;
wc = engine.getWaveConfigs().getWaveConfig(0);
break;
case 3:
numOfEnemies = 15;
fireDelay = 0.2;
launchDelay = 0.4;
numOfHits = 4;
wc = engine.getWaveConfigs().getWaveConfig(6);
break;
case 4:
numOfEnemies = 35;
fireDelay = 0.2;
launchDelay = 0.4;
numOfHits = 4;
wc = engine.getWaveConfigs().getWaveConfig(6);
break;
case 5:
numOfEnemies = 35;
fireDelay = 0.2;
launchDelay = 0.4;
numOfHits = 4;
wc = engine.getWaveConfigs().getWaveConfig(4);
break;
case 6:
numOfEnemies = 35;
fireDelay = 0.2;
launchDelay = 0.4;
numOfHits = 4;
wc = engine.getWaveConfigs().getWaveConfig(7);
break;
default:
wc = engine.getWaveConfigs().getWaveConfig(WaveConfigs.DEMO);
break;
}
waves.add(new Wave(numOfEnemies, wc.getMoveVector(), fireDelay, wc.getStepDelay(), launchDelay, wc.getAcc(), "L1-ES1.png", wc.getStartX(), wc.getStartY(), this, numOfHits));
currentWave++;
}
}

View file

@ -46,7 +46,6 @@ public class Stage extends JPanel implements Runnable{
@Override
public void paintComponent(Graphics g) {
// System.out.println("Paint Component");
super.paintComponent(g);
g.drawImage(engine.getScene(),0,0,this);
g.dispose();

View file

@ -26,32 +26,32 @@ public class ThirdStage extends Level{
double launchDelay = 0.5, fireDelay = 5;
switch (currentWave){
case 0:
numOfEnemies = 5;
fireDelay = 0.5;
launchDelay = 0.5;
numOfEnemies = 10;
fireDelay = 0.8;
launchDelay = 1.5;
numOfHits = 1;
wc = engine.getWaveConfigs().getWaveConfig(6);
wc = engine.getWaveConfigs().getWaveConfig(7);
break;
case 1:
numOfEnemies = 5;
fireDelay = 0.3;
launchDelay = 1;
numOfHits = 2;
wc = engine.getWaveConfigs().getWaveConfig(3);
break;
case 2:
numOfEnemies = 10;
fireDelay = 0.3;
launchDelay = 1;
numOfHits = 3;
numOfEnemies = 15;
fireDelay = 0.7;
launchDelay = 1.4;
numOfHits = 1;
wc = engine.getWaveConfigs().getWaveConfig(2);
break;
case 2:
numOfEnemies = 25;
fireDelay = 0.5;
launchDelay = 1.4;
numOfHits = 2;
wc = engine.getWaveConfigs().getWaveConfig(0);
break;
case 3:
numOfEnemies = 15;
fireDelay = 0.2;
numOfEnemies = 5;
fireDelay = 0.4;
launchDelay = 1;
numOfHits = 5;
wc = engine.getWaveConfigs().getWaveConfig(7);
numOfHits = 4;
wc = engine.getWaveConfigs().getWaveConfig(1);
break;
default:
wc = engine.getWaveConfigs().getWaveConfig(WaveConfigs.DEMO);