Updated USE_CREDIT

This commit is contained in:
Sagi Dayan 2016-03-20 14:57:34 +02:00
parent 60d30f2ed2
commit d49a78e71a
2 changed files with 18 additions and 14 deletions

View file

@ -34,11 +34,11 @@ public class GameEngine {
private Scene scene; private Scene scene;
private int p1CreditTime, p2CreditTime, creditTickTime = 1; 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; 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_Q}; 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;

View file

@ -170,8 +170,8 @@ public abstract class Level extends Scene {
System.out.println("Done"); System.out.println("Done");
engine.changeLevel(); engine.changeLevel();
} }
for(int i =0; i<blasts.size();i++){ for(int i =0; i<blasts.size();i++){
if (blasts.get(i).isDone()){ if (blasts.get(i).isDone()){
System.out.println("removing blast"); System.out.println("removing blast");
@ -217,11 +217,13 @@ 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() && !players.get(0).isGameOver()){ 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)); 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(engine.getP1Health() <= 0 && engine.getCredits() > 0) { }
if(keys.get(engine.getP1Controlles()[GameEngine.USE_CREDIT]) && engine.getP1Health() <= 0 ){
if(engine.getCredits() > 0) {
engine.revivePlayer(0); engine.revivePlayer(0);
players.get(0).resetPlayer(); players.get(0).resetPlayer();
@ -255,9 +257,11 @@ public abstract class Level extends Scene {
p2Missiles.add(new Missile(players.get(1).getCenterX() - 15, (int)players.get(1).getLocY(),getStageWidth(),getStageHeight(),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(engine.getP2Health() <= 0 && engine.getCredits() > 0) { }
if(keys.get(engine.getP2Controlles()[GameEngine.USE_CREDIT]) && engine.getP2Health() <= 0 ){
if(engine.getCredits() > 0) {
engine.revivePlayer(1); engine.revivePlayer(1);
players.get(0).resetPlayer(); players.get(1).resetPlayer();
} }
} }
@ -296,7 +300,7 @@ public abstract class Level extends Scene {
if (isGameOver()) if (isGameOver())
{ {
try { try {
System.in.read(); System.in.read();
} catch (IOException e) { } catch (IOException e) {
@ -372,7 +376,7 @@ 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).render(g,p); waves.get(i).render(g,p);
} }
for(int i =0; i<blasts.size();i++){ for(int i =0; i<blasts.size();i++){
blasts.get(i).drawSprite(g, p); blasts.get(i).drawSprite(g, p);
} }
@ -454,7 +458,7 @@ public abstract class Level extends Scene {
eMTR.add(enemyMissiles.get(j)); eMTR.add(enemyMissiles.get(j));
}else{ }else{
blasts.add(new Blast((int)players.get(i).getLocX(),(int)players.get(i).getLocY(),"explosion.png",15)); blasts.add(new Blast((int)players.get(i).getLocX(),(int)players.get(i).getLocY(),"explosion.png",15));
} }
} }
} }
@ -471,7 +475,7 @@ public abstract class Level extends Scene {
waves.get(j).enemyHit(waves.get(j).getEnemies().get(k)); waves.get(j).enemyHit(waves.get(j).getEnemies().get(k));
}else{ }else{
blasts.add(new Blast((int)players.get(i).getLocX(),(int)players.get(i).getLocY(),"explosion.png",15)); blasts.add(new Blast((int)players.get(i).getLocX(),(int)players.get(i).getLocY(),"explosion.png",15));
} }
} }
} }