From d8a7c2d77fb9a3e3f5382d70bfdff4a532ae202d Mon Sep 17 00:00:00 2001 From: Pan Date: Tue, 26 Mar 2019 19:13:25 +1300 Subject: [PATCH] home commit --- core/camera.java | 11 +- core/mainThread.java | 18 +- core/postProcessingThread.java | 22 ++- core/terrain.java | 2 +- enemyAI/enemyCommander.java | 16 +- enemyAI/mapAwarenessAI.java | 4 +- enemyAI/unitProductionAI.java | 4 +- entity/communicationCenter.java | 6 +- entity/constructionVehicle.java | 4 +- entity/constructionYard.java | 4 +- entity/drone.java | 6 +- entity/factory.java | 4 +- entity/gunTurret.java | 8 +- entity/harvester.java | 4 +- entity/heavyTank.java | 8 +- entity/lightTank.java | 6 +- entity/missileTurret.java | 14 +- entity/powerPlant.java | 4 +- entity/refinery.java | 4 +- entity/rocketTank.java | 6 +- entity/solidObject.java | 2 +- entity/stealthTank.java | 8 +- entity/techCenter.java | 6 +- gui/.gitignore | 2 + gui/SideBar.java | 8 +- gui/button.java | 176 +++++++++++++++++ gui/gameMenu.java | 341 +++++++++++++++++++++++++++++++- gui/inputHandler.java | 9 + {core => gui}/textRenderer.java | 6 +- images/title.png | Bin 0 -> 13466 bytes 30 files changed, 631 insertions(+), 82 deletions(-) create mode 100644 gui/button.java rename {core => gui}/textRenderer.java (94%) create mode 100644 images/title.png diff --git a/core/camera.java b/core/camera.java index 5990af5..6311ee1 100644 --- a/core/camera.java +++ b/core/camera.java @@ -23,6 +23,8 @@ public class camera{ public static vector cameraMovement; + public static int frameIndex; + public camera(vector p, int XZ, int YZ){ view_Direction = new vector(0, 0, 1); @@ -37,18 +39,19 @@ public class camera{ } public void update(){ + frameIndex++; if(!mainThread.gameStarted) { //when game has not started, use a "fly through" as the background for the menu - if(mainThread.frameIndex == 1) { - mainThread.Camera.position.z = 2.5f; - mainThread.Camera.position.x = 9; + if(frameIndex == 1) { + position.z = 2.5f; + position.x = 9; cameraMovement = new vector(-0.01f,0,0); } - if(mainThread.frameIndex > 90 && mainThread.frameIndex%400 >= 0 && mainThread.frameIndex%400 < 90) { + if(frameIndex > 90 && frameIndex%400 >= 0 && frameIndex%400 < 90) { XZ_angle+=1; cameraMovement.rotate_XZ(359); } diff --git a/core/mainThread.java b/core/mainThread.java index a9df4ab..c249a8c 100644 --- a/core/mainThread.java +++ b/core/mainThread.java @@ -25,6 +25,7 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M public static Ticker t; public static int frameInterval; public static int frameIndex; + public static int gameFrame; public static long lastDraw; public static int sleepTime; public static int framePerSecond, cpuUsage; @@ -49,7 +50,8 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M public static short[] displacementBuffer; public static short[] displacementBuffer2; - + public static boolean leftMouseButtonReleased; + public static String buttonAction; public mainThread(){ setTitle("Battle Tank 3"); @@ -148,9 +150,6 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M PPT = new postProcessingThread(); Thread theTread = new Thread(PPT); - //test only - gameStarted = false; - //start threads t.start(); dt.start(); @@ -166,14 +165,19 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M //thread is always lag the main thread by 1 frame. However it is barely noticeable. public void actionPerformed(ActionEvent e){ + + frameIndex++; + inputHandler.processInput(); if(!gamePaused) { + if(gameStarted) + gameFrame++; //handle user's interaction with game GUI - if(frameIndex == 1 && gameStarted){ + if(gameFrame == 1 && gameStarted){ theAssetManager.prepareAssetForNewGame(); } @@ -238,8 +242,8 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M Graphics2D g2 =(Graphics2D)bf.getGraphics(); //(Graphics2D)g; //display polygon count and frame rate - g2.setColor(Color.WHITE); - g2.drawString("FPS: " + framePerSecond + " " + "Polygons: " + theAssetManager.polygonCount + " " + "Thread1 Sleep: " + sleepTime + "ms " + "Thread2 Sleep: " + postProcessingThread.sleepTime + "ms " , 5, 15); + //g2.setColor(Color.WHITE); + //g2.drawString("FPS: " + framePerSecond + " " + "Polygons: " + theAssetManager.polygonCount + " " + "Thread1 Sleep: " + sleepTime + "ms " + "Thread2 Sleep: " + postProcessingThread.sleepTime + "ms " , 5, 15); //copy the screen buffer to video memory g.drawImage(bf, 0, 0, this); diff --git a/core/postProcessingThread.java b/core/postProcessingThread.java index 594acc8..bdedcdd 100644 --- a/core/postProcessingThread.java +++ b/core/postProcessingThread.java @@ -5,6 +5,8 @@ import gui.MiniMap; import gui.SideBar; import gui.confirmationIcon; import gui.gameMenu; +import gui.inputHandler; +import gui.textRenderer; import particles.explosion; import particles.helix; import particles.smokeParticle; @@ -34,6 +36,7 @@ public class postProcessingThread implements Runnable{ public static MiniMap theMiniMap; public static SideBar theSideBar; + public static gameMenu theGameMenu; private boolean isWorking; public static int sleepTime; @@ -74,6 +77,10 @@ public class postProcessingThread implements Runnable{ public static boolean gamePaused, gameStarted, gameEnded; + public static int mouse_x, mouse_y; + public static boolean leftMouseButtonReleased; + public static String buttonAction; + //A pool of vectors which will be used for vector arithmetic public static vector @@ -130,6 +137,10 @@ public class postProcessingThread implements Runnable{ theSideBar = new SideBar(); theSideBar.init(); + //init game menu + theGameMenu = new gameMenu(); + theGameMenu.init(); + unitInfoTable = new int[201][4]; @@ -196,8 +207,8 @@ public class postProcessingThread implements Runnable{ if(!gamePaused) doPostProcesssing(); - - gameMenu.updateAndDraw(currentScreen, gameStarted, gamePaused); + + theGameMenu.updateAndDraw(currentScreen, gameStarted, gamePaused, gameEnded); frameIndex++; @@ -973,7 +984,14 @@ public class postProcessingThread implements Runnable{ theMiniMap.findCorners(); + mouse_x = inputHandler.mouse_x; + mouse_y = inputHandler.mouse_y; + leftMouseButtonReleased = mainThread.leftMouseButtonReleased; + mainThread.leftMouseButtonReleased = false; + //feed main thread with button action + mainThread.buttonAction = buttonAction; + buttonAction = null; } diff --git a/core/terrain.java b/core/terrain.java index b03a9e4..714f778 100644 --- a/core/terrain.java +++ b/core/terrain.java @@ -831,7 +831,7 @@ public class terrain { } //animate water surface - mainThread.textures[54].waterHeightMap = mainThread.textures[54].waterHeightMaps[(mainThread.frameIndex)%48]; + mainThread.textures[54].waterHeightMap = mainThread.textures[54].waterHeightMaps[(mainThread.gameFrame)%48]; for(int i = 0; i < roadPolygonIndex; i++){ road[i].update(); diff --git a/enemyAI/enemyCommander.java b/enemyAI/enemyCommander.java index bab4b53..66a7735 100644 --- a/enemyAI/enemyCommander.java +++ b/enemyAI/enemyCommander.java @@ -85,35 +85,35 @@ public class enemyCommander { public void thinkHardLikeHumanPlayer(){ //the order is important!! - if(mainThread.frameIndex % 30 == 0){ + if(mainThread.gameFrame % 30 == 0){ theMapAwarenessAI.processAI(); } - if(mainThread.frameIndex % 30 == 1){ + if(mainThread.gameFrame % 30 == 1){ theBuildingManagerAI.processAI(); } - if(mainThread.frameIndex % 30 == 2){ + if(mainThread.gameFrame % 30 == 2){ theEconomyManagerAI.processAI(); } - if(mainThread.frameIndex % 30 == 3){ + if(mainThread.gameFrame % 30 == 3){ theScoutingManagerAI.processAI(); } - if(mainThread.frameIndex % 30 == 4){ + if(mainThread.gameFrame % 30 == 4){ theUnitProductionAI.processAI(); } - if(mainThread.frameIndex % 30 == 5){ + if(mainThread.gameFrame % 30 == 5){ theBaseExpentionAI.processAI(); } - if(mainThread.frameIndex % 30 == 6){ + if(mainThread.gameFrame % 30 == 6){ theCombatManagerAI.processAI(); } - if(mainThread.frameIndex % 30 == 7){ + if(mainThread.gameFrame % 30 == 7){ theDefenseManagerAI.processAI(); } diff --git a/enemyAI/mapAwarenessAI.java b/enemyAI/mapAwarenessAI.java index 487c850..d0fc0b7 100644 --- a/enemyAI/mapAwarenessAI.java +++ b/enemyAI/mapAwarenessAI.java @@ -443,7 +443,7 @@ public class mapAwarenessAI { playerHasMostlyHeavyTanks = numberOfHeavyTanks_player > 3 && (float)(numberOfHeavyTanks_player)/(numberOfLightTanks_player + numberOfRocketTanks_player + numberOfStealthTanks_player + numberOfHeavyTanks_player) > 0.6f; playerHasManyLightTanksButNoHeavyTank = lightTankRatio > 0.5 && lightTankRatio <=0.8 && numberOfHeavyTanks_player < 3; - playIsRushingHighTierUnits = mainThread.frameIndex/30 > 250 && mainThread.frameIndex/30 < 400 + playIsRushingHighTierUnits = mainThread.gameFrame/30 > 250 && mainThread.gameFrame/30 < 400 && mainThread.ec.theMapAwarenessAI.numberOfTechCenter_player >0 && mainThread.ec.theMapAwarenessAI.numberOfMissileTurret_player < 2 && mainThread.ec.theMapAwarenessAI.numberOfGunTurret_player < 4 @@ -452,7 +452,7 @@ public class mapAwarenessAI { playerLikelyCanNotProduceHighTierUnits = mainThread.ec.theMapAwarenessAI.numberOfTechCenter_player == 0 && mainThread.ec.theMapAwarenessAI.numberOfHeavyTanks_player == 0; playerDoesntHaveMassHeavyTanks = (float)numberOfHeavyTanks_player/( 1 + numberOfLightTanks_AI + numberOfRocketTanks_player + numberOfStealthTanks_player) < 0.2f; - playerIsRushingLightTank = mainThread.frameIndex/30 > 300 && mainThread.frameIndex/30 < 600 && ((playerLikelyCanNotProduceHighTierUnits && numberOfStealthTanks_player < 3) || playerHasMostlyLightTanks); + playerIsRushingLightTank = mainThread.gameFrame/30 > 300 && mainThread.gameFrame/30 < 600 && ((playerLikelyCanNotProduceHighTierUnits && numberOfStealthTanks_player < 3) || playerHasMostlyLightTanks); playerHasMostlyHeavyAndStealthTanks = (maxNumberOfStealthTanks_playerInLastFiveMinutes >=2 ) && (float)(numberOfHeavyTanks_player + numberOfStealthTanks_player)/(numberOfLightTanks_player + numberOfRocketTanks_player + numberOfStealthTanks_player + numberOfHeavyTanks_player) > 0.8f; diff --git a/enemyAI/unitProductionAI.java b/enemyAI/unitProductionAI.java index 6e9a339..eb47424 100644 --- a/enemyAI/unitProductionAI.java +++ b/enemyAI/unitProductionAI.java @@ -161,9 +161,9 @@ public class unitProductionAI { playerHasMostlyHeavyAndStealthTanks || (!playerHasManyLightTanksButNoHeavyTank && !playerHasMostlyLightTanks - && !(numberOfHeavyTanks_player == 0 && maxNumberOfStealthTanks_playerInLastFiveMinutes < 3 && mainThread.frameIndex/30 > 600) + && !(numberOfHeavyTanks_player == 0 && maxNumberOfStealthTanks_playerInLastFiveMinutes < 3 && mainThread.gameFrame/30 > 600) && !(playerHasMostlyHeavyTanks && numberOfStealthTanks_player < numberOfHeavyTanks_AI*2) - && (playIsRushingHighTierUnits || gameData.getRandom() > 985 || maxNumberOfStealthTanks_playerInLastFiveMinutes*4 > numberOfHeavyTanks_AI || (mainThread.frameIndex/30 > 400 && mainThread.frameIndex/30 < 600 && numberOfPlayerGunTurrets + numberOfPlayerMissileTurrets+ numberOfLightTanks_player + numberOfRocketTanks_player + numberOfHeavyTanks_player*5 < 5)))){ + && (playIsRushingHighTierUnits || gameData.getRandom() > 985 || maxNumberOfStealthTanks_playerInLastFiveMinutes*4 > numberOfHeavyTanks_AI || (mainThread.gameFrame/30 > 400 && mainThread.gameFrame/30 < 600 && numberOfPlayerGunTurrets + numberOfPlayerMissileTurrets+ numberOfLightTanks_player + numberOfRocketTanks_player + numberOfHeavyTanks_player*5 < 5)))){ currentProductionOrder = produceHeavyTank; }else if(theBaseInfo.canBuildStealthTank && (playerHasMostlyLightTanks || playerLikelyCanNotProduceHighTierUnits || playerDoesntHaveMassHeavyTanks) && !playerHasMostlyHeavyTanks){ currentProductionOrder = produceStealthTank; diff --git a/entity/communicationCenter.java b/entity/communicationCenter.java index 310668f..cd26311 100644 --- a/entity/communicationCenter.java +++ b/entity/communicationCenter.java @@ -924,7 +924,7 @@ public class communicationCenter extends solidObject{ } if(isRepairing && currentHP >0){ - if(mainThread.frameIndex%8==0 && theBaseInfo.currentCredit > 0 && currentHP 0 && currentHP maxHP) @@ -933,7 +933,7 @@ public class communicationCenter extends solidObject{ } //process researching - if(mainThread.frameIndex%2==0 && (!(theBaseInfo.lowPower && mainThread.frameIndex%4==0))){ + if(mainThread.gameFrame%2==0 && (!(theBaseInfo.lowPower && mainThread.gameFrame%4==0))){ if(teamNo == 0){ if(harvesterSpeedResearchProgress_player < 240){ @@ -1132,7 +1132,7 @@ public class communicationCenter extends solidObject{ } //scan for clocked unit - if((ID + mainThread.frameIndex)%10 == 0 && !theBaseInfo.lowPower){ + if((ID + mainThread.gameFrame)%10 == 0 && !theBaseInfo.lowPower){ currentOccupiedTile = (int)(centre.x*64)/16 + (127 - (int)(centre.z*64)/16)*128; for(int i = 0; i < tileCheckList.length; i++){ diff --git a/entity/constructionVehicle.java b/entity/constructionVehicle.java index dc6cafc..8f7f14a 100644 --- a/entity/constructionVehicle.java +++ b/entity/constructionVehicle.java @@ -1202,7 +1202,7 @@ public class constructionVehicle extends solidObject { // test if the tank object is visible in camera point of view if (visible_minimap) { - if (currentHP <= maxHP / 2 && (mainThread.frameIndex + ID) % 3 == 0) { + if (currentHP <= maxHP / 2 && (mainThread.gameFrame + ID) % 3 == 0) { // spawn smoke particle if the unit is badly damaged float[] tempFloat = theAssetManager.smokeEmmiterList[theAssetManager.smokeEmmiterCount]; tempFloat[0] = centre.x + (float) (Math.random() / 20) - 0.025f; @@ -1591,7 +1591,7 @@ public class constructionVehicle extends solidObject { if (obstacle != null) { if ((unStableObstacle != null || !isStable(obstacle.owner)) - && (ID + randomNumber + mainThread.frameIndex) % 128 == 0) { + && (ID + randomNumber + mainThread.gameFrame) % 128 == 0) { newDestinationisGiven = true; currentMovementStatus = freeToMove; hugWallCoolDown = 0; diff --git a/entity/constructionYard.java b/entity/constructionYard.java index ad1d80d..95180d8 100644 --- a/entity/constructionYard.java +++ b/entity/constructionYard.java @@ -1241,7 +1241,7 @@ public class constructionYard extends solidObject{ } if(isRepairing && currentHP >0){ - if(mainThread.frameIndex%8==0 && theBaseInfo.currentCredit > 0 && currentHP 0 && currentHP maxHP) @@ -1251,7 +1251,7 @@ public class constructionYard extends solidObject{ //process building event - if(!(theBaseInfo.lowPower && mainThread.frameIndex%2==0)){ + if(!(theBaseInfo.lowPower && mainThread.gameFrame%2==0)){ if(powerPlantProgress < 240){ if(theBaseInfo.currentCredit >0){ diff --git a/entity/drone.java b/entity/drone.java index d5271e7..45a248f 100644 --- a/entity/drone.java +++ b/entity/drone.java @@ -470,12 +470,12 @@ public class drone extends solidObject{ //heal unit if(targetUnit.currentHP < targetUnit.getMaxHp() || targetUnit.underAttackCountDown > 60){ - if(mainThread.frameIndex%5 == 1 && centre.y <=-0.1){ + if(mainThread.gameFrame%5 == 1 && centre.y <=-0.1){ targetUnit.currentHP+=5; if(targetUnit.currentHP > targetUnit.getMaxHp()) targetUnit.currentHP = targetUnit.getMaxHp(); } - if(mainThread.frameIndex%2==0 && centre.y <=-0.15){ + if(mainThread.gameFrame%2==0 && centre.y <=-0.15){ //spawn a healing steam particle float[] tempFloat = theAssetManager.smokeEmmiterList[theAssetManager.smokeEmmiterCount]; tempFloat[0] = armCenterClone.x + (float)(Math.random()/20) - 0.025f; @@ -534,7 +534,7 @@ public class drone extends solidObject{ fan1Angle = fan1Angle%360; fan2Angle = fan2Angle%360; - heightVariance = gameData.sin[((mainThread.frameIndex+randomNumber)*5)%360] * 0.01f; + heightVariance = gameData.sin[((mainThread.gameFrame+randomNumber)*5)%360] * 0.01f; //update center in camera coordinate diff --git a/entity/factory.java b/entity/factory.java index 18bfade..e798a89 100644 --- a/entity/factory.java +++ b/entity/factory.java @@ -953,7 +953,7 @@ public class factory extends solidObject{ } if(isRepairing && currentHP >0){ - if(mainThread.frameIndex%8==0 && theBaseInfo.currentCredit > 0 && currentHP 0 && currentHP maxHP) @@ -964,7 +964,7 @@ public class factory extends solidObject{ //process building event (at half speed when lower power) if(currentStatus == isBuilding){ - if(!(theBaseInfo.lowPower && mainThread.frameIndex%2==0)){ + if(!(theBaseInfo.lowPower && mainThread.gameFrame%2==0)){ //light tank event if(lightTankProgress < 240){ diff --git a/entity/gunTurret.java b/entity/gunTurret.java index bd60acf..063b3ba 100644 --- a/entity/gunTurret.java +++ b/entity/gunTurret.java @@ -369,7 +369,7 @@ public class gunTurret extends solidObject{ return; }else{ - if(mainThread.frameIndex%2==0){ + if(mainThread.gameFrame%2==0){ float[] tempFloat = theAssetManager.explosionInfo[theAssetManager.explosionCount]; tempFloat[0] = centre.x + (float)Math.random()/4f - 0.125f; tempFloat[1] = centre.y + 0.15f; @@ -386,7 +386,7 @@ public class gunTurret extends solidObject{ } if(isRepairing && currentHP >0){ - if(mainThread.frameIndex%5==0 && theBaseInfo.currentCredit > 0 && currentHP 0 && currentHP = 160){ level = 2; myDamage = 40; - if(currentHP < maxHP && mainThread.frameIndex%8==0) + if(currentHP < maxHP && mainThread.gameFrame%8==0) currentHP++; } } - if(canSelfRepair && currentHP < maxHP && mainThread.frameIndex%6==0){ + if(canSelfRepair && currentHP < maxHP && mainThread.gameFrame%6==0){ currentHP++; } @@ -524,7 +524,7 @@ public class heavyTank extends solidObject{ //test if the tank object is visible in camera point of view if(visible_minimap){ - if(currentHP <= 160 && (mainThread.frameIndex + ID) % 3 ==0){ + if(currentHP <= 160 && (mainThread.gameFrame + ID) % 3 ==0){ //spawn smoke particle if the tank is badly damaged float[] tempFloat = theAssetManager.smokeEmmiterList[theAssetManager.smokeEmmiterCount]; tempFloat[0] = centre.x + (float)(Math.random()/20) - 0.025f; @@ -706,7 +706,7 @@ public class heavyTank extends solidObject{ //the tank will attack with any hostile unit that moved into its firing range public void performStandByLogic(){ //scan for hostile unit - if((ID + mainThread.frameIndex)%32 == 0){ + if((ID + mainThread.gameFrame)%32 == 0){ currentOccupiedTile = (int)(centre.x*64)/16 + (127 - (int)(centre.z*64)/16)*128; for(int i = 0; i < tileCheckList.length; i++){ diff --git a/entity/lightTank.java b/entity/lightTank.java index 75241f5..285533a 100644 --- a/entity/lightTank.java +++ b/entity/lightTank.java @@ -277,7 +277,7 @@ public class lightTank extends solidObject{ if(experience >= 80){ level = 2; myDamage = 30 ; - if(currentHP < maxHP && mainThread.frameIndex%12==0) + if(currentHP < maxHP && mainThread.gameFrame%12==0) currentHP++; } } @@ -425,7 +425,7 @@ public class lightTank extends solidObject{ //test if the tank object is visible in camera point of view if(visible_minimap){ - if(currentHP <= 60 && (mainThread.frameIndex + ID) % 3 ==0){ + if(currentHP <= 60 && (mainThread.gameFrame + ID) % 3 ==0){ //spawn smoke particle if the tank is badly damaged float[] tempFloat = theAssetManager.smokeEmmiterList[theAssetManager.smokeEmmiterCount]; tempFloat[0] = centre.x + (float)(Math.random()/20) - 0.025f; @@ -612,7 +612,7 @@ public class lightTank extends solidObject{ tileCheckList = tileCheckList_enemy; //scan for hostile unit - if((ID + mainThread.frameIndex)%32 == 0){ + if((ID + mainThread.gameFrame)%32 == 0){ currentOccupiedTile = (int)(centre.x*64)/16 + (127 - (int)(centre.z*64)/16)*128; for(int i = 0; i < tileCheckList.length; i++){ diff --git a/entity/missileTurret.java b/entity/missileTurret.java index f12cd02..6df235b 100644 --- a/entity/missileTurret.java +++ b/entity/missileTurret.java @@ -477,7 +477,7 @@ public class missileTurret extends solidObject{ return; }else{ - if(mainThread.frameIndex%2==0){ + if(mainThread.gameFrame%2==0){ float[] tempFloat = theAssetManager.explosionInfo[theAssetManager.explosionCount]; tempFloat[0] = centre.x + (float)Math.random()/4f - 0.125f; tempFloat[1] = centre.y + 0.15f; @@ -494,7 +494,7 @@ public class missileTurret extends solidObject{ } if(isRepairing && currentHP >0){ - if(mainThread.frameIndex%5==0 && theBaseInfo.currentCredit > 0 && currentHP 0 && currentHP 100 ||targetObject.type <199) && !attackLock && (randomInt + mainThread.frameIndex)%4 == 2){ + if((targetObject.type > 100 ||targetObject.type <199) && !attackLock && (randomInt + mainThread.gameFrame)%4 == 2){ currentOccupiedTile = (int)(centre.x*64)/16 + (127 - (int)(centre.z*64)/16)*128; for(int i = 0; i < tileCheckList.length; i++){ @@ -824,7 +824,7 @@ public class missileTurret extends solidObject{ attackLock = false; - if((randomInt + mainThread.frameIndex)%240 == 0){ + if((randomInt + mainThread.gameFrame)%240 == 0){ attackAngle = (int)(Math.random()*360); } if(turretAngle != attackAngle){ @@ -838,7 +838,7 @@ public class missileTurret extends solidObject{ } - if((ID + mainThread.frameIndex)%4 == 0){ + if((ID + mainThread.gameFrame)%4 == 0){ currentOccupiedTile = (int)(centre.x*64)/16 + (127 - (int)(centre.z*64)/16)*128; for(int i = 0; i < tileCheckList.length; i++){ diff --git a/entity/powerPlant.java b/entity/powerPlant.java index 9de0e7a..f21c52d 100644 --- a/entity/powerPlant.java +++ b/entity/powerPlant.java @@ -671,7 +671,7 @@ public class powerPlant extends solidObject{ //processing repair event if(isRepairing && currentHP >0){ - if(mainThread.frameIndex%8==0 && theBaseInfo.currentCredit > 0 && currentHP 0 && currentHP maxHP) @@ -805,7 +805,7 @@ public class powerPlant extends solidObject{ //spawn smoke particle - if((mainThread.frameIndex + ID) % 5 ==0 && centre.y >= -0.5f){ + if((mainThread.gameFrame + ID) % 5 ==0 && centre.y >= -0.5f){ float[] tempFloat = theAssetManager.smokeEmmiterList[theAssetManager.smokeEmmiterCount]; tempFloat[0] = centre.x - 0.053f + (float)(Math.random()/20) - 0.025f; tempFloat[1] = centre.y + 0.45f; diff --git a/entity/refinery.java b/entity/refinery.java index f5cf1c6..0f0d27b 100644 --- a/entity/refinery.java +++ b/entity/refinery.java @@ -825,7 +825,7 @@ public class refinery extends solidObject{ } if(isRepairing && currentHP >0){ - if(mainThread.frameIndex%8==0 && theBaseInfo.currentCredit > 0 && currentHP 0 && currentHP maxHP) @@ -964,7 +964,7 @@ public class refinery extends solidObject{ //spawn smoke particle - if((mainThread.frameIndex + ID) % 5 ==0 && centre.y >= -0.79f){ + if((mainThread.gameFrame + ID) % 5 ==0 && centre.y >= -0.79f){ float[] tempFloat = theAssetManager.smokeEmmiterList[theAssetManager.smokeEmmiterCount]; tempFloat[0] = centre.x + 0.265f + (float)(Math.random()/40) - 0.0125f; tempFloat[1] = centre.y + 0.4f + 0.5f; diff --git a/entity/rocketTank.java b/entity/rocketTank.java index 486479f..c8e6b8a 100644 --- a/entity/rocketTank.java +++ b/entity/rocketTank.java @@ -299,7 +299,7 @@ public class rocketTank extends solidObject{ if(experience >= 100){ level = 2; myDamage = 44; - if(currentHP < maxHP && mainThread.frameIndex%16==0) + if(currentHP < maxHP && mainThread.gameFrame%16==0) currentHP++; } } @@ -439,7 +439,7 @@ public class rocketTank extends solidObject{ //test if the tank object is visible in camera point of view if(visible_minimap){ - if(currentHP <= maxHP/2 && (mainThread.frameIndex + ID) % 3 ==0){ + if(currentHP <= maxHP/2 && (mainThread.gameFrame + ID) % 3 ==0){ //spawn smoke particle if the tank is badly damaged float[] tempFloat = theAssetManager.smokeEmmiterList[theAssetManager.smokeEmmiterCount]; tempFloat[0] = centre.x + (float)(Math.random()/20) - 0.025f; @@ -646,7 +646,7 @@ public class rocketTank extends solidObject{ else bitmapVision = enemyCommander.visionMap; - if((ID + mainThread.frameIndex)%32 == 0){ + if((ID + mainThread.gameFrame)%32 == 0){ currentOccupiedTile = (int)(centre.x*64)/16 + (127 - (int)(centre.z*64)/16)*128; for(int i = 0; i < tileCheckList.length; i++){ diff --git a/entity/solidObject.java b/entity/solidObject.java index 59f4985..c8b9f0b 100644 --- a/entity/solidObject.java +++ b/entity/solidObject.java @@ -1471,7 +1471,7 @@ public abstract class solidObject{ if(obstacle != null && attackStatus != isAttacking){ - if((unStableObstacle != null || !isStable(obstacle.owner)) && (ID + randomNumber + mainThread.frameIndex)%128 ==0){ + if((unStableObstacle != null || !isStable(obstacle.owner)) && (ID + randomNumber + mainThread.gameFrame)%128 ==0){ newDestinationisGiven = true; currentMovementStatus = freeToMove; diff --git a/entity/stealthTank.java b/entity/stealthTank.java index 55a934f..794356a 100644 --- a/entity/stealthTank.java +++ b/entity/stealthTank.java @@ -389,7 +389,7 @@ public class stealthTank extends solidObject{ if(experience >= 120){ level = 2; myDamage = 60; - if(currentHP < maxHP && mainThread.frameIndex%16==0) + if(currentHP < maxHP && mainThread.gameFrame%16==0) currentHP++; } } @@ -575,7 +575,7 @@ public class stealthTank extends solidObject{ //test if the tank object is visible in camera point of view if(visible_minimap){ - if(currentHP <= (maxHP/2) && (mainThread.frameIndex + ID) % 3 ==0 && !isCloaked){ + if(currentHP <= (maxHP/2) && (mainThread.gameFrame + ID) % 3 ==0 && !isCloaked){ //spawn smoke particle if the tank is badly damaged float[] tempFloat = theAssetManager.smokeEmmiterList[theAssetManager.smokeEmmiterCount]; tempFloat[0] = centre.x + (float)(Math.random()/20) - 0.025f; @@ -788,7 +788,7 @@ public class stealthTank extends solidObject{ //the tank will attack with any hostile unit that moved into its firing range public void performStandByLogic(){ //scan for hostile unit - if((ID + mainThread.frameIndex)%32 == 0){ + if((ID + mainThread.gameFrame)%32 == 0){ currentOccupiedTile = (int)(centre.x*64)/16 + (127 - (int)(centre.z*64)/16)*128; for(int i = 0; i < tileCheckList.length; i++){ @@ -1341,7 +1341,7 @@ public class stealthTank extends solidObject{ rasterizer.modelCenterX = (int)(tempCentre.screenX); rasterizer.modelCenterY = (int)(tempCentre.screenY); - rasterizer.cloakTexture = gameData.cloakTextures[(randomNumber + mainThread.frameIndex * 2)%120]; + rasterizer.cloakTexture = gameData.cloakTextures[(randomNumber + mainThread.gameFrame * 2)%120]; rasterizer.cloakedThreshold = currentCloakingStatus; diff --git a/entity/techCenter.java b/entity/techCenter.java index ba88f85..7c55dfc 100644 --- a/entity/techCenter.java +++ b/entity/techCenter.java @@ -1429,7 +1429,7 @@ public class techCenter extends solidObject{ //processing repair event if(isRepairing && currentHP >0){ - if(mainThread.frameIndex%8==0 && theBaseInfo.currentCredit > 0 && currentHP 0 && currentHP maxHP) @@ -1438,7 +1438,7 @@ public class techCenter extends solidObject{ } //process researching - if(mainThread.frameIndex%2==0 && (!(theBaseInfo.lowPower && mainThread.frameIndex%4==0))){ + if(mainThread.gameFrame%2==0 && (!(theBaseInfo.lowPower && mainThread.gameFrame%4==0))){ //light tank research if(teamNo == 0){ @@ -1666,7 +1666,7 @@ public class techCenter extends solidObject{ } if(visible){ - float ratio = ((float)Math.sin((float)(mainThread.frameIndex + ID)/10) + 1)/2; + float ratio = ((float)Math.sin((float)(mainThread.gameFrame + ID)/10) + 1)/2; diff --git a/gui/.gitignore b/gui/.gitignore index 13b3f11..d4621fa 100644 --- a/gui/.gitignore +++ b/gui/.gitignore @@ -6,3 +6,5 @@ /playerCommander.class /sideBarManager.class /gameMenu.class +/button.class +/textRenderer.class diff --git a/gui/SideBar.java b/gui/SideBar.java index 7a4d78d..ad0c7d9 100644 --- a/gui/SideBar.java +++ b/gui/SideBar.java @@ -329,10 +329,10 @@ public class SideBar { if(iconTextureIndex == 17) d = 768*44; - int startIndex1 = (int)(mainThread.frameIndex/1.5)%74; - int startIndex2 = ((int)(mainThread.frameIndex/1.5)%74 + 18)%74; - int startIndex3 = ((int)(mainThread.frameIndex/1.5)%74 + 37)%74; - int startIndex4 = ((int)(mainThread.frameIndex/1.5)%74 + 55)%74; + int startIndex1 = (int)(mainThread.gameFrame/1.5)%74; + int startIndex2 = ((int)(mainThread.gameFrame/1.5)%74 + 18)%74; + int startIndex3 = ((int)(mainThread.gameFrame/1.5)%74 + 37)%74; + int startIndex4 = ((int)(mainThread.gameFrame/1.5)%74 + 55)%74; int markerR = 255; int markerG = 255; diff --git a/gui/button.java b/gui/button.java new file mode 100644 index 0000000..545c34a --- /dev/null +++ b/gui/button.java @@ -0,0 +1,176 @@ +package gui; + +public class button { + + public int xPos, yPos, width, height; + public String name, text; + public boolean display, cursorIsOnTop; + public int actionCooldown; + + public button(String name, String text, int xPos, int yPos, int width, int height) { + this.name = name; + this.text = text; + this.xPos = xPos; + this.yPos = yPos; + this.width = width; + this.height = height; + } + + public boolean checkIfCursorIsOnTop(int mouse_x, int mouse_y) { + cursorIsOnTop = mouse_x > xPos && mouse_x < xPos + width && mouse_y > yPos && mouse_y < yPos + height; + + return cursorIsOnTop && display; + } + + public void draw(int[] screen) { + if(display == false) { + cursorIsOnTop = false; + return; + } + + + int R = 6; + int G = 141; + int B = 198; + + //drawButton; + int color = ((R) << 16 | (G) << 8 | (B)); + int pos = xPos + yPos* 768; + for(int i = 0; i < height/3; i++) { + for(int j = height/3 -i; j < width; j++) { + screen[pos+ j+ i*768] = color; + } + } + + for(int i = height/3; i < height/3*2; i++) { + for(int j = 0; j < width; j++) { + screen[pos+ j+ i*768] = color; + } + } + + for(int i = height/3*2; i < height; i++) { + for(int j = 0; j < width - (i - height/3*2); j++) { + screen[pos+ j+ i*768] = color; + } + } + + //draw highlight of cursor is on top of the button + if(cursorIsOnTop) { + + R = 239; + G = 253; + B = 155; + color = ((R) << 16 | (G) << 8 | (B)); + + //inner layer + for(int i = 0; i < 1; i++) { + for(int j = height/3 -i; j < width; j++) { + int pixel = screen[pos+ j+ (i-1)*768]; + int R1 = (pixel&0xff0000) >> 16; + int G1 = (pixel&0xff00) >> 8; + int B1 = (pixel&0xff); + screen[pos+ j+ (i-1)*768] = (R1 + (R - R1)/4*3) << 16 | (G1 + (G - G1)/4*3) << 8 | (B1 + (B - B1)/4*3); + } + } + + for(int i = height; i < height+1; i++) { + for(int j = 0; j < width + 1 - (i + 1 - height/3*2); j++) { + int pixel = screen[pos+ j+ i*768]; + int R1 = (pixel&0xff0000) >> 16; + int G1 = (pixel&0xff00) >> 8; + int B1 = (pixel&0xff); + screen[pos+ j+ i*768] = (R1 + (R - R1)/4*3) << 16 | (G1 + (G - G1)/4*3) << 8 | (B1 + (B - B1)/4*3); + } + } + + for(int i = height/3+1; i < height + 1; i++) { + int pixel = screen[pos -1 + i*768]; + int R1 = (pixel&0xff0000) >> 16; + int G1 = (pixel&0xff00) >> 8; + int B1 = (pixel&0xff); + screen[pos -1 + i*768] = (R1 + (R - R1)/4*3) << 16 | (G1 + (G - G1)/4*3) << 8 | (B1 + (B - B1)/4*3); + } + + for(int i = -1; i < height/3*2 + 1; i++) { + int pixel = screen[pos + width + i*768]; + int R1 = (pixel&0xff0000) >> 16; + int G1 = (pixel&0xff00) >> 8; + int B1 = (pixel&0xff); + screen[pos + width + i*768] = (R1 + (R - R1)/4*3) << 16 | (G1 + (G - G1)/4*3) << 8 | (B1 + (B - B1)/4*3); + } + + for(int i = height/3 + 1; i > 0; i--) { + int pixel = screen[pos + height/3- i + (i-1)*768]; + int R1 = (pixel&0xff0000) >> 16; + int G1 = (pixel&0xff00) >> 8; + int B1 = (pixel&0xff); + screen[pos + height/3- i + (i-1)*768] = (R1 + (R - R1)/4*3) << 16 | (G1 + (G - G1)/4*3) << 8 | (B1 + (B - B1)/4*3); + } + + for(int i = height; i > height/3*2; i--) { + int pixel = screen[pos + width + height/3*2- i + (i)*768]; + int R1 = (pixel&0xff0000) >> 16; + int G1 = (pixel&0xff00) >> 8; + int B1 = (pixel&0xff); + screen[pos + width + height/3*2- i + (i)*768] = (R1 + (R - R1)/4*3) << 16 | (G1 + (G - G1)/4*3) << 8 | (B1 + (B - B1)/4*3); + } + + //outer layer + for(int i = 0; i < 1; i++) { + for(int j = height/3 -i; j < width+2; j++) { + int pixel = screen[pos+ j+ (i-2)*768]; + int R1 = (pixel&0xff0000) >> 16; + int G1 = (pixel&0xff00) >> 8; + int B1 = (pixel&0xff); + screen[pos+ j+ (i-2)*768] = (R1 + (R - R1)/3) << 16 | (G1 + (G - G1)/3) << 8 | (B1 + (B - B1)/3); + } + } + + for(int i = height + 1; i < height+2; i++) { + for(int j = -2; j < width + 2 - (i + 1 - height/3*2); j++) { + int pixel = screen[pos+ j+ i*768]; + int R1 = (pixel&0xff0000) >> 16; + int G1 = (pixel&0xff00) >> 8; + int B1 = (pixel&0xff); + screen[pos+ j+ i*768] = (R1 + (R - R1)/3) << 16 | (G1 + (G - G1)/3) << 8 | (B1 + (B - B1)/3); + } + } + + for(int i = height/3; i < height + 1; i++) { + int pixel = screen[pos -2 + i*768]; + int R1 = (pixel&0xff0000) >> 16; + int G1 = (pixel&0xff00) >> 8; + int B1 = (pixel&0xff); + screen[pos -2 + i*768] = (R1 + (R - R1)/3) << 16 | (G1 + (G - G1)/3) << 8 | (B1 + (B - B1)/3); + } + + for(int i = -1; i < height/3*2 + 1; i++) { + int pixel = screen[pos + 1 + width + i*768]; + int R1 = (pixel&0xff0000) >> 16; + int G1 = (pixel&0xff00) >> 8; + int B1 = (pixel&0xff); + screen[pos + width + 1 + i*768] = (R1 + (R - R1)/3) << 16 | (G1 + (G - G1)/3) << 8 | (B1 + (B - B1)/3); + } + + for(int i = height/3 + 1; i > 0; i--) { + int pixel = screen[pos + height/3- i + (i-2)*768]; + int R1 = (pixel&0xff0000) >> 16; + int G1 = (pixel&0xff00) >> 8; + int B1 = (pixel&0xff); + screen[pos + height/3- i + (i-2)*768] = (R1 + (R - R1)/3) << 16 | (G1 + (G - G1)/3) << 8 | (B1 + (B - B1)/3); + } + + for(int i = height + 1; i > height/3*2; i--) { + int pixel = screen[pos +1 + width + height/3*2- i + (i)*768]; + int R1 = (pixel&0xff0000) >> 16; + int G1 = (pixel&0xff00) >> 8; + int B1 = (pixel&0xff); + screen[pos + 1 + width + height/3*2- i + (i)*768] = (R1 + (R - R1)/3) << 16 | (G1 + (G - G1)/3) << 8 | (B1 + (B - B1)/3); + } + + } + + cursorIsOnTop = false; + } + +} diff --git a/gui/gameMenu.java b/gui/gameMenu.java index b13a498..af05639 100644 --- a/gui/gameMenu.java +++ b/gui/gameMenu.java @@ -1,20 +1,355 @@ package gui; +import java.util.ArrayList; + +import java.awt.Image; +import java.awt.image.PixelGrabber; + +import javax.imageio.ImageIO; import core.*; public class gameMenu { - public static int menuStatus = 0; + public int gameSuspendCount; + + public 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 int[] screen; + public int[] screenBlurBuffer; + public boolean gameStarted, gamePaused, gameEnded; + + public String imageFolder = ""; + + public int[] titleImage; + + public button newGame, unpauseGame, showHelp, quitGame, restartGame; + + ArrayList