From 7d69d4a467d2fc5a04fa35e5aea212b2847d0a24 Mon Sep 17 00:00:00 2001 From: Aehmttw Date: Mon, 7 Oct 2019 10:16:23 -0700 Subject: [PATCH] Tanks v0.7.3 - Improved party player list, fixed some animations in multiplayer, and changed some effect animations to be 3D --- src/main/java/lwjglwindow/FontRenderer.java | 8 +-- src/main/java/lwjglwindow/LWJGLWindow.java | 37 +++++++---- src/main/java/tanks/AreaEffectFreeze.java | 7 +- src/main/java/tanks/Drawing.java | 15 +++-- src/main/java/tanks/Effect.java | 34 +++++----- src/main/java/tanks/Game.java | 6 +- src/main/java/tanks/LevelGenerator.java | 54 ++++++++++++++-- src/main/java/tanks/LevelGeneratorVersus.java | 25 ++++++-- src/main/java/tanks/Movable.java | 26 ++++++++ src/main/java/tanks/Panel.java | 2 + src/main/java/tanks/bullet/Bullet.java | 9 ++- .../java/tanks/event/EventCreatePlayer.java | 1 + .../tanks/event/EventTankRedUpdateCharge.java | 60 ++++++++++++++++++ .../java/tanks/event/EventTankTeleport.java | 12 ++++ .../event/EventTankUpdateVisibility.java | 49 ++++++++++++++ src/main/java/tanks/gui/Button.java | 33 ++++++---- src/main/java/tanks/gui/ChatBox.java | 5 +- src/main/java/tanks/gui/screen/Screen.java | 6 +- .../java/tanks/gui/screen/ScreenGame.java | 13 ++-- .../tanks/gui/screen/ScreenLevelBuilder.java | 16 ++++- .../tanks/gui/screen/ScreenPartyHost.java | 42 +++++++++++- .../tanks/gui/screen/ScreenPartyKick.java | 36 ++++++++++- src/main/java/tanks/obstacle/Obstacle.java | 11 ++-- .../tanks/obstacle/ObstacleTeleporter.java | 20 +++--- src/main/java/tanks/tank/Mine.java | 9 ++- src/main/java/tanks/tank/NameTag.java | 46 ++++++++++++++ src/main/java/tanks/tank/Ray.java | 2 +- src/main/java/tanks/tank/Tank.java | 26 +++----- src/main/java/tanks/tank/TankRed.java | 19 ++++-- src/main/java/tanks/tank/TankRemote.java | 52 ++++++++++++++- src/main/java/tanks/tank/TankWhite.java | 16 +++-- src/main/java/tanks/tank/TeleporterOrb.java | 20 ++++-- src/main/resources/font.png | Bin 10239 -> 10239 bytes 33 files changed, 588 insertions(+), 129 deletions(-) create mode 100755 src/main/java/tanks/event/EventTankRedUpdateCharge.java create mode 100755 src/main/java/tanks/event/EventTankUpdateVisibility.java create mode 100644 src/main/java/tanks/tank/NameTag.java diff --git a/src/main/java/lwjglwindow/FontRenderer.java b/src/main/java/lwjglwindow/FontRenderer.java index 9f6d9b7b..9bc3a19a 100755 --- a/src/main/java/lwjglwindow/FontRenderer.java +++ b/src/main/java/lwjglwindow/FontRenderer.java @@ -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); @@ -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; } @@ -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); @@ -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; } } diff --git a/src/main/java/lwjglwindow/LWJGLWindow.java b/src/main/java/lwjglwindow/LWJGLWindow.java index 90c88dba..36e578c2 100755 --- a/src/main/java/lwjglwindow/LWJGLWindow.java +++ b/src/main/java/lwjglwindow/LWJGLWindow.java @@ -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; @@ -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) @@ -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) { @@ -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); } @@ -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; @@ -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(); diff --git a/src/main/java/tanks/AreaEffectFreeze.java b/src/main/java/tanks/AreaEffectFreeze.java index 27f20610..09355f22 100755 --- a/src/main/java/tanks/AreaEffectFreeze.java +++ b/src/main/java/tanks/AreaEffectFreeze.java @@ -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); } diff --git a/src/main/java/tanks/Drawing.java b/src/main/java/tanks/Drawing.java index 1a7c8ae0..8244b5e3 100755 --- a/src/main/java/tanks/Drawing.java +++ b/src/main/java/tanks/Drawing.java @@ -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); @@ -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) @@ -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; @@ -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) @@ -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) diff --git a/src/main/java/tanks/Effect.java b/src/main/java/tanks/Effect.java index fa3f57cd..c45f2798 100755 --- a/src/main/java/tanks/Effect.java +++ b/src/main/java/tanks/Effect.java @@ -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); @@ -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); } /** @@ -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) @@ -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) @@ -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); diff --git a/src/main/java/tanks/Game.java b/src/main/java/tanks/Game.java index c6d28a5b..ebc08703 100755 --- a/src/main/java/tanks/Game.java +++ b/src/main/java/tanks/Game.java @@ -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; @@ -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")); diff --git a/src/main/java/tanks/LevelGenerator.java b/src/main/java/tanks/LevelGenerator.java index f36102c9..458d1ae9 100755 --- a/src/main/java/tanks/LevelGenerator.java +++ b/src/main/java/tanks/LevelGenerator.java @@ -1,5 +1,7 @@ package tanks; +import tanks.gui.screen.ScreenPartyHost; + import java.util.ArrayList; public class LevelGenerator @@ -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("-"); diff --git a/src/main/java/tanks/LevelGeneratorVersus.java b/src/main/java/tanks/LevelGeneratorVersus.java index 7032aaea..1b3f5911 100755 --- a/src/main/java/tanks/LevelGeneratorVersus.java +++ b/src/main/java/tanks/LevelGeneratorVersus.java @@ -409,27 +409,40 @@ 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 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; 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++) + + int bound; + + if (numTanks < 6) + bound = 4; + else if (numTanks < 10) + bound = 3; + else if (numTanks < 20) + bound = 2; + else if (numTanks < 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("-"); diff --git a/src/main/java/tanks/Movable.java b/src/main/java/tanks/Movable.java index 89edfdab..8eb7f4c3 100755 --- a/src/main/java/tanks/Movable.java +++ b/src/main/java/tanks/Movable.java @@ -2,6 +2,7 @@ import tanks.gui.screen.ScreenGame; import tanks.obstacle.Obstacle; +import tanks.tank.NameTag; import java.util.ArrayList; @@ -16,6 +17,9 @@ public abstract class Movable implements IDrawableForInterface public double cooldown = 0; public boolean destroy = false; + public NameTag nameTag; + public boolean showName = false; + public int drawLevel = 3; //public boolean drawBelow = false; //public boolean drawAbove = false; @@ -202,6 +206,17 @@ public void setPolarMotion(double angle, double velocity) this.vY = velY; } + public void set3dPolarMotion(double angle1, double angle2, double velocity) + { + double velX = velocity * Math.cos(angle1) * Math.cos(angle2); + double velY = velocity * Math.sin(angle1) * Math.cos(angle2); + double velZ = velocity * Math.sin(angle2); + + this.vX = velX; + this.vY = velY; + this.vZ = velZ; + } + public void addPolarMotion(double angle, double velocity) { double velX = velocity * Math.cos(angle); @@ -210,6 +225,17 @@ public void addPolarMotion(double angle, double velocity) this.vY += velY; } + public void add3dPolarMotion(double angle1, double angle2, double velocity) + { + double velX = velocity * Math.cos(angle1) * Math.cos(angle2); + double velY = velocity * Math.sin(angle1) * Math.cos(angle2); + double velZ = velocity * Math.sin(angle2); + + this.vX += velX; + this.vY += velY; + this.vZ += velZ; + } + public void moveInDirection(double x, double y, double amount) { this.posX += amount * x; diff --git a/src/main/java/tanks/Panel.java b/src/main/java/tanks/Panel.java index 3ef89ad1..a1c16d01 100755 --- a/src/main/java/tanks/Panel.java +++ b/src/main/java/tanks/Panel.java @@ -219,6 +219,8 @@ public void draw() this.drawBar(); this.drawMouseTarget(); + + } public void drawMouseTarget() diff --git a/src/main/java/tanks/bullet/Bullet.java b/src/main/java/tanks/bullet/Bullet.java index cd277335..686cd6b7 100755 --- a/src/main/java/tanks/bullet/Bullet.java +++ b/src/main/java/tanks/bullet/Bullet.java @@ -349,7 +349,12 @@ public void update() e.colR = Math.min(255, Math.max(0, this.baseColorR + Math.random() * var - var / 2)); e.colG = Math.min(255, Math.max(0, this.baseColorG + Math.random() * var - var / 2)); e.colB = Math.min(255, Math.max(0, this.baseColorB + Math.random() * var - var / 2)); - e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 50.0 * 4); + + if (Game.enable3d) + e.set3dPolarMotion(Math.random() * 2 * Math.PI, Math.random() * Math.PI, Math.random() * this.size / 50.0 * 4); + else + e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 50.0 * 4); + Game.effects.add(e); } } @@ -437,7 +442,7 @@ public void draw() Drawing.drawing.setColor(this.baseColorR, this.baseColorG, this.baseColorB, (int)(opacity * opacity * opacity * 255.0)); if (Game.enable3d) - Drawing.drawing.fillOval(posX, posY, posZ, (size + sizeModifier) * 0.6, (size + sizeModifier) * 0.6); + Drawing.drawing.fillOval(posX, posY, posZ + 1, (size + sizeModifier) * 0.6, (size + sizeModifier) * 0.6); else Drawing.drawing.fillOval(posX, posY, (size + sizeModifier) * 0.6, (size + sizeModifier) * 0.6); diff --git a/src/main/java/tanks/event/EventCreatePlayer.java b/src/main/java/tanks/event/EventCreatePlayer.java index e5f22d85..5879dd31 100755 --- a/src/main/java/tanks/event/EventCreatePlayer.java +++ b/src/main/java/tanks/event/EventCreatePlayer.java @@ -59,6 +59,7 @@ public void execute() } t.name = this.username; + t.nameTag.name = this.username; if (Game.enableChatFilter) t.name = Game.chatFilter.filterChat(t.name); diff --git a/src/main/java/tanks/event/EventTankRedUpdateCharge.java b/src/main/java/tanks/event/EventTankRedUpdateCharge.java new file mode 100755 index 00000000..56e83b5c --- /dev/null +++ b/src/main/java/tanks/event/EventTankRedUpdateCharge.java @@ -0,0 +1,60 @@ +package tanks.event; + +import io.netty.buffer.ByteBuf; +import tanks.Effect; +import tanks.Game; +import tanks.tank.Tank; + +public class EventTankRedUpdateCharge implements INetworkEvent +{ + public int tank; + public double charge; + + public EventTankRedUpdateCharge() + { + + } + + public EventTankRedUpdateCharge(int tank, double charge) + { + this.tank = tank; + this.charge = charge; + } + + @Override + public void execute() + { + Tank t = Tank.idMap.get(this.tank); + + t.colorR = Math.min((200 + charge * 55), 255); + t.colorG = charge * 100; + t.colorB = charge * 100; + + if (Math.random() < charge && Game.fancyGraphics) + { + Effect e = Effect.createNewEffect(t.posX, t.posY, t.size / 4, Effect.EffectType.charge); + + double var = 50; + e.colR = Math.min(255, Math.max(0, t.colorR + Math.random() * var - var / 2)); + e.colG = Math.min(255, Math.max(0, t.colorG + Math.random() * var - var / 2)); + e.colB = Math.min(255, Math.max(0, t.colorB + Math.random() * var - var / 2)); + + Game.effects.add(e); + } + + } + + @Override + public void write(ByteBuf b) + { + b.writeInt(this.tank); + b.writeDouble(this.charge); + } + + @Override + public void read(ByteBuf b) + { + this.tank = b.readInt(); + this.charge = b.readDouble(); + } +} diff --git a/src/main/java/tanks/event/EventTankTeleport.java b/src/main/java/tanks/event/EventTankTeleport.java index 86f8db9f..0bbcad5a 100644 --- a/src/main/java/tanks/event/EventTankTeleport.java +++ b/src/main/java/tanks/event/EventTankTeleport.java @@ -2,6 +2,8 @@ import io.netty.buffer.ByteBuf; import tanks.Game; +import tanks.obstacle.Obstacle; +import tanks.obstacle.ObstacleTeleporter; import tanks.tank.Tank; import tanks.tank.TeleporterOrb; @@ -80,6 +82,16 @@ public void execute() t.maxAge = this.maxAge; t.endAge = this.endAge; Game.movables.add(t); + + for (int i = 0; i < Game.obstacles.size(); i++) + { + Obstacle o = Game.obstacles.get(i); + + if (o instanceof ObstacleTeleporter && ((o.posX == this.iX && o.posY == this.iY) || (o.posX == this.dX && o.posY == this.dY))) + { + ((ObstacleTeleporter)o).cooldown = 500; + } + } } } diff --git a/src/main/java/tanks/event/EventTankUpdateVisibility.java b/src/main/java/tanks/event/EventTankUpdateVisibility.java new file mode 100755 index 00000000..c4273b5e --- /dev/null +++ b/src/main/java/tanks/event/EventTankUpdateVisibility.java @@ -0,0 +1,49 @@ +package tanks.event; + +import io.netty.buffer.ByteBuf; +import tanks.Game; +import tanks.gui.screen.ScreenPartyLobby; +import tanks.tank.Tank; +import tanks.tank.TankRemote; + +public class EventTankUpdateVisibility implements INetworkEvent +{ + public int tank; + public boolean visible; + + public EventTankUpdateVisibility() + { + + } + + public EventTankUpdateVisibility(int tank, boolean visible) + { + this.tank = tank; + this.visible = visible; + } + + @Override + public void execute() + { + Tank t = Tank.idMap.get(this.tank); + + if (t instanceof TankRemote) + { + ((TankRemote) t).invisible = !visible; + } + } + + @Override + public void write(ByteBuf b) + { + b.writeInt(this.tank); + b.writeBoolean(this.visible); + } + + @Override + public void read(ByteBuf b) + { + this.tank = b.readInt(); + this.visible = b.readBoolean(); + } +} diff --git a/src/main/java/tanks/gui/Button.java b/src/main/java/tanks/gui/Button.java index 825e75c3..3b4ff716 100755 --- a/src/main/java/tanks/gui/Button.java +++ b/src/main/java/tanks/gui/Button.java @@ -23,17 +23,24 @@ public class Button public boolean enabled = true; - double disabledColR = 200; - double disabledColG = 200; - double disabledColB = 200; - - double unselectedColR = 255; - double unselectedColG = 255; - double unselectedColB = 255; - - double selectedColR = 240; - double selectedColG = 240; - double selectedColB = 255; + public double disabledColR = 200; + public double disabledColG = 200; + public double disabledColB = 200; + + public double unselectedColR = 255; + public double unselectedColG = 255; + public double unselectedColB = 255; + + public double selectedColR = 240; + public double selectedColG = 240; + public double selectedColB = 255; + + public double textColR = 0; + public double textColG = 0; + public double textColB = 0; + + public double textOffsetX = 0; + public double textOffsetY = 0; public Button(double x, double y, double sX, double sY, String text, Runnable f) { @@ -91,8 +98,8 @@ else if (selected) drawing.fillInterfaceOval(posX - sizeX / 2 + sizeY / 2, posY, sizeY, sizeY); drawing.fillInterfaceOval(posX + sizeX / 2 - sizeY / 2, posY, sizeY, sizeY); - drawing.setColor(0, 0, 0); - drawing.drawInterfaceText(posX, posY, text); + drawing.setColor(this.textColR, this.textColG, this.textColB); + drawing.drawInterfaceText(posX + this.textOffsetX, posY + this.textOffsetY, text); if (enableHover) { diff --git a/src/main/java/tanks/gui/ChatBox.java b/src/main/java/tanks/gui/ChatBox.java index 75158008..06ee6e28 100755 --- a/src/main/java/tanks/gui/ChatBox.java +++ b/src/main/java/tanks/gui/ChatBox.java @@ -81,7 +81,10 @@ public void update() { if (this.inputText.length() > 0) this.function.run(); - + + Game.game.window.validPressedKeys.remove((Integer)GLFW.GLFW_KEY_ENTER); + Game.game.window.pressedKeys.remove((Integer)GLFW.GLFW_KEY_ENTER); + this.selected = false; this.inputText = this.defaultText; } diff --git a/src/main/java/tanks/gui/screen/Screen.java b/src/main/java/tanks/gui/screen/Screen.java index 249aca55..9a0056c3 100755 --- a/src/main/java/tanks/gui/screen/Screen.java +++ b/src/main/java/tanks/gui/screen/Screen.java @@ -48,14 +48,16 @@ public void drawDefaultBackground(double size) if (size != 1) Drawing.drawing.fillBox( (i + 0.5) / Game.bgResMultiplier * Obstacle.obstacle_size, - (j + 0.5) / Game.bgResMultiplier * Obstacle.obstacle_size, Math.max(0, 2000 - size * 2000 * (1 + Game.tilesDepth[i][j] / 10)) - Obstacle.obstacle_size + Game.tilesDepth[i][j], + (j + 0.5) / Game.bgResMultiplier * Obstacle.obstacle_size, + Math.max(0, 2000 - size * 2000 * (1 + Game.tilesDepth[i][j] / 10)) - Obstacle.obstacle_size + Game.tilesDepth[i][j], Obstacle.obstacle_size / Game.bgResMultiplier, Obstacle.obstacle_size / Game.bgResMultiplier, Obstacle.obstacle_size); else Drawing.drawing.fillBox( (i + 0.5) / Game.bgResMultiplier * Obstacle.obstacle_size, - (j + 0.5) / Game.bgResMultiplier * Obstacle.obstacle_size, 0, + (j + 0.5) / Game.bgResMultiplier * Obstacle.obstacle_size, + 0, Obstacle.obstacle_size / Game.bgResMultiplier, Obstacle.obstacle_size / Game.bgResMultiplier, Game.tilesDepth[i][j]); diff --git a/src/main/java/tanks/gui/screen/ScreenGame.java b/src/main/java/tanks/gui/screen/ScreenGame.java index 26f5a5cd..27cf5de0 100755 --- a/src/main/java/tanks/gui/screen/ScreenGame.java +++ b/src/main/java/tanks/gui/screen/ScreenGame.java @@ -8,12 +8,10 @@ import tanks.hotbar.Item; import tanks.network.Client; import tanks.obstacle.Obstacle; -import tanks.tank.Mine; -import tanks.tank.Tank; -import tanks.tank.TankPlayer; -import tanks.tank.TankRemote; +import tanks.tank.*; import org.lwjgl.glfw.GLFW; +import javax.naming.Name; import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -44,7 +42,6 @@ public class ScreenGame extends Screen @SuppressWarnings("unchecked") protected ArrayList[] drawables = (ArrayList[])(new ArrayList[10]); - Button play = new Button(Drawing.drawing.interfaceSizeX-200, Drawing.drawing.interfaceSizeY-50, 350, 40, "Play", new Runnable() { @@ -732,13 +729,18 @@ public void draw() { this.drawDefaultBackground(); + for (int i = 0; i < Game.belowEffects.size(); i++) drawables[0].add(Game.belowEffects.get(i)); for (int i = 0; i < Game.movables.size(); i++) { Movable m = Game.movables.get(i); + drawables[m.drawLevel].add(m); + + if (m.showName) + drawables[m.nameTag.drawLevel].add(m.nameTag); } for (int i = 0; i < Game.obstacles.size(); i++) @@ -750,7 +752,6 @@ public void draw() for (int i = 0; i < Game.effects.size(); i++) drawables[7].add(Game.effects.get(i)); - for (int i = 0; i < this.drawables.length; i++) { for (int j = 0; j < this.drawables[i].size(); j++) diff --git a/src/main/java/tanks/gui/screen/ScreenLevelBuilder.java b/src/main/java/tanks/gui/screen/ScreenLevelBuilder.java index f7ffb8b3..7b8b516d 100755 --- a/src/main/java/tanks/gui/screen/ScreenLevelBuilder.java +++ b/src/main/java/tanks/gui/screen/ScreenLevelBuilder.java @@ -531,7 +531,14 @@ public void run() if (levelName.inputText.length() > 0 && !new File(Game.homedir + ScreenSavedLevels.levelDir + "/" + levelName.inputText + ".tanks").exists()) { if (file.exists()) + { file.renameTo(new File(Game.homedir + ScreenSavedLevels.levelDir + "/" + levelName.inputText + ".tanks")); + } + + while (file.exists()) + { + file.delete(); + } name = levelName.inputText + ".tanks"; } @@ -1389,12 +1396,17 @@ else if (currentPlaceable == Placeable.playerTank) for (int z = 0; z < 100; z++) { - Effect e = Effect.createNewEffect(m.posX, m.posY, Effect.EffectType.piece); + Effect e = Effect.createNewEffect(m.posX, m.posY, ((Tank) m).size / 2, Effect.EffectType.piece); double var = 50; e.colR = Math.min(255, Math.max(0, ((Tank)m).colorR + Math.random() * var - var / 2)); e.colG = Math.min(255, Math.max(0, ((Tank)m).colorG + Math.random() * var - var / 2)); e.colB = Math.min(255, Math.max(0, ((Tank)m).colorB + Math.random() * var - var / 2)); - e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * 2); + + if (Game.enable3d) + e.set3dPolarMotion(Math.random() * 2 * Math.PI, Math.random() * Math.PI, Math.random() * 2); + else + e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * 2); + e.maxAge /= 2; Game.effects.add(e); } diff --git a/src/main/java/tanks/gui/screen/ScreenPartyHost.java b/src/main/java/tanks/gui/screen/ScreenPartyHost.java index 4d06e40c..9adf5674 100755 --- a/src/main/java/tanks/gui/screen/ScreenPartyHost.java +++ b/src/main/java/tanks/gui/screen/ScreenPartyHost.java @@ -22,13 +22,14 @@ public class ScreenPartyHost extends Screen implements IPartyMenuScreen public static ScreenPartyHost activeScreen; public String ip = ""; + Button[] kickButtons = new Button[entries_per_page]; + public int usernamePage = 0; public static int entries_per_page = 10; public static int username_spacing = 30; public static int username_y_offset = -120; - public static SynchronizedList chat = new SynchronizedList(); public static ChatBox chatbox = new ChatBox(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY - 30, 1380, 40, GLFW.GLFW_KEY_T, @@ -119,6 +120,35 @@ public void run() public ScreenPartyHost() { + for (int i = 0; i < this.kickButtons.length; i++) + { + final int j = i; + kickButtons[i] = new Button(Drawing.drawing.interfaceSizeX / 2 - 20, + Drawing.drawing.interfaceSizeY / 2 + (1 + i) * username_spacing + username_y_offset, 25, 25, "x", new Runnable() + { + @Override + public void run() + { + Game.screen = new ScreenPartyKick(server.connections.get(j + usernamePage * entries_per_page)); + } + }); + + kickButtons[i].textOffsetY = -1; + kickButtons[i].textOffsetX = 1; + + kickButtons[i].textColR = 255; + kickButtons[i].textColG = 255; + kickButtons[i].textColB = 255; + + kickButtons[i].unselectedColR = 255; + kickButtons[i].unselectedColG = 0; + kickButtons[i].unselectedColB = 0; + + kickButtons[i].selectedColR = 255; + kickButtons[i].selectedColG = 127; + kickButtons[i].selectedColB = 127; + } + activeScreen = this; isServer = true; serverThread = new Thread(new Runnable() @@ -183,8 +213,16 @@ public void update() if ((this.usernamePage + 1) * 10 < server.connections.size()) this.nextUsernamePage.update(); + + int entries = Math.min(10, server.connections.size() - this.usernamePage * entries_per_page); + + for (int i = 0; i < entries; i++) + { + this.kickButtons[i].update(); + } } + chatbox.update(); } @@ -249,6 +287,8 @@ public void draw() Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2 - 190, Drawing.drawing.interfaceSizeY / 2 + (1 + i - this.usernamePage * entries_per_page) * username_spacing + username_y_offset, server.connections.get(i).username); + + this.kickButtons[i - this.usernamePage * entries_per_page].draw(); } } } diff --git a/src/main/java/tanks/gui/screen/ScreenPartyKick.java b/src/main/java/tanks/gui/screen/ScreenPartyKick.java index 549fb582..6bca9b15 100644 --- a/src/main/java/tanks/gui/screen/ScreenPartyKick.java +++ b/src/main/java/tanks/gui/screen/ScreenPartyKick.java @@ -1,25 +1,59 @@ package tanks.gui.screen; +import tanks.Drawing; +import tanks.Game; +import tanks.event.EventKick; +import tanks.gui.Button; import tanks.network.ServerHandler; public class ScreenPartyKick extends Screen implements IPartyMenuScreen { public ServerHandler handler; + public Button kick; + + public Button cancel = new Button(Drawing.drawing.interfaceSizeX / 2 - 190, Drawing.drawing.interfaceSizeY / 2 + 120, 360, 40, "Cancel", new Runnable() + { + @Override + public void run() + { + Game.screen = ScreenPartyHost.activeScreen; + } + } + ); + public ScreenPartyKick(ServerHandler h) { handler = h; + kick = new Button(Drawing.drawing.interfaceSizeX / 2 + 190, Drawing.drawing.interfaceSizeY / 2 + 120, 360, 40, "Kick " + handler.username, new Runnable() + { + @Override + public void run() + { + handler.sendEventAndClose(new EventKick("You were kicked from the party")); + Game.screen = ScreenPartyHost.activeScreen; + } + } + ); } @Override public void update() { - + cancel.update(); + kick.update(); } @Override public void draw() { + this.drawDefaultBackground(); + + Drawing.drawing.setFontSize(24); + Drawing.drawing.setColor(0, 0, 0); + Drawing.drawing.drawInterfaceText(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - 90, "Would you like to kick " + handler.username + " from the party?"); + cancel.draw(); + kick.draw(); } } diff --git a/src/main/java/tanks/obstacle/Obstacle.java b/src/main/java/tanks/obstacle/Obstacle.java index c1de0ddd..d6668ddb 100755 --- a/src/main/java/tanks/obstacle/Obstacle.java +++ b/src/main/java/tanks/obstacle/Obstacle.java @@ -1,9 +1,6 @@ package tanks.obstacle; -import tanks.Drawing; -import tanks.Game; -import tanks.IDrawableForInterface; -import tanks.Movable; +import tanks.*; public class Obstacle implements IDrawableForInterface { @@ -28,8 +25,8 @@ public class Obstacle implements IDrawableForInterface public double colorB; public double colorA = 255; public static double draw_size = 0; - public static double obstacle_size = Game.tank_size; - + public static double obstacle_size = Game.tank_size; + public String name; public Obstacle(String name, double posX, double posY) @@ -49,7 +46,7 @@ public void draw() Drawing drawing = Drawing.drawing; drawing.setColor(this.colorR, this.colorG, this.colorB, this.colorA); - + if (Game.enable3d) drawing.fillBox(this.posX, this.posY, (obstacle_size - draw_size) / 2, draw_size, draw_size, draw_size); else diff --git a/src/main/java/tanks/obstacle/ObstacleTeleporter.java b/src/main/java/tanks/obstacle/ObstacleTeleporter.java index 98cb10b8..9facd6e6 100755 --- a/src/main/java/tanks/obstacle/ObstacleTeleporter.java +++ b/src/main/java/tanks/obstacle/ObstacleTeleporter.java @@ -11,8 +11,8 @@ public class ObstacleTeleporter extends Obstacle { - double cooldown; - double green = 255; + public double cooldown; + public double green = 255; public ObstacleTeleporter(String name, double posX, double posY) { @@ -70,7 +70,7 @@ public void update() { Movable m = Game.movables.get(i); - if (m instanceof Tank && ((Tank) m).targetable && !m.isRemote && Movable.distanceBetween(this, m) < ((Tank)m).size) + if (m instanceof Tank && ((Tank) m).targetable && Movable.distanceBetween(this, m) < ((Tank)m).size) { t = (Tank) m; @@ -80,15 +80,17 @@ public void update() continue; } - for (int j = 0; j < Game.obstacles.size(); j++) + if (!m.isRemote) { - Obstacle o = Game.obstacles.get(j); - if (o instanceof ObstacleTeleporter && o != this) + for (int j = 0; j < Game.obstacles.size(); j++) { - teleporters.add((ObstacleTeleporter) o); + Obstacle o = Game.obstacles.get(j); + if (o instanceof ObstacleTeleporter && o != this) + { + teleporters.add((ObstacleTeleporter) o); + } } - } - + } } } diff --git a/src/main/java/tanks/tank/Mine.java b/src/main/java/tanks/tank/Mine.java index 1cf3e4a9..522127d5 100755 --- a/src/main/java/tanks/tank/Mine.java +++ b/src/main/java/tanks/tank/Mine.java @@ -92,7 +92,11 @@ public void explode() e.colR = 255; e.colG = (1 - random) * 155 + Math.random() * 100; e.colB = 0; - e.setPolarMotion(Math.random() * 2 * Math.PI, random * (this.radius - Game.tank_size / 2) / Game.tank_size * 2); + + if (Game.enable3d) + e.set3dPolarMotion(Math.random() * 2 * Math.PI, Math.random() * Math.PI / 2, random * (this.radius - Game.tank_size / 2) / Game.tank_size * 2); + else + e.setPolarMotion(Math.random() * 2 * Math.PI, random * (this.radius - Game.tank_size / 2) / Game.tank_size * 2); Game.effects.add(e); } } @@ -145,8 +149,7 @@ else if (o instanceof Mine && !o.destroy) { for (int l = 0; l < Obstacle.obstacle_size; l += 10) { - Effect e = Effect.createNewEffect(o.posX + j + 5 - Obstacle.obstacle_size / 2, o.posY + k + 5 - Obstacle.obstacle_size / 2, Effect.EffectType.obstaclePiece3d); - e.posZ = l; + Effect e = Effect.createNewEffect(o.posX + j + 5 - Obstacle.obstacle_size / 2, o.posY + k + 5 - Obstacle.obstacle_size / 2, l, Effect.EffectType.obstaclePiece3d); e.colR = o.colorR; e.colG = o.colorG; diff --git a/src/main/java/tanks/tank/NameTag.java b/src/main/java/tanks/tank/NameTag.java new file mode 100644 index 00000000..8e91e3c0 --- /dev/null +++ b/src/main/java/tanks/tank/NameTag.java @@ -0,0 +1,46 @@ +package tanks.tank; + +import tanks.Drawing; +import tanks.Game; +import tanks.IDrawable; +import tanks.Movable; + +public class NameTag implements IDrawable +{ + public Movable movable; + public double ox; + public double oy; + public double oz; + public double size = 20; + public String name; + public int drawLevel = 9; + + public double colorR; + public double colorG; + public double colorB; + + public NameTag(Movable m, double ox, double oy, double oz, String name, double r, double g, double b) + { + this.movable = m; + this.ox = ox; + this.oy = oy; + this.oz = oz; + this.name = name; + + this.colorR = r; + this.colorG = g; + this.colorB = b; + } + + @Override + public void draw() + { + Drawing.drawing.setFontSize(size); + Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB); + + if (Game.enable3d) + Drawing.drawing.drawText(movable.posX + ox, movable.posY + oy, movable.posZ + oz, name); + else + Drawing.drawing.drawText(movable.posX + ox, movable.posY + oy, name); + } +} diff --git a/src/main/java/tanks/tank/Ray.java b/src/main/java/tanks/tank/Ray.java index 80dc3bfa..8bcba79c 100755 --- a/src/main/java/tanks/tank/Ray.java +++ b/src/main/java/tanks/tank/Ray.java @@ -83,7 +83,7 @@ public Movable getTarget() age++; if (trace && (!dotted || (this.age % 2 == 0))) - Game.effects.add(Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.ray)); + Game.effects.add(Effect.createNewEffect(this.posX, this.posY, Game.tank_size / 4, Effect.EffectType.ray)); this.posX += this.vX; this.posY += this.vY; diff --git a/src/main/java/tanks/tank/Tank.java b/src/main/java/tanks/tank/Tank.java index 984e1190..c3fb37fa 100755 --- a/src/main/java/tanks/tank/Tank.java +++ b/src/main/java/tanks/tank/Tank.java @@ -16,8 +16,6 @@ public abstract class Tank extends Movable public double angle = 0; - public boolean showName = false; - public boolean invulnerable = false; public boolean targetable = true; @@ -62,6 +60,8 @@ public Tank(String name, double x, double y, double size, double r, double g, do this.colorB = b; turret = new Turret(this); this.name = name; + this.nameTag = new NameTag(this, 0, this.size / 7 * 5, this.size / 2, this.name, r, g, b); + this.drawLevel = 4; if (countID) @@ -265,13 +265,18 @@ public void update() { for (int i = 0; i < this.size * 4; i++) { - Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece); + Effect e = Effect.createNewEffect(this.posX, this.posY, this.size / 4, Effect.EffectType.piece); double var = 50; e.colR = Math.min(255, Math.max(0, this.colorR + Math.random() * var - var / 2)); e.colG = Math.min(255, Math.max(0, this.colorG + Math.random() * var - var / 2)); e.colB = Math.min(255, Math.max(0, this.colorB + Math.random() * var - var / 2)); - e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 50.0); + + if (Game.enable3d) + e.set3dPolarMotion(Math.random() * 2 * Math.PI, Math.random() * Math.PI, Math.random() * this.size / 50.0); + else + e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 50.0); + Game.effects.add(e); } } @@ -457,9 +462,6 @@ public void drawTank(boolean forInterface) } this.turret.draw(angle, forInterface, true); - - if (this.showName) - this.drawName(); } @Override @@ -469,16 +471,6 @@ public void draw() this.drawTank(false); } - public void drawName() - { - Drawing.drawing.setFontSize(20); - - if (Game.enable3d) - Drawing.drawing.drawText(this.posX, this.posY + 35, this.size / 2, this.name); - else - Drawing.drawing.drawText(this.posX, this.posY + 35, this.name); - } - public void drawOutline() { drawAge = Game.tank_size; diff --git a/src/main/java/tanks/tank/TankRed.java b/src/main/java/tanks/tank/TankRed.java index 6ded2ab8..b75099b0 100755 --- a/src/main/java/tanks/tank/TankRed.java +++ b/src/main/java/tanks/tank/TankRed.java @@ -4,12 +4,13 @@ import tanks.bullet.BulletLaser; import tanks.Panel; import tanks.event.EventShootBullet; +import tanks.event.EventTankRedUpdateCharge; public class TankRed extends TankAIControlled { - boolean lineOfSight = false; - double maxCooldown = 100; - double idleTime = 0; + public boolean lineOfSight = false; + public double maxCooldown = 100; + public double idleTime = 0; public TankRed(String name, double x, double y, double angle) { @@ -38,6 +39,9 @@ public void update() if (this.cooldown < this.maxCooldown) { + if (!this.destroy) + Game.eventsOut.add(new EventTankRedUpdateCharge(this.networkID, (maxCooldown - this.cooldown) / maxCooldown)); + this.colorR = Math.min((200 + (maxCooldown - this.cooldown) / maxCooldown * 55), 255); this.colorG = (maxCooldown - this.cooldown) / maxCooldown * 100; this.colorB = (maxCooldown - this.cooldown) / maxCooldown * 100; @@ -51,6 +55,9 @@ public void update() this.colorR = 200; this.colorG = 0; this.colorB = 0; + + if (!this.destroy) + Game.eventsOut.add(new EventTankRedUpdateCharge(this.networkID, 0)); } } @@ -58,12 +65,14 @@ public void update() public void shoot() { this.lineOfSight = true; + if (this.cooldown > 0) { this.idleTime = 0; if (Math.random() * maxCooldown > cooldown && Game.fancyGraphics) { - Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.charge); + Effect e = Effect.createNewEffect(this.posX, this.posY, this.size / 4, Effect.EffectType.charge); + double var = 50; e.colR = Math.min(255, Math.max(0, this.colorR + Math.random() * var - var / 2)); e.colG = Math.min(255, Math.max(0, this.colorG + Math.random() * var - var / 2)); @@ -75,7 +84,7 @@ public void shoot() } - Ray r = new Ray(this.posX, this.posX, this.angle, 0, this); + Ray r = new Ray(this.posX, this.posY, this.angle, 0, this); r.moveOut(4); Movable m = r.getTarget(); diff --git a/src/main/java/tanks/tank/TankRemote.java b/src/main/java/tanks/tank/TankRemote.java index 9b913587..530a7dc8 100755 --- a/src/main/java/tanks/tank/TankRemote.java +++ b/src/main/java/tanks/tank/TankRemote.java @@ -1,12 +1,17 @@ package tanks.tank; -import tanks.Team; +import tanks.*; public class TankRemote extends Tank { public final boolean isCopy; public final Tank tank; + public boolean invisible = false; + public boolean vanished = false; + + public double localAge = 0; + public TankRemote(String name, double x, double y, double angle, Team team, double size, double ts, double tl, double r, double g, double b, double lives, double baselives) { super(name, x, y, size, r, g, b); @@ -40,4 +45,49 @@ public TankRemote(Tank t) Tank.idMap.put(this.networkID, this); } + @Override + public void update() + { + this.localAge += Panel.frameFrequency; + super.update(); + } + + @Override + public void draw() + { + if (!this.invisible || this.localAge <= 0 || this.destroy) + super.draw(); + else + { + if (!this.vanished) + { + this.vanished = true; + + if (Game.fancyGraphics) + { + for (int i = 0; i < 50; i++) + { + Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece); + double var = 50; + e.colR = Math.min(255, Math.max(0, this.colorR + Math.random() * var - var / 2)); + e.colG = Math.min(255, Math.max(0, this.colorG + Math.random() * var - var / 2)); + e.colB = Math.min(255, Math.max(0, this.colorB + Math.random() * var - var / 2)); + + if (Game.enable3d) + e.set3dPolarMotion(Math.random() * 2 * Math.PI, Math.random() * Math.PI, Math.random() * this.size / 50.0); + else + e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 50.0); + + Game.effects.add(e); Game.effects.add(e); + } + } + } + + for (int i = 0; i < Game.tank_size * 2 - this.localAge; i++) + { + Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, (this.size * 2 - i - this.localAge) * 2.55); + Drawing.drawing.fillOval(this.posX, this.posY, i, i); + } + } + } } diff --git a/src/main/java/tanks/tank/TankWhite.java b/src/main/java/tanks/tank/TankWhite.java index 0e783277..ec94bcd1 100755 --- a/src/main/java/tanks/tank/TankWhite.java +++ b/src/main/java/tanks/tank/TankWhite.java @@ -3,6 +3,7 @@ import tanks.Drawing; import tanks.Effect; import tanks.Game; +import tanks.event.EventTankUpdateVisibility; public class TankWhite extends TankAIControlled { @@ -15,6 +16,8 @@ public TankWhite(String name, double x, double y, double angle) this.enableDefensiveFiring = true; this.coinValue = 4; + + Game.eventsOut.add(new EventTankUpdateVisibility(this.networkID, false)); } @Override @@ -32,12 +35,17 @@ public void draw() { for (int i = 0; i < 50; i++) { - Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece); + Effect e = Effect.createNewEffect(this.posX, this.posY, this.size / 4, Effect.EffectType.piece); double var = 50; e.colR = Math.min(255, Math.max(0, this.colorR + Math.random() * var - var / 2)); - e.colG = Math.min(255, Math.max(0, this.colorR + Math.random() * var - var / 2)); - e.colB = Math.min(255, Math.max(0, this.colorR + Math.random() * var - var / 2)); - e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 50.0); + e.colG = Math.min(255, Math.max(0, this.colorG + Math.random() * var - var / 2)); + e.colB = Math.min(255, Math.max(0, this.colorB + Math.random() * var - var / 2)); + + if (Game.enable3d) + e.set3dPolarMotion(Math.random() * 2 * Math.PI, Math.random() * Math.PI, Math.random() * this.size / 50.0); + else + e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 50.0); + Game.effects.add(e); } } diff --git a/src/main/java/tanks/tank/TeleporterOrb.java b/src/main/java/tanks/tank/TeleporterOrb.java index af66d774..733542bc 100755 --- a/src/main/java/tanks/tank/TeleporterOrb.java +++ b/src/main/java/tanks/tank/TeleporterOrb.java @@ -46,7 +46,11 @@ public void draw() for (int i = 0; i < this.size - this.tank.size; i++) { Drawing.drawing.setColor(255, 255, 255, 20); - Drawing.drawing.fillOval(this.posX, this.posY, i, i); + + if (Game.enable3d) + Drawing.drawing.fillOval(this.posX, this.posY, this.posZ, i, i, false); + else + Drawing.drawing.fillOval(this.posX, this.posY, i, i); } } @@ -74,7 +78,10 @@ public void update() double frac = (Math.sin((this.maxAge - this.age) / this.maxAge * Math.PI - Math.PI / 2) + 1) / 2; double frac2 = (Math.sin((-this.age + 50) / 50 * Math.PI - Math.PI / 2) + 1) / 2; - + + this.posZ = Math.sin((this.maxAge - Math.max(0, Math.min(this.maxAge, this.age))) / this.maxAge * Math.PI) * + Math.sqrt(Math.pow(this.dX - this.iX, 2) + Math.pow(this.dY - this.iY, 2)) / 2; + if (this.age <= 0) frac = 1; @@ -114,13 +121,18 @@ public void createEffect() if (!Game.fancyGraphics) return; - Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece); + Effect e = Effect.createNewEffect(this.posX, this.posY, this.posZ, Effect.EffectType.piece); 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)); - e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * 4); + + if (Game.enable3d) + e.set3dPolarMotion(Math.random() * 2 * Math.PI, Math.random() * Math.PI * 2, Math.random() * 4); + else + e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * 4); + Game.effects.add(e); } } diff --git a/src/main/resources/font.png b/src/main/resources/font.png index e2f57baa03d82c3815233c1821517e9b1c5a71bf..e7d81f7fa3b5c7481389bc79f7b66779be0f0df1 100755 GIT binary patch delta 21 ccmezG|KESZVJ;2{F%A(v!Fa39r@2gI0bDi){Qv*} delta 21 ccmezG|KESZVJ;395lt(1;p+I!r@2gI0b#TUssI20