Home commit before adding game menu
This commit is contained in:
parent
7a94718937
commit
af1fe0338a
@ -508,14 +508,14 @@ public class AssetManager {
|
|||||||
|
|
||||||
//start drawing
|
//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
|
//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;
|
int start2 = 381 * 768 + 635;
|
||||||
for(int y = 0; y < 131; y++){
|
for(int y = 0; y < 131; y++){
|
||||||
for(int x = 0; x < 128; x ++){
|
for(int x = 0; x < 128; x ++){
|
||||||
mainThread.zBuffer[start + x + y*768] = Integer.MAX_VALUE;
|
mainThread.zBuffer[start + x + y*768] = Integer.MAX_VALUE;
|
||||||
mainThread.zBuffer[start2 + 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 int framePerSecond, cpuUsage;
|
||||||
public static double thisTime, lastTime;
|
public static double thisTime, lastTime;
|
||||||
public static boolean JavaRTSLoaded;
|
public static boolean JavaRTSLoaded;
|
||||||
public static boolean inGame;
|
public static boolean gamePaused, gameStarted;
|
||||||
public static texture[] textures;
|
public static texture[] textures;
|
||||||
public static byte[][] lightMapTextures;
|
public static byte[][] lightMapTextures;
|
||||||
public static int[][] lightMapTexturesInfo;
|
public static int[][] lightMapTexturesInfo;
|
||||||
@ -134,7 +134,7 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
|
|||||||
JavaRTSLoaded = true;
|
JavaRTSLoaded = true;
|
||||||
|
|
||||||
//test only
|
//test only
|
||||||
inGame = true;
|
gamePaused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -184,27 +184,28 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
|
|||||||
theAssetManager.prepareAssetForNewGame();
|
theAssetManager.prepareAssetForNewGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
gridMap.update();
|
if(!gamePaused) {
|
||||||
|
|
||||||
|
gridMap.update();
|
||||||
|
|
||||||
//Clears the z-buffer. All depth values are set to 0.
|
//Clears the z-buffer. All depth values are set to 0.
|
||||||
clearDepthBuffer();
|
clearDepthBuffer();
|
||||||
|
|
||||||
//update camera
|
//update camera
|
||||||
Camera.update();
|
Camera.update();
|
||||||
|
|
||||||
//update light source
|
//update light source
|
||||||
sunLight.update();
|
sunLight.update();
|
||||||
|
|
||||||
//update and draw 3D mashes from game objects
|
//update and draw 3D mashes from game objects
|
||||||
theAssetManager.updateAndDraw();
|
theAssetManager.updateAndDraw();
|
||||||
|
|
||||||
pc.update();
|
pc.update();
|
||||||
ec.update();
|
ec.update();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//show inpassible obstacle
|
||||||
//gridMap.draw();
|
//gridMap.draw();
|
||||||
|
|
||||||
if(this.getGraphics() != null && PPT!= null){
|
if(this.getGraphics() != null && PPT!= null){
|
||||||
@ -268,7 +269,9 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
|
|||||||
inputHandler.rightKeyPressed = true;
|
inputHandler.rightKeyPressed = true;
|
||||||
else if(e.getKeyCode() == KeyEvent.VK_CONTROL)
|
else if(e.getKeyCode() == KeyEvent.VK_CONTROL)
|
||||||
inputHandler.controlKeyPressed = true;
|
inputHandler.controlKeyPressed = true;
|
||||||
|
else if(e.getKeyCode() == KeyEvent.VK_ESCAPE)
|
||||||
|
inputHandler.escapeKeyPressed = true;
|
||||||
|
|
||||||
inputHandler.readCharacter(e.getKeyChar());
|
inputHandler.readCharacter(e.getKeyChar());
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -280,6 +283,8 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
|
|||||||
inputHandler.rightKeyPressed = false;
|
inputHandler.rightKeyPressed = false;
|
||||||
else if(e.getKeyCode() == KeyEvent.VK_CONTROL)
|
else if(e.getKeyCode() == KeyEvent.VK_CONTROL)
|
||||||
inputHandler.controlKeyPressed = false;
|
inputHandler.controlKeyPressed = false;
|
||||||
|
else if(e.getKeyCode() == KeyEvent.VK_ESCAPE)
|
||||||
|
inputHandler.escapeKeyReleased = true;
|
||||||
|
|
||||||
inputHandler.handleKeyRelease(e.getKeyChar());
|
inputHandler.handleKeyRelease(e.getKeyChar());
|
||||||
}
|
}
|
||||||
@ -292,7 +297,6 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void mouseDragged(MouseEvent e) {
|
public void mouseDragged(MouseEvent e) {
|
||||||
inputHandler.mouse_x = e.getX();
|
inputHandler.mouse_x = e.getX();
|
||||||
inputHandler.mouse_y = e.getY();
|
inputHandler.mouse_y = e.getY();
|
||||||
@ -495,7 +499,7 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
|
|||||||
|
|
||||||
|
|
||||||
sleepTime = 0;
|
sleepTime = 0;
|
||||||
/*while(System.currentTimeMillis()-lastDraw<frameInterval){
|
while(System.currentTimeMillis()-lastDraw<frameInterval){
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1);
|
Thread.sleep(1);
|
||||||
@ -504,7 +508,7 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
|
|||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
lastDraw=System.currentTimeMillis();
|
lastDraw=System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +71,8 @@ public class postProcessingThread implements Runnable{
|
|||||||
|
|
||||||
public static textRenderer theTextRenderer;
|
public static textRenderer theTextRenderer;
|
||||||
|
|
||||||
|
public static boolean gamePaused;
|
||||||
|
|
||||||
//A pool of vectors which will be used for vector arithmetic
|
//A pool of vectors which will be used for vector arithmetic
|
||||||
public static vector
|
public static vector
|
||||||
tempVector1 = new vector(0,0,0),
|
tempVector1 = new vector(0,0,0),
|
||||||
@ -171,6 +173,7 @@ public class postProcessingThread implements Runnable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run(){
|
public void run(){
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
try {
|
try {
|
||||||
@ -189,7 +192,8 @@ public class postProcessingThread implements Runnable{
|
|||||||
isWorking = true;
|
isWorking = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
doPostProcesssing();
|
if(!gamePaused)
|
||||||
|
doPostProcesssing();
|
||||||
frameIndex++;
|
frameIndex++;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -957,6 +961,7 @@ public class postProcessingThread implements Runnable{
|
|||||||
|
|
||||||
playerMoney = mainThread.pc.theBaseInfo.currentCredit;
|
playerMoney = mainThread.pc.theBaseInfo.currentCredit;
|
||||||
playerPowerStatus = mainThread.pc.theBaseInfo.powerStatus;
|
playerPowerStatus = mainThread.pc.theBaseInfo.powerStatus;
|
||||||
|
gamePaused = mainThread.gamePaused;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,8 @@ public class combatManagerAI {
|
|||||||
|
|
||||||
public boolean staticDefenseAhead;
|
public boolean staticDefenseAhead;
|
||||||
|
|
||||||
|
public boolean staticDefenseNearAttackPosition;
|
||||||
|
|
||||||
public boolean dealWithMajorThreat;
|
public boolean dealWithMajorThreat;
|
||||||
|
|
||||||
public boolean unitCountLow;
|
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
|
//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;
|
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(d > teamRadius){
|
||||||
if(!playerForceIsMuchWeakerThanAI || mainThread.ec.theMapAwarenessAI.playerAssetDestoryedCountDown == 0)
|
if(staticDefenseNearAttackPosition || !playerForceIsMuchWeakerThanAI || mainThread.ec.theMapAwarenessAI.playerAssetDestoryedCountDown == 0)
|
||||||
team[i].attackMoveTo(gatherPoint.x, gatherPoint.z);
|
team[i].attackMoveTo(gatherPoint.x, gatherPoint.z);
|
||||||
else
|
else
|
||||||
team[i].attackMoveTo(team[i].centre.x + attackDirection.x*teamRadius, team[i].centre.z + attackDirection.z*teamRadius);
|
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
|
//make decision on what tech to research
|
||||||
if(mainThread.ec.theBuildingManagerAI.theBaseInfo.numberOfCommunicationCenter > 0) {
|
if(mainThread.ec.theBuildingManagerAI.theBaseInfo.numberOfCommunicationCenter > 0) {
|
||||||
if(mainThread.ec.theDefenseManagerAI.needMissileTurret || theBaseInfo.currentCredit > 1500) {
|
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
|
//Immediately start stealth tank upgrades when a tech center is built
|
||||||
if(!techCenter.stealthTankResearched_enemy){
|
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.cancelResearch(1);
|
||||||
techCenter.researchStealthTank(1);
|
techCenter.researchStealthTank(1);
|
||||||
System.out.println("----------------------------AI starts researching stealth tank------------------------------------");
|
System.out.println("----------------------------AI starts researching stealth tank------------------------------------");
|
||||||
@ -204,16 +214,6 @@ public class unitProductionAI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//System.out.println("enemy light tank count: " + numberOfLightTanks_player + " at " + mainThread.frameIndex/30);
|
|
||||||
if(currentProductionOrder == produceStealthTank)
|
|
||||||
System.out.println("should make stealth tank now--------------");
|
|
||||||
if(currentProductionOrder == produceHeavyTank)
|
|
||||||
System.out.println("should make Heavy tank now-----------------");
|
|
||||||
if(currentProductionOrder == produceRocketTank)
|
|
||||||
System.out.println("should make Rocket tank now----------------");
|
|
||||||
|
|
||||||
|
|
||||||
if(numberOfRocketTanks_AI > 2 && theBaseInfo.currentCredit > 750 && (numberOfPlayerGunTurrets > 0 || numberOfPlayerMissileTurrets > 0)){
|
if(numberOfRocketTanks_AI > 2 && theBaseInfo.currentCredit > 750 && (numberOfPlayerGunTurrets > 0 || numberOfPlayerMissileTurrets > 0)){
|
||||||
if(!techCenter.rocketTankResearched_enemy){
|
if(!techCenter.rocketTankResearched_enemy){
|
||||||
|
@ -12,8 +12,20 @@ public class inputHandler {
|
|||||||
|
|
||||||
public static int mouse_x, mouse_y,mouse_x0, mouse_x1, mouse_y0, mouse_y1, cameraMovementAngle;
|
public static int mouse_x, mouse_y,mouse_x0, mouse_x1, mouse_y0, mouse_y1, cameraMovementAngle;
|
||||||
|
|
||||||
public static boolean mouseIsInsideScreen, leftKeyPressed, rightKeyPressed, controlKeyPressed, leftMouseButtonPressed, rightMouseButtonPressed, leftMouseButtonReleased, rightMouseButtonReleased, H_pressed,A_pressed, userIsHoldingA;
|
public static boolean mouseIsInsideScreen, userIsHoldingA;
|
||||||
|
|
||||||
|
public static boolean leftKeyPressed,
|
||||||
|
rightKeyPressed,
|
||||||
|
controlKeyPressed,
|
||||||
|
leftMouseButtonPressed,
|
||||||
|
rightMouseButtonPressed,
|
||||||
|
leftMouseButtonReleased,
|
||||||
|
rightMouseButtonReleased,
|
||||||
|
H_pressed,
|
||||||
|
A_pressed,
|
||||||
|
escapeKeyPressed,
|
||||||
|
escapeKeyReleased;
|
||||||
|
|
||||||
public static int numberTyped;
|
public static int numberTyped;
|
||||||
|
|
||||||
public static final Rectangle mouseMovementArea = new Rectangle(30,20, 708, 472);
|
public static final Rectangle mouseMovementArea = new Rectangle(30,20, 708, 472);
|
||||||
@ -24,15 +36,20 @@ public class inputHandler {
|
|||||||
public static int inputCounter, inputBufferIndex, keyReleaseCounter, keyReleaseBufferIndex;
|
public static int inputCounter, inputBufferIndex, keyReleaseCounter, keyReleaseBufferIndex;
|
||||||
|
|
||||||
public static void processInput(){
|
public static void processInput(){
|
||||||
|
|
||||||
|
|
||||||
//read input char
|
//read input char
|
||||||
int theCounter = inputCounter;
|
int theCounter = inputCounter;
|
||||||
|
|
||||||
//handle over flow
|
//handle over flow
|
||||||
if(inputBufferIndex > theCounter){
|
if(inputBufferIndex > theCounter){
|
||||||
while(inputBufferIndex < 1024){
|
while(inputBufferIndex < 1024){
|
||||||
char c = inputBuffer[inputBufferIndex];
|
char c = inputBuffer[inputBufferIndex];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(c == 'h' || c == 'H'){
|
if(c == 'h' || c == 'H'){
|
||||||
|
|
||||||
H_pressed = true;
|
H_pressed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,10 +63,12 @@ public class inputHandler {
|
|||||||
|
|
||||||
|
|
||||||
inputBufferIndex++;
|
inputBufferIndex++;
|
||||||
|
|
||||||
}
|
}
|
||||||
inputBufferIndex = 0;
|
inputBufferIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
while(inputBufferIndex < theCounter){
|
while(inputBufferIndex < theCounter){
|
||||||
char c = inputBuffer[inputBufferIndex];
|
char c = inputBuffer[inputBufferIndex];
|
||||||
|
|
||||||
@ -68,6 +87,7 @@ public class inputHandler {
|
|||||||
|
|
||||||
inputBufferIndex++;
|
inputBufferIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//read released char
|
//read released char
|
||||||
theCounter = keyReleaseCounter;
|
theCounter = keyReleaseCounter;
|
||||||
@ -104,7 +124,7 @@ public class inputHandler {
|
|||||||
|
|
||||||
|
|
||||||
//handle input when game is running
|
//handle input when game is running
|
||||||
if(mainThread.inGame){
|
if(!mainThread.gamePaused){
|
||||||
if(!mainThread.pc.isSelectingUnit){
|
if(!mainThread.pc.isSelectingUnit){
|
||||||
mouse_x0 = mouse_x;
|
mouse_x0 = mouse_x;
|
||||||
mouse_y0 = mouse_y;
|
mouse_y0 = mouse_y;
|
||||||
@ -214,13 +234,24 @@ public class inputHandler {
|
|||||||
|
|
||||||
//handle hotheys
|
//handle hotheys
|
||||||
if(A_pressed){
|
if(A_pressed){
|
||||||
|
|
||||||
if(!userIsHoldingA){
|
if(!userIsHoldingA){
|
||||||
mainThread.pc.attackKeyPressed = true;
|
mainThread.pc.attackKeyPressed = true;
|
||||||
userIsHoldingA = 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;
|
rightMouseButtonPressed = false;
|
||||||
leftMouseButtonReleased = false;
|
leftMouseButtonReleased = false;
|
||||||
rightMouseButtonReleased = false;
|
rightMouseButtonReleased = false;
|
||||||
|
escapeKeyPressed = false;
|
||||||
|
escapeKeyReleased = false;
|
||||||
|
|
||||||
A_pressed = false;
|
A_pressed = false;
|
||||||
|
H_pressed = false;
|
||||||
numberTyped = 0;
|
numberTyped = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user