Home commit before adding game menu
This commit is contained in:
parent
7a94718937
commit
af1fe0338a
@ -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;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
@ -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();
|
||||
if(!gamePaused) {
|
||||
|
||||
gridMap.update();
|
||||
|
||||
//Clears the z-buffer. All depth values are set to 0.
|
||||
clearDepthBuffer();
|
||||
|
||||
//Clears the z-buffer. All depth values are set to 0.
|
||||
clearDepthBuffer();
|
||||
//update camera
|
||||
Camera.update();
|
||||
|
||||
//update camera
|
||||
Camera.update();
|
||||
//update light source
|
||||
sunLight.update();
|
||||
|
||||
//update light source
|
||||
sunLight.update();
|
||||
|
||||
//update and draw 3D mashes from game objects
|
||||
theAssetManager.updateAndDraw();
|
||||
|
||||
pc.update();
|
||||
ec.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,6 +269,8 @@ 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<frameInterval){
|
||||
while(System.currentTimeMillis()-lastDraw<frameInterval){
|
||||
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
@ -504,7 +508,7 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
lastDraw=System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
@ -71,6 +71,8 @@ public class postProcessingThread implements Runnable{
|
||||
|
||||
public static textRenderer theTextRenderer;
|
||||
|
||||
public static boolean gamePaused;
|
||||
|
||||
//A pool of vectors which will be used for vector arithmetic
|
||||
public static vector
|
||||
tempVector1 = new vector(0,0,0),
|
||||
@ -171,6 +173,7 @@ public class postProcessingThread implements Runnable{
|
||||
}
|
||||
|
||||
public void run(){
|
||||
|
||||
while(true){
|
||||
synchronized (this) {
|
||||
try {
|
||||
@ -189,7 +192,8 @@ public class postProcessingThread implements Runnable{
|
||||
isWorking = true;
|
||||
}
|
||||
|
||||
doPostProcesssing();
|
||||
if(!gamePaused)
|
||||
doPostProcesssing();
|
||||
frameIndex++;
|
||||
|
||||
}
|
||||
@ -957,6 +961,7 @@ public class postProcessingThread implements Runnable{
|
||||
|
||||
playerMoney = mainThread.pc.theBaseInfo.currentCredit;
|
||||
playerPowerStatus = mainThread.pc.theBaseInfo.powerStatus;
|
||||
gamePaused = mainThread.gamePaused;
|
||||
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,8 @@ public class combatManagerAI {
|
||||
|
||||
public boolean staticDefenseAhead;
|
||||
|
||||
public boolean staticDefenseNearAttackPosition;
|
||||
|
||||
public boolean dealWithMajorThreat;
|
||||
|
||||
public boolean unitCountLow;
|
||||
@ -374,7 +376,20 @@ public class combatManagerAI {
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(staticDefenseAhead + " " + attackPosition);
|
||||
staticDefenseNearAttackPosition = false;
|
||||
for(int i = 0; i < mainThread.ec.theMapAwarenessAI.playerStaticDefenseLocations.length; i++) {
|
||||
if(mainThread.ec.theMapAwarenessAI.playerStaticDefenseSize[i] > 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);
|
||||
|
@ -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------------------------------------");
|
||||
@ -205,16 +215,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){
|
||||
if(techCenter.lightTankResearchProgress_enemy >= 240 && techCenter.stealthTankResearchProgress_enemy >= 240 && techCenter.rocketTankResearchProgress_enemy >= 240 && techCenter.heavyTankResearchProgress_enemy >= 240){
|
||||
|
@ -12,7 +12,19 @@ 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;
|
||||
|
||||
@ -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];
|
||||
|
||||
@ -69,6 +88,7 @@ public class inputHandler {
|
||||
inputBufferIndex++;
|
||||
}
|
||||
|
||||
|
||||
//read released char
|
||||
theCounter = keyReleaseCounter;
|
||||
//handle over flow
|
||||
@ -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;
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user