From 48d5716b55b03f3826e028a703cc4afa88f892ee Mon Sep 17 00:00:00 2001 From: Pan Date: Sat, 30 Mar 2019 10:43:38 +1300 Subject: [PATCH] home commit --- core/AssetManager.java | 70 +++++++++++++++++++- core/grid.java | 15 ++++- core/mainThread.java | 24 ++++++- core/postProcessingThread.java | 9 ++- enemyAI/enemyCommander.java | 2 + entity/palmTree.java | 2 +- gui/SideBar.java | 13 ++-- gui/button.java | 14 ++++ gui/gameMenu.java | 117 +++++++++++++++++++++++++++++---- gui/inputHandler.java | 28 +++++++- gui/textRenderer.java | 84 +++++++++++++++++++++-- images/menuFont.png | Bin 0 -> 13217 bytes 12 files changed, 347 insertions(+), 31 deletions(-) create mode 100644 images/menuFont.png diff --git a/core/AssetManager.java b/core/AssetManager.java index 9b9f6d4..037e2e4 100644 --- a/core/AssetManager.java +++ b/core/AssetManager.java @@ -135,6 +135,11 @@ public class AssetManager { } public void prepareAssetForNewGame(){ + + camera.position.set(3,2f,-1.25f); + camera.view_Direction.set(0, 0, 1); + camera.XZ_angle = 0; + selectedUnitsInfo = new int[100][6]; selectedUnitsInfo2 = new int[100][6]; @@ -247,11 +252,70 @@ public class AssetManager { } } - - - } + public void destoryAsset() { + camera.view_Direction.set(0, 0, 1); + camera.frameIndex = 0; + camera.XZ_angle = 0; + + selectedUnitsInfo = null; + selectedUnitsInfo2 = null; + + visionPolygonInfo = null; + visionPolygonInfo2 = null; + + unitsForMiniMap = null; + unitsForMiniMap2 = null; + + + smokeEmmiterList = null; + smokeEmmiterList2 = null; + + minimapBitmap = null; + minimapBitmap2 = null; + + + explosionInfo = null; + explosionInfo2 = null; + helixInfo = null; + helixInfo2 = null; + + confirmationIconInfo = null; + confirmationIconInfo2 = null; + + lightTanks = null; + heavyTanks = null; + powerPlants = null; + refineries = null; + rocketTanks = null; + harvesters = null; + constructionVehicles = null; + constructionYards = null; + factories = null; + drones = null; + communicationCenters = null; + techCenters = null; + stealthTanks = null; + gunTurrets = null; + missileTurrets = null; + + goldMines[0].goldDeposite = 45000; + goldMines[1].goldDeposite = 45000; + goldMines[2].goldDeposite = 50000; + goldMines[3].goldDeposite = 50000; + goldMines[4].goldDeposite = 45000; + goldMines[5].goldDeposite = 45000; + goldMines[6].goldDeposite = 55000; + goldMines[7].goldDeposite = 55000; + + bullets = null; + rockets = null; + + mainThread.gridMap.reset(); + } + + public void addContructionYard(constructionYard o){ for(int i = 0; i < constructionYards.length; i++){ if(constructionYards[i] == null){ diff --git a/core/grid.java b/core/grid.java index 91b7a68..5c3c72b 100644 --- a/core/grid.java +++ b/core/grid.java @@ -19,7 +19,6 @@ public class grid { previousObstacleMap[i] = true; currentObstacleMap[i] = true; } - } public void update(){ @@ -37,7 +36,21 @@ public class grid { } } + public void reset() { + for(int i = 0; i < size * size; i++){ + previousObstacleMap[i] = true; + currentObstacleMap[i] = true; + + for(int j = 0; j < 5; j++) { + if(tiles[i][j] != null && tiles[i][j].teamNo != -1) + tiles[i][j] = null; + } + } + + + + } public void draw(){ diff --git a/core/mainThread.java b/core/mainThread.java index c249a8c..490175a 100644 --- a/core/mainThread.java +++ b/core/mainThread.java @@ -50,8 +50,15 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M public static short[] displacementBuffer; public static short[] displacementBuffer2; - public static boolean leftMouseButtonReleased; + public static boolean leftMouseButtonReleased, escapeKeyReleased; public static String buttonAction; + public static int menuStatus = 0; + public static final int mainMenu = 0; + public static final int difficulitySelectionMenu = 1; + public static final int helpMenu = 2; + public static final int endGameMenu = 3; + + public static String timeString; public mainThread(){ setTitle("Battle Tank 3"); @@ -168,7 +175,6 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M frameIndex++; - inputHandler.processInput(); @@ -176,6 +182,8 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M if(gameStarted) gameFrame++; + timeString = secondsToString(gameFrame/30); + //handle user's interaction with game GUI if(gameFrame == 1 && gameStarted){ theAssetManager.prepareAssetForNewGame(); @@ -511,7 +519,19 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M } lastDraw=System.currentTimeMillis(); } + + public static String secondsToString(int pTime) { + int min = pTime/60; + int sec = pTime-(min*60); + String strMin = placeZeroIfNeede(min); + String strSec = placeZeroIfNeede(sec); + return String.format("%s:%s",strMin,strSec); + } + + public static String placeZeroIfNeede(int number) { + return (number >=10)? Integer.toString(number):String.format("0%s",Integer.toString(number)); + } @Override public void focusGained(FocusEvent arg0) { diff --git a/core/postProcessingThread.java b/core/postProcessingThread.java index bdedcdd..8eed649 100644 --- a/core/postProcessingThread.java +++ b/core/postProcessingThread.java @@ -78,9 +78,11 @@ public class postProcessingThread implements Runnable{ public static boolean gamePaused, gameStarted, gameEnded; public static int mouse_x, mouse_y; - public static boolean leftMouseButtonReleased; + public static boolean leftMouseButtonReleased, escapeKeyReleased; public static String buttonAction; + public static String timeString; + //A pool of vectors which will be used for vector arithmetic public static vector @@ -952,6 +954,8 @@ public class postProcessingThread implements Runnable{ gameStarted = mainThread.gameStarted; gameEnded = mainThread.gameEnded; + timeString = mainThread.timeString; + currentScreen = mainThread.screen; currentZbuffer = mainThread.zBuffer; displacementBuffer = mainThread.displacementBuffer; @@ -987,11 +991,14 @@ public class postProcessingThread implements Runnable{ mouse_x = inputHandler.mouse_x; mouse_y = inputHandler.mouse_y; leftMouseButtonReleased = mainThread.leftMouseButtonReleased; + escapeKeyReleased = mainThread.escapeKeyReleased; mainThread.leftMouseButtonReleased = false; + mainThread.escapeKeyReleased = false; //feed main thread with button action mainThread.buttonAction = buttonAction; buttonAction = null; + mainThread.menuStatus = gameMenu.menuStatus; } diff --git a/enemyAI/enemyCommander.java b/enemyAI/enemyCommander.java index 66a7735..56de5da 100644 --- a/enemyAI/enemyCommander.java +++ b/enemyAI/enemyCommander.java @@ -21,6 +21,8 @@ public class enemyCommander { public defenseManagerAI theDefenseManagerAI; public combatManagerAI theCombatManagerAI; public microManagementAI theMicroManagementAI; + public int difficulty; + public void init(){ diff --git a/entity/palmTree.java b/entity/palmTree.java index c8b6a12..28b8260 100644 --- a/entity/palmTree.java +++ b/entity/palmTree.java @@ -34,7 +34,7 @@ public class palmTree extends solidObject{ public palmTree(float x, float y, float z){ //uncontrollable unit, but act as a small sized static collidable agent ID = -1; - + teamNo = -1; type = 100; diff --git a/gui/SideBar.java b/gui/SideBar.java index ad0c7d9..c18e864 100644 --- a/gui/SideBar.java +++ b/gui/SideBar.java @@ -51,8 +51,8 @@ public class SideBar { } - iconImages = new int[24][44 * 44]; - iconImages_dark = new int[24][44 * 44]; + iconImages = new int[25][44 * 44]; + iconImages_dark = new int[25][44 * 44]; String folder = "../images/"; loadTexture(folder + "44.jpg", iconImages[0], 44, 44, iconImages_dark[0]); loadTexture(folder + "47.jpg", iconImages[1], 44, 44, iconImages_dark[1]); @@ -78,6 +78,7 @@ public class SideBar { loadTexture(folder + "87.jpg", iconImages[21], 44, 44, iconImages_dark[21]); loadTexture(folder + "88.jpg", iconImages[22], 44, 44, iconImages_dark[22]); loadTexture(folder + "89.jpg", iconImages[23], 44, 44, iconImages_dark[23]); + loadTexture(folder + "time.png", iconImages[24], 16, 16, iconImages_dark[24]); } @@ -88,14 +89,18 @@ public class SideBar { drawSideBarInfo(screen, sideBarInfo); - drawCreditAndPowerLevel(screen, postProcessingThread.playerMoney, postProcessingThread.playerPowerStatus); + drawCreditAndPowerLevelAndTime(screen, postProcessingThread.playerMoney, postProcessingThread.playerPowerStatus); drawFrame(screen); } - public void drawCreditAndPowerLevel(int[] screen, int playerMoney, int playerPowerStatus){ + public void drawCreditAndPowerLevelAndTime(int[] screen, int playerMoney, int playerPowerStatus){ + drawInfoBackGround(screen, 2, 3, 65, 16, 100); + drawIcon(screen, 5 + 2 * 768, 24); + postProcessingThread.theTextRenderer.drawText(23, 3, postProcessingThread.timeString, screen, 255,255,255); + drawInfoBackGround(screen, 637, 3, 129, 16, 100); int startIndex = 639 + 3 * 768; diff --git a/gui/button.java b/gui/button.java index 545c34a..10edc57 100644 --- a/gui/button.java +++ b/gui/button.java @@ -1,9 +1,12 @@ package gui; +import core.postProcessingThread; + public class button { public int xPos, yPos, width, height; public String name, text; + public char[] theText; public boolean display, cursorIsOnTop; public int actionCooldown; @@ -14,6 +17,7 @@ public class button { this.yPos = yPos; this.width = width; this.height = height; + theText = text.toCharArray(); } public boolean checkIfCursorIsOnTop(int mouse_x, int mouse_y) { @@ -170,6 +174,16 @@ public class button { } + //draw text + textRenderer tRenderer = postProcessingThread.theTextRenderer; + if(text != "x") + tRenderer.drawMenuText(xPos+ (width-tRenderer.getMenuTextWidth(theText))/2,yPos+6,theText, screen, 255,255,255); + else{ + tRenderer.drawMenuText(xPos+ (width-tRenderer.getMenuTextWidth(theText))/2-1,yPos,theText, screen, 255,255,255); + } + + + cursorIsOnTop = false; } diff --git a/gui/gameMenu.java b/gui/gameMenu.java index af05639..3d3eb05 100644 --- a/gui/gameMenu.java +++ b/gui/gameMenu.java @@ -1,18 +1,16 @@ package gui; -import java.util.ArrayList; +import java.util.ArrayList; import java.awt.Image; import java.awt.image.PixelGrabber; - import javax.imageio.ImageIO; - import core.*; public class gameMenu { public int gameSuspendCount; - public int menuStatus = 0; + public static int menuStatus = 0; public static final int mainMenu = 0; public static final int difficulitySelectionMenu = 1; public static final int helpMenu = 2; @@ -25,9 +23,13 @@ public class gameMenu { public int[] titleImage; - public button newGame, unpauseGame, showHelp, quitGame, restartGame; + public button newGame, unpauseGame, showHelp, quitGame, abortGame, easyGame, normalGame, hardGame, quitDifficulty, quitHelpMenu, nextPage, previousPage; - ArrayList