home commit
This commit is contained in:
parent
d8a7c2d77f
commit
48d5716b55
@ -135,6 +135,11 @@ public class AssetManager {
|
||||
}
|
||||
|
||||
public void prepareAssetForNewGame(){
|
||||
|
||||
camera.position.set(3,2f,-1.25f);
|
||||
camera.view_Direction.set(0, 0, 1);
|
||||
camera.XZ_angle = 0;
|
||||
|
||||
|
||||
selectedUnitsInfo = new int[100][6];
|
||||
selectedUnitsInfo2 = new int[100][6];
|
||||
@ -247,11 +252,70 @@ public class AssetManager {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void destoryAsset() {
|
||||
camera.view_Direction.set(0, 0, 1);
|
||||
camera.frameIndex = 0;
|
||||
camera.XZ_angle = 0;
|
||||
|
||||
selectedUnitsInfo = null;
|
||||
selectedUnitsInfo2 = null;
|
||||
|
||||
visionPolygonInfo = null;
|
||||
visionPolygonInfo2 = null;
|
||||
|
||||
unitsForMiniMap = null;
|
||||
unitsForMiniMap2 = null;
|
||||
|
||||
|
||||
smokeEmmiterList = null;
|
||||
smokeEmmiterList2 = null;
|
||||
|
||||
minimapBitmap = null;
|
||||
minimapBitmap2 = null;
|
||||
|
||||
|
||||
explosionInfo = null;
|
||||
explosionInfo2 = null;
|
||||
helixInfo = null;
|
||||
helixInfo2 = null;
|
||||
|
||||
confirmationIconInfo = null;
|
||||
confirmationIconInfo2 = null;
|
||||
|
||||
lightTanks = null;
|
||||
heavyTanks = null;
|
||||
powerPlants = null;
|
||||
refineries = null;
|
||||
rocketTanks = null;
|
||||
harvesters = null;
|
||||
constructionVehicles = null;
|
||||
constructionYards = null;
|
||||
factories = null;
|
||||
drones = null;
|
||||
communicationCenters = null;
|
||||
techCenters = null;
|
||||
stealthTanks = null;
|
||||
gunTurrets = null;
|
||||
missileTurrets = null;
|
||||
|
||||
goldMines[0].goldDeposite = 45000;
|
||||
goldMines[1].goldDeposite = 45000;
|
||||
goldMines[2].goldDeposite = 50000;
|
||||
goldMines[3].goldDeposite = 50000;
|
||||
goldMines[4].goldDeposite = 45000;
|
||||
goldMines[5].goldDeposite = 45000;
|
||||
goldMines[6].goldDeposite = 55000;
|
||||
goldMines[7].goldDeposite = 55000;
|
||||
|
||||
bullets = null;
|
||||
rockets = null;
|
||||
|
||||
mainThread.gridMap.reset();
|
||||
}
|
||||
|
||||
|
||||
public void addContructionYard(constructionYard o){
|
||||
for(int i = 0; i < constructionYards.length; i++){
|
||||
if(constructionYards[i] == null){
|
||||
|
@ -19,7 +19,6 @@ public class grid {
|
||||
previousObstacleMap[i] = true;
|
||||
currentObstacleMap[i] = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void update(){
|
||||
@ -37,7 +36,21 @@ public class grid {
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
|
||||
for(int i = 0; i < size * size; i++){
|
||||
previousObstacleMap[i] = true;
|
||||
currentObstacleMap[i] = true;
|
||||
|
||||
for(int j = 0; j < 5; j++) {
|
||||
if(tiles[i][j] != null && tiles[i][j].teamNo != -1)
|
||||
tiles[i][j] = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void draw(){
|
||||
|
@ -50,8 +50,15 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
|
||||
public static short[] displacementBuffer;
|
||||
public static short[] displacementBuffer2;
|
||||
|
||||
public static boolean leftMouseButtonReleased;
|
||||
public static boolean leftMouseButtonReleased, escapeKeyReleased;
|
||||
public static String buttonAction;
|
||||
public static 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 static String timeString;
|
||||
|
||||
public mainThread(){
|
||||
setTitle("Battle Tank 3");
|
||||
@ -168,7 +175,6 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
|
||||
|
||||
|
||||
frameIndex++;
|
||||
|
||||
|
||||
inputHandler.processInput();
|
||||
|
||||
@ -176,6 +182,8 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
|
||||
if(gameStarted)
|
||||
gameFrame++;
|
||||
|
||||
timeString = secondsToString(gameFrame/30);
|
||||
|
||||
//handle user's interaction with game GUI
|
||||
if(gameFrame == 1 && gameStarted){
|
||||
theAssetManager.prepareAssetForNewGame();
|
||||
@ -511,7 +519,19 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
|
||||
}
|
||||
lastDraw=System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public static String secondsToString(int pTime) {
|
||||
int min = pTime/60;
|
||||
int sec = pTime-(min*60);
|
||||
|
||||
String strMin = placeZeroIfNeede(min);
|
||||
String strSec = placeZeroIfNeede(sec);
|
||||
return String.format("%s:%s",strMin,strSec);
|
||||
}
|
||||
|
||||
public static String placeZeroIfNeede(int number) {
|
||||
return (number >=10)? Integer.toString(number):String.format("0%s",Integer.toString(number));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focusGained(FocusEvent arg0) {
|
||||
|
@ -78,9 +78,11 @@ public class postProcessingThread implements Runnable{
|
||||
public static boolean gamePaused, gameStarted, gameEnded;
|
||||
|
||||
public static int mouse_x, mouse_y;
|
||||
public static boolean leftMouseButtonReleased;
|
||||
public static boolean leftMouseButtonReleased, escapeKeyReleased;
|
||||
public static String buttonAction;
|
||||
|
||||
public static String timeString;
|
||||
|
||||
|
||||
//A pool of vectors which will be used for vector arithmetic
|
||||
public static vector
|
||||
@ -952,6 +954,8 @@ public class postProcessingThread implements Runnable{
|
||||
gameStarted = mainThread.gameStarted;
|
||||
gameEnded = mainThread.gameEnded;
|
||||
|
||||
timeString = mainThread.timeString;
|
||||
|
||||
currentScreen = mainThread.screen;
|
||||
currentZbuffer = mainThread.zBuffer;
|
||||
displacementBuffer = mainThread.displacementBuffer;
|
||||
@ -987,11 +991,14 @@ public class postProcessingThread implements Runnable{
|
||||
mouse_x = inputHandler.mouse_x;
|
||||
mouse_y = inputHandler.mouse_y;
|
||||
leftMouseButtonReleased = mainThread.leftMouseButtonReleased;
|
||||
escapeKeyReleased = mainThread.escapeKeyReleased;
|
||||
mainThread.leftMouseButtonReleased = false;
|
||||
mainThread.escapeKeyReleased = false;
|
||||
|
||||
//feed main thread with button action
|
||||
mainThread.buttonAction = buttonAction;
|
||||
buttonAction = null;
|
||||
mainThread.menuStatus = gameMenu.menuStatus;
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,8 @@ public class enemyCommander {
|
||||
public defenseManagerAI theDefenseManagerAI;
|
||||
public combatManagerAI theCombatManagerAI;
|
||||
public microManagementAI theMicroManagementAI;
|
||||
public int difficulty;
|
||||
|
||||
|
||||
public void init(){
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class palmTree extends solidObject{
|
||||
public palmTree(float x, float y, float z){
|
||||
//uncontrollable unit, but act as a small sized static collidable agent
|
||||
ID = -1;
|
||||
|
||||
teamNo = -1;
|
||||
type = 100;
|
||||
|
||||
|
||||
|
@ -51,8 +51,8 @@ public class SideBar {
|
||||
}
|
||||
|
||||
|
||||
iconImages = new int[24][44 * 44];
|
||||
iconImages_dark = new int[24][44 * 44];
|
||||
iconImages = new int[25][44 * 44];
|
||||
iconImages_dark = new int[25][44 * 44];
|
||||
String folder = "../images/";
|
||||
loadTexture(folder + "44.jpg", iconImages[0], 44, 44, iconImages_dark[0]);
|
||||
loadTexture(folder + "47.jpg", iconImages[1], 44, 44, iconImages_dark[1]);
|
||||
@ -78,6 +78,7 @@ public class SideBar {
|
||||
loadTexture(folder + "87.jpg", iconImages[21], 44, 44, iconImages_dark[21]);
|
||||
loadTexture(folder + "88.jpg", iconImages[22], 44, 44, iconImages_dark[22]);
|
||||
loadTexture(folder + "89.jpg", iconImages[23], 44, 44, iconImages_dark[23]);
|
||||
loadTexture(folder + "time.png", iconImages[24], 16, 16, iconImages_dark[24]);
|
||||
|
||||
|
||||
}
|
||||
@ -88,14 +89,18 @@ public class SideBar {
|
||||
|
||||
drawSideBarInfo(screen, sideBarInfo);
|
||||
|
||||
drawCreditAndPowerLevel(screen, postProcessingThread.playerMoney, postProcessingThread.playerPowerStatus);
|
||||
drawCreditAndPowerLevelAndTime(screen, postProcessingThread.playerMoney, postProcessingThread.playerPowerStatus);
|
||||
|
||||
drawFrame(screen);
|
||||
}
|
||||
|
||||
|
||||
public void drawCreditAndPowerLevel(int[] screen, int playerMoney, int playerPowerStatus){
|
||||
public void drawCreditAndPowerLevelAndTime(int[] screen, int playerMoney, int playerPowerStatus){
|
||||
|
||||
drawInfoBackGround(screen, 2, 3, 65, 16, 100);
|
||||
drawIcon(screen, 5 + 2 * 768, 24);
|
||||
postProcessingThread.theTextRenderer.drawText(23, 3, postProcessingThread.timeString, screen, 255,255,255);
|
||||
|
||||
drawInfoBackGround(screen, 637, 3, 129, 16, 100);
|
||||
int startIndex = 639 + 3 * 768;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
package gui;
|
||||
|
||||
import core.postProcessingThread;
|
||||
|
||||
public class button {
|
||||
|
||||
public int xPos, yPos, width, height;
|
||||
public String name, text;
|
||||
public char[] theText;
|
||||
public boolean display, cursorIsOnTop;
|
||||
public int actionCooldown;
|
||||
|
||||
@ -14,6 +17,7 @@ public class button {
|
||||
this.yPos = yPos;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
theText = text.toCharArray();
|
||||
}
|
||||
|
||||
public boolean checkIfCursorIsOnTop(int mouse_x, int mouse_y) {
|
||||
@ -170,6 +174,16 @@ public class button {
|
||||
|
||||
}
|
||||
|
||||
//draw text
|
||||
textRenderer tRenderer = postProcessingThread.theTextRenderer;
|
||||
if(text != "x")
|
||||
tRenderer.drawMenuText(xPos+ (width-tRenderer.getMenuTextWidth(theText))/2,yPos+6,theText, screen, 255,255,255);
|
||||
else{
|
||||
tRenderer.drawMenuText(xPos+ (width-tRenderer.getMenuTextWidth(theText))/2-1,yPos,theText, screen, 255,255,255);
|
||||
}
|
||||
|
||||
|
||||
|
||||
cursorIsOnTop = false;
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,16 @@
|
||||
package gui;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.PixelGrabber;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import core.*;
|
||||
|
||||
public class gameMenu {
|
||||
|
||||
public int gameSuspendCount;
|
||||
|
||||
public int menuStatus = 0;
|
||||
public static int menuStatus = 0;
|
||||
public static final int mainMenu = 0;
|
||||
public static final int difficulitySelectionMenu = 1;
|
||||
public static final int helpMenu = 2;
|
||||
@ -25,9 +23,13 @@ public class gameMenu {
|
||||
|
||||
public int[] titleImage;
|
||||
|
||||
public button newGame, unpauseGame, showHelp, quitGame, restartGame;
|
||||
public button newGame, unpauseGame, showHelp, quitGame, abortGame, easyGame, normalGame, hardGame, quitDifficulty, quitHelpMenu, nextPage, previousPage;
|
||||
|
||||
ArrayList<button> buttons = new ArrayList<button>();
|
||||
public char[] easyDescription, normalDescription, hardDescription, helpPage1;
|
||||
|
||||
public int currentHelpPage;
|
||||
|
||||
public ArrayList<button> buttons = new ArrayList<button>();
|
||||
|
||||
public void init() {
|
||||
if(titleImage == null)
|
||||
@ -49,6 +51,41 @@ public class gameMenu {
|
||||
|
||||
quitGame = new button("quitGame", "Quit Game", 324, 345, 120, 28);
|
||||
buttons.add(quitGame);
|
||||
|
||||
abortGame = new button("abortGame", "Abort Game", 324, 345, 120, 28);
|
||||
buttons.add(abortGame);
|
||||
|
||||
easyGame = new button("easyGame", "Easy", 190, 120, 85, 28);
|
||||
buttons.add(easyGame);
|
||||
|
||||
normalGame = new button("normalGame", "Normal", 190, 200, 85, 28);
|
||||
buttons.add(normalGame);
|
||||
|
||||
hardGame = new button("hardGame", "Hard", 190, 280, 85, 28);
|
||||
buttons.add(hardGame);
|
||||
|
||||
quitDifficulty = new button("quitDifficulty", "x", 570, 80, 18,16);
|
||||
buttons.add(quitDifficulty);
|
||||
|
||||
easyDescription = "AI will attack blindly at player's base \nwithout thinking too much. ".toCharArray();
|
||||
normalDescription = "AI will launch timed attacks, it will also \nchange its army composition based on \nthe scouted information.".toCharArray();
|
||||
hardDescription = "AI will micro each of its units, expand \nmore aggressively and carry out high\nlevel maneuver such as harassing during \npeaceful peirod.".toCharArray();
|
||||
|
||||
helpPage1 = (" Controls \n\n"
|
||||
+ "\"Left Click\" -- Select a unit. Left click + mouse drag can be used to select up to \n100 units at a time.\n\n"
|
||||
+ "\"Right Click\" -- Issue a move or attack command to the selected unit(s). You can \nalso use right click to set rally point and cancel build orders.\n\n"
|
||||
+ "\"a\" -- Force attack a unit. If no unit is under the cursor, then the selected units will \nbe set to attack move to the cursor location.\n\n"
|
||||
+ "\"h\" -- stop current action for the selected unit(s).\n\n"
|
||||
+ "\"Ctrl + number\" -- Create a control group and assigned the number to the group.\n\n"
|
||||
+ "\"Ctrl + Left Click\" -- Add/Remove the selected unit to/from the current control \ngroup.\n\n"
|
||||
+ "\"Ctrl + Mouse Drag\" -- Add all the units inside the dragging box to the current \ncontrol group.\n\n\n"
|
||||
+ " 1/3 ").toCharArray();
|
||||
|
||||
quitHelpMenu = new button("quitHelpMenu", "x", 670, 80, 18,16);
|
||||
buttons.add(quitHelpMenu);
|
||||
|
||||
nextPage = new button("nextPage", "Next Page ", 550, 445, 120, 28);
|
||||
buttons.add(nextPage);
|
||||
}
|
||||
|
||||
|
||||
@ -82,6 +119,8 @@ public class gameMenu {
|
||||
}
|
||||
|
||||
if(menuStatus == mainMenu) {
|
||||
currentHelpPage = 0;
|
||||
|
||||
|
||||
if(gameSuspendCount > 0) {
|
||||
drawBluredBackground();
|
||||
@ -96,28 +135,80 @@ public class gameMenu {
|
||||
quitGame.display = true;
|
||||
}else {
|
||||
unpauseGame.display = true;
|
||||
|
||||
abortGame.display = true;
|
||||
}
|
||||
|
||||
showHelp.display = true;
|
||||
|
||||
updateButtons();
|
||||
}else if(menuStatus == difficulitySelectionMenu) {
|
||||
if(postProcessingThread.escapeKeyReleased) {
|
||||
menuStatus = mainMenu;
|
||||
|
||||
}else {
|
||||
drawTitle();
|
||||
drawMenuFrame(420, 260);
|
||||
|
||||
textRenderer tRenderer = postProcessingThread.theTextRenderer;
|
||||
easyGame.display = true;
|
||||
tRenderer.drawMenuText(285,118,easyDescription, screen, 255,255,50);
|
||||
|
||||
normalGame.display = true;
|
||||
tRenderer.drawMenuText(285,188,normalDescription, screen, 255,255,50);
|
||||
|
||||
hardGame.display = true;
|
||||
tRenderer.drawMenuText(285,265,hardDescription, screen, 255,255,50);
|
||||
|
||||
quitDifficulty.display = true;
|
||||
}
|
||||
|
||||
drawButtons();
|
||||
|
||||
}else if(menuStatus == helpMenu) {
|
||||
if(postProcessingThread.escapeKeyReleased) {
|
||||
menuStatus = mainMenu;
|
||||
|
||||
}else{
|
||||
if(gameSuspendCount > 0) {
|
||||
drawBluredBackground();
|
||||
}
|
||||
|
||||
drawTitle();
|
||||
drawMenuFrame(620, 380);
|
||||
|
||||
if(currentHelpPage == 0) {
|
||||
textRenderer tRenderer = postProcessingThread.theTextRenderer;
|
||||
tRenderer.drawMenuText(82,97,helpPage1, screen, 255,255,255);
|
||||
nextPage.display = true;
|
||||
}
|
||||
|
||||
quitHelpMenu.display = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
updateButtons();
|
||||
drawButtons();
|
||||
|
||||
}
|
||||
|
||||
public void updateButtons() {
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
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;
|
||||
if(buttons.get(i).actionCooldown == 0 && buttons.get(i).display == true) {
|
||||
buttons.get(i).actionCooldown = 15;
|
||||
|
||||
|
||||
if(buttons.get(i).name == "newGame") {
|
||||
menuStatus = difficulitySelectionMenu;
|
||||
}else if(buttons.get(i).name == "showHelp") {
|
||||
menuStatus = helpMenu;
|
||||
}if(buttons.get(i).name == "quitDifficulty" || buttons.get(i).name == "quitHelpMenu") {
|
||||
menuStatus = mainMenu;
|
||||
}if(buttons.get(i).name == "nextPage") {
|
||||
currentHelpPage++;
|
||||
}
|
||||
|
||||
postProcessingThread.buttonAction = buttons.get(i).name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -242,20 +242,42 @@ public class inputHandler {
|
||||
}
|
||||
|
||||
//handle escape key
|
||||
if(escapeKeyReleased) {
|
||||
if(escapeKeyReleased && mainThread.menuStatus != mainThread.helpMenu) {
|
||||
mainThread.gamePaused = true; //if game is running, pause the game when esc key is hit
|
||||
|
||||
}
|
||||
|
||||
}else {
|
||||
//handle event when game is paused
|
||||
if(escapeKeyReleased && mainThread.gameStarted)
|
||||
if((escapeKeyReleased || 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
|
||||
|
||||
//quit the game when the quit button is pressed
|
||||
if(!mainThread.gameStarted) {
|
||||
if(mainThread.buttonAction == "quitGame")
|
||||
System.exit(0);
|
||||
|
||||
if(mainThread.buttonAction == "easyGame") {
|
||||
mainThread.gameStarted = true;
|
||||
mainThread.gameFrame = 0;
|
||||
mainThread.ec.difficulty = 0;
|
||||
}else if(mainThread.buttonAction == "normalGame") {
|
||||
mainThread.gameStarted = true;
|
||||
mainThread.gameFrame = 0;
|
||||
mainThread.ec.difficulty = 1;
|
||||
}else if(mainThread.buttonAction == "hardGame") {
|
||||
mainThread.gameStarted = true;
|
||||
mainThread.gameFrame = 0;
|
||||
mainThread.ec.difficulty = 2;
|
||||
}
|
||||
}
|
||||
|
||||
//abort current game when the abort button is pressed
|
||||
if(mainThread.gameStarted && mainThread.buttonAction == "abortGame") {
|
||||
mainThread.gameStarted = false;
|
||||
mainThread.gameFrame = 0;
|
||||
mainThread.gamePaused = false;
|
||||
mainThread.theAssetManager.destoryAsset();
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,6 +285,8 @@ public class inputHandler {
|
||||
if(leftMouseButtonReleased)
|
||||
mainThread.leftMouseButtonReleased = true;
|
||||
|
||||
if(escapeKeyReleased)
|
||||
mainThread.escapeKeyReleased = true;
|
||||
|
||||
mouseIsInsideScreen = false;
|
||||
leftMouseButtonPressed = false;
|
||||
|
@ -12,11 +12,13 @@ import core.mainThread;
|
||||
|
||||
public class textRenderer {
|
||||
|
||||
public int[] fontBuffer, star, halfStar;
|
||||
public int[][] chars;
|
||||
public int[] fontBuffer, menuFontBuffer, star, halfStar;
|
||||
public int[][] chars, menuChars;
|
||||
public int[] menuCharsWidth;
|
||||
|
||||
public void init(){
|
||||
fontBuffer = new int[665*16];
|
||||
menuFontBuffer = new int[789*16];
|
||||
star = new int[12*12];
|
||||
halfStar = new int[12*12];
|
||||
|
||||
@ -28,7 +30,6 @@ public class textRenderer {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
PixelGrabber pg = new PixelGrabber(img, 0, 0, 665, 16, fontBuffer, 0, 665);
|
||||
try {
|
||||
pg.grabPixels();
|
||||
@ -36,7 +37,21 @@ public class textRenderer {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//create character bitmaps
|
||||
try{
|
||||
img = ImageIO.read(getClass().getResource("../images/" + "menuFont.png"));
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
pg = new PixelGrabber(img, 0, 0, 789, 16, menuFontBuffer, 0, 789);
|
||||
try {
|
||||
pg.grabPixels();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
//create character bitmaps for in game text
|
||||
chars = new int[93][16*7];
|
||||
for(int i = 0; i < 93; i++){
|
||||
for(int j = 0; j < 16; j++){
|
||||
@ -46,6 +61,27 @@ public class textRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
//create character bitmaps for menu text
|
||||
menuChars = new int[95][];
|
||||
int[] charEndPosition = new int[]{6,9,15,25,34,46,57,61,65,69,76,86,90,95,99, 105,114,120,130,138,146,155, 163,172,180,189,193,197,206,216,225,234,246,259,267,280,291,300,307,320,330,334,340, 350,357,372,382,396,404,419,428,435,443, 451,463,478,487,496,503,507,516,520,530,539,545,555,565,574,585,594,600,610,619,622,625,633,636,650,659,668,679,689,694,700,705,714,722,735,743,750,757,763,770,778,787};
|
||||
int[] charStartPosition = new int[95];
|
||||
menuCharsWidth = new int[95];
|
||||
for(int i = 1; i < 95; i++) {
|
||||
menuCharsWidth[i] = charEndPosition[i] - charEndPosition[i-1];
|
||||
charStartPosition[i] = charEndPosition[i-1] + 1;
|
||||
}
|
||||
menuCharsWidth[0] = 6;
|
||||
charStartPosition[0] = 0;
|
||||
for(int i = 0; i < 95; i++) {
|
||||
menuChars[i] = new int[menuCharsWidth[i] * 16];
|
||||
for(int j = 0; j < 16; j++) {
|
||||
for(int k = 0; k < menuCharsWidth[i]; k++) {
|
||||
menuChars[i][k+j*menuCharsWidth[i]] = menuFontBuffer[charStartPosition[i] + k + j*789];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//load half star images
|
||||
try{
|
||||
img = ImageIO.read(getClass().getResource("../images/" + "84.jpg"));
|
||||
@ -77,6 +113,46 @@ public class textRenderer {
|
||||
|
||||
}
|
||||
|
||||
public void drawMenuText(int xPos, int yPos, char[] theText, int[] screen, int r, int g, int b) {
|
||||
int pixel, SpriteValue, screenValue, overflow, screenIndex;
|
||||
int MASK7Bit = 0xFEFEFF;
|
||||
int xPos_initial = xPos;
|
||||
|
||||
for(int i = 0; i < theText.length; i++){
|
||||
if(theText[i] == 10) {
|
||||
yPos+=16;
|
||||
xPos = xPos_initial;
|
||||
continue;
|
||||
}
|
||||
|
||||
int charIndex = theText[i] - 32;
|
||||
int w = menuCharsWidth[charIndex];
|
||||
int pos = 768*yPos + xPos;
|
||||
for(int j = 0; j < 16; j++){
|
||||
for(int k = 0; k < w; k++){
|
||||
screenIndex = pos + k + j*768;
|
||||
screenValue = screen[screenIndex];
|
||||
SpriteValue = menuChars[charIndex][k+ j*w]&255;
|
||||
SpriteValue = (r*SpriteValue/256) << 16 | (g*SpriteValue/256) << 8 | (b*SpriteValue/256);
|
||||
|
||||
|
||||
pixel=(SpriteValue&MASK7Bit)+(screenValue&MASK7Bit);
|
||||
overflow=pixel&0x1010100;
|
||||
overflow=overflow-(overflow>>8);
|
||||
screen[screenIndex] = overflow|pixel;
|
||||
}
|
||||
}
|
||||
xPos+=w;
|
||||
}
|
||||
}
|
||||
|
||||
public int getMenuTextWidth(char[] theText) {
|
||||
int w = 0;
|
||||
for(int i = 0; i< theText.length; i++)
|
||||
w+=menuCharsWidth[theText[i] - 32];
|
||||
return w;
|
||||
}
|
||||
|
||||
public void drawFlashingText(int xPos, int yPos, String text, int[] screen){
|
||||
int pixel, SpriteValue, screenValue, overflow, screenIndex;
|
||||
int MASK7Bit = 0xFEFEFF;
|
||||
|
BIN
images/menuFont.png
Normal file
BIN
images/menuFont.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
Loading…
x
Reference in New Issue
Block a user