Skip to content

Commit

Permalink
Tanks v0.8.0 - Added Online mode support, mobile support, tall obstac…
Browse files Browse the repository at this point in the history
…les, linked teleporters, level editor improvements, menu music, and much more.
  • Loading branch information
aehmttw committed Jun 6, 2020
1 parent 071a167 commit 76c21e2
Show file tree
Hide file tree
Showing 109 changed files with 3,712 additions and 1,526 deletions.
2 changes: 2 additions & 0 deletions src/main/java/basewindow/BaseWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,6 @@ public abstract void fillQuadBox(double x1, double y1,
public abstract void transform(double[] matrix);

public abstract double getEdgeBounds();

public abstract void setBatchMode(boolean enabled);
}
6 changes: 3 additions & 3 deletions src/main/java/basewindow/transformation/Rotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public void apply()

public static void transform(BaseWindow window, double yaw, double pitch, double roll)
{
window.transform(new double[]{Math.cos(roll), -Math.sin(roll), 0, 0, Math.sin(roll), Math.cos(roll), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1});
window.transform(new double[]{1, 0, 0, 0, 0, Math.cos(pitch), -Math.sin(pitch), 0, 0, Math.sin(pitch), Math.cos(pitch), 0, 0, 0, 0, 1});
window.transform(new double[]{Math.cos(yaw), 0, -Math.sin(yaw), 0, 0, 1, 0, 0, Math.sin(yaw), 0, Math.cos(yaw), 0, 0, 0, 0, 1});
transform(window, Math.cos(roll), -Math.sin(roll), 0, 0, Math.sin(roll), Math.cos(roll), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
transform(window, 1, 0, 0, 0, 0, Math.cos(pitch), -Math.sin(pitch), 0, 0, Math.sin(pitch), Math.cos(pitch), 0, 0, 0, 0, 1);
transform(window, Math.cos(yaw), 0, -Math.sin(yaw), 0, 0, 1, 0, 0, Math.sin(yaw), 0, Math.cos(yaw), 0, 0, 0, 0, 1);
}
}
10 changes: 5 additions & 5 deletions src/main/java/basewindow/transformation/RotationAboutPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public void apply()

public static void transform(BaseWindow window, double yaw, double pitch, double roll, double x, double y, double z)
{
window.transform(new double[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x * window.absoluteWidth, y * window.absoluteHeight, z * window.absoluteDepth, 1});
transform(window, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x * window.absoluteWidth, y * window.absoluteHeight, z * window.absoluteDepth, 1);

window.transform(new double[]{Math.cos(roll), -Math.sin(roll), 0, 0, Math.sin(roll), Math.cos(roll), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1});
window.transform(new double[]{1, 0, 0, 0, 0, Math.cos(pitch), -Math.sin(pitch), 0, 0, Math.sin(pitch), Math.cos(pitch), 0, 0, 0, 0, 1});
window.transform(new double[]{Math.cos(yaw), 0, -Math.sin(yaw), 0, 0, 1, 0, 0, Math.sin(yaw), 0, Math.cos(yaw), 0, 0, 0, 0, 1});
transform(window, Math.cos(roll), -Math.sin(roll), 0, 0, Math.sin(roll), Math.cos(roll), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
transform(window, 1, 0, 0, 0, 0, Math.cos(pitch), -Math.sin(pitch), 0, 0, Math.sin(pitch), Math.cos(pitch), 0, 0, 0, 0, 1);
transform(window, Math.cos(yaw), 0, -Math.sin(yaw), 0, 0, 1, 0, 0, Math.sin(yaw), 0, Math.cos(yaw), 0, 0, 0, 0, 1);

window.transform(new double[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -x * window.absoluteWidth, -y * window.absoluteHeight, -z * window.absoluteDepth, 1});
transform(window, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -x * window.absoluteWidth, -y * window.absoluteHeight, -z * window.absoluteDepth, 1);
}
}
30 changes: 30 additions & 0 deletions src/main/java/basewindow/transformation/Transformation.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,41 @@
public abstract class Transformation
{
public BaseWindow window;
protected static double[] matrix = new double[16];

public Transformation(BaseWindow window)
{
this.window = window;
}

public abstract void apply();

protected static void transform(BaseWindow w,
double a1, double a2, double a3, double a4,
double b1, double b2, double b3, double b4,
double c1, double c2, double c3, double c4,
double d1, double d2, double d3, double d4)
{
matrix[0] = a1;
matrix[1] = a2;
matrix[2] = a3;
matrix[3] = a4;

matrix[4] = b1;
matrix[5] = b2;
matrix[6] = b3;
matrix[7] = b4;

matrix[8] = c1;
matrix[9] = c2;
matrix[10] = c3;
matrix[11] = c4;

matrix[12] = d1;
matrix[13] = d2;
matrix[14] = d3;
matrix[15] = d4;

w.transform(matrix);
}
}
3 changes: 2 additions & 1 deletion src/main/java/basewindow/transformation/Translation.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void apply()

public static void transform(BaseWindow window, double x, double y, double z)
{
window.transform(new double[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x * window.absoluteWidth, y * window.absoluteHeight, z * window.absoluteDepth, 1});
transform(window,
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x * window.absoluteWidth, y * window.absoluteHeight, z * window.absoluteDepth, 1);
}
}
57 changes: 43 additions & 14 deletions src/main/java/lwjglwindow/LWJGLWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ public class LWJGLWindow extends BaseWindow
public double colorB;
public double colorA;

protected double[] mx = new double[1];
protected double[] my = new double[1];

protected int[] w = new int[1];
protected int[] h = new int[1];

protected HashMap<String, Integer> textures = new HashMap<String, Integer>();
protected HashMap<String, Integer> textureSX = new HashMap<String, Integer>();
protected HashMap<String, Integer> textureSY = new HashMap<String, Integer>();

public boolean batchMode = false;

public LWJGLWindow(String name, int x, int y, int z, IUpdater u, IDrawer d, IWindowHandler w, boolean vsync, boolean showMouse)
{
super(name, x, y, z, u, d, w, vsync, showMouse);
Expand Down Expand Up @@ -227,14 +235,10 @@ protected void loop()

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

int[] w = new int[1];
int[] h = new int[1];
glfwGetWindowSize(window, w, h);
absoluteWidth = w[0];
absoluteHeight = h[0];

double[] mx = new double[1];
double[] my = new double[1];
glfwGetCursorPos(window, mx, my);
absoluteMouseX = mx[0];
absoluteMouseY = my[0];
Expand Down Expand Up @@ -295,7 +299,9 @@ public void fillOval(double x, double y, double z, double sX, double sY, boolean
if (depthTest)
{
glEnable(GL_DEPTH_TEST);
glDepthMask(false);

if (colorA < 1)
glDepthMask(false);
}

x += sX / 2;
Expand Down Expand Up @@ -435,14 +441,17 @@ public void fillBox(double x, double y, double z, double sX, double sY, double s
* */
public void fillBox(double x, double y, double z, double sX, double sY, double sZ, byte options)
{
glEnable(GL_DEPTH_TEST);
if (!batchMode)
{
glEnable(GL_DEPTH_TEST);

if ((options >> 6) % 2 == 0)
glDepthFunc(GL_LESS);
else
glDepthFunc(GL_ALWAYS);
if ((options >> 6) % 2 == 0)
glDepthFunc(GL_LESS);
else
glDepthFunc(GL_ALWAYS);

GL11.glBegin(GL11.GL_QUADS);
GL11.glBegin(GL11.GL_QUADS);
}

if (options % 2 == 0)
{
Expand Down Expand Up @@ -498,9 +507,11 @@ public void fillBox(double x, double y, double z, double sX, double sY, double s
GL11.glVertex3d(x + sX, y, z + sZ);
}

GL11.glEnd();

glDisable(GL_DEPTH_TEST);
if (!batchMode)
{
GL11.glEnd();
glDisable(GL_DEPTH_TEST);
}
}

public void fillQuad(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
Expand Down Expand Up @@ -877,4 +888,22 @@ public double getEdgeBounds()
{
return 0;
}

@Override
public void setBatchMode(boolean enabled)
{
this.batchMode = enabled;

if (enabled)
{
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glBegin(GL_QUADS);
}
else
{
GL11.glEnd();
glDisable(GL_DEPTH_TEST);
}
}
}
12 changes: 9 additions & 3 deletions src/main/java/lwjglwindow/SoundPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void playSound(String path, float pitch)

public void playSound(String path, float pitch, float volume)
{
if (sources.size() >= 250)
if (sources.size() >= 240)
alDeleteSources(sources.remove(0));

if (this.buffers.get(path) == null)
Expand All @@ -80,6 +80,7 @@ public void playSound(String path, float pitch, float volume)
int bufferPointer = this.buffers.get(path);

int sourcePointer = alGenSources();

alSourcei(sourcePointer, AL_BUFFER, bufferPointer);
alSourcef(sourcePointer, AL_PITCH, pitch);
alSourcef(sourcePointer, AL_GAIN, volume);
Expand All @@ -92,7 +93,7 @@ public void playSound(String path, float pitch, float volume)
@Override
public void playMusic(String path, float volume, boolean looped, String continueID, long fadeTime)
{
if (musicSources.size() >= 6)
if (musicSources.size() >= 15)
alDeleteSources(musicSources.remove(0));

if (this.musicBuffers.get(path) == null)
Expand All @@ -107,6 +108,8 @@ public void playMusic(String path, float volume, boolean looped, String continue

int sourcePointer = alGenSources();

alSourceStop(prevMusic);
alSourceUnqueueBuffers(prevMusic);
prevMusic = currentMusic;
currentMusic = sourcePointer;
currentVolume = volume;
Expand All @@ -129,7 +132,7 @@ public void playMusic(String path, float volume, boolean looped, String continue

this.musicID = continueID;

sources.add(sourcePointer);
musicSources.add(sourcePointer);
}

@Override
Expand All @@ -142,6 +145,9 @@ public void playMusic(String path, float volume, boolean looped, String continue
public void stopMusic()
{
alSourceStop(currentMusic);
alSourceStop(prevMusic);
alSourceUnqueueBuffers(currentMusic);
alSourceUnqueueBuffers(prevMusic);
this.currentMusic = -1;
this.prevMusic = -1;
this.musicID = null;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/main/Tanks.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import lwjglwindow.LWJGLWindow;
import swingwindow.SwingWindow;
import tanks.*;
import tanks.registry.RegistryTank;
import tanks.tank.Tank;
import tanksonline.CommandExecutor;
import tanksonline.PlayerMap;
import tanksonline.TanksOnlineServer;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/swingwindow/SwingWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,10 @@ public double getEdgeBounds()
{
return 0;
}

//@Override
public void setBatchMode(boolean enabled)
{

}
}
4 changes: 2 additions & 2 deletions src/main/java/tanks/AreaEffectFreeze.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public void imbueEffects()
@Override
public void draw()
{
double size = Math.min(this.size + Game.tank_size / 2, this.age * 8);
double size = Math.min(this.size + Game.tile_size / 2, this.age * 8);
for (int i = (int) Math.max(0, size - ((int) (50 * Math.min(100, 600 - this.age) / 100.0))); i < size; i += 2)
{
Drawing.drawing.setColor(200, 255, 255, 10);

if (Game.enable3d)
Drawing.drawing.fillOval(this.posX, this.posY, (size - i) + Game.tank_size / 4, i, i, true, false);
Drawing.drawing.fillOval(this.posX, this.posY, (size - i) + Game.tile_size / 4, i, i, true, false);
else
Drawing.drawing.fillOval(this.posX, this.posY, i, i);
}
Expand Down
33 changes: 27 additions & 6 deletions src/main/java/tanks/Crusade.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Crusade
public boolean lifeGained = false;

public int currentLevel = 0;
public int saveLevel = 0;

public ArrayList<String> levels = new ArrayList<String>();
public int bonusLifeFrequency = 3;
Expand All @@ -33,16 +34,22 @@ public class Crusade
public ArrayList<Item> crusadeItems = new ArrayList<Item>();

public String name = "";
public String fileName = "";

public Crusade(ArrayList<String> levelArray, String name)
{
public boolean internal = false;

public Crusade(ArrayList<String> levelArray, String name, String file)
{
internal = true;
this.fileName = file;
this.initialize(levelArray, name);
}

public Crusade(BaseFile f, String name)
{
try
{
this.fileName = f.path;
f.startReading();
ArrayList<String> list = new ArrayList<String>();

Expand Down Expand Up @@ -172,16 +179,30 @@ public void levelFinished(boolean win)
{
this.win = true;
}
else if ((this.currentLevel + 1) % this.bonusLifeFrequency == 0 && !replay)
else if (!replay)
{
this.lifeGained = true;
this.saveLevel++;

for (Player player : Game.players)
if ((this.currentLevel + 1) % this.bonusLifeFrequency == 0)
{
player.remainingLives++;
this.lifeGained = true;

for (Player player : Game.players)
{
player.remainingLives++;
}
}
}
}

try
{
Game.player.saveCrusade(Game.game.fileManager.getFile(Game.homedir + Game.savedCrusadePath), win);
}
catch (Exception e)
{
Game.exitToCrash(e);
}
}

public boolean finalLife()
Expand Down
Loading

0 comments on commit 76c21e2

Please sign in to comment.