From 48ff37eed2b63f1755601fcc56626e48c3d8c256 Mon Sep 17 00:00:00 2001 From: Pan Date: Wed, 22 May 2019 08:22:19 +1200 Subject: [PATCH] h --- core/AssetManager.java | 78 ++++++++++++++++++++++++++++------ core/mainThread.java | 2 +- core/postProcessingThread.java | 7 +-- gui/gameMenu.java | 18 +++++--- 4 files changed, 80 insertions(+), 25 deletions(-) diff --git a/core/AssetManager.java b/core/AssetManager.java index 2ccf696..af49e6b 100644 --- a/core/AssetManager.java +++ b/core/AssetManager.java @@ -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; + } + } } } diff --git a/core/mainThread.java b/core/mainThread.java index 9f30642..1df08ed 100644 --- a/core/mainThread.java +++ b/core/mainThread.java @@ -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; diff --git a/core/postProcessingThread.java b/core/postProcessingThread.java index 84a39a9..db52ab4 100644 --- a/core/postProcessingThread.java +++ b/core/postProcessingThread.java @@ -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; diff --git a/gui/gameMenu.java b/gui/gameMenu.java index fb4e472..13908fd 100644 --- a/gui/gameMenu.java +++ b/gui/gameMenu.java @@ -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