From af1fe0338aaaed5529034943f4bf9245cc045c8a Mon Sep 17 00:00:00 2001 From: Pan Date: Tue, 19 Mar 2019 13:53:00 +1300 Subject: [PATCH] Home commit before adding game menu --- core/AssetManager.java | 4 +-- core/mainThread.java | 54 ++++++++++++++++++---------------- core/postProcessingThread.java | 7 ++++- enemyAI/combatManagerAI.java | 19 ++++++++++-- enemyAI/unitProductionAI.java | 24 +++++++-------- gui/inputHandler.java | 40 +++++++++++++++++++++++-- 6 files changed, 103 insertions(+), 45 deletions(-) diff --git a/core/AssetManager.java b/core/AssetManager.java index 652fa07..c0098f0 100644 --- a/core/AssetManager.java +++ b/core/AssetManager.java @@ -508,14 +508,14 @@ public class AssetManager { //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 - int start = 381 * 768 + 3; + /*int start = 381 * 768 + 3; int start2 = 381 * 768 + 635; for(int y = 0; y < 131; y++){ for(int x = 0; x < 128; x ++){ mainThread.zBuffer[start + x + y*768] = Integer.MAX_VALUE; mainThread.zBuffer[start2 + x + y*768] = Integer.MAX_VALUE; } - } + }*/ diff --git a/core/mainThread.java b/core/mainThread.java index fb013d0..a64382a 100644 --- a/core/mainThread.java +++ b/core/mainThread.java @@ -30,7 +30,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 inGame; + public static boolean gamePaused, gameStarted; public static texture[] textures; public static byte[][] lightMapTextures; public static int[][] lightMapTexturesInfo; @@ -134,7 +134,7 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M JavaRTSLoaded = true; //test only - inGame = true; + gamePaused = false; } @@ -184,27 +184,28 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M theAssetManager.prepareAssetForNewGame(); } - gridMap.update(); - - - - //Clears the z-buffer. All depth values are set to 0. - clearDepthBuffer(); - - //update camera - Camera.update(); - - //update light source - sunLight.update(); - - //update and draw 3D mashes from game objects - theAssetManager.updateAndDraw(); - - pc.update(); - ec.update(); - + if(!gamePaused) { + + gridMap.update(); + + //Clears the z-buffer. All depth values are set to 0. + clearDepthBuffer(); + + //update camera + Camera.update(); + + //update light source + sunLight.update(); + + //update and draw 3D mashes from game objects + theAssetManager.updateAndDraw(); + + pc.update(); + ec.update(); + } + //show inpassible obstacle //gridMap.draw(); if(this.getGraphics() != null && PPT!= null){ @@ -268,7 +269,9 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M inputHandler.rightKeyPressed = true; else if(e.getKeyCode() == KeyEvent.VK_CONTROL) inputHandler.controlKeyPressed = true; - + else if(e.getKeyCode() == KeyEvent.VK_ESCAPE) + inputHandler.escapeKeyPressed = true; + inputHandler.readCharacter(e.getKeyChar()); } @@ -280,6 +283,8 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M inputHandler.rightKeyPressed = false; else if(e.getKeyCode() == KeyEvent.VK_CONTROL) inputHandler.controlKeyPressed = false; + else if(e.getKeyCode() == KeyEvent.VK_ESCAPE) + inputHandler.escapeKeyReleased = true; inputHandler.handleKeyRelease(e.getKeyChar()); } @@ -292,7 +297,6 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M } - public void mouseDragged(MouseEvent e) { inputHandler.mouse_x = e.getX(); inputHandler.mouse_y = e.getY(); @@ -495,7 +499,7 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M sleepTime = 0; - /*while(System.currentTimeMillis()-lastDraw 0) { + if(mainThread.ec.theMapAwarenessAI.playerStaticDefenseStrength[i] > 6) { + float xPos = mainThread.ec.theMapAwarenessAI.playerStaticDefenseLocations[i].x; + float zPos = mainThread.ec.theMapAwarenessAI.playerStaticDefenseLocations[i].z; + float d = (xPos - attackPosition.x)*(xPos - attackPosition.x) + (zPos - attackPosition.z)*(zPos - attackPosition.z); + if(d < 16) { + staticDefenseNearAttackPosition = true; + break; + } + } + } + } //send units to attack-move to target position @@ -569,7 +584,7 @@ public class combatManagerAI { double d = Math.sqrt((team[i].centre.x - combatCenterX)*(team[i].centre.x - combatCenterX) + (team[i].centre.z - combatCenterZ)*(team[i].centre.z - combatCenterZ))*3; if(d > teamRadius){ - if(!playerForceIsMuchWeakerThanAI || mainThread.ec.theMapAwarenessAI.playerAssetDestoryedCountDown == 0) + if(staticDefenseNearAttackPosition || !playerForceIsMuchWeakerThanAI || mainThread.ec.theMapAwarenessAI.playerAssetDestoryedCountDown == 0) team[i].attackMoveTo(gatherPoint.x, gatherPoint.z); else team[i].attackMoveTo(team[i].centre.x + attackDirection.x*teamRadius, team[i].centre.z + attackDirection.z*teamRadius); diff --git a/enemyAI/unitProductionAI.java b/enemyAI/unitProductionAI.java index 6bb08be..6e9a339 100644 --- a/enemyAI/unitProductionAI.java +++ b/enemyAI/unitProductionAI.java @@ -172,6 +172,7 @@ public class unitProductionAI { } + //make decision on what tech to research if(mainThread.ec.theBuildingManagerAI.theBaseInfo.numberOfCommunicationCenter > 0) { if(mainThread.ec.theDefenseManagerAI.needMissileTurret || theBaseInfo.currentCredit > 1500) { @@ -184,11 +185,20 @@ public class unitProductionAI { } } - if(mainThread.ec.theBuildingManagerAI.theBaseInfo.numberOfTechCenter > 0 && ((numberOfLightTanks_player + numberOfStealthTanks_player> 8) || theBaseInfo.currentCredit > 2000 || numberOfStealthTanks_AI > 6)){ + if(mainThread.ec.theBuildingManagerAI.theBaseInfo.numberOfTechCenter > 0){ + + if(currentProductionOrder == produceStealthTank) + System.out.println("should make stealth tank now--------------"); + if(currentProductionOrder == produceHeavyTank) + System.out.println("should make Heavy tank now-----------------"); + if(currentProductionOrder == produceRocketTank) + System.out.println("should make Rocket tank now----------------"); + + //Immediately start stealth tank upgrades when a tech center is built if(!techCenter.stealthTankResearched_enemy){ - if(techCenter.stealthTankResearchProgress_enemy == 255){ + if(techCenter.stealthTankResearchProgress_enemy == 255 && ((numberOfLightTanks_player + numberOfStealthTanks_player> 8) || theBaseInfo.currentCredit > 2000 || numberOfStealthTanks_AI > 6)){ techCenter.cancelResearch(1); techCenter.researchStealthTank(1); System.out.println("----------------------------AI starts researching stealth tank------------------------------------"); @@ -204,16 +214,6 @@ public class unitProductionAI { } } } - - - //System.out.println("enemy light tank count: " + numberOfLightTanks_player + " at " + mainThread.frameIndex/30); - if(currentProductionOrder == produceStealthTank) - System.out.println("should make stealth tank now--------------"); - if(currentProductionOrder == produceHeavyTank) - System.out.println("should make Heavy tank now-----------------"); - if(currentProductionOrder == produceRocketTank) - System.out.println("should make Rocket tank now----------------"); - if(numberOfRocketTanks_AI > 2 && theBaseInfo.currentCredit > 750 && (numberOfPlayerGunTurrets > 0 || numberOfPlayerMissileTurrets > 0)){ if(!techCenter.rocketTankResearched_enemy){ diff --git a/gui/inputHandler.java b/gui/inputHandler.java index 2fbf80a..fd05a85 100644 --- a/gui/inputHandler.java +++ b/gui/inputHandler.java @@ -12,8 +12,20 @@ public class inputHandler { public static int mouse_x, mouse_y,mouse_x0, mouse_x1, mouse_y0, mouse_y1, cameraMovementAngle; - public static boolean mouseIsInsideScreen, leftKeyPressed, rightKeyPressed, controlKeyPressed, leftMouseButtonPressed, rightMouseButtonPressed, leftMouseButtonReleased, rightMouseButtonReleased, H_pressed,A_pressed, userIsHoldingA; + public static boolean mouseIsInsideScreen, userIsHoldingA; + public static boolean leftKeyPressed, + rightKeyPressed, + controlKeyPressed, + leftMouseButtonPressed, + rightMouseButtonPressed, + leftMouseButtonReleased, + rightMouseButtonReleased, + H_pressed, + A_pressed, + escapeKeyPressed, + escapeKeyReleased; + public static int numberTyped; public static final Rectangle mouseMovementArea = new Rectangle(30,20, 708, 472); @@ -24,15 +36,20 @@ public class inputHandler { public static int inputCounter, inputBufferIndex, keyReleaseCounter, keyReleaseBufferIndex; public static void processInput(){ + + //read input char int theCounter = inputCounter; + //handle over flow if(inputBufferIndex > theCounter){ while(inputBufferIndex < 1024){ char c = inputBuffer[inputBufferIndex]; + if(c == 'h' || c == 'H'){ + H_pressed = true; } @@ -46,10 +63,12 @@ public class inputHandler { inputBufferIndex++; + } inputBufferIndex = 0; } + while(inputBufferIndex < theCounter){ char c = inputBuffer[inputBufferIndex]; @@ -68,6 +87,7 @@ public class inputHandler { inputBufferIndex++; } + //read released char theCounter = keyReleaseCounter; @@ -104,7 +124,7 @@ public class inputHandler { //handle input when game is running - if(mainThread.inGame){ + if(!mainThread.gamePaused){ if(!mainThread.pc.isSelectingUnit){ mouse_x0 = mouse_x; mouse_y0 = mouse_y; @@ -214,13 +234,24 @@ public class inputHandler { //handle hotheys if(A_pressed){ - if(!userIsHoldingA){ mainThread.pc.attackKeyPressed = true; userIsHoldingA = true; } } + + //handle escape key + if(escapeKeyReleased) { + mainThread.gamePaused = true; //when game is running, pause the game when esc key is hit + + } + + }else { + //handle event when game is paused + if(escapeKeyReleased) + mainThread.gamePaused = false; //when game is paused unpause the game when esc key is hit + } @@ -229,8 +260,11 @@ public class inputHandler { rightMouseButtonPressed = false; leftMouseButtonReleased = false; rightMouseButtonReleased = false; + escapeKeyPressed = false; + escapeKeyReleased = false; A_pressed = false; + H_pressed = false; numberTyped = 0; }