Skip to content

Commit

Permalink
Tanks v0.7.3 - Improved party player list, fixed some animations in m…
Browse files Browse the repository at this point in the history
…ultiplayer, and changed some effect animations to be 3D
  • Loading branch information
aehmttw committed Oct 7, 2019
1 parent 36d7084 commit 7d69d4a
Show file tree
Hide file tree
Showing 33 changed files with 588 additions and 129 deletions.
8 changes: 4 additions & 4 deletions src/main/java/lwjglwindow/FontRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public FontRenderer(LWJGLWindow h, String fontFile)
this.image = fontFile;
}

public int drawChar(double x, double y, double z, double sX, double sY, char c)
public int drawChar(double x, double y, double z, double sX, double sY, char c, boolean depthtest)
{
int i = this.chars.indexOf(c);

Expand All @@ -35,7 +35,7 @@ public int drawChar(double x, double y, double z, double sX, double sY, char c)
int col = i % 16;
int row = i / 16;
int width = charSizes[i];
this.home.drawImage(x, y, z, sX, sY - 0.0001, col / 16f, row / 16f, (col + width / 8f) / 16f, (row + 1) / 16f, image, true, false);
this.home.drawImage(x, y, z, sX, sY - 0.0001, col / 16f, row / 16f, (col + width / 8f) / 16f, (row + 1) / 16f, image, true, depthtest);
return width;
}

Expand All @@ -61,7 +61,7 @@ else if (c[i] == '\u00A7')
i += 12;
}
else
curX += (drawChar(curX, y, z, sX, sY, c[i]) + 1) * sX * 4;
curX += (drawChar(curX, y, z, sX, sY, c[i], true) + 1) * sX * 4;
}

GL11.glDisable(GL11.GL_DEPTH_TEST);
Expand All @@ -87,7 +87,7 @@ else if (c[i] == '\u00A7')
i += 12;
}
else
curX += (drawChar(curX, y, 0, sX, sY, c[i]) + 1) * sX * 4;
curX += (drawChar(curX, y, 0, sX, sY, c[i], false) + 1) * sX * 4;
}
}

Expand Down
37 changes: 25 additions & 12 deletions src/main/java/lwjglwindow/LWJGLWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,14 @@ public void fillOval(double x, double y, double sX, double sY)
glEnd();
}

public void fillOval(double x, double y, double z, double sX, double sY)
{
public void fillOval(double x, double y, double z, double sX, double sY, boolean depthTest)
{
if (depthTest)
{
glEnable(GL_DEPTH_TEST);
glDepthMask(false);
}

x += sX / 2;
y += sY / 2;

Expand All @@ -329,6 +335,12 @@ public void fillOval(double x, double y, double z, double sX, double sY)
}

glEnd();

if (depthTest)
{
glDepthMask(true);
glDisable(GL_DEPTH_TEST);
}
}

public void setColor(double r, double g, double b, double a)
Expand Down Expand Up @@ -415,15 +427,15 @@ public void fillBox(double x, double y, double z, double sX, double sY, double s
* +64 draw on top
* */
public void fillBox(double x, double y, double z, double sX, double sY, double sZ, byte options)
{
{
glEnable(GL_DEPTH_TEST);

if ((options >> 6) % 2 == 0)
glDepthFunc(GL_LESS);
glDepthFunc(GL_LESS);
else
glDepthFunc(GL_ALWAYS);
GL11.glBegin(GL11.GL_QUADS);
glDepthFunc(GL_ALWAYS);

GL11.glBegin(GL11.GL_QUADS);

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

GL11.glEnd();
GL11.glEnd();
glDisable(GL_DEPTH_TEST);
}

Expand Down Expand Up @@ -672,7 +684,7 @@ public void setPerspective()
//double ang1 = Math.PI / 4;
//glMultMatrixd(new double[]{Math.cos(ang1), -Math.sin(ang1), 0, 0, Math.sin(ang1), Math.cos(ang1), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1});

//double ang2 = -Math.PI / 16;
//double ang2 = -Math.PI * 6 / 16;
//glMultMatrixd(new double[]{1, 0, 0, 0, 0, Math.cos(ang2), -Math.sin(ang2), 0, 0, Math.sin(ang2), Math.cos(ang2), 0, 0, 0, 0, 1});

//double ang3 = Math.PI / 5;
Expand Down Expand Up @@ -740,8 +752,9 @@ public void drawImage(double x, double y, double z, double sX, double sY, double
if (depthtest)
glEnable(GL_DEPTH_TEST);

glFrustum(-absoluteWidth / (absoluteDepth * 2.0), absoluteWidth / (absoluteDepth * 2.0), absoluteHeight / (absoluteDepth * 2.0), -absoluteHeight / (absoluteDepth * 2.0), 1, absoluteDepth * 2);
glTranslated(-absoluteWidth / 2, -absoluteHeight / 2, -absoluteDepth);
//glFrustum(-absoluteWidth / (absoluteDepth * 2.0), absoluteWidth / (absoluteDepth * 2.0), absoluteHeight / (absoluteDepth * 2.0), -absoluteHeight / (absoluteDepth * 2.0), 1, absoluteDepth * 2);
//glTranslated(-absoluteWidth / 2, -absoluteHeight / 2, -absoluteDepth);
setPerspective();

glMatrixMode(GL_MODELVIEW);
//glLoadIdentity();
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/tanks/AreaEffectFreeze.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public void imbueEffects()
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));
e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 200.0);

if (Game.enable3d)
e.set3dPolarMotion(Math.random() * 2 * Math.PI, Math.random() * Math.PI, Math.random() * this.size / 200.0);
else
e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 200.0);

e.maxAge *= 4;
Game.effects.add(e);
}
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/tanks/Drawing.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ public void fillOval(double x, double y, double sizeX, double sizeY)

Game.game.window.fillOval(drawX, drawY, drawSizeX, drawSizeY);
}

public void fillOval(double x, double y, double z, double sizeX, double sizeY)
{
this.fillOval(x, y, z, sizeX, sizeY, true);
}

public void fillOval(double x, double y, double z, double sizeX, double sizeY, boolean depthTest)
{
double drawX = (scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - this.sizeX * this.scale) / 2);
double drawY = (scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - this.sizeY * this.scale) / 2);
Expand All @@ -92,7 +97,7 @@ public void fillOval(double x, double y, double z, double sizeX, double sizeY)

double dZ = z * scale / interfaceScale;

Game.game.window.fillOval(drawX, drawY, dZ, drawSizeX, drawSizeY);
Game.game.window.fillOval(drawX, drawY, dZ, drawSizeX, drawSizeY, depthTest);
}

public void fillForcedOval(double x, double y, double sizeX, double sizeY)
Expand Down Expand Up @@ -265,6 +270,7 @@ public void fillBox(double x, double y, double z, double sizeX, double sizeY, do
{
double drawX = (scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - this.sizeX * scale) / 2);
double drawY = (scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - this.sizeY * scale) / 2);
double drawZ = z * scale / interfaceScale;

if (drawX - 200 * scale > Panel.windowWidth || drawX + 200 * scale < 0 || drawY - 200 * scale > Panel.windowHeight || drawY + 200 * scale < 0)
return;
Expand All @@ -273,7 +279,7 @@ public void fillBox(double x, double y, double z, double sizeX, double sizeY, do
double drawSizeY = sizeY * scale;
double drawSizeZ = sizeZ * scale / interfaceScale;

Game.game.window.fillBox(drawX, drawY, z, drawSizeX, drawSizeY, drawSizeZ, options);
Game.game.window.fillBox(drawX, drawY, drawZ, drawSizeX, drawSizeY, drawSizeZ, options);
}

public void drawRect(double x, double y, double sizeX, double sizeY)
Expand Down Expand Up @@ -368,8 +374,9 @@ public void drawText(double x, double y, double z, String text)

double drawX = (scale * (x + getPlayerOffsetX() - sizeX / 2) + Math.max(0, Panel.windowWidth - this.sizeX * scale) / 2);
double drawY = (scale * (y + getPlayerOffsetY() - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - this.sizeY * scale) / 2);
double drawZ = z * scale / interfaceScale;

Game.game.window.fontRenderer.drawString(drawX, drawY, z, this.fontSize, this.fontSize, text);
Game.game.window.fontRenderer.drawString(drawX, drawY, drawZ, this.fontSize, this.fontSize, text);
}

public void drawInterfaceText(double x, double y, String text)
Expand Down
34 changes: 18 additions & 16 deletions src/main/java/tanks/Effect.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum EffectType {fire, smokeTrail, trail, ray, mineExplosion, laser, piec
public double angle;
public double distance;

public static Effect createNewEffect(double x, double y, EffectType type)
public static Effect createNewEffect(double x, double y, double z, EffectType type)
{
//while (Game.recycleEffects.size() > 0 && Game.recycleEffects.get(0) == null)
// Game.recycleEffects.remove(0);
Expand All @@ -31,38 +31,34 @@ public static Effect createNewEffect(double x, double y, EffectType type)
Effect e = Game.recycleEffects.remove(0);

e.refurbish();
e.initialize(x, y, type);
e.initialize(x, y, z, type);

return e;
}
else
{
Effect e = new Effect();
e.initialize(x, y, type);
e.initialize(x, y, z, type);
return e;
}
}

public static Effect createNewEffect(double x, double y, EffectType type, double opacityMultiplier, double age)
{
Effect e = Effect.createNewEffect(x, y, type);
e.ffOpacityMultiplier = Math.min(1, Panel.frameFrequency * opacityMultiplier);
e.age = age * Panel.frameFrequency;
return e;
return Effect.createNewEffect(x, y, 0, type, opacityMultiplier, age);
}

public static Effect createNewEffect(double x, double y, double z, EffectType type, double opacityMultiplier, double age)
{
Effect e = Effect.createNewEffect(x, y, type, opacityMultiplier, age);
e.posZ = z;
Effect e = Effect.createNewEffect(x, y, z, type);
e.ffOpacityMultiplier = Math.min(1, Panel.frameFrequency * opacityMultiplier);
e.age = age * Panel.frameFrequency;
return e;
}

public static Effect createNewEffect(double x, double y, double z, EffectType type)
public static Effect createNewEffect(double x, double y, EffectType type)
{
Effect e = Effect.createNewEffect(x, y, type);
e.posZ = z;
return e;
return Effect.createNewEffect(x, y, 0, type);
}

/**
Expand All @@ -73,10 +69,11 @@ protected Effect()
super(0, 0);
}

protected void initialize(double x, double y, EffectType type)
protected void initialize(double x, double y, double z, EffectType type)
{
this.posX = x;
this.posY = y;
this.posZ = z;
this.type = type;

if (type == EffectType.fire)
Expand All @@ -99,9 +96,14 @@ else if (type == EffectType.obstaclePiece3d)
this.maxAge = Math.random() * 100 + 50;
else if (type.equals(EffectType.charge))
{
this.addPolarMotion(Math.random() * Math.PI * 2, Math.random() * 3 + 3);
if (Game.enable3d)
this.add3dPolarMotion(Math.random() * Math.PI * 2,-Math.random() * Math.PI / 2, Math.random() * 3 + 3);
else
this.addPolarMotion(Math.random() * Math.PI * 2, Math.random() * 3 + 3);

this.posX -= this.vX * 25;
this.posY -= this.vY * 25;
this.posZ -= this.vZ * 25;
this.maxAge = 25;
}
else if (type == EffectType.tread)
Expand Down Expand Up @@ -254,7 +256,7 @@ else if (this.type == EffectType.obstaclePiece3d)
drawing.fillBox(this.posX, this.posY, this.posZ, size, size, size);
}
else if (this.type == EffectType.charge)
{
{
double size = 1 + (Bullet.bullet_size * (this.age / this.maxAge));
drawing.setColor(this.colR, this.colG, this.colB);

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/tanks/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public class Game

public static double[][] tilesDepth = new double[28][18];

public static final int network_protocol = 5;
public static final String version = "Tanks 0.7.2";
public static final int network_protocol = 6;
public static final String version = "Tanks 0.7.3";

public static int port = 8080;

Expand Down Expand Up @@ -150,6 +150,8 @@ public static void initScript()
/* 19*/ NetworkEventMap.register(EventShootBullet.class);
/* 20*/ NetworkEventMap.register(EventLayMine.class);
/* 21*/ NetworkEventMap.register(EventTankTeleport.class);
/* 22*/ NetworkEventMap.register(EventTankUpdateVisibility.class);
/* 23*/ NetworkEventMap.register(EventTankRedUpdateCharge.class);

defaultObstacles.add(new RegistryObstacle.DefaultObstacleEntry(Obstacle.class, "normal"));
defaultObstacles.add(new RegistryObstacle.DefaultObstacleEntry(ObstacleIndestructible.class, "hard"));
Expand Down
54 changes: 49 additions & 5 deletions src/main/java/tanks/LevelGenerator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tanks;

import tanks.gui.screen.ScreenPartyHost;

import java.util.ArrayList;

public class LevelGenerator
Expand Down Expand Up @@ -407,28 +409,70 @@ else if (rand < 0.75)

int x = (int) (Math.random() * (width));
int y = (int) (Math.random() * (height));
while (cells[x][y])

while (cells[x][y])
{
x = (int) (Math.random() * (width));
y = (int) (Math.random() * (height));
}
for (int i = -2; i <= 2; i++)

/*for (int i = -2; i <= 2; i++)
for (int j = -2; j <= 2; j++)
cells[Math.max(0, Math.min(width - 1, x+i))][Math.max(0, Math.min(height - 1, y+j))] = true;
s.append(x).append("-").append(y).append("-player-").append((int) (Math.random() * 4)).append(",");
for (int i = 0; i < numTanks; i++)
s.append(x).append("-").append(y).append("-player-").append((int) (Math.random() * 4)).append(",");*/

int numPlayers = 1;

if (ScreenPartyHost.isServer)
numPlayers += ScreenPartyHost.server.connections.size();

for (int i = 0; i < numPlayers; i++)
{
int angle = (int) (Math.random() * 4);
x = (int) (Math.random() * (width));
y = (int) (Math.random() * (height));

while (cells[x][y])
{
x = (int) (Math.random() * (width));
y = (int) (Math.random() * (height));
}

int bound;

if (numPlayers < 20)
bound = 2;
else if (numPlayers < 56)
bound = 1;
else
bound = 0;

for (int a = -bound; a <= bound; a++)
for (int j = -bound; j <= bound; j++)
cells[Math.max(0, Math.min(width - 1, x+a))][Math.max(0, Math.min(height - 1, y+j))] = true;

s.append(x).append("-").append(y).append("-");
s.append("player");
s.append("-").append(angle);

s.append(",");
}

for (int i = 0; i < numTanks; i++)
{
int angle = (int) (Math.random() * 4);
x = (int) (Math.random() * (width));
y = (int) (Math.random() * (height));

while (cells[x][y])
{
x = (int) (Math.random() * (width));
y = (int) (Math.random() * (height));
}

for (int a = -1; a <= 1; a++)
for (int j = -2; j <= 1; j++)
for (int j = -1; j <= 1; j++)
cells[Math.max(0, Math.min(width - 1, x+a))][Math.max(0, Math.min(height - 1, y+j))] = true;

s.append(x).append("-").append(y).append("-");
Expand Down
Loading

0 comments on commit 7d69d4a

Please sign in to comment.