Skip to content

Commit

Permalink
Tanks v0.7.0 - Added 3D Graphics and Party mode, and made many other …
Browse files Browse the repository at this point in the history
…changes.
  • Loading branch information
aehmttw committed Sep 8, 2019
1 parent c6033f8 commit 73cd4dd
Show file tree
Hide file tree
Showing 159 changed files with 3,215 additions and 2,336 deletions.
3 changes: 3 additions & 0 deletions src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: tanks.Game

9 changes: 0 additions & 9 deletions src/main/java/lwjglwindow/Drawer.java

This file was deleted.

12 changes: 7 additions & 5 deletions src/main/java/lwjglwindow/FontRenderer.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ public class FontRenderer
public FontRenderer(LWJGLWindow h, String fontFile)
{
this.home = h;
this.chars = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'abcdefghijklmnopqrstuvwxyz{|}";
this.chars = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'abcdefghijklmnopqrstuvwxyz{|}~`";
this.charSizes = new int[]
{
3, 2, 4, 5, 5, 5, 5, 2, 4, 4, 4, 5, 1, 5, 1, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 5, 5, 5, 5,
6, 5, 5, 5, 5, 5, 5, 5, 5, 3, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 5, 3, 5, 5,
2, 5, 5, 5, 5, 5, 4, 5, 5, 1, 5, 4, 2, 5, 5, 5,
5, 5, 5, 5, 3, 5, 5, 5, 5, 5, 5, 4, 1, 4, 6, 5
5, 5, 5, 5, 3, 5, 5, 5, 5, 5, 5, 4, 1, 4, 6, 2
};
this.image = fontFile;
}
Expand All @@ -28,7 +28,7 @@ public int drawChar(double x, double y, double sX, double sY, char c)
int i = this.chars.indexOf(c);

if (i == -1)
i = 95;
i = 31;

int col = i % 16;
int row = i / 16;
Expand Down Expand Up @@ -65,13 +65,15 @@ public double getStringSizeX(double sX, String s)
{
double w = 0;
char[] c = s.toCharArray();

for (int i = 0; i < c.length; i++)
{
{
if (c[i] == '\u00C2')
continue;
else if (c[i] == '\u00A7')
i += 12;
else if (this.chars.indexOf(c[i]) == -1)
c[i] = '?';
else
w += (charSizes[this.chars.indexOf(c[i])] + 1) * sX * 4;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/lwjglwindow/IDrawer.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public interface IDrawer
{
public void draw();
void draw();
}
2 changes: 1 addition & 1 deletion src/main/java/lwjglwindow/IUpdater.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public interface IUpdater
{
public void update();
void update();
}
2 changes: 1 addition & 1 deletion src/main/java/lwjglwindow/IWindowHandler.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public interface IWindowHandler
{
public void onWindowClose();
void onWindowClose();
}
145 changes: 44 additions & 101 deletions src/main/java/lwjglwindow/LWJGLWindow.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,109 +1,35 @@
package lwjglwindow;
import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks;
import static org.lwjgl.glfw.GLFW.GLFW_FALSE;
import static org.lwjgl.glfw.GLFW.GLFW_PRESS;
import static org.lwjgl.glfw.GLFW.GLFW_RELEASE;
import static org.lwjgl.glfw.GLFW.GLFW_RESIZABLE;
import static org.lwjgl.glfw.GLFW.GLFW_TRUE;
import static org.lwjgl.glfw.GLFW.GLFW_VISIBLE;
import static org.lwjgl.glfw.GLFW.glfwCreateWindow;
import static org.lwjgl.glfw.GLFW.glfwDefaultWindowHints;
import static org.lwjgl.glfw.GLFW.glfwDestroyWindow;
import static org.lwjgl.glfw.GLFW.glfwGetCursorPos;
import static org.lwjgl.glfw.GLFW.glfwGetPrimaryMonitor;
import static org.lwjgl.glfw.GLFW.glfwGetVideoMode;
import static org.lwjgl.glfw.GLFW.glfwGetWindowSize;
import static org.lwjgl.glfw.GLFW.glfwInit;
import static org.lwjgl.glfw.GLFW.glfwMakeContextCurrent;
import static org.lwjgl.glfw.GLFW.glfwPollEvents;
import static org.lwjgl.glfw.GLFW.glfwSetErrorCallback;
import static org.lwjgl.glfw.GLFW.glfwSetKeyCallback;
import static org.lwjgl.glfw.GLFW.glfwSetMouseButtonCallback;
import static org.lwjgl.glfw.GLFW.glfwSetScrollCallback;
import static org.lwjgl.glfw.GLFW.glfwSetWindowPos;
import static org.lwjgl.glfw.GLFW.glfwShowWindow;
import static org.lwjgl.glfw.GLFW.glfwSwapBuffers;
import static org.lwjgl.glfw.GLFW.glfwTerminate;
import static org.lwjgl.glfw.GLFW.glfwWindowHint;
import static org.lwjgl.glfw.GLFW.glfwWindowShouldClose;
import static org.lwjgl.opengl.GL11.GL_ALWAYS;
import static org.lwjgl.opengl.GL11.GL_BLEND;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST;
import static org.lwjgl.opengl.GL11.GL_LESS;
import static org.lwjgl.opengl.GL11.GL_LINES;
import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
import static org.lwjgl.opengl.GL11.GL_NEAREST;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
import static org.lwjgl.opengl.GL11.GL_REPEAT;
import static org.lwjgl.opengl.GL11.GL_RGBA;
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MAG_FILTER;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_S;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_T;
import static org.lwjgl.opengl.GL11.GL_TRIANGLE_FAN;
import static org.lwjgl.opengl.GL11.GL_UNPACK_ALIGNMENT;
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_BYTE;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glBindTexture;
import static org.lwjgl.opengl.GL11.glBlendFunc;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glClearColor;
import static org.lwjgl.opengl.GL11.glColor3d;
import static org.lwjgl.opengl.GL11.glColor4d;
import static org.lwjgl.opengl.GL11.glDepthFunc;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.opengl.GL11.glFrustum;
import static org.lwjgl.opengl.GL11.glGenTextures;
import static org.lwjgl.opengl.GL11.glLoadIdentity;
import static org.lwjgl.opengl.GL11.glMatrixMode;
import static org.lwjgl.opengl.GL11.glPixelStorei;
import static org.lwjgl.opengl.GL11.glTexCoord2d;
import static org.lwjgl.opengl.GL11.glTexImage2D;
import static org.lwjgl.opengl.GL11.glTexParameteri;
import static org.lwjgl.opengl.GL11.glTranslated;
import static org.lwjgl.opengl.GL11.glVertex2d;
import static org.lwjgl.opengl.GL11.glVertex3d;
import static org.lwjgl.opengl.GL11.glViewport;
import static org.lwjgl.system.MemoryStack.stackPush;
import static org.lwjgl.system.MemoryUtil.NULL;

import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.HashMap;

import de.matthiasmann.twl.utils.PNGDecoder;
import de.matthiasmann.twl.utils.PNGDecoder.Format;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11;
import org.lwjgl.system.MemoryStack;

import de.matthiasmann.twl.utils.PNGDecoder;
import de.matthiasmann.twl.utils.PNGDecoder.Format;
import lombok.Getter;
import tanks.Resources;
import tanks.gui.Panel;
import tanks.gui.screen.ScreenOptions;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.HashMap;

import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryStack.stackPush;
import static org.lwjgl.system.MemoryUtil.NULL;

public class LWJGLWindow
{
public FontRenderer fontRenderer;

// The window handle
@Getter
protected long window;
public int absoluteWidth;
public int absoluteHeight;
public int absoluteDepth;
public double absoluteWidth;
public double absoluteHeight;
public double absoluteDepth;

public double absoluteMouseX;
public double absoluteMouseY;
Expand All @@ -125,6 +51,7 @@ public class LWJGLWindow
public boolean mac = false;

public boolean vsync;
public boolean showMouseOnLaunch;

protected ArrayList<Long> framesList = new ArrayList<Long>();
protected ArrayList<Double> frameFrequencies = new ArrayList<Double>();
Expand All @@ -141,7 +68,7 @@ public class LWJGLWindow
public IUpdater updater;
public IWindowHandler windowHandler;

public LWJGLWindow(String name, int x, int y, int z, IUpdater u, IDrawer d, IWindowHandler w, boolean vsync)
public LWJGLWindow(String name, int x, int y, int z, IUpdater u, IDrawer d, IWindowHandler w, boolean vsync, boolean showMouse)
{
this.name = name;
this.absoluteWidth = x;
Expand All @@ -151,11 +78,17 @@ public LWJGLWindow(String name, int x, int y, int z, IUpdater u, IDrawer d, IWin
this.drawer = d;
this.vsync = vsync;
this.windowHandler = w;
this.showMouseOnLaunch = showMouse;

if (System.getProperties().toString().contains("Mac OS X"))
mac = true;
}

public long getWindow()
{
return this.window;
}

public void run()
{
init();
Expand Down Expand Up @@ -191,7 +124,7 @@ protected void init()
// resizable

// Create the window
window = glfwCreateWindow(this.absoluteWidth, this.absoluteHeight, this.name, NULL, NULL);
window = glfwCreateWindow((int)this.absoluteWidth, (int)this.absoluteHeight, this.name, NULL, NULL);
if (window == NULL)
throw new RuntimeException("Failed to create the GLFW window");

Expand All @@ -201,8 +134,8 @@ protected void init()
{
if (action == GLFW_PRESS)
{
pressedKeys.add((Integer)key);
validPressedKeys.add((Integer)key);
pressedKeys.add(key);
validPressedKeys.add(key);
}
else if (action == GLFW_RELEASE)
{
Expand Down Expand Up @@ -252,14 +185,13 @@ else if (action == GLFW_RELEASE)
// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable v-sync

this.setShowCursor(this.showMouseOnLaunch);

if (vsync)
GLFW.glfwSwapInterval(1);
else
GLFW.glfwSwapInterval(0);

if (Panel.showMouseTarget)
ScreenOptions.setShowCursor(false);

// Make the window visible
glfwShowWindow(window);
Expand Down Expand Up @@ -319,7 +251,7 @@ protected void loop()
absoluteMouseY = my[0];

if (!mac)
glViewport(0, 0, absoluteWidth, absoluteHeight);
glViewport(0, 0, (int)absoluteWidth, (int)absoluteHeight);

setPerspective();

Expand Down Expand Up @@ -357,7 +289,15 @@ protected void loop()
this.windowHandler.onWindowClose();
System.exit(0);
}


public void setShowCursor(boolean show)
{
int mouse = GLFW.GLFW_CURSOR_HIDDEN;
if (show)
mouse = GLFW.GLFW_CURSOR_NORMAL;

GLFW.glfwSetInputMode(window, GLFW.GLFW_CURSOR, mouse);
}

public void fillOval(double x, double y, double sX, double sY)
{
Expand Down Expand Up @@ -675,10 +615,13 @@ protected void createImage(String image)
{
try
{
InputStream in = Resources.getResourceAsStream(image);
InputStream in;


in = getClass().getResourceAsStream(image);

if (in == null)
in = Resources.getResourceAsStream("missing.png");
in = getClass().getResourceAsStream("/missing.png");

try
{
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/lwjglwindow/Updater.java

This file was deleted.

11 changes: 1 addition & 10 deletions src/main/java/tanks/AreaEffect.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package tanks;

import tanks.gui.Panel;

public abstract class AreaEffect extends Movable
{
public double duration = 500;
public boolean constantlyImbue = true;
public double age = 0;
public double maxAge = 1000;
Expand All @@ -13,14 +10,8 @@ public AreaEffect(double x, double y)
{
super(x, y);
this.drawLevel = 5;
}

@Override
public void checkCollision()
{

}

@Override
public void update()
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tanks/AreaEffectFreeze.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void imbueEffects()
for (int i = 0; i < 200; i++)
{
Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece);
int var = 50;
double var = 50;
e.colR = Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2));
e.colG = Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2));
e.colB = Math.min(255, Math.max(0, 255 + Math.random() * var - var / 2));
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/tanks/AttributeModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.util.UUID;

import tanks.gui.Panel;

public class AttributeModifier
{
public enum Operation {add, multiply}
Expand Down Expand Up @@ -53,7 +51,7 @@ public void update()

public double getValue(double in)
{
double val = 0;
double val;

if (this.expired)
return in;
Expand Down
Loading

0 comments on commit 73cd4dd

Please sign in to comment.