This commit is contained in:
Pan 2019-05-15 15:18:55 +12:00
parent 1bb4756930
commit d558b4dc39
8 changed files with 205 additions and 18 deletions

View File

@ -230,9 +230,9 @@ public class AssetManager {
//techCenter.rocketTankResearched_enemy = true;
//}else {
heavyTank l = new heavyTank(new vector(j*0.25f+ 1.125f,-0.3f, 22.125f - i*0.25f), 90, 1);
//heavyTank l = new heavyTank(new vector(j*0.25f+ 1.125f,-0.3f, 22.125f - i*0.25f), 90, 1);
addHeavyTank(l);
//addHeavyTank(l);
//}
@ -245,13 +245,13 @@ 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 + 18.625f + j*0.25f), 90, 0);
//l.attackRange = 1.99f;
//lightTank.tileCheckList_player = lightTank.generateTileCheckList(6);
addLightTank(l);
//addLightTank(l);
//if(j == 0 && i == 0)
//addMissileTurret(new missileTurret(i*0.25f -0.125f + 1, -0.65f, 0.25f + 17.125f + j*0.25f, 0));

View File

@ -144,12 +144,7 @@ public class camera{
position.add(-view_Direction.x*3, 0 , -view_Direction.z*3);
MOVE_LEFT = false;
MOVE_RIGHT = false;
MOVE_UP = false;
MOVE_DOWN = false;
TURN_LEFT = false;
TURN_RIGHT = false;
}

View File

@ -15,8 +15,8 @@ import gui.*;
public class mainThread extends JFrame implements KeyListener, ActionListener, MouseMotionListener, MouseListener, FocusListener{
public static int[] screen;
public static int[] screen2;
public static int[] screen, bufferScreen;
public static int[] screen2, buffer2Screen;
public static int[] zBuffer;
public static int[] zBuffer2;
public static BufferedImage doubleBuffer;
@ -39,6 +39,7 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
public static playerCommander pc;
public static enemyCommander ec;
public static AssetManager theAssetManager;
public static gameCursor theGameCursor;
public static grid gridMap;
public static postProcessingThread PPT;
public static Object PPT_Lock;
@ -59,7 +60,8 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
public static final int endGameMenu = 3;
public static String timeString;
public static boolean fogOfWarDisabled = false;
public static boolean fogOfWarDisabled;
public mainThread(){
setTitle("Battle Tank 3");
@ -75,14 +77,28 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//hide mouse cursor
// Transparent 16 x 16 pixel cursor image.
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
// Create a new blank cursor.
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
cursorImg, new Point(0, 0), "blank cursor");
// Set the blank cursor to the JFrame.
this.getContentPane().setCursor(blankCursor);
//create screen buffer
doubleBuffer = new BufferedImage(768, 512, BufferedImage.TYPE_INT_RGB);
DataBuffer dest = doubleBuffer.getRaster().getDataBuffer();
screen = ((DataBufferInt)dest).getData();
bufferScreen = screen;
doubleBuffer2 = new BufferedImage(768, 512, BufferedImage.TYPE_INT_RGB);
DataBuffer dest2 = doubleBuffer2.getRaster().getDataBuffer();
screen2 = ((DataBufferInt)dest2).getData();
buffer2Screen = screen2;
//create depth buffer
zBuffer = new int[393216];
@ -172,6 +188,9 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
theAssetManager = new AssetManager();
theAssetManager.init();
theGameCursor = new gameCursor();
theGameCursor.init();
}
frameIndex++;
@ -229,12 +248,19 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
if(frameIndex %2 == 0 && frameIndex > 3){
bf = doubleBuffer;
paintComponent(panel.getGraphics());
//draw mouse cursor
theGameCursor.updateAndDraw(bufferScreen);
}else if(frameIndex != 1 && frameIndex > 3){
bf = doubleBuffer2;
paintComponent(panel.getGraphics());
//draw mouse cursor
theGameCursor.updateAndDraw(buffer2Screen);
}
if(frameIndex > 3)
paintComponent(panel.getGraphics());
swapResources();
//maintain a constant frame rate
@ -247,7 +273,7 @@ public class mainThread extends JFrame implements KeyListener, ActionListener, M
public void paintComponent(Graphics g){
//copy the pixel information to the video memory
Graphics2D g2 =(Graphics2D)bf.getGraphics(); //(Graphics2D)g;
//Graphics2D g2 =(Graphics2D)bf.getGraphics(); //(Graphics2D)g;
//display polygon count and frame rate
//g2.setColor(Color.WHITE);

View File

@ -726,6 +726,7 @@ public class postProcessingThread implements Runnable{
//draw mini map
theMiniMap.draw(currentScreen, minimapBitmap, unitsForMiniMap, unitsForMiniMapCount);
theSideBar.draw(currentScreen, sideBarInfo);
}
}

1
gui/.gitignore vendored
View File

@ -8,3 +8,4 @@
/gameMenu.class
/button.class
/textRenderer.class
/gameCursor.class

View File

@ -9,7 +9,6 @@ import core.mainThread;
import core.postProcessingThread;
public class SideBar {
public String imageFolder = "";
public int[][] iconImages;
public int[][] iconImages_dark;
@ -630,7 +629,7 @@ public class SideBar {
public void loadTexture(String imgName, int[] buffer, int width, int height, int[] buffer_dark){
Image img = null;
try{
img = ImageIO.read(getClass().getResource(imageFolder + imgName));
img = ImageIO.read(getClass().getResource(imgName));
}catch(Exception e){
e.printStackTrace();
}

158
gui/gameCursor.java Normal file
View File

@ -0,0 +1,158 @@
package gui;
import java.awt.Image;
import java.awt.image.PixelGrabber;
import javax.imageio.ImageIO;
import core.camera;
import core.mainThread;
public class gameCursor {
public int[][] arrowIcons;
public int[] cursorIcon;
public int[] screen;
public void init() {
String folder = "../images/";
arrowIcons = new int[8][24*24];
for(int i = 0; i < 8; i++) {
loadTexture(folder + "arrow"+i+".png", arrowIcons[i], 24,24);
}
cursorIcon = new int[24*24];
loadTexture(folder + "cursor.png", cursorIcon, 24,24);
}
public void updateAndDraw(int[] screen) {
this.screen = screen;
int mouseX = inputHandler.mouse_x;
int mouseY = inputHandler.mouse_y;
if(!mainThread.gamePaused && mainThread.gameStarted) {
//draw arrow icons if the player is scrolling the screen with the mouse
int cursorX = 0;
int cursorY = 0;
if(camera.MOVE_DOWN && !camera.MOVE_LEFT && ! camera.MOVE_RIGHT) {
drawIcon(arrowIcons[1], mouseX-12,489);
}else if(camera.MOVE_UP && !camera.MOVE_LEFT && ! camera.MOVE_RIGHT) {
drawIcon(arrowIcons[3], mouseX-12,0);
}else if(camera.MOVE_LEFT && !camera.MOVE_UP && ! camera.MOVE_DOWN) {
drawIcon(arrowIcons[2], 0,mouseY-12);
}else if(camera.MOVE_RIGHT && !camera.MOVE_UP && ! camera.MOVE_DOWN) {
drawIcon(arrowIcons[0], 745,mouseY-12);
}else if(camera.MOVE_RIGHT && camera.MOVE_UP) {
if(mouseY> 768 - mouseX) {
cursorX = 747;
cursorY = mouseY-12;
}else {
cursorX = mouseX-12;
cursorY = -3;
}
if(cursorX > 747)
cursorX = 747;
if(cursorY < -3)
cursorY = -3;
drawIcon(arrowIcons[4], cursorX, cursorY);
}else if(camera.MOVE_LEFT && camera.MOVE_UP) {
if(mouseY > mouseX) {
cursorX = -3;
cursorY = mouseY-12;
}else {
cursorX = mouseX - 12;
cursorY = -3;
}
if(cursorX < -3)
cursorX = -3;
if(cursorY < -3)
cursorY = -3;
drawIcon(arrowIcons[7], cursorX, cursorY);
}else if(camera.MOVE_LEFT && camera.MOVE_DOWN) {
if(512 - mouseY > mouseX) {
cursorX = -3;
cursorY = mouseY-12;
}else {
cursorX = mouseX-12;
cursorY = 491;
}
if(cursorX < -3)
cursorX = -3;
if(cursorY > 491)
cursorY = 491;
drawIcon(arrowIcons[6], cursorX, cursorY);
}else if(camera.MOVE_RIGHT && camera.MOVE_DOWN) {
if(512 - mouseY > 768 -mouseX) {
cursorX = 747;
cursorY = mouseY-12;
}else {
cursorX = mouseX-12;
cursorY = 491;
}
if(cursorX >747)
cursorX = 747;
if(cursorY > 491)
cursorY = 491;
drawIcon(arrowIcons[5], cursorX, cursorY);
}else {
//draw default icon
drawIcon(cursorIcon, mouseX, mouseY);
}
}else {
//draw default icon
drawIcon(cursorIcon, mouseX, mouseY);
}
}
public void loadTexture(String imgName, int[] buffer, int width, int height){
Image img = null;
try{
img = ImageIO.read(getClass().getResource(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();
}
}
public void drawIcon(int[] icon, int xPos, int yPos) {
for(int i = 0; i < 24; i++) {
for(int j = 0; j < 24; j++) {
int x = xPos + j;
int y = yPos + i;
if(x < 0 || x >= 768)
continue;
if(y < 0 || y >= 512)
continue;
int color = icon[j+i*24];
int blue = color&0xff;
int red = (color&0xff0000) >> 16;
if(red < 100 && blue > 100)
continue;
screen[x + y*768] = color;
}
}
}
}

View File

@ -169,6 +169,13 @@ public class inputHandler {
//handle input when game is running
if(!mainThread.gamePaused && mainThread.gameStarted){
camera.MOVE_LEFT = false;
camera.MOVE_RIGHT = false;
camera.MOVE_UP = false;
camera.MOVE_DOWN = false;
camera.TURN_LEFT = false;
camera.TURN_RIGHT = false;
if(!mainThread.pc.isSelectingUnit){
mouse_x0 = mouse_x;
mouse_y0 = mouse_y;