Merge pull request #2 from sagidayan/master

add changes
This commit is contained in:
Aran Zaiger 2016-03-20 18:49:45 +02:00
commit 956dc01677
26 changed files with 1039 additions and 464 deletions

View file

@ -1,15 +1,14 @@
package com.sagi.dayan.Games.Elements; package com.sagi.dayan.Games.Elements;
import javax.imageio.ImageIO; import java.awt.Graphics;
import javax.swing.*; import java.awt.Graphics2D;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.ImageProducer;
import java.io.IOException; import java.io.IOException;
import java.util.Vector; import java.util.Vector;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
/** /**
* Created by sagi on 2/10/16. * Created by sagi on 2/10/16.
*/ */
@ -18,8 +17,6 @@ public abstract class AnimatedSprite extends Sprite {
protected int currentAnimation; protected int currentAnimation;
public AnimatedSprite(int x, int y, int w, int h, int acc, String imgName, double angle, int sWidth, int sHeight, int numOfFirstFrames) { public AnimatedSprite(int x, int y, int w, int h, int acc, String imgName, double angle, int sWidth, int sHeight, int numOfFirstFrames) {
super(x, y, w, h, acc, imgName, angle, sWidth, sHeight); super(x, y, w, h, acc, imgName, angle, sWidth, sHeight);
animations = new Vector<>(); animations = new Vector<>();
@ -50,6 +47,10 @@ public abstract class AnimatedSprite extends Sprite {
super.drawScreenLoopFix(g,p); super.drawScreenLoopFix(g,p);
} }
public int getFrameNum(){
return animations.get(currentAnimation).getFrameIndex();
}
public void setCurrentAnimation(int animation){ public void setCurrentAnimation(int animation){
if(animation < 0){ if(animation < 0){
throw new IllegalArgumentException("Animation index cant be negative"); throw new IllegalArgumentException("Animation index cant be negative");

View file

@ -0,0 +1,33 @@
package com.sagi.dayan.Games.Elements;
import com.sagi.dayan.Games.Elements.AnimatedSprite.Animation;
public class Blast extends AnimatedSprite {
protected boolean isDone;
protected int numOfFirstFrames;
public Blast(int x, int y, String imgName, int numOfFirstFrames) {
super(x, y, 0, 0, 0, imgName, 0, 15, 15, numOfFirstFrames);
// TODO Auto-generated constructor stub
isDone = false;
this.numOfFirstFrames = numOfFirstFrames;
}
@Override
protected void initFirstAnimation(String spriteSheet, int numOfFirstFrames) {
animations.add(new Animation("explosion.png", 16, 500));
}
@Override
public void update() {
System.out.println("curr: "+currentAnimation+", total: "+numOfFirstFrames);
if (getFrameNum() == numOfFirstFrames-1)
isDone=true;
// TODO Auto-generated method stub
}
public boolean isDone(){
return isDone;
}
}

View file

@ -1,9 +1,5 @@
package com.sagi.dayan.Games.Elements; package com.sagi.dayan.Games.Elements;
import javax.swing.*;
import javax.swing.border.MatteBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/** /**
@ -68,7 +64,7 @@ public class EnemyShip extends AnimatedSprite {
System.out.println("GOT HIT " + hitsToDestroy); System.out.println("GOT HIT " + hitsToDestroy);
} }
public boolean isDead() { public boolean isDead() {
return hitsToDestroy == 0; return hitsToDestroy <= 0;
} }
public boolean isDone(){ public boolean isDone(){

View file

@ -6,8 +6,8 @@ package com.sagi.dayan.Games.Elements;
public class Missile extends AnimatedSprite { public class Missile extends AnimatedSprite {
public Missile(int x, int y, int acc, String imgName, int numOfFrames) { public Missile(int x, int y, int w, int h, int acc, String imgName, int numOfFrames) {
super(x, y, 0, 0, acc, imgName, 0, 15, 15, numOfFrames); super(x, y, w, h, acc, imgName, 0, 15, 15, numOfFrames);
} }

View file

@ -1,7 +1,8 @@
package com.sagi.dayan.Games.Elements; package com.sagi.dayan.Games.Elements;
import javax.swing.*; import java.awt.Graphics;
import java.awt.*;
import javax.swing.JPanel;
/** /**
* Created by sagi on 2/20/16. * Created by sagi on 2/20/16.
@ -14,6 +15,8 @@ public class Player extends AnimatedSprite {
private int fireDelay; private int fireDelay;
private double imortalPulse = 0.2; private double imortalPulse = 0.2;
private long lastFired, lastDrawn, created; private long lastFired, lastDrawn, created;
private int startX, startY;
private boolean isGameOver;
@ -30,6 +33,25 @@ public class Player extends AnimatedSprite {
setImageDimensions(); setImageDimensions();
isMortal = false; isMortal = false;
toDraw = true; toDraw = true;
startX = locX;
startY = locY;
isGameOver = false;
}
public boolean isGameOver() {
return isGameOver;
}
public void setGameOver(boolean gameOver) {
isGameOver = gameOver;
}
public void resetPlayer(){
locX = startX;
locY = startY;
isMortal = false;
lastDrawn = System.currentTimeMillis();
created = lastDrawn;
} }
@Override @Override
@ -68,6 +90,10 @@ public class Player extends AnimatedSprite {
locY = pHeight - animations.get(currentAnimation).getCurrentFrame().getHeight() - PADDING_BOTTOM; locY = pHeight - animations.get(currentAnimation).getCurrentFrame().getHeight() - PADDING_BOTTOM;
} }
if(isGameOver){
//System.exit(1);
}
} }

View file

@ -1,13 +1,16 @@
package com.sagi.dayan.Games.Elements; package com.sagi.dayan.Games.Elements;
import javax.imageio.ImageIO; import java.awt.Graphics;
import javax.swing.*; import java.awt.Graphics2D;
import java.awt.*; import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.Vector;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
public abstract class Sprite { public abstract class Sprite {
@ -261,7 +264,10 @@ public abstract class Sprite {
} }
public boolean isOutOfScreen() { public boolean isOutOfScreen() {
if (this.getLocX() + this.sWidth < 0 || this.getLocX() - this.sWidth > pHeight || this.getLocY() + this.sHeight < 0 || this.getLocY() - sHeight > pHeight) { if (this.getLocX() + sWidth < 0
|| this.getLocX() > pWidth
|| this.getLocY() +sHeight < 0
|| this.getLocY() >pHeight){
return true; return true;
} else { } else {
return false; return false;

View file

@ -1,12 +1,12 @@
package com.sagi.dayan.Games.Elements; package com.sagi.dayan.Games.Elements;
import com.sagi.dayan.Games.Stage.Level; import java.awt.Graphics;
import com.sagi.dayan.Games.Stage.Scene;
import javax.swing.*;
import java.awt.*;
import java.util.Vector; import java.util.Vector;
import javax.swing.JPanel;
import com.sagi.dayan.Games.Stage.Level;
/** /**
* Created by sagi on 3/11/16. * Created by sagi on 3/11/16.
*/ */
@ -52,6 +52,7 @@ public class Wave {
for (int i = 0; i < enemies.size() ; i++){ for (int i = 0; i < enemies.size() ; i++){
enemies.get(i).update(); enemies.get(i).update();
if (enemies.get(i).isDone() || enemies.get(i).isOutOfScreen()) { if (enemies.get(i).isDone() || enemies.get(i).isOutOfScreen()) {
enemiesToRemove.add(enemies.get(i)); enemiesToRemove.add(enemies.get(i));
} }
} }
@ -72,6 +73,7 @@ public class Wave {
} }
public void fireFromEnemy(EnemyShip e){ public void fireFromEnemy(EnemyShip e){
if(!e.isDead())
level.enemyFire(e.getCenterX(), (int)(e.getLocY() + e.getsHeight()), -(e.getAcceleration() + 2)); level.enemyFire(e.getCenterX(), (int)(e.getLocY() + e.getsHeight()), -(e.getAcceleration() + 2));
} }
@ -83,6 +85,6 @@ public class Wave {
es.gotHit(); es.gotHit();
} }
public boolean isWaveOver() { public boolean isWaveOver() {
return enemies.size() == 0 && currentAmount == enemyMaxAmount; return enemies.size() == 0 && currentAmount >= enemyMaxAmount;
} }
} }

View file

@ -7,11 +7,11 @@ package com.sagi.dayan.Games.Engine;
* Created by sagi on 12/19/15. * Created by sagi on 12/19/15.
*/ */
import java.awt.Rectangle;
import java.awt.image.PixelGrabber;
import com.sagi.dayan.Games.Elements.AnimatedSprite; import com.sagi.dayan.Games.Elements.AnimatedSprite;
import com.sagi.dayan.Games.Elements.Sprite; import com.sagi.dayan.Games.Elements.Sprite;
import java.awt.*;
import java.awt.image.PixelGrabber;
public class CollisionUtil { public class CollisionUtil {
/** /**

View file

@ -4,58 +4,60 @@ package com.sagi.dayan.Games.Engine;
* Created by sagi on 2/8/16. * Created by sagi on 2/8/16.
*/ */
import com.sagi.dayan.Games.Stage.*; import java.awt.Font;
import com.sagi.dayan.Games.Utils.Utils; import java.awt.FontFormatException;
import com.sagi.dayan.Games.Utils.WaveConfigs; import java.awt.event.KeyEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
import java.util.Vector;
/** import javax.swing.JFrame;
* Created by sagi on 12/18/15. import javax.swing.JPanel;
*/
import com.sagi.dayan.Games.Stage.*;
import com.sagi.dayan.Games.Stage.MainMenuScene;
import com.sagi.dayan.Games.Stage.Scene;
import com.sagi.dayan.Games.Stage.SettingsMenuScene;
import com.sagi.dayan.Games.Stage.Stage;
import com.sagi.dayan.Games.Utils.Utils;
import com.sagi.dayan.Games.Utils.WaveConfigs;
public class GameEngine { public class GameEngine {
private final int CREDIT_TIME = 10;
public boolean gameOn , gameOver, isFirstGame; public boolean gameOn , gameOver, isFirstGame;
private JFrame frame; private JFrame frame;
private int pWidth, pHeight, numOfPlayers; //panel dimensions private int pWidth, pHeight, numOfPlayers; //panel dimensions
private Random r; private Random r;
private Stage stage; private Stage stage;
private Vector<Scene> scenes; private Scene scene;
private int currentScene; private int p1CreditTime, p2CreditTime, creditTickTime = 1;
public static final int PLAYER_WIDTH = 120, PLAYER_HEIGHT = 120; public static final int PLAYER_WIDTH = 120, PLAYER_HEIGHT = 120;
public static final int UP=0,RIGHT=1,DOWN=2, LEFT=3, FIRE=4, SPECIAL=5; public static final int UP=0,RIGHT=1,DOWN=2, LEFT=3, FIRE=4, USE_CREDIT=5;
public int p1HighScore, p2HighScore;
private int[] p1Controlles = {KeyEvent.VK_UP, KeyEvent.VK_RIGHT, KeyEvent.VK_DOWN, KeyEvent.VK_LEFT, KeyEvent.VK_K}; private int[] p1Controlles = {KeyEvent.VK_UP, KeyEvent.VK_RIGHT, KeyEvent.VK_DOWN, KeyEvent.VK_LEFT, KeyEvent.VK_K, KeyEvent.VK_J};
private int[] p2Controlles = {KeyEvent.VK_W, KeyEvent.VK_D, KeyEvent.VK_S, KeyEvent.VK_A, KeyEvent.VK_SHIFT}; private int[] p2Controlles = {KeyEvent.VK_W, KeyEvent.VK_D, KeyEvent.VK_S, KeyEvent.VK_A, KeyEvent.VK_Q, KeyEvent.VK_Z};
private int p1Lives, p2Lives, p1Health, p2Health, credits, p1Score, p2Score; private int p1Lives, p2Lives, p1Health, p2Health, credits, p1Score, p2Score;
private long lastP1CreditTick, lastP2CreditTick;
private Font gameFont; private Font gameFont;
private WaveConfigs waveConfigs; private WaveConfigs waveConfigs;
private int currentLevel;
public GameEngine(int width, int height, Stage stage){ public GameEngine(int width, int height, Stage stage){
this.currentScene = 0; p1HighScore = p2HighScore = 0;
this.isFirstGame = true; this.isFirstGame = true;
this.gameOver = true; this.gameOver = true;
this.pWidth = width; this.pWidth = width;
this.pHeight = height; this.pHeight = height;
this.scenes = new Vector<>();
this.stage = stage; this.stage = stage;
// scenes.add(new Level(width, height, 2)); // Need to be a menu Scene currentLevel = -1;
scenes.add(new MainMenuScene(width, height, this)); goToMenu();
stage.addKeyListener(scenes.get(currentScene));
stage.addMouseListener(scenes.get(currentScene));
r = new Random(); r = new Random();
try{ try{
gameFont = Font.createFont(Font.TRUETYPE_FONT,Utils.getFontStream("transformers.ttf")); gameFont = Font.createFont(Font.TRUETYPE_FONT,Utils.getFontStream("transformers.ttf"));
@ -68,9 +70,7 @@ public class GameEngine {
} }
this.waveConfigs = new WaveConfigs(); this.waveConfigs = new WaveConfigs();
startNewGame(); startNewGame();
resetPlayerHealth(0);
resetPlayerHealth(1);
credits = 3;
} }
@ -82,16 +82,9 @@ public class GameEngine {
p2Health = 100; p2Health = 100;
} }
} }
private void resetPlayer(int i){
resetPlayerHealth(i);
if (i==0){
p1Lives = 3;
}
else{
p2Lives = 3;
}
}
/** /**
@ -99,6 +92,7 @@ public class GameEngine {
*/ */
private void startNewGame(){ private void startNewGame(){
this.gameOn = true; this.gameOn = true;
this.currentLevel = -1;
initGame(); initGame();
} }
@ -106,9 +100,20 @@ public class GameEngine {
* Setup all actors in the game to a new game - reset timer * Setup all actors in the game to a new game - reset timer
*/ */
private void initGame(){ private void initGame(){
resetPlayerHealth(0);
resetPlayerHealth(1);
p1Score = p2Score = 0;
credits = 3;
p1Lives = 1;
p2Lives = 1;
}
public int getP1CreditTime() {
return p1CreditTime;
}
public int getP2CreditTime() {
return p2CreditTime;
} }
public WaveConfigs getWaveConfigs() { public WaveConfigs getWaveConfigs() {
@ -135,51 +140,65 @@ public class GameEngine {
* Update all sprites, including collision handling. * Update all sprites, including collision handling.
*/ */
public void update(){ public void update(){
scenes.get(currentScene).update(); long now = System.currentTimeMillis();
if(now - lastP1CreditTick >= creditTickTime * 1000){
p1CreditTime--;
lastP1CreditTick = now;
}
if(now - lastP2CreditTick >= creditTickTime * 1000){
p2CreditTime--;
lastP2CreditTick = now;
}
scene.update();
} }
public void render(JPanel p) { public void render(JPanel p) {
scenes.get(currentScene).render(p); scene.render(p);
} }
public BufferedImage getScene() { public BufferedImage getScene() {
return scenes.get(currentScene).getSceneImage(); return scene.getSceneImage();
}
private void changeScene(int index) {
if (index >= scenes.size()){
throw new IllegalArgumentException("Invalid Index. scenes size: "+scenes.size());
}
stage.removeKeyListener(scenes.get(currentScene));
stage.removeMouseListener(scenes.get(currentScene));
currentScene = index;
stage.addKeyListener(scenes.get(currentScene));
stage.addMouseListener(scenes.get(currentScene));
} }
public void startGame(int numOfPlayers){ public void startGame(int numOfPlayers){
this.numOfPlayers = numOfPlayers; this.numOfPlayers = numOfPlayers;
scenes.add(new FirstStage(pWidth, pHeight, numOfPlayers, this, "-= STAGE 1.0 =-", new int[]{5, 20})); startNewGame();
changeScene(currentScene+1); changeLevel();
}
public void changeLevel(){
System.out.println("current level: "+currentLevel);
currentLevel++;
stage.removeMouseListener(scene);
stage.removeKeyListener(scene);
switch (currentLevel){
case 0:
scene = new FirstStage(pWidth, pHeight, numOfPlayers, this, "-= STAGE 1.0 =-", new int[]{5, 1,1,1});
break;
case 1:
scene = new SecondStage(pWidth, pHeight, numOfPlayers, this, "-= STAGE 2.0 =-", new int[]{5, 5,5,5});
break;
case 2:
scene = new ThirdStage(pWidth, pHeight, numOfPlayers, this, "-= STAGE 3.0 =-", new int[]{5, 0,0,8});
break;
case 3:
scene = new FourthStage(pWidth, pHeight, numOfPlayers, this, "-= STAGE 4.0 =-", new int[]{5, 0,0,8});
break;
}
stage.addKeyListener(scene);
stage.addMouseListener(scene);
} }
public void goToSettings() { public void goToSettings() {
scenes.add(new SettingsMenuScene(pWidth, pHeight, this)); stage.removeMouseListener(scene);
changeScene(currentScene+1); stage.removeKeyListener(scene);
scene = new SettingsMenuScene(pWidth, pHeight, this);
stage.addKeyListener(scene);
stage.addMouseListener(scene);
} }
public void goToMainMenu() {
changeScene(0);
for(int i = scenes.size() -1 ; i > 0 ; i--){
scenes.remove(i);
}
}
public int getScenesSize(){
return scenes.size();
}
public int[] getP1Controlles(){ public int[] getP1Controlles(){
return p1Controlles; return p1Controlles;
@ -223,6 +242,22 @@ public class GameEngine {
credits--; credits--;
} }
public void revivePlayer(int i)
{
useCredit();
if(i==0){
p1Health=100;
p1Lives =3;
}
else{
p2Health=100;
p2Lives =3;
}
}
public void setScore(int i, int score) public void setScore(int i, int score)
{ {
if (i == 0) { if (i == 0) {
@ -234,9 +269,65 @@ public class GameEngine {
public void setPlayerHealth(int i, int strike) { public void setPlayerHealth(int i, int strike) {
if (i == 0) { if (i == 0) {
p1Health += strike; p1Health += strike;
if(p1Health <= 0){
p1Lives--;
if(p1Lives > 0)
resetPlayerHealth(i);
if(p1Lives <= 0){
p1CreditTime = 10;
lastP1CreditTick = System.currentTimeMillis();
}
}
} else { } else {
p2Health += strike; p2Health += strike;
if(p2Health <= 0){
p2Lives--;
if(p2Lives > 0)
resetPlayerHealth(i);
if(p2Health <= 0){
p2CreditTime = 10;
lastP2CreditTick = System.currentTimeMillis();
}
}
} }
} }
public void goToMenu(){
stage.removeMouseListener(scene);
stage.removeKeyListener(scene);
scene = new MainMenuScene(pWidth, pHeight, this);
stage.addKeyListener(scene);
stage.addMouseListener(scene);
}
public void setGameOver(boolean gameOver) {
if(gameOver){
goToMenu();
this.gameOver = true;
}
}
public int getP1HighScore() {
return p1HighScore;
}
public void setP1HighScore(int p1HighScore) {
this.p1HighScore = p1HighScore;
}
public int getP2HighScore() {
return p2HighScore;
}
public void setP2HighScore(int p2HighScore) {
this.p2HighScore = p2HighScore;
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 322 KiB

After

Width:  |  Height:  |  Size: 328 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 319 KiB

After

Width:  |  Height:  |  Size: 319 KiB

View file

@ -10,31 +10,48 @@ import com.sagi.dayan.Games.Utils.WaveConfigs;
*/ */
public class FirstStage extends Level{ public class FirstStage extends Level{
protected final int NUM_OF_WAVES = 4;
public FirstStage(int width, int height, int numOfPlayers, GameEngine engine, String stageTitle, int[] waveDelay) { public FirstStage(int width, int height, int numOfPlayers, GameEngine engine, String stageTitle, int[] waveDelay) {
super(width, height, numOfPlayers, engine, stageTitle, waveDelay); super(width, height, numOfPlayers, engine, stageTitle, waveDelay);
numOfWaves = NUM_OF_WAVES;
} }
@Override @Override
protected void launchWave(long now) { protected void launchWave(long now) {
lastWaveTime = now; lastWaveTime = now;
System.out.println("New Wave!! Time: " + now); System.out.println("New Wave!! " + currentWave + ", Time: " + now);
WaveConfig wc; WaveConfig wc;
int numOfEnemies = 5, numOfHits = 1; int numOfEnemies = 5, numOfHits = 1;
double launchDelay = 0.5, fireDelay = 5; double launchDelay = 0.5, fireDelay = 5;
switch (currentWave){ switch (currentWave){
case 0: case 0:
numOfEnemies = 5; numOfEnemies = 5;
fireDelay = 0.2; fireDelay = 0.1;
launchDelay = 0.5; launchDelay = 0.5;
numOfHits = 1; numOfHits = 1;
wc = engine.getWaveConfigs().getWaveConfig(WaveConfigs.DEMO); wc = engine.getWaveConfigs().getWaveConfig(6);
break; break;
case 1: case 1:
numOfEnemies = 5; numOfEnemies = 5;
fireDelay = 5; fireDelay = 1;
launchDelay = 1; launchDelay = 1;
numOfHits = 1; numOfHits = 2;
wc = engine.getWaveConfigs().getWaveConfig(WaveConfigs.DEMO); wc = engine.getWaveConfigs().getWaveConfig(3);
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);
break; break;
default: default:
wc = engine.getWaveConfigs().getWaveConfig(WaveConfigs.DEMO); wc = engine.getWaveConfigs().getWaveConfig(WaveConfigs.DEMO);

View file

@ -0,0 +1,63 @@
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 FourthStage extends Level{
protected final int NUM_OF_WAVES = 4;
public FourthStage(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 = 5;
fireDelay = 0.5;
launchDelay = 0.5;
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:
numOfEnemies = 10;
fireDelay = 0.3;
launchDelay = 1;
numOfHits = 3;
wc = engine.getWaveConfigs().getWaveConfig(2);
break;
case 3:
numOfEnemies = 15;
fireDelay = 0.2;
launchDelay = 1;
numOfHits = 5;
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

@ -1,26 +1,35 @@
package com.sagi.dayan.Games.Stage; package com.sagi.dayan.Games.Stage;
import com.sagi.dayan.Games.Elements.*; import java.awt.Color;
import com.sagi.dayan.Games.Engine.CollisionUtil; import java.awt.Font;
import com.sagi.dayan.Games.Engine.GameEngine; import java.awt.FontMetrics;
import com.sagi.dayan.Games.Utils.Utils; import java.awt.Graphics;
import com.sagi.dayan.Games.Utils.WaveConfig; import java.awt.Image;
import com.sagi.dayan.Games.Utils.WaveConfigs;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
import javax.swing.JLabel;
import javax.swing.JPanel;
import com.sagi.dayan.Games.Elements.Background;
import com.sagi.dayan.Games.Elements.Blast;
import com.sagi.dayan.Games.Elements.Missile;
import com.sagi.dayan.Games.Elements.Player;
import com.sagi.dayan.Games.Elements.Wave;
import com.sagi.dayan.Games.Engine.CollisionUtil;
import com.sagi.dayan.Games.Engine.GameEngine;
import com.sagi.dayan.Games.Utils.Utils;
/** /**
* Created by sagi on 2/20/16. * Created by sagi on 2/20/16.
*/ */
public abstract class Level extends Scene { public abstract class Level extends Scene {
protected final double PRESS_START_PULE = 0.3;
protected boolean toDrawStart;
protected Vector<Player> players; protected Vector<Player> players;
protected int p1Speed = 10; protected int p1Speed = 10;
protected Vector<Missile> p1Missiles, p2Missiles, enemyMissiles; protected Vector<Missile> p1Missiles, p2Missiles, enemyMissiles;
@ -31,11 +40,13 @@ public abstract class Level extends Scene {
protected int startingAnimationIndex; protected int startingAnimationIndex;
protected boolean isStarted; protected boolean isStarted;
protected Vector<Wave> waves; protected Vector<Wave> waves;
protected Vector<Blast> blasts;
protected int numOfPlayers; protected int numOfPlayers;
protected Map<Integer, Boolean> keys; protected Map<Integer, Boolean> keys;
protected String title; protected String title;
protected JLabel stageTitle; protected JLabel stageTitle;
protected long lastWaveTime; protected long lastWaveTime, lastPulseTime;
protected int numOfWaves;
@ -44,6 +55,7 @@ public abstract class Level extends Scene {
players = new Vector<>(); players = new Vector<>();
p1Missiles = new Vector<>(); p1Missiles = new Vector<>();
p2Missiles = new Vector<>(); p2Missiles = new Vector<>();
blasts = new Vector<Blast>();
enemyMissiles = new Vector<>(); enemyMissiles = new Vector<>();
this.waveDelay = waveDelay; this.waveDelay = waveDelay;
this.lastWaveTime = System.currentTimeMillis(); this.lastWaveTime = System.currentTimeMillis();
@ -59,15 +71,20 @@ public abstract class Level extends Scene {
this.stageTitle = new JLabel(this.title); this.stageTitle = new JLabel(this.title);
if(numOfPlayers == 1) { if(numOfPlayers == 1) {
players.add(new Player((width / 2) + (GameEngine.PLAYER_WIDTH / 2), yAxisStartingAnimation[startingAnimationIndex], width, height, p1Speed, "emptyImage.png", 0, GameEngine.PLAYER_WIDTH, GameEngine.PLAYER_HEIGHT, "P1",6)); players.add(new Player((width / 2) + (GameEngine.PLAYER_WIDTH / 2), yAxisStartingAnimation[startingAnimationIndex],
width, height, p1Speed, "emptyImage.png", 0, GameEngine.PLAYER_WIDTH, GameEngine.PLAYER_HEIGHT, "P1",6));
}else{ }else{
players.add(new Player((width / 2) + (GameEngine.PLAYER_WIDTH / 2) + GameEngine.PLAYER_WIDTH, yAxisStartingAnimation[startingAnimationIndex], width, height, p1Speed, "emptyImage.png", 0, GameEngine.PLAYER_WIDTH, GameEngine.PLAYER_HEIGHT, "P1", 6)); players.add(new Player((width / 2) + (GameEngine.PLAYER_WIDTH / 2) + GameEngine.PLAYER_WIDTH, yAxisStartingAnimation[startingAnimationIndex],
players.add(new Player((width / 2) + (GameEngine.PLAYER_WIDTH / 2) - GameEngine.PLAYER_WIDTH*3, yAxisStartingAnimation[startingAnimationIndex], width, height, p1Speed, "emptyImage.png", 0, GameEngine.PLAYER_WIDTH, GameEngine.PLAYER_HEIGHT, "P2", 6)); width, height, p1Speed, "emptyImage.png", 0, GameEngine.PLAYER_WIDTH, GameEngine.PLAYER_HEIGHT, "P1", 6));
players.add(new Player((width / 2) + (GameEngine.PLAYER_WIDTH / 2) - GameEngine.PLAYER_WIDTH*3, yAxisStartingAnimation[startingAnimationIndex],
width, height, p1Speed, "emptyImage.png", 0, GameEngine.PLAYER_WIDTH, GameEngine.PLAYER_HEIGHT, "P2", 6));
} }
setupKeys(); setupKeys();
Utils.playSound("jetSound.wav"); Utils.playSound("jetSound.wav");
lastPulseTime = System.currentTimeMillis();
toDrawStart = true;
} }
private void setupKeys() { private void setupKeys() {
@ -87,10 +104,12 @@ public abstract class Level extends Scene {
public void update() { public void update() {
bg.update(); bg.update();
movePlayers(); movePlayers();
Vector <Wave> wavesToRemove = new Vector<Wave>(); Vector <Wave> wavesToRemove = new Vector<>();
Vector<Blast> blastTRM = new Vector<>();
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if(currentWave < waveDelay.length && now - lastWaveTime >= waveDelay[currentWave] * 1000){ // if(currentWave < waveDelay.length && now - lastWaveTime >= waveDelay[currentWave] * 1000){
if(currentWave < numOfWaves && now - lastWaveTime >= waveDelay[currentWave] * 1000){
launchWave(now); launchWave(now);
} }
@ -101,7 +120,6 @@ public abstract class Level extends Scene {
if(players.get(0).getLocY() > yAxisStartingAnimation[startingAnimationIndex] && startingAnimationIndex == 1){ if(players.get(0).getLocY() > yAxisStartingAnimation[startingAnimationIndex] && startingAnimationIndex == 1){
for(int i = 0 ; i < players.size() ; i++){ for(int i = 0 ; i < players.size() ; i++){
players.get(i).setLocY((int)players.get(i).getLocY() - (p1Speed)); players.get(i).setLocY((int)players.get(i).getLocY() - (p1Speed));
// players.get(i).update();
} }
if(players.get(0).getLocY() <= yAxisStartingAnimation[startingAnimationIndex]){ if(players.get(0).getLocY() <= yAxisStartingAnimation[startingAnimationIndex]){
startingAnimationIndex++; startingAnimationIndex++;
@ -110,7 +128,6 @@ public abstract class Level extends Scene {
for(int i = 0 ; i < players.size() ; i++){ for(int i = 0 ; i < players.size() ; i++){
players.get(i).setLocY((int)players.get(i).getLocY() + (p1Speed - 5)); players.get(i).setLocY((int)players.get(i).getLocY() + (p1Speed - 5));
// players.get(i).update();
} }
if(players.get(0).getLocY() >= yAxisStartingAnimation[startingAnimationIndex]){ if(players.get(0).getLocY() >= yAxisStartingAnimation[startingAnimationIndex]){
startingAnimationIndex++; startingAnimationIndex++;
@ -135,16 +152,48 @@ public abstract class Level extends Scene {
for(int i = 0 ; i < waves.size() ; i++){ for(int i = 0 ; i < waves.size() ; i++){
waves.get(i).update(); waves.get(i).update();
if(waves.get(i).isWaveOver()) { if(waves.get(i).isWaveOver()) {
System.out.println("in remove");
wavesToRemove.add(waves.get(i)); wavesToRemove.add(waves.get(i));
} }
} }
waves.removeAll(wavesToRemove); waves.removeAll(wavesToRemove);
if(engine.getP1Score() > engine.getP1HighScore())
engine.setP1HighScore(engine.getP1Score());
if(engine.getP2Score() > engine.getP2HighScore())
engine.setP2HighScore(engine.getP2Score());
} }
checkCollision(); checkCollision();
engine.setGameOver(isGameOver());
if(currentWave >= numOfWaves && waves.size()==0)
{
System.out.println("Done");
engine.changeLevel();
}
for(int i =0; i<blasts.size();i++){
if (blasts.get(i).isDone()){
System.out.println("removing blast");
blastTRM.add(blasts.get(i));
}
blasts.get(i).update();
}
blasts.removeAll(blastTRM);
} }
protected abstract void launchWave(long time); protected abstract void launchWave(long time);
private boolean isGameOver(){
if(numOfPlayers == 1) {
return players.get(0).isGameOver();
}else{
return players.get(0).isGameOver() && players.get(1).isGameOver();
}
}
private void movePlayers() { private void movePlayers() {
/** /**
* Player 1 Movement: * Player 1 Movement:
@ -168,11 +217,18 @@ public abstract class Level extends Scene {
players.get(0).setvDirection(0); players.get(0).setvDirection(0);
} }
if(keys.get(engine.getP1Controlles()[GameEngine.FIRE]) ){ if(keys.get(engine.getP1Controlles()[GameEngine.FIRE]) ){
if(players.get(0).isAbleToFire()){ if(players.get(0).isAbleToFire() && !players.get(0).isGameOver()) {
p1Missiles.add(new Missile(players.get(0).getCenterX() - 15, (int)players.get(0).getLocY(), players.get(0).getAcceleration() + 3, "P1Laser.png", 4)); 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(); players.get(0).updateFireTime();
} }
} }
if(keys.get(engine.getP1Controlles()[GameEngine.USE_CREDIT]) && engine.getP1Health() <= 0 ){
if(engine.getCredits() > 0) {
engine.revivePlayer(0);
players.get(0).resetPlayer();
}
}
/** /**
* Player 2 Movement * Player 2 Movement
@ -197,11 +253,19 @@ public abstract class Level extends Scene {
players.get(1).setvDirection(0); players.get(1).setvDirection(0);
} }
if(keys.get(engine.getP2Controlles()[GameEngine.FIRE]) ){ if(keys.get(engine.getP2Controlles()[GameEngine.FIRE]) ){
if(players.get(1).isAbleToFire()){ if(players.get(1).isAbleToFire() && !players.get(1).isGameOver()){
p2Missiles.add(new Missile(players.get(1).getCenterX() - 15, (int)players.get(1).getLocY(), players.get(1).getAcceleration() + 3, "P1Laser.png", 4)); 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(); players.get(1).updateFireTime();
} }
} }
if(keys.get(engine.getP2Controlles()[GameEngine.USE_CREDIT]) && engine.getP2Health() <= 0 ){
if(engine.getCredits() > 0) {
engine.revivePlayer(1);
players.get(1).resetPlayer();
}
}
} }
} }
@ -234,16 +298,26 @@ public abstract class Level extends Scene {
} }
if (isGameOver())
{
try {
System.in.read();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//print score //print score
f = f.deriveFont(15F); f = f.deriveFont(15F);
g.setFont(f); g.setFont(f);
//print life bar //print life bar
for(int i=0; i<players.size(); i++){ for(int i=0; i<players.size(); i++){
g.setColor(Color.WHITE);
g.drawString("Player "+ (i+1) +" - Lives: " + ((i == 0) ? engine.getP1Lives() : engine.getP2Lives())+ ", Score: " + ((i == 0) ? engine.getP1Score() : engine.getP2Score()), 15, 35*(i+1));
g.setColor(Color.WHITE);
g.drawRect(15,35*(i+1)+10,100,10); g.drawRect(15,35*(i+1)+10,100,10);
g.setColor(Color.GREEN); g.setColor(Color.GREEN);
if (i==0 && engine.getP1Health()<=30) if (i==0 && engine.getP1Health()<=30)
@ -273,12 +347,79 @@ public abstract class Level extends Scene {
enemyMissiles.get(i).drawSprite(g,p); enemyMissiles.get(i).drawSprite(g,p);
} }
for(int i = 0 ; i < players.size() ; i++){ for(int i = 0 ; i < players.size() ; i++){
if(i == 0){
if(engine.getP1Health() > 0){
players.get(i).drawSprite(g,p); players.get(i).drawSprite(g,p);
g.setColor(Color.WHITE);
g.drawString("Player "+ (i+1) +" - Lives: " + ((i == 0) ? engine.getP1Lives() : engine.getP2Lives())+ ", Score: " + ((i == 0) ? engine.getP1Score() : engine.getP2Score()), 15, 35*(i+1));
}else{
if(players.get(i).isGameOver()){
renderGameOver(g, p, i);
}else{
renderPressStart(g, p, i);
}
}
}else{
if(engine.getP2Health() > 0){
players.get(i).drawSprite(g,p);
g.setColor(Color.WHITE);
g.drawString("Player "+ (i+1) +" - Lives: " + ((i == 0) ? engine.getP1Lives() : engine.getP2Lives())+ ", Score: " + ((i == 0) ? engine.getP1Score() : engine.getP2Score()), 15, 35*(i+1));
}else{
if(players.get(i).isGameOver()){
renderGameOver(g, p, i);
}else{
renderPressStart(g, p, i);
}
}
}
} }
for(int i = 0 ; i < waves.size() ; i++){ for(int i = 0 ; i < waves.size() ; i++){
waves.get(i).render(g,p); waves.get(i).render(g,p);
} }
for(int i =0; i<blasts.size();i++){
blasts.get(i).drawSprite(g, p);
}
}
protected void renderPressStart(Graphics g, JPanel p, int i){
long now = System.currentTimeMillis();
if(now - lastPulseTime >= PRESS_START_PULE * 1000){
toDrawStart = !toDrawStart;
lastPulseTime = now;
}
if(i == 0){
g.drawString(engine.getP1CreditTime()+"", 15, 35 * (i + 1));
if(engine.getP1CreditTime() <= 0){
players.get(i).setGameOver(true);
}
}else{
g.drawString(engine.getP2CreditTime()+"", 15, 35 * (i + 1));
if(engine.getP2CreditTime() <= 0){
players.get(i).setGameOver(true);
}
}
if(toDrawStart) {
g.drawString("PRESS START", 45, 35 * (i + 1));
}
players.get(i).setLocY(-500);
players.get(i).setLocX(-500);
}
protected void renderGameOver(Graphics g, JPanel p, int i){
System.out.println("HERE");
long now = System.currentTimeMillis();
players.get(i).setGameOver(true);
if(now - lastPulseTime >= PRESS_START_PULE * 1000){
toDrawStart = !toDrawStart;
lastPulseTime = now;
}
if(toDrawStart) {
g.drawString("P" + (i+1) + " GAME OVER", 15, 35 * (i + 1));
}
} }
public void checkCollision() { public void checkCollision() {
@ -287,16 +428,38 @@ public abstract class Level extends Scene {
p1MTR = new Vector<>(); p1MTR = new Vector<>();
p2MTR = new Vector<>(); p2MTR = new Vector<>();
// remove missiles - out of screen
for( int i = 0; i < enemyMissiles.size(); i++) {
if (enemyMissiles.get(i).isOutOfScreen()) {
eMTR.add(enemyMissiles.get(i));
}
}
for( int i = 0; i < p1Missiles.size(); i++) {
if (p1Missiles.get(i).isOutOfScreen()) {
p1MTR.add(p1Missiles.get(i));
}
}
if (players.size() > 1) {
for( int i = 0; i < p2Missiles.size(); i++) {
if (p2Missiles.get(i).isOutOfScreen()) {
p2MTR.add(p2Missiles.get(i));
}
}
}
//for each player check collisions //for each player check collisions
for (int i = 0; i < players.size(); i++) { for (int i = 0; i < players.size(); i++) {
//player vs. enemy missile //player vs. enemy missile
for (int j = 0; j < enemyMissiles.size(); j++) { for (int j = 0; j < enemyMissiles.size(); j++) {
if(CollisionUtil.collidesWith(players.get(i),enemyMissiles.get(j))){ if(CollisionUtil.collidesWith(players.get(i),enemyMissiles.get(j))){
if(players.get(i).isMortal()) playerHit(i);
engine.setPlayerHealth(i, -10); if(playerIsAlive(i)) {
eMTR.add(enemyMissiles.get(j)); eMTR.add(enemyMissiles.get(j));
System.out.println("Hit Missile"); }else{
blasts.add(new Blast((int)players.get(i).getLocX(),(int)players.get(i).getLocY(),"explosion.png",15));
}
} }
} }
@ -305,9 +468,15 @@ public abstract class Level extends Scene {
// Ship hits enemy // Ship hits enemy
for (int k = 0; k < waves.get(j).getEnemies().size(); k++) { for (int k = 0; k < waves.get(j).getEnemies().size(); k++) {
if (CollisionUtil.collidesWith(waves.get(j).getEnemies().get(k), players.get(i))) { if (CollisionUtil.collidesWith(waves.get(j).getEnemies().get(k), players.get(i))) {
if(players.get(i).isMortal()) if(!waves.get(j).getEnemies().get(k).isDead()){
engine.setPlayerHealth(i, -10); playerHit(i);
}
if(playerIsAlive(i)) {
waves.get(j).enemyHit(waves.get(j).getEnemies().get(k)); waves.get(j).enemyHit(waves.get(j).getEnemies().get(k));
}else{
blasts.add(new Blast((int)players.get(i).getLocX(),(int)players.get(i).getLocY(),"explosion.png",15));
}
} }
} }
} }
@ -358,8 +527,31 @@ public abstract class Level extends Scene {
} }
protected boolean playerIsAlive(int i){
if(i == 0){
return !(engine.getP1Lives() <= 0);
}else{
return !(engine.getP2Lives() <= 0);
}
}
protected void playerHit(int i){
if(players.get(i).isMortal()){
engine.setPlayerHealth(i, -10);
if(i == 0){
if(engine.getP1Health() == 100){
players.get(i).resetPlayer();
}
}else{
if(engine.getP2Health() == 100){
players.get(i).resetPlayer();
}
}
}
}
public void enemyFire(int x, int y, int acc) { public void enemyFire(int x, int y, int acc) {
enemyMissiles.add(new Missile(x, y, acc,"E1-Fire.png", 15)); enemyMissiles.add(new Missile(x, y,getStageWidth(),getStageHeight(), acc,"E1-Fire.png", 15));
} }
@Override @Override

View file

@ -1,16 +1,20 @@
package com.sagi.dayan.Games.Stage; package com.sagi.dayan.Games.Stage;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.swing.JPanel;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
import com.sagi.dayan.Games.Elements.MenuBoxSprite; import com.sagi.dayan.Games.Elements.MenuBoxSprite;
import com.sagi.dayan.Games.Engine.GameEngine; import com.sagi.dayan.Games.Engine.GameEngine;
import com.sagi.dayan.Games.Utils.Utils; import com.sagi.dayan.Games.Utils.Utils;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.*;
/** /**
* Created by sagi on 2/24/16. * Created by sagi on 2/24/16.
@ -20,7 +24,6 @@ public class MainMenuScene extends Scene {
private MenuBoxSprite menuBox; private MenuBoxSprite menuBox;
private int menuItem; private int menuItem;
private final int MAX_ITEM_INDEX = 3, X_AXIS=560, ITEM_EXIT = 3, ITEM_SETTINGS = 2, ITEM_2P = 1, ITEM_1P = 0; private final int MAX_ITEM_INDEX = 3, X_AXIS=560, ITEM_EXIT = 3, ITEM_SETTINGS = 2, ITEM_2P = 1, ITEM_1P = 0;
private int[] axis = {370, 480, 590, 700}; private int[] axis = {370, 480, 590, 700};
@ -51,6 +54,25 @@ public class MainMenuScene extends Scene {
Graphics g = sceneImage.getGraphics(); Graphics g = sceneImage.getGraphics();
g.drawImage(menuBox.getbImage(), 0, 0, p); g.drawImage(menuBox.getbImage(), 0, 0, p);
menuBox.drawSprite(g, p); menuBox.drawSprite(g, p);
Font f = engine.getGameFont();
f = f.deriveFont(25F);
g.setFont(f);
g.drawString("Player1 record: " +engine.p1HighScore, 700, 50);
g.drawString("Player2 record: " +engine.p2HighScore, 700, 100);
try {
if(!AudioPlayer.player.isAlive()){
System.out.println("Start again");
AudioPlayer.player.start(new AudioStream(Utils.getSoundResourceAsStream("intro_LowQuality.wav")));
}
}catch (IOException e) {
e.printStackTrace();
}
} }
@Override @Override

View file

@ -4,15 +4,14 @@ package com.sagi.dayan.Games.Stage;
* Created by sagi on 2/8/16. * Created by sagi on 2/8/16.
*/ */
import com.sagi.dayan.Games.Elements.*;
import com.sagi.dayan.Games.Engine.GameEngine;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyListener; import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import javax.swing.JPanel;
import com.sagi.dayan.Games.Engine.GameEngine;
public abstract class Scene extends MouseAdapter implements KeyListener{ public abstract class Scene extends MouseAdapter implements KeyListener{
public int getStageWidth() { public int getStageWidth() {

View file

@ -0,0 +1,63 @@
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 SecondStage extends Level{
protected final int NUM_OF_WAVES = 4;
public SecondStage(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 = 5;
fireDelay = 0.5;
launchDelay = 0.5;
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:
numOfEnemies = 10;
fireDelay = 0.3;
launchDelay = 1;
numOfHits = 3;
wc = engine.getWaveConfigs().getWaveConfig(2);
break;
case 3:
numOfEnemies = 15;
fireDelay = 0.2;
launchDelay = 1;
numOfHits = 5;
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

@ -1,17 +1,19 @@
package com.sagi.dayan.Games.Stage; package com.sagi.dayan.Games.Stage;
import com.sagi.dayan.Games.Engine.GameEngine; import java.awt.Graphics;
import com.sagi.dayan.Games.Utils.Utils; import java.awt.Image;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import com.sagi.dayan.Games.Engine.GameEngine;
import com.sagi.dayan.Games.Utils.Utils;
//import sun.audio.AudioPlayer;
//import sun.audio.AudioStream;
/** /**
* Created by sagi on 2/27/16. * Created by sagi on 2/27/16.
*/ */
@ -51,7 +53,7 @@ public class SettingsMenuScene extends Scene {
switch (keyEvent.getKeyCode()){ switch (keyEvent.getKeyCode()){
case KeyEvent.VK_ESCAPE: case KeyEvent.VK_ESCAPE:
Utils.playSound("menuItem.wav"); Utils.playSound("menuItem.wav");
engine.goToMainMenu(); engine.goToMenu();
break; break;
} }
} }

View file

@ -1,13 +1,12 @@
package com.sagi.dayan.Games.Stage; package com.sagi.dayan.Games.Stage;
import com.sagi.dayan.Games.Engine.GameEngine; import java.awt.Graphics;
import com.sagi.dayan.Games.Utils.Utils;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferStrategy;
import java.util.Vector; import java.util.Vector;
import javax.swing.JPanel;
import com.sagi.dayan.Games.Engine.GameEngine;
/** /**
* Created by sagi on 2/8/16. * Created by sagi on 2/8/16.
*/ */
@ -92,9 +91,9 @@ public class Stage extends JPanel implements Runnable{
if (System.currentTimeMillis() - lastTimer > 1000) { if (System.currentTimeMillis() - lastTimer > 1000) {
lastTimer += 1000; lastTimer += 1000;
if(frames <= 35){ if(frames <= 35){
System.err.println("Ticks: " + ticks + "\tFps: " + frames + "\tScenes Size: " + engine.getScenesSize()); System.err.println("Ticks: " + ticks + "\tFps: " + frames);
}else{ }else{
System.out.println("Ticks: " + ticks + "\tFps: " + frames + "\tScenes Size: " + engine.getScenesSize()); System.out.println("Ticks: " + ticks + "\tFps: " + frames);
} }
frames = 0; frames = 0;
ticks = 0; ticks = 0;

View file

@ -0,0 +1,63 @@
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 ThirdStage extends Level{
protected final int NUM_OF_WAVES = 4;
public ThirdStage(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 = 5;
fireDelay = 0.5;
launchDelay = 0.5;
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:
numOfEnemies = 10;
fireDelay = 0.3;
launchDelay = 1;
numOfHits = 3;
wc = engine.getWaveConfigs().getWaveConfig(2);
break;
case 3:
numOfEnemies = 15;
fireDelay = 0.2;
launchDelay = 1;
numOfHits = 5;
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

@ -1,12 +1,12 @@
package com.sagi.dayan.Games.Utils; package com.sagi.dayan.Games.Utils;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
/** /**
* Created by sagi on 2/24/16. * Created by sagi on 2/24/16.
*/ */

View file

@ -26,17 +26,17 @@ public class WaveConfigs {
//top right to middle top //top right to middle top
configs.add(new WaveConfig(new int[]{90,90,120, 120, 150, 150, 270} , 0.5, 8,900 , -30)); configs.add(new WaveConfig(new int[]{90,90,120, 120, 150, 150, 270} , 0.5, 8,900 , -30));
//right buttom to middle buttom //right buttom to middle bottom
configs.add(new WaveConfig(new int[]{270,270,300, 300, 330, 330, 90} , 0.5, 8,100 , 0)); configs.add(new WaveConfig(new int[]{270,270,300, 300, 330, 330, 90} , 0.5, 8,100 , 1000));
//left buttom to middle buttom //left buttom to middle bottom
configs.add(new WaveConfig(new int[]{270,270,240, 240, 210, 210, 90} , 0.5, 8,900 , 0)); configs.add(new WaveConfig(new int[]{270,270,240, 240, 210, 210, 90} , 0.5, 8,900 , 1000));
//middle right to middle right //middle right to middle right
configs.add(new WaveConfig(new int[]{180,180,180,90, 90, 0} , 0.5, 8,1010 , 400)); configs.add(new WaveConfig(new int[]{180,180,180,180,180,90, 90, 0} , 0.5, 8,999 , 400));
//middle left to middle left //middle left to middle left
configs.add(new WaveConfig(new int[]{0,0,0,90, 90, 180} , 0.5, 8,-30 , 400)); configs.add(new WaveConfig(new int[]{0,0,0,0,0,90, 90, 180} , 0.5, 8,-10 , 400));
} }