This commit is contained in:
Pan 2019-05-24 23:44:45 +12:00
parent 850628ff9c
commit 4b66ded27c
5 changed files with 223 additions and 77 deletions

View File

@ -68,6 +68,9 @@ public class AssetManager {
public rocket[] rockets;
public polygon3D[] visionPolygon;
public int numberOfPlayerBuildings;
public int numberOfAIBuildings;
public void init(){
@ -217,6 +220,8 @@ public class AssetManager {
addConstructionVehicle(new constructionVehicle(new vector(29.625f,-0.3f, 28.875f), 90, 1));
constructionVehicles[1].expand();
numberOfPlayerBuildings = 1;
numberOfAIBuildings = 1;
//testing only
for(int i = 0; i < 6; i ++){
@ -245,7 +250,7 @@ public class AssetManager {
//harvester l = new harvester(new vector(i*0.25f+ 1.125f,-0.3f, 17.375f - 0.25f*j), 90, 0);
//addHarvester(l);
//l.hasMultiShotUpgrade = true;
lightTank l = new lightTank(new vector(i*0.25f + 1.125f,-0.3f, 0.5f + 18.625f + j*0.25f), 90, 0);
lightTank l = new lightTank(new vector(i*0.25f + 1.125f,-0.3f, 0.5f + 4.625f + j*0.25f), 90, 0);
//l.attackRange = 1.99f;
@ -461,8 +466,68 @@ public class AssetManager {
}
}
public void destoryAllUnit(int teamNo) {
for(int i = 0; i < lightTanks.length; i++){
if(lightTanks[i] != null && lightTanks[i].teamNo == teamNo){
lightTanks[i].currentHP = 0;
lightTanks[i].attacker = goldMines[0];
}
}
for(int i = 0; i < rocketTanks.length; i++){
if(rocketTanks[i] != null && rocketTanks[i].teamNo == teamNo){
rocketTanks[i].currentHP = 0;
rocketTanks[i].attacker = goldMines[0];
}
}
for(int i = 0; i < stealthTanks.length; i++){
if(stealthTanks[i] != null && stealthTanks[i].teamNo == teamNo){
stealthTanks[i].currentHP = 0;
stealthTanks[i].attacker = goldMines[0];
}
}
for(int i = 0; i < heavyTanks.length; i++){
if(heavyTanks[i] != null && heavyTanks[i].teamNo == teamNo){
heavyTanks[i].currentHP = 0;
heavyTanks[i].attacker = goldMines[0];
}
}
for(int i = 0; i < harvesters.length; i++){
if(harvesters[i] != null && harvesters[i].teamNo == teamNo){
harvesters[i].currentHP = 0;
harvesters[i].attacker = goldMines[0];
}
}
}
public void updateAndDraw(){
//check end game condition
//game ends when either player or the AI have lost all the buildings and construction vehicles
if(mainThread.gameStarted) {
if(!mainThread.playerVictory && !mainThread.AIVictory && !mainThread.afterMatch) {
if(numberOfAIBuildings == 0) {
mainThread.playerVictory = true;
mainThread.gamePaused = true;
destoryAllUnit(1);
}else if(numberOfPlayerBuildings == 0) {
mainThread.AIVictory = true;
mainThread.gamePaused = true;
destoryAllUnit(0);
}
}
if(mainThread.AIVictory || mainThread.playerVictory)
return;
}
polygonCount = 0;
visibleUnitCount = 0;
visionPolygonCount = 0;
@ -565,11 +630,13 @@ public class AssetManager {
Terrain.update();
int numberOfPlayerBuildings = 0;
int numberOfAIBuildings = 0;
//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
if(mainThread.gameStarted) {
numberOfPlayerBuildings = 0;
numberOfAIBuildings = 0;
int start = 381 * 768 + 3;
int start2 = 381 * 768 + 635;
for(int y = 0; y < 131; y++){
@ -747,17 +814,6 @@ public class AssetManager {
}
}
//check end game condition
//game ends when either player or the AI have lost all the buildings and construction vehicles
if(!mainThread.playerVictory && !mainThread.AIVictory && !mainThread.afterMatch) {
if(numberOfAIBuildings == 0) {
mainThread.playerVictory = true;
mainThread.gamePaused = true;
}else if(numberOfPlayerBuildings == 0) {
mainThread.AIVictory = true;
mainThread.gamePaused = true;
}
}
}
}

View File

@ -57,34 +57,44 @@ public class highscoreManager implements Runnable{
stmt = connect.createStatement();
ResultSet rs=stmt.executeQuery("select * from highscore where skillLevel = 0 order by finishingTime");
while(rs.next()) {
myResult[numOfRows][0] = rs.getString(1);
myResult[numOfRows][1] = secondsToString(rs.getInt(2));
numOfRows++;
if(numOfRows == 10)
break;
String playerName = rs.getString(1);
if(!hasDuplicateName(0, numOfRows, myResult, playerName)) {
myResult[numOfRows][0] = playerName;
myResult[numOfRows][1] = secondsToString(rs.getInt(2));
numOfRows++;
if(numOfRows == 10)
break;
}
}
numOfRows = 10;
rs=stmt.executeQuery("select * from highscore where skillLevel = 1 order by finishingTime");
while(rs.next()) {
myResult[numOfRows][0] = rs.getString(1);
myResult[numOfRows][1] = secondsToString(rs.getInt(2));
numOfRows++;
if(numOfRows == 20)
break;
String playerName = rs.getString(1);
if(!hasDuplicateName(10, numOfRows, myResult, playerName)) {
myResult[numOfRows][0] = rs.getString(1);
myResult[numOfRows][1] = secondsToString(rs.getInt(2));
numOfRows++;
if(numOfRows == 20)
break;
}
}
numOfRows = 20;
rs=stmt.executeQuery("select * from highscore where skillLevel = 2 order by finishingTime");
while(rs.next()) {
myResult[numOfRows][0] = rs.getString(1);
myResult[numOfRows][1] = secondsToString(rs.getInt(2));
numOfRows++;
if(numOfRows == 30)
break;
String playerName = rs.getString(1);
if(!hasDuplicateName(20, numOfRows, myResult, playerName)) {
myResult[numOfRows][0] = rs.getString(1);
myResult[numOfRows][1] = secondsToString(rs.getInt(2));
numOfRows++;
if(numOfRows == 30)
break;
}
}
result = myResult;
@ -117,6 +127,16 @@ public class highscoreManager implements Runnable{
}
public boolean hasDuplicateName(int start, int current, String[][] myResult, String name) {
for(int i = start; i < current; i++) {
if(myResult[i][0].toLowerCase().equals(name.toLowerCase())) {
return true;
}
}
return false;
}
public String secondsToString(int pTime) {
int min = pTime/60;
int sec = pTime-(min*60);

View File

@ -216,8 +216,12 @@ public class postProcessingThread implements Runnable{
isWorking = true;
}
if(!gamePaused)
if(!gamePaused) {
doPostProcesssing();
}
theGameMenu.updateAndDraw(currentScreen, gameStarted, gamePaused, playerVictory, AIVictory);

View File

@ -26,7 +26,8 @@ public class gameMenu {
public int[] titleImage, lightTankImage, rocketTankImage, stealthTankImage, heavyTankImage;
public button newGame, unpauseGame, showHelp, showOptions, showHighscores, quitGame, abortGame, easyGame, normalGame, hardGame, quitDifficulty, quitHelpMenu, quitOptionMenu, quitHighscoreMenu, nextPage, previousPage,
enableMouseCapture, disableMouseCapture, enableFogOfWar, disableFogOfWar, confirmErrorLoadingHighscore, normalToHardButton, normalToEasyButton;
enableMouseCapture, disableMouseCapture, enableFogOfWar, disableFogOfWar, confirmErrorLoadingHighscore, normalToHardButton, normalToEasyButton, hardToNormalButton, easyToNormalButton,
backToMapDefeat, leaveGameDefeat;
public char[] easyDescription, normalDescription, hardDescription, helpPage1, helpPage2, helpPage3, helpPage4, mouseMode;
@ -173,11 +174,23 @@ public class gameMenu {
confirmErrorLoadingHighscore = new button("confirmErrorLoadingHighscore", "Ok", 350, 280, 80, 25);
buttons.add(confirmErrorLoadingHighscore);
normalToHardButton = new button("normalToHardButton", "Hard", 503, 430, 80, 25);
normalToHardButton = new button("normalToHardButton", ">", 543, 430, 40, 25);
buttons.add(normalToHardButton);
normalToEasyButton = new button("normalToEasyButton", "Easy", 185, 430, 80, 25);
normalToEasyButton = new button("normalToEasyButton", "<", 185, 430, 40, 25);
buttons.add(normalToEasyButton);
hardToNormalButton = new button("hardToNormalButton", "<", 185, 430, 40, 25);
buttons.add(hardToNormalButton);
easyToNormalButton = new button("easyToNormalButton", ">", 543, 430, 40, 25);
buttons.add(easyToNormalButton);
backToMapDefeat = new button("backToMap", "Back to Map", 210, 235, 120, 25);
buttons.add(backToMapDefeat);
leaveGameDefeat = new button("abortGame", "Leave game", 440, 235, 120, 25);
buttons.add(leaveGameDefeat);
}
@ -194,20 +207,9 @@ public class gameMenu {
if(gameSuspendCount == 1) {
for(int i = 0; i < 512*768; i++)
screenBlurBuffer[i] = screen[i];
}
if(playerVictory || AIVictory) {
if(gameSuspendCount > 0) {
drawBluredBackground();
}
return;
}
//only show game menu when the game is not started or game is paused
if(!(!gameStarted || gamePaused))
return;
//make all buttons off screen and reduce their action cooldown
for (int i = 0; i < buttons.size(); i++) {
buttons.get(i).display = false;
@ -215,6 +217,34 @@ public class gameMenu {
buttons.get(i).actionCooldown--;
}
if(playerVictory || AIVictory) {
if(gameSuspendCount > 0) {
drawBluredBackground();
}
if(AIVictory) {
drawMenuFrame(400, 100, 70);
textRenderer tRenderer = postProcessingThread.theTextRenderer;
tRenderer.drawMenuText(320,178,"You are Defeated! ".toCharArray(), screen, 255,255,255, 0);
backToMapDefeat.display = true;
leaveGameDefeat.display = true;
}
updateButtons();
drawButtons();
return;
}
//only show game menu when the game is not started or game is paused
if(!(!gameStarted || gamePaused))
return;
if(menuStatus == mainMenu) {
currentHelpPage = 0;
@ -390,20 +420,22 @@ public class gameMenu {
int startRow = 0;
//draw high scores
if(highscoreLevel == 1) {
tRenderer.drawText_outline(280,100,"Highscores for normal difficulty", screen, 0xffffff,0);
tRenderer.drawText_outline(270,100,"Highscores For Normal Difficulty", screen, 0xffffff,0);
startRow = 10;
normalToHardButton.display = true;
normalToEasyButton.display = true;
}else if(highscoreLevel == 0) {
tRenderer.drawText_outline(280,100,"Highscores for easy difficulty", screen, 0xffffff,0);
tRenderer.drawText_outline(270,100,"Highscores For Easy Difficulty", screen, 0xffffff,0);
startRow = 0;
easyToNormalButton.display = true;
}else if(highscoreLevel == 2) {
tRenderer.drawText_outline(280,100,"Highscores for hard difficulty", screen, 0xffffff,0);
tRenderer.drawText_outline(270,100,"Highscores For Hard Difficulty", screen, 0xffffff,0);
startRow = 20;
hardToNormalButton.display = true;
}
tRenderer.drawText_outline(230,130," Rank Player Name Time", screen, 0xf2989d,0);
tRenderer.drawText_outline(230,135,"_____________________________________________", screen, 0xaaaaaa,0);
tRenderer.drawText_outline(220,130," Rank Player Name Time", screen, 0xf2989d,0);
tRenderer.drawText_outline(220,135,"_____________________________________________", screen, 0xaaaaaa,0);
for(int i = startRow; i < startRow + 10; i++) {
int color = 0xbbbbbb;
@ -414,15 +446,15 @@ public class gameMenu {
if(i -startRow == 2)
color = 0xc99684;
if(i -startRow == 9)
tRenderer.drawText_outline(220,160 + (i -startRow)*25, " " + (i -startRow + 1), screen, color,0);
tRenderer.drawText_outline(210,160 + (i -startRow)*25, " " + (i -startRow + 1), screen, color,0);
else
tRenderer.drawText_outline(223,160 + (i -startRow)*25, " " + (i -startRow + 1), screen, color,0);
tRenderer.drawText_outline(213,160 + (i -startRow)*25, " " + (i -startRow + 1), screen, color,0);
if(result[i][0] != null) {
int l = (30 - result[i][0].length())/2;
tRenderer.drawText_outline(230,160 + (i -startRow)*25, " " + result[i][1], screen, color,0);
tRenderer.drawText_outline(275 + l*7,160 + (i -startRow)*25, result[i][0], screen, color,0);
tRenderer.drawText_outline(220,160 + (i -startRow)*25, " " + result[i][1], screen, color,0);
tRenderer.drawText_outline(265 + l*7,160 + (i -startRow)*25, result[i][0], screen, color,0);
}
}
@ -480,6 +512,16 @@ public class gameMenu {
}
}else if(buttons.get(i).name == "quitHighscoreMenu" || buttons.get(i).name == "confirmErrorLoadingHighscore") {
quitHighscoreMenu();
}else if(buttons.get(i).name == "normalToHardButton") {
highscoreLevel = 2;
}else if(buttons.get(i).name == "hardToNormalButton") {
highscoreLevel = 1;
}else if(buttons.get(i).name == "easyToNormalButton") {
highscoreLevel = 1;
}else if(buttons.get(i).name == "normalToEasyButton") {
highscoreLevel = 0;
}else if(buttons.get(i).name == "abortGame") {
menuStatus = mainMenu;
}
postProcessingThread.buttonAction = buttons.get(i).name;
@ -522,7 +564,15 @@ public class gameMenu {
screen[i] = screenBlurBuffer[i];
}
public void drawMenuFrame(int width, int height) {
public void drawMenuFrame(int width, int height){
drawFrame(width, height, 0);
}
public void drawMenuFrame(int width, int height, int topDistance){
drawFrame(width, height, topDistance);
}
public void drawFrame(int width, int height, int topDistance) {
int R = 4;
@ -537,7 +587,7 @@ public class gameMenu {
int G2 = 70;
int B2 = 99;
int pos = (768 - width)/2 + 90 * 768;
int pos = (768 - width)/2 + (90+topDistance) * 768;
//background
@ -566,43 +616,43 @@ public class gameMenu {
}
//left
pos = (768 - width)/2 + 90 * 768;
pos = (768 - width)/2 + (90+topDistance) * 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;
pos = (768 - width)/2 + (90+topDistance) * 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;
pos = (768 - width)/2 + (90+topDistance) * 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;
pos = (768 - width)/2 + ((90+topDistance)+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;
pos = (768 - width)/2 + ((90+topDistance)+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;
pos = (768 - width)/2 + ((90+topDistance)+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;
pos = (768 - width)/2 + width - 18 + ((90+topDistance)+height+16) * 768;
for(int i = 2; i < 20; i++) {
int delta = (int)((17f/d)*i);
int pixel = screen[pos + i -2 + (-delta)*768];
@ -625,36 +675,36 @@ public class gameMenu {
//right
pos = (768 - width)/2 + width -3 + 75 * 768;
pos = (768 - width)/2 + width -3 + (75+topDistance) * 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;
pos = (768 - width)/2 + width -2+ (74+topDistance) * 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;
pos = (768 - width)/2 + width - 1 + (73+topDistance) * 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;
pos = (768 - width)/2 + ((90+topDistance)-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;
pos = (768 - width)/2 + ((90+topDistance)-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;
pos = (768 - width)/2 + ((90+topDistance)-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));
@ -662,7 +712,7 @@ public class gameMenu {
//top left
pos = (768 - width)/2 + 90 * 768;
pos = (768 - width)/2 + (90+topDistance) * 768;
for(int i = 0; i < 17; i++) {
int delta = (int)((d/17)*i);
for(int j = 20-delta-1; j < 20-delta; j++) {
@ -671,7 +721,7 @@ public class gameMenu {
}
}
pos = (768 - width)/2 + 2 + 90 * 768;
pos = (768 - width)/2 + 2 + (90+topDistance) * 768;
for(int i = 2; i < 17; i++) {
int delta = (int)((d/17)*i);
for(int j = 20-delta-1; j < 20-delta; j++) {
@ -680,7 +730,7 @@ public class gameMenu {
}
}
pos = (768 - width)/2 + 1 + 90 * 768;
pos = (768 - width)/2 + 1 + (90+topDistance) * 768;
for(int i = 0; i < 17; i++) {
int delta = (int)((d/17)*i);
for(int j = 20-delta-1; j < 20-delta; j++) {

View File

@ -318,8 +318,12 @@ public class inputHandler {
}else {
//handle event when game is paused
if(((escapeKeyPressed && escapePressedCooldown == 0)|| mainThread.buttonAction == "unpauseGame") && mainThread.gamePaused && mainThread.gameStarted && mainThread.menuStatus != mainThread.helpMenu) {
mainThread.gamePaused = false; //if game is paused, unpause the game when esc key is hit
escapePressedCooldown = 5;
if(!mainThread.AIVictory && ! mainThread.playerVictory) {
mainThread.gamePaused = false; //if game is paused, unpause the game when esc key is hit
escapePressedCooldown = 5;
}
}
//quit the game when the quit button is pressed
@ -359,6 +363,10 @@ public class inputHandler {
mainThread.gameStarted = false;
mainThread.gameFrame = 0;
mainThread.gamePaused = false;
mainThread.AIVictory = false;
mainThread.playerVictory = false;
mainThread.afterMatch = false;
mainThread.fogOfWarDisabled = false;
mainThread.theAssetManager.destoryAsset();
camera.MOVE_LEFT = false;
@ -369,6 +377,14 @@ public class inputHandler {
camera.TURN_RIGHT = false;
}
if(mainThread.gameStarted && mainThread.buttonAction == "backToMap") {
mainThread.AIVictory = false;
mainThread.playerVictory = false;
mainThread.afterMatch = true;
mainThread.gamePaused = false;
mainThread.fogOfWarDisabled = true;
}
//toggle mouse capture mode
if(mainThread.buttonAction == "enableMouseCapture") {
mainThread.capturedMouse = true;