home commit
This commit is contained in:
parent
a327f66010
commit
d8a7c2d77f
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -924,7 +924,7 @@ public class communicationCenter extends solidObject{
|
||||
}
|
||||
|
||||
if(isRepairing && currentHP >0){
|
||||
if(mainThread.frameIndex%8==0 && theBaseInfo.currentCredit > 0 && currentHP <maxHP){
|
||||
if(mainThread.gameFrame%8==0 && theBaseInfo.currentCredit > 0 && currentHP <maxHP){
|
||||
currentHP+=2;
|
||||
theBaseInfo.currentCredit--;
|
||||
if(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++){
|
||||
|
@ -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;
|
||||
|
@ -1241,7 +1241,7 @@ public class constructionYard extends solidObject{
|
||||
}
|
||||
|
||||
if(isRepairing && currentHP >0){
|
||||
if(mainThread.frameIndex%8==0 && theBaseInfo.currentCredit > 0 && currentHP <maxHP){
|
||||
if(mainThread.gameFrame%8==0 && theBaseInfo.currentCredit > 0 && currentHP <maxHP){
|
||||
currentHP+=2;
|
||||
theBaseInfo.currentCredit--;
|
||||
if(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){
|
||||
|
||||
|
@ -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
|
||||
|
@ -953,7 +953,7 @@ public class factory extends solidObject{
|
||||
}
|
||||
|
||||
if(isRepairing && currentHP >0){
|
||||
if(mainThread.frameIndex%8==0 && theBaseInfo.currentCredit > 0 && currentHP <maxHP){
|
||||
if(mainThread.gameFrame%8==0 && theBaseInfo.currentCredit > 0 && currentHP <maxHP){
|
||||
currentHP+=2;
|
||||
theBaseInfo.currentCredit--;
|
||||
if(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){
|
||||
|
@ -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 <maxHP){
|
||||
if(mainThread.gameFrame%5==0 && theBaseInfo.currentCredit > 0 && currentHP <maxHP){
|
||||
currentHP+=1;
|
||||
theBaseInfo.currentCredit--;
|
||||
}
|
||||
@ -654,7 +654,7 @@ public class gunTurret extends solidObject{
|
||||
//if there is no target, perform standby logic
|
||||
//scan for hostile unit
|
||||
|
||||
if((randomInt + mainThread.frameIndex)%240 == 0){
|
||||
if((randomInt + mainThread.gameFrame)%240 == 0){
|
||||
attackAngle = (int)(Math.random()*360);
|
||||
}
|
||||
if(turretAngle != attackAngle){
|
||||
@ -668,7 +668,7 @@ public class gunTurret 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++){
|
||||
|
@ -705,7 +705,7 @@ public class harvester extends solidObject{
|
||||
|
||||
//test if the tank object is visible in camera point of view
|
||||
if(visible_minimap){
|
||||
if(currentHP <= 130 && (mainThread.frameIndex + ID) % 3 ==0){
|
||||
if(currentHP <= 130 && (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;
|
||||
@ -1352,7 +1352,7 @@ public class harvester extends solidObject{
|
||||
|
||||
|
||||
if(obstacle != null){
|
||||
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;
|
||||
|
@ -376,12 +376,12 @@ public class heavyTank extends solidObject{
|
||||
if(experience >= 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++){
|
||||
|
@ -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++){
|
||||
|
@ -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 <maxHP){
|
||||
if(mainThread.gameFrame%5==0 && theBaseInfo.currentCredit > 0 && currentHP <maxHP){
|
||||
currentHP+=1;
|
||||
theBaseInfo.currentCredit--;
|
||||
}
|
||||
@ -679,7 +679,7 @@ public class missileTurret extends solidObject{
|
||||
accumulatedDelta= accumulatedDelta%360;
|
||||
if(visible){
|
||||
if(!overCharge){
|
||||
float ratio = ((float)Math.sin((float)(mainThread.frameIndex + ID)/10) + 1)/2;
|
||||
float ratio = ((float)Math.sin((float)(mainThread.gameFrame + ID)/10) + 1)/2;
|
||||
|
||||
if(theBaseInfo.lowPower)
|
||||
ratio = 0;
|
||||
@ -691,7 +691,7 @@ public class missileTurret extends solidObject{
|
||||
polygons[i].diffuse_I = 100;
|
||||
}
|
||||
}else{
|
||||
float ratio = ((float)Math.sin((float)(mainThread.frameIndex + ID)/10) + 1)/2;
|
||||
float ratio = ((float)Math.sin((float)(mainThread.gameFrame + ID)/10) + 1)/2;
|
||||
|
||||
if(theBaseInfo.lowPower)
|
||||
ratio = 0;
|
||||
@ -752,7 +752,7 @@ public class missileTurret extends solidObject{
|
||||
if(targetObject != null){
|
||||
|
||||
//target enemy military unit first
|
||||
if((targetObject.type > 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++){
|
||||
|
@ -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 <maxHP){
|
||||
if(mainThread.gameFrame%8==0 && theBaseInfo.currentCredit > 0 && currentHP <maxHP){
|
||||
currentHP+=2;
|
||||
theBaseInfo.currentCredit--;
|
||||
if(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;
|
||||
|
@ -825,7 +825,7 @@ public class refinery extends solidObject{
|
||||
}
|
||||
|
||||
if(isRepairing && currentHP >0){
|
||||
if(mainThread.frameIndex%8==0 && theBaseInfo.currentCredit > 0 && currentHP <maxHP){
|
||||
if(mainThread.gameFrame%8==0 && theBaseInfo.currentCredit > 0 && currentHP <maxHP){
|
||||
currentHP+=2;
|
||||
theBaseInfo.currentCredit--;
|
||||
if(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;
|
||||
|
@ -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++){
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
@ -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 <maxHP){
|
||||
if(mainThread.gameFrame%8==0 && theBaseInfo.currentCredit > 0 && currentHP <maxHP){
|
||||
currentHP+=2;
|
||||
theBaseInfo.currentCredit--;
|
||||
if(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;
|
||||
|
||||
|
||||
|
||||
|
2
gui/.gitignore
vendored
2
gui/.gitignore
vendored
@ -6,3 +6,5 @@
|
||||
/playerCommander.class
|
||||
/sideBarManager.class
|
||||
/gameMenu.class
|
||||
/button.class
|
||||
/textRenderer.class
|
||||
|
@ -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;
|
||||
|
176
gui/button.java
Normal file
176
gui/button.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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<button> buttons = new ArrayList<button>();
|
||||
|
||||
public void init() {
|
||||
if(titleImage == null)
|
||||
titleImage = new int[288*46];
|
||||
if(screenBlurBuffer == null)
|
||||
screenBlurBuffer = new int[512 * 768];
|
||||
|
||||
String folder = "../images/";
|
||||
loadTexture(folder + "title.png", titleImage, 216, 35);
|
||||
|
||||
newGame = new button("newGame", "New Game", 324, 110, 120, 28);
|
||||
buttons.add(newGame);
|
||||
|
||||
unpauseGame = new button("unpauseGame", "Resume Game", 324, 110, 120, 28);
|
||||
buttons.add(unpauseGame);
|
||||
|
||||
showHelp = new button("showHelp", "Help", 324, 160, 120, 28);
|
||||
buttons.add(showHelp);
|
||||
|
||||
quitGame = new button("quitGame", "Quit Game", 324, 345, 120, 28);
|
||||
buttons.add(quitGame);
|
||||
}
|
||||
|
||||
|
||||
public static void updateAndDraw(int[] screen, boolean gameStarted, boolean gamePaused) {
|
||||
public void updateAndDraw(int[] screen, boolean gameStarted, boolean gamePaused, boolean gameEnded) {
|
||||
this.screen = screen;
|
||||
this.gameStarted = gameStarted;
|
||||
this.gamePaused = gamePaused;
|
||||
this.gameEnded = gameEnded;
|
||||
|
||||
|
||||
if(gamePaused){
|
||||
gameSuspendCount++;
|
||||
}else {
|
||||
gameSuspendCount = 0;
|
||||
}
|
||||
|
||||
if(gameSuspendCount == 1) {
|
||||
for(int i = 0; i < 512*768; i++)
|
||||
screenBlurBuffer[i] = screen[i];
|
||||
}
|
||||
|
||||
|
||||
//only show game menu when the game is not started or game is paused or game has ended
|
||||
if(!(!gameStarted || gamePaused || gameEnded))
|
||||
return;
|
||||
|
||||
//make all buttons off screen and reduce their action cooldown
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
buttons.get(i).display = false;
|
||||
if(buttons.get(i).actionCooldown > 0)
|
||||
buttons.get(i).actionCooldown--;
|
||||
}
|
||||
|
||||
if(menuStatus == mainMenu) {
|
||||
|
||||
if(gameSuspendCount > 0) {
|
||||
drawBluredBackground();
|
||||
}
|
||||
|
||||
drawTitle();
|
||||
|
||||
drawMenuFrame(220, 300);
|
||||
|
||||
if(!gameStarted) {
|
||||
newGame.display = true;
|
||||
quitGame.display = true;
|
||||
}else {
|
||||
unpauseGame.display = true;
|
||||
|
||||
}
|
||||
|
||||
showHelp.display = true;
|
||||
|
||||
updateButtons();
|
||||
|
||||
drawButtons();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void updateButtons() {
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
if(buttons.get(i).checkIfCursorIsOnTop(postProcessingThread.mouse_x, postProcessingThread.mouse_y)) {
|
||||
if(postProcessingThread.leftMouseButtonReleased) {
|
||||
if(buttons.get(i).actionCooldown == 0) {
|
||||
postProcessingThread.buttonAction = buttons.get(i).name;
|
||||
buttons.get(i).actionCooldown = 15;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawButtons() {
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
buttons.get(i).draw(screen);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawBluredBackground() {
|
||||
if(gameSuspendCount < 6) {
|
||||
|
||||
for(int k = 0; k < 3; k++)
|
||||
for(int i = 1; i < 511; i++ ) {
|
||||
for(int j = 1; j < 767; j++) {
|
||||
int index = j + i*768;
|
||||
|
||||
|
||||
|
||||
int r = ((screenBlurBuffer[index]&0xff0000) >> 16) + ((screenBlurBuffer[index + 1]&0xff0000) >> 16) + ((screenBlurBuffer[index - 1]&0xff0000) >> 16) + ((screenBlurBuffer[index - 768]&0xff0000) >> 16) + ((screenBlurBuffer[index + 768]&0xff0000) >> 16);
|
||||
int g = ((screenBlurBuffer[index]&0xff00) >> 8) + ((screenBlurBuffer[index + 1]&0xff00) >> 8) + ((screenBlurBuffer[index - 1]&0xff00) >> 8) + ((screenBlurBuffer[index - 768]&0xff00) >> 8) + ((screenBlurBuffer[index + 768]&0xff00) >> 8);
|
||||
int b = (screenBlurBuffer[index]&0xff) + (screenBlurBuffer[index + 1]&0xff) + (screenBlurBuffer[index - 1]&0xff) + (screenBlurBuffer[index - 768]&0xff) + (screenBlurBuffer[index + 768]&0xff);
|
||||
|
||||
|
||||
|
||||
screenBlurBuffer[index] = (r/5) << 16 | (g/5) << 8 | (b/5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
for(int i = 0; i < 512*768; i++)
|
||||
screen[i] = screenBlurBuffer[i];
|
||||
}
|
||||
|
||||
public void drawMenuFrame(int width, int height) {
|
||||
|
||||
|
||||
int R = 4;
|
||||
int G = 94;
|
||||
int B = 132;
|
||||
|
||||
int R1 = 8;
|
||||
int G1 = 188;
|
||||
int B1 = 255;
|
||||
|
||||
int pos = (768 - width)/2 + 90 * 768;
|
||||
|
||||
|
||||
//background
|
||||
for(int i = 0; i < height; i++) {
|
||||
for(int j = 0; j < width; j++) {
|
||||
int pixel = screen[pos + j + i* 768];
|
||||
screen[pos + j + i* 768] = ((pixel&0xFEFEFE)>>1) + ((R/2) << 16 | (G/2) << 8 | (B/2));
|
||||
}
|
||||
}
|
||||
float d = 20f;
|
||||
for(int i = 0; i < 17; i++) {
|
||||
int delta = (int)((d/17)*i);
|
||||
for(int j = 20-delta-1; j < width; j++) {
|
||||
int pixel = screen[pos - 17*768 + j + i* 768];
|
||||
screen[pos - 17*768 + j + i* 768] = ((pixel&0xFEFEFE)>>1) + ((R/2) << 16 | (G/2) << 8 | (B/2));
|
||||
}
|
||||
}
|
||||
|
||||
pos+=(height+17)*768;
|
||||
for(int i = 0; i < 17; i++) {
|
||||
int delta = (int)((d/17)*i);
|
||||
for(int j =0; j < width - delta; j++) {
|
||||
int pixel = screen[pos - 17*768 + j + i* 768];
|
||||
screen[pos - 17*768 + j + i* 768] = ((pixel&0xFEFEFE)>>1) + ((R/2) << 16 | (G/2) << 8 | (B/2));
|
||||
}
|
||||
}
|
||||
|
||||
//left
|
||||
pos = (768 - width)/2 + 90 * 768;
|
||||
for(int i = 0; i < height + 17; i++) {
|
||||
int pixel = screen[pos + i*768];
|
||||
screen[pos + i*768] = pixel + ((R/2) << 16 | (G/2) << 8 | (B/2));
|
||||
}
|
||||
|
||||
pos = (768 - width)/2 + 90 * 768+1;
|
||||
for(int i = 0; i < height + 16; i++) {
|
||||
screen[pos + i*768] = ((R1) << 16 | (G1) << 8 | (B1));
|
||||
}
|
||||
|
||||
pos = (768 - width)/2 + 90 * 768 + 2;
|
||||
for(int i = 0; i < height + 15; i++) {
|
||||
int pixel = screen[pos + i*768];
|
||||
screen[pos + i*768] = pixel + ((R/3) << 16 | (G/3) << 8 | (B/3));
|
||||
}
|
||||
|
||||
//bottom
|
||||
pos = (768 - width)/2 + (90+height+14) * 768;
|
||||
for(int i = 3; i < width - 18; i++) {
|
||||
int pixel = screen[pos + i];
|
||||
screen[pos + i] = pixel + ((R/3) << 16 | (G/3) << 8 | (B/3));
|
||||
}
|
||||
|
||||
pos = (768 - width)/2 + (90+height+15) * 768;
|
||||
for(int i = 2; i < width - 18; i++) {
|
||||
screen[pos + i] = ((R1) << 16 | (G1) << 8 | (B1));
|
||||
}
|
||||
|
||||
pos = (768 - width)/2 + (90+height+16) * 768;
|
||||
for(int i = 1; i < width - 18; i++) {
|
||||
int pixel = screen[pos + i];
|
||||
screen[pos + i] = pixel + ((R/2) << 16 | (G/2) << 8 | (B/2));
|
||||
}
|
||||
|
||||
//bottom right
|
||||
pos = (768 - width)/2 + width - 18 + (90+height+16) * 768;
|
||||
for(int i = 2; i < 20; i++) {
|
||||
int delta = (int)((17f/d)*i);
|
||||
int pixel = screen[pos + i -2 + (-delta)*768];
|
||||
screen[pos + i - 2 + (-delta)*768] = pixel + ((R/2) << 16 | (G/2) << 8 | (B/2));
|
||||
}
|
||||
|
||||
for(int i = 2; i < 18; i++) {
|
||||
int delta = (int)((17f/d)*i);
|
||||
int pixel = screen[pos + i -2 + (-delta - 2)*768];
|
||||
screen[pos + i - 2 + (-delta - 2)*768] = pixel + ((R/3) << 16 | (G/3) << 8 | (B/3));
|
||||
}
|
||||
|
||||
for(int i = 2; i < 19; i++) {
|
||||
int delta = (int)((17f/d)*i);
|
||||
screen[pos + i - 2 + (-delta-1)*768] = ((R1) << 16 | (G1) << 8 | (B1));
|
||||
}
|
||||
screen[pos - 5*768 + 4] = ((R1) << 16 | (G1) << 8 | (B1));
|
||||
screen[pos - 11*768 + 11] = ((R1) << 16 | (G1) << 8 | (B1));
|
||||
|
||||
|
||||
|
||||
//right
|
||||
pos = (768 - width)/2 + width -3 + 75 * 768;
|
||||
for(int i = 0; i < height + 15; i++) {
|
||||
int pixel = screen[pos + i*768];
|
||||
screen[pos + i*768] = pixel + ((R/2) << 16 | (G/2) << 8 | (B/2));
|
||||
}
|
||||
|
||||
pos = (768 - width)/2 + width -2+ 74 * 768;
|
||||
for(int i = 0; i < height + 16; i++) {
|
||||
screen[pos + i*768] = ((R1) << 16 | (G1) << 8 | (B1));
|
||||
}
|
||||
|
||||
pos = (768 - width)/2 + width - 1 + 73 * 768;
|
||||
for(int i = 0; i < height + 17; i++) {
|
||||
int pixel = screen[pos + i*768];
|
||||
screen[pos + i*768] = pixel + ((R/3) << 16 | (G/3) << 8 | (B/3));
|
||||
}
|
||||
|
||||
//top
|
||||
pos = (768 - width)/2 + (90-17) * 768;
|
||||
for(int i = 20; i < width -1; i++) {
|
||||
int pixel = screen[pos + i];
|
||||
screen[pos + i] = pixel + ((R/2) << 16 | (G/2) << 8 | (B/2));
|
||||
}
|
||||
|
||||
pos = (768 - width)/2 + (90-16) * 768;
|
||||
for(int i = 20; i < width - 2; i++) {
|
||||
screen[pos + i] = ((R1) << 16 | (G1) << 8 | (B1));
|
||||
}
|
||||
|
||||
pos = (768 - width)/2 + (90-15) * 768;
|
||||
for(int i = 20; i < width - 3; i++) {
|
||||
int pixel = screen[pos + i];
|
||||
screen[pos + i] = pixel + ((R/3) << 16 | (G/3) << 8 | (B/3));
|
||||
}
|
||||
|
||||
|
||||
//top left
|
||||
pos = (768 - width)/2 + 90 * 768;
|
||||
for(int i = 0; i < 17; i++) {
|
||||
int delta = (int)((d/17)*i);
|
||||
for(int j = 20-delta-1; j < 20-delta; j++) {
|
||||
int pixel = screen[pos - 17*768 + j + i* 768];
|
||||
screen[pos - 17*768 + j + i* 768] = pixel + ((R/2) << 16 | (G/2) << 8 | (B/2));
|
||||
}
|
||||
}
|
||||
|
||||
pos = (768 - width)/2 + 2 + 90 * 768;
|
||||
for(int i = 2; i < 17; i++) {
|
||||
int delta = (int)((d/17)*i);
|
||||
for(int j = 20-delta-1; j < 20-delta; j++) {
|
||||
int pixel = screen[pos - 17*768 + j + i* 768];
|
||||
screen[pos - 17*768 + j + i* 768] = pixel + ((R/3) << 16 | (G/3) << 8 | (B/3));
|
||||
}
|
||||
}
|
||||
|
||||
pos = (768 - width)/2 + 1 + 90 * 768;
|
||||
for(int i = 0; i < 17; i++) {
|
||||
int delta = (int)((d/17)*i);
|
||||
for(int j = 20-delta-1; j < 20-delta; j++) {
|
||||
int pixel = screen[pos - 17*768 + j + i* 768];
|
||||
screen[pos - 17*768 + j + i* 768] = ((R1) << 16 | (G1) << 8 | (B1));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void drawTitle() {
|
||||
int pos = 276 + 35*768;
|
||||
|
||||
for(int i = 0; i < 35; i++) {
|
||||
for(int j = 0; j < 216; j++) {
|
||||
int c = titleImage[j + i*216];
|
||||
if(!((c&0xff0000 >> 16) > 254 && (c&0x00ff00 >> 8) > 254 && ((c&0xff) > 254)))
|
||||
screen[pos+ 768*i + j] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadTexture(String imgName, int[] buffer, int width, int height){
|
||||
Image img = null;
|
||||
try{
|
||||
img = ImageIO.read(getClass().getResource(imageFolder + imgName));
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, buffer, 0, width);
|
||||
try {
|
||||
pg.grabPixels();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -252,8 +252,17 @@ public class inputHandler {
|
||||
if(escapeKeyReleased && mainThread.gameStarted)
|
||||
mainThread.gamePaused = false; //if game is paused, unpause the game when esc key is hit
|
||||
|
||||
//quit the game when the quit button is pressed
|
||||
if(!mainThread.gameStarted) {
|
||||
if(mainThread.buttonAction == "quitGame")
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(leftMouseButtonReleased)
|
||||
mainThread.leftMouseButtonReleased = true;
|
||||
|
||||
|
||||
mouseIsInsideScreen = false;
|
||||
leftMouseButtonPressed = false;
|
||||
|
@ -1,10 +1,12 @@
|
||||
package core;
|
||||
package gui;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.image.PixelGrabber;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import core.mainThread;
|
||||
|
||||
//handle text rendering
|
||||
|
||||
|
||||
@ -81,7 +83,7 @@ public class textRenderer {
|
||||
|
||||
char[] theText = text.toCharArray();
|
||||
|
||||
int t = (int)(35 * Math.sin((double)mainThread.frameIndex/7)) + 35;
|
||||
int t = (int)(35 * Math.sin((double)mainThread.gameFrame/7)) + 35;
|
||||
if(t > 64)
|
||||
t = 64;
|
||||
|
BIN
images/title.png
Normal file
BIN
images/title.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
Loading…
x
Reference in New Issue
Block a user