This commit is contained in:
Pan 2019-05-22 08:22:19 +12:00
parent 6cc8612441
commit 48ff37eed2
4 changed files with 80 additions and 25 deletions

View File

@ -245,13 +245,13 @@ public class AssetManager {
//harvester l = new harvester(new vector(i*0.25f+ 1.125f,-0.3f, 17.375f - 0.25f*j), 90, 0); //harvester l = new harvester(new vector(i*0.25f+ 1.125f,-0.3f, 17.375f - 0.25f*j), 90, 0);
//addHarvester(l); //addHarvester(l);
//l.hasMultiShotUpgrade = true; //l.hasMultiShotUpgrade = true;
//lightTank l = new lightTank(new vector(i*0.25f + 1.125f,-0.3f, 0.5f + 18.625f + j*0.25f), 90, 0); lightTank l = new lightTank(new vector(i*0.25f + 1.125f,-0.3f, 0.5f + 18.625f + j*0.25f), 90, 0);
//l.attackRange = 1.99f; //l.attackRange = 1.99f;
//lightTank.tileCheckList_player = lightTank.generateTileCheckList(6); //lightTank.tileCheckList_player = lightTank.generateTileCheckList(6);
//addLightTank(l); addLightTank(l);
//if(j == 0 && i == 0) //if(j == 0 && i == 0)
//addMissileTurret(new missileTurret(i*0.25f -0.125f + 1, -0.65f, 0.25f + 17.125f + j*0.25f, 0)); //addMissileTurret(new missileTurret(i*0.25f -0.125f + 1, -0.65f, 0.25f + 17.125f + j*0.25f, 0));
@ -565,6 +565,8 @@ public class AssetManager {
Terrain.update(); Terrain.update();
int numberOfPlayerBuildings = 0;
int numberOfAIBuildings = 0;
//start drawing //start drawing
//maximize the zbuffer value in the area that are occupied by UI, so the drawing process will not waste time filling the pixels which would eventually get overdrawn //maximize the zbuffer value in the area that are occupied by UI, so the drawing process will not waste time filling the pixels which would eventually get overdrawn
if(mainThread.gameStarted) { if(mainThread.gameStarted) {
@ -577,10 +579,6 @@ public class AssetManager {
} }
} }
for(int i = 0; i < 200; i ++) for(int i = 0; i < 200; i ++)
bullets[i].updateAndDraw(); bullets[i].updateAndDraw();
@ -604,33 +602,63 @@ public class AssetManager {
} }
for(int i = 0; i < powerPlants.length; i++){ for(int i = 0; i < powerPlants.length; i++){
if(powerPlants[i] != null) if(powerPlants[i] != null) {
powerPlants[i].draw(); powerPlants[i].draw();
if(powerPlants[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
} }
for(int i = 0; i < gunTurrets.length; i++){ for(int i = 0; i < gunTurrets.length; i++){
if(gunTurrets[i] != null) if(gunTurrets[i] != null) {
gunTurrets[i].draw(); gunTurrets[i].draw();
if(gunTurrets[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
} }
for(int i = 0; i < missileTurrets.length; i++){ for(int i = 0; i < missileTurrets.length; i++){
if(missileTurrets[i] != null) if(missileTurrets[i] != null) {
missileTurrets[i].draw(); missileTurrets[i].draw();
if(missileTurrets[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
} }
for(int i = 0; i < communicationCenters.length; i++){ for(int i = 0; i < communicationCenters.length; i++){
if(communicationCenters[i] != null) if(communicationCenters[i] != null) {
communicationCenters[i].draw(); communicationCenters[i].draw();
if(communicationCenters[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
} }
for(int i = 0; i < techCenters.length; i++){ for(int i = 0; i < techCenters.length; i++){
if(techCenters[i] != null) if(techCenters[i] != null) {
techCenters[i].draw(); techCenters[i].draw();
if(techCenters[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
} }
for(int i = 0; i < refineries.length; i++){ for(int i = 0; i < refineries.length; i++){
if(refineries[i] != null) if(refineries[i] != null) {
refineries[i].draw(); refineries[i].draw();
if(refineries[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
} }
for(int i = 0; i < rocketTanks.length; i++){ for(int i = 0; i < rocketTanks.length; i++){
@ -644,13 +672,23 @@ public class AssetManager {
} }
for(int i = 0; i < constructionVehicles.length; i++){ for(int i = 0; i < constructionVehicles.length; i++){
if(constructionVehicles[i] != null) if(constructionVehicles[i] != null) {
constructionVehicles[i].draw(); constructionVehicles[i].draw();
if(constructionVehicles[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
} }
for(int i = 0; i < constructionYards.length; i++){ for(int i = 0; i < constructionYards.length; i++){
if(constructionYards[i] != null) if(constructionYards[i] != null) {
constructionYards[i].draw(); constructionYards[i].draw();
if(constructionYards[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
} }
for(int i = 0; i < 200; i ++) for(int i = 0; i < 200; i ++)
@ -708,6 +746,18 @@ public class AssetManager {
selectedUnitsInfo[i][0] = -1; selectedUnitsInfo[i][0] = -1;
} }
} }
//check end game condition
//game ends when either player or the AI have lost all the buildings and construction vehicles
if(!mainThread.playerVictory && !mainThread.AIVictory && !mainThread.afterMatch) {
if(numberOfAIBuildings == 0) {
mainThread.playerVictory = true;
mainThread.gamePaused = true;
}else if(numberOfPlayerBuildings == 0) {
mainThread.AIVictory = true;
mainThread.gamePaused = true;
}
}
} }
} }

View File

@ -32,7 +32,7 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
public static int framePerSecond, cpuUsage; public static int framePerSecond, cpuUsage;
public static double thisTime, lastTime; public static double thisTime, lastTime;
public static boolean JavaRTSLoaded; public static boolean JavaRTSLoaded;
public static boolean gamePaused, gameStarted, gameEnded; public static boolean gamePaused, gameStarted, playerVictory, AIVictory, afterMatch;
public static texture[] textures; public static texture[] textures;
public static byte[][] lightMapTextures; public static byte[][] lightMapTextures;
public static int[][] lightMapTexturesInfo; public static int[][] lightMapTexturesInfo;

View File

@ -75,7 +75,7 @@ public class postProcessingThread implements Runnable{
public static textRenderer theTextRenderer; public static textRenderer theTextRenderer;
public static boolean gamePaused, gameStarted, gameEnded; public static boolean gamePaused, gameStarted, playerVictory, AIVictory;
public static int mouse_x, mouse_y; public static int mouse_x, mouse_y;
public static boolean leftMouseButtonReleased, escapeKeyPressed; public static boolean leftMouseButtonReleased, escapeKeyPressed;
@ -219,7 +219,7 @@ public class postProcessingThread implements Runnable{
if(!gamePaused) if(!gamePaused)
doPostProcesssing(); doPostProcesssing();
theGameMenu.updateAndDraw(currentScreen, gameStarted, gamePaused, gameEnded); theGameMenu.updateAndDraw(currentScreen, gameStarted, gamePaused, playerVictory, AIVictory);
frameIndex++; frameIndex++;
@ -963,7 +963,8 @@ public class postProcessingThread implements Runnable{
gamePaused = mainThread.gamePaused; gamePaused = mainThread.gamePaused;
gameStarted = mainThread.gameStarted; gameStarted = mainThread.gameStarted;
gameEnded = mainThread.gameEnded; playerVictory = mainThread.playerVictory;
AIVictory = mainThread.AIVictory;
timeString = mainThread.timeString; timeString = mainThread.timeString;
fogOfWarDisabled = mainThread.fogOfWarDisabled; fogOfWarDisabled = mainThread.fogOfWarDisabled;

View File

@ -18,7 +18,6 @@ public class gameMenu {
public static final int optionMenu = 4; public static final int optionMenu = 4;
public int[] screen; public int[] screen;
public int[] screenBlurBuffer; public int[] screenBlurBuffer;
public boolean gameStarted, gamePaused, gameEnded;
public String imageFolder = ""; public String imageFolder = "";
@ -158,11 +157,9 @@ public class gameMenu {
} }
public void updateAndDraw(int[] screen, boolean gameStarted, boolean gamePaused, boolean gameEnded) { public void updateAndDraw(int[] screen, boolean gameStarted, boolean gamePaused, boolean playerVictory, boolean AIVictory) {
this.screen = screen; this.screen = screen;
this.gameStarted = gameStarted;
this.gamePaused = gamePaused;
this.gameEnded = gameEnded;
if(gamePaused){ if(gamePaused){
gameSuspendCount++; gameSuspendCount++;
@ -176,8 +173,15 @@ public class gameMenu {
} }
//only show game menu when the game is not started or game is paused or game has ended if(playerVictory || AIVictory) {
if(!(!gameStarted || gamePaused || gameEnded)) if(gameSuspendCount > 0) {
drawBluredBackground();
}
return;
}
//only show game menu when the game is not started or game is paused
if(!(!gameStarted || gamePaused))
return; return;
//make all buttons off screen and reduce their action cooldown //make all buttons off screen and reduce their action cooldown