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);
//addHarvester(l);
//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;
//lightTank.tileCheckList_player = lightTank.generateTileCheckList(6);
//addLightTank(l);
addLightTank(l);
//if(j == 0 && i == 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();
int numberOfPlayerBuildings = 0;
int numberOfAIBuildings = 0;
//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
if(mainThread.gameStarted) {
@ -577,10 +579,6 @@ public class AssetManager {
}
}
for(int i = 0; i < 200; i ++)
bullets[i].updateAndDraw();
@ -604,33 +602,63 @@ public class AssetManager {
}
for(int i = 0; i < powerPlants.length; i++){
if(powerPlants[i] != null)
if(powerPlants[i] != null) {
powerPlants[i].draw();
if(powerPlants[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
}
for(int i = 0; i < gunTurrets.length; i++){
if(gunTurrets[i] != null)
if(gunTurrets[i] != null) {
gunTurrets[i].draw();
if(gunTurrets[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
}
for(int i = 0; i < missileTurrets.length; i++){
if(missileTurrets[i] != null)
if(missileTurrets[i] != null) {
missileTurrets[i].draw();
if(missileTurrets[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
}
for(int i = 0; i < communicationCenters.length; i++){
if(communicationCenters[i] != null)
if(communicationCenters[i] != null) {
communicationCenters[i].draw();
if(communicationCenters[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
}
for(int i = 0; i < techCenters.length; i++){
if(techCenters[i] != null)
if(techCenters[i] != null) {
techCenters[i].draw();
if(techCenters[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
}
for(int i = 0; i < refineries.length; i++){
if(refineries[i] != null)
if(refineries[i] != null) {
refineries[i].draw();
if(refineries[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
}
for(int i = 0; i < rocketTanks.length; i++){
@ -644,13 +672,23 @@ public class AssetManager {
}
for(int i = 0; i < constructionVehicles.length; i++){
if(constructionVehicles[i] != null)
if(constructionVehicles[i] != null) {
constructionVehicles[i].draw();
if(constructionVehicles[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
}
for(int i = 0; i < constructionYards.length; i++){
if(constructionYards[i] != null)
if(constructionYards[i] != null) {
constructionYards[i].draw();
if(constructionYards[i].teamNo == 0)
numberOfPlayerBuildings++;
else
numberOfAIBuildings++;
}
}
for(int i = 0; i < 200; i ++)
@ -708,6 +746,18 @@ public class AssetManager {
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 double thisTime, lastTime;
public static boolean JavaRTSLoaded;
public static boolean gamePaused, gameStarted, gameEnded;
public static boolean gamePaused, gameStarted, playerVictory, AIVictory, afterMatch;
public static texture[] textures;
public static byte[][] lightMapTextures;
public static int[][] lightMapTexturesInfo;

View File

@ -75,7 +75,7 @@ public class postProcessingThread implements Runnable{
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 boolean leftMouseButtonReleased, escapeKeyPressed;
@ -219,7 +219,7 @@ public class postProcessingThread implements Runnable{
if(!gamePaused)
doPostProcesssing();
theGameMenu.updateAndDraw(currentScreen, gameStarted, gamePaused, gameEnded);
theGameMenu.updateAndDraw(currentScreen, gameStarted, gamePaused, playerVictory, AIVictory);
frameIndex++;
@ -963,7 +963,8 @@ public class postProcessingThread implements Runnable{
gamePaused = mainThread.gamePaused;
gameStarted = mainThread.gameStarted;
gameEnded = mainThread.gameEnded;
playerVictory = mainThread.playerVictory;
AIVictory = mainThread.AIVictory;
timeString = mainThread.timeString;
fogOfWarDisabled = mainThread.fogOfWarDisabled;

View File

@ -18,7 +18,6 @@ public class gameMenu {
public static final int optionMenu = 4;
public int[] screen;
public int[] screenBlurBuffer;
public boolean gameStarted, gamePaused, gameEnded;
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.gameStarted = gameStarted;
this.gamePaused = gamePaused;
this.gameEnded = gameEnded;
if(gamePaused){
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(!(!gameStarted || gamePaused || gameEnded))
if(playerVictory || AIVictory) {
if(gameSuspendCount > 0) {
drawBluredBackground();
}
return;
}
//only show game menu when the game is not started or game is paused
if(!(!gameStarted || gamePaused))
return;
//make all buttons off screen and reduce their action cooldown