diff --git a/src/main/java/tanks/Drawing.java b/src/main/java/tanks/Drawing.java index f315cf0f..10b25be0 100755 --- a/src/main/java/tanks/Drawing.java +++ b/src/main/java/tanks/Drawing.java @@ -368,6 +368,14 @@ public void fillRect(double x, double y, double sizeX, double sizeY) Game.game.window.shapeRenderer.fillRect(drawX, drawY, drawSizeX, drawSizeY); } + public void fillBackgroundRect(IBatchRenderableObject o, double x, double y, double sizeX, double sizeY) + { + if (this.terrainRendering) + this.currentTerrainRenderer.fillRect(o, x - sizeX / 2, y - sizeY / 2, sizeX, sizeY); + else + this.fillBackgroundRect(x, y, sizeX, sizeY); + } + public void fillRect(IBatchRenderableObject o, double x, double y, double sizeX, double sizeY) { if (this.terrainRendering) @@ -1096,57 +1104,39 @@ public void playVibration(String vibration) public double toGameCoordsX(double x) { return absoluteToGameX(interfaceToAbsoluteX(x)); - - /*double x1 = x; - - if (enableMovingCamera && movingCamera && enableMovingCameraX) - x1 += (Game.game.window.absoluteWidth - interfaceScale * interfaceSizeX) / 2 / interfaceScale; - - double rawX = interfaceScale * (x1); - - rawX -= (Drawing.drawing.interfaceSizeX - sizeX * scale / interfaceScale) / 2 * interfaceScale; - - return (rawX) / scale - getPlayerMouseOffsetX();*/ } public double toGameCoordsY(double y) { return absoluteToGameY(interfaceToAbsoluteY(y)); - - /*double y1 = y; - - if (enableMovingCamera && movingCamera && enableMovingCameraY) - y1 += (Game.game.window.absoluteHeight - interfaceScale * interfaceSizeY - statsHeight) / 2 / interfaceScale; - - double rawY = interfaceScale * (y1); - - rawY -= (Drawing.drawing.interfaceSizeY - sizeY * scale / interfaceScale) / 2 * interfaceScale; - - return (rawY) / scale - getPlayerMouseOffsetY();*/ } public double toInterfaceCoordsX(double x) { - double rawX = (x + getPlayerMouseOffsetX()) * scale; + return absoluteToInterfaceX(gameToAbsoluteX(x, 0)); + + /*double rawX = (x + getPlayerMouseOffsetX()) * scale; rawX += (Drawing.drawing.interfaceSizeX - sizeX * scale / interfaceScale) / 2 * interfaceScale; double x1 = rawX / interfaceScale; if (enableMovingCamera && movingCamera && enableMovingCameraX) x1 -= (Game.game.window.absoluteWidth - interfaceScale * interfaceSizeX) / 2 / interfaceScale; - return x1; + return x1;*/ } public double toInterfaceCoordsY(double y) { - double rawY = (y + getPlayerMouseOffsetY()) * scale; + return absoluteToInterfaceY(gameToAbsoluteY(y, 0)); + + /*double rawY = (y + getPlayerMouseOffsetY()) * scale; rawY += (Drawing.drawing.interfaceSizeY - sizeY * scale / interfaceScale) / 2 * interfaceScale; double y1 = rawY / interfaceScale; if (enableMovingCamera && movingCamera && enableMovingCameraY) y1 -= (Game.game.window.absoluteHeight - interfaceScale * interfaceSizeY - statsHeight) / 2 / interfaceScale; - return y1; + return y1;*/ } public double getMouseX() @@ -1411,6 +1401,16 @@ public double interfaceToAbsoluteY(double y) return (interfaceScale * y + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2); } + public double absoluteToInterfaceX(double x) + { + return (x - Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2) / interfaceScale; + } + + public double absoluteToInterfaceY(double y) + { + return (y - Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2 ) / interfaceScale; + } + public boolean isOutOfBounds(double drawX, double drawY) { int dist = 200; diff --git a/src/main/java/tanks/Game.java b/src/main/java/tanks/Game.java index d07416f5..ba8946b1 100755 --- a/src/main/java/tanks/Game.java +++ b/src/main/java/tanks/Game.java @@ -92,8 +92,8 @@ public enum Framework {lwjgl, libgdx} public static double[][] tilesDepth = new double[28][18]; //Remember to change the version in android's build.gradle and ios's robovm.properties - public static final String version = "Tanks v1.3.1b"; - public static final int network_protocol = 38; + public static final String version = "Tanks v1.3.1"; + public static final int network_protocol = 39; public static boolean debug = false; public static boolean traceAllRays = false; public static final boolean cinematic = false; @@ -257,6 +257,7 @@ public static void registerEvents() NetworkEventMap.register(EventPlayerChat.class); NetworkEventMap.register(EventLoadLevel.class); NetworkEventMap.register(EventEnterLevel.class); + NetworkEventMap.register(EventLevelEndQuick.class); NetworkEventMap.register(EventLevelEnd.class); NetworkEventMap.register(EventReturnToLobby.class); NetworkEventMap.register(EventBeginCrusade.class); @@ -765,22 +766,6 @@ else if (s.length() == 1) return Character.toUpperCase(s.charAt(0)) + s.substring(1).replace("-", " ").replace("_", " ").toLowerCase(); } - /*public static void reset() - { - resetNetworkIDs(); - - obstacles.clear(); - tracks.clear(); - movables.clear(); - effects.clear(); - recycleEffects.clear(); - removeEffects.clear(); - removeTracks.clear(); - - System.gc(); - start(); - }*/ - public static void exitToInterlevel() { silentCleanUp(); @@ -789,16 +774,6 @@ public static void exitToInterlevel() public static void exitToEditor(String name) { - /*obstacles.clear(); - tracks.clear(); - movables.clear(); - effects.clear(); - recycleEffects.clear(); - removeEffects.clear(); - removeTracks.clear(); - - System.gc();*/ - silentCleanUp(); ScreenLevelEditor s = new ScreenLevelEditor(name, Game.currentLevel); @@ -909,14 +884,19 @@ public static void resetTiles() Game.game.groundHeightGrid = new double[28][18]; Game.tileDrawables = new Obstacle[28][18]; + double var = 0; + + if (Game.fancyTerrain) + var = 20; + for (int i = 0; i < 28; i++) { for (int j = 0; j < 18; j++) { - Game.tilesR[i][j] = (255 - Math.random() * 20); - Game.tilesG[i][j] = (227 - Math.random() * 20); - Game.tilesB[i][j] = (186 - Math.random() * 20); - Game.tilesDepth[i][j] = Math.random() * 10; + Game.tilesR[i][j] = (235 + Math.random() * var); + Game.tilesG[i][j] = (207 + Math.random() * var); + Game.tilesB[i][j] = (166 + Math.random() * var); + Game.tilesDepth[i][j] = Math.random() * var / 2; } } diff --git a/src/main/java/tanks/Level.java b/src/main/java/tanks/Level.java index bef1d828..29d9c606 100755 --- a/src/main/java/tanks/Level.java +++ b/src/main/java/tanks/Level.java @@ -664,10 +664,20 @@ public void reloadTiles() { for (int j = 0; j < Game.currentSizeY; j++) { - Game.tilesR[i][j] = (colorR + Math.random() * colorVarR); - Game.tilesG[i][j] = (colorG + Math.random() * colorVarG); - Game.tilesB[i][j] = (colorB + Math.random() * colorVarB); - Game.tilesDepth[i][j] = Math.random() * 10; + if (Game.fancyTerrain) + { + Game.tilesR[i][j] = (colorR + Math.random() * colorVarR); + Game.tilesG[i][j] = (colorG + Math.random() * colorVarG); + Game.tilesB[i][j] = (colorB + Math.random() * colorVarB); + Game.tilesDepth[i][j] = Math.random() * 10; + } + else + { + Game.tilesR[i][j] = colorR; + Game.tilesG[i][j] = colorG; + Game.tilesB[i][j] = colorB; + Game.tilesDepth[i][j] = 0; + } } } diff --git a/src/main/java/tanks/Panel.java b/src/main/java/tanks/Panel.java index 865a381a..b028f43e 100755 --- a/src/main/java/tanks/Panel.java +++ b/src/main/java/tanks/Panel.java @@ -212,6 +212,8 @@ public void setUp() for (Extension e: Game.extensionRegistry.extensions) e.loadResources(); + + Game.resetTiles(); } public void update() @@ -407,7 +409,8 @@ public void update() if (!(Game.screen instanceof ScreenInfo)) { - if (!(Game.screen instanceof ScreenGame) || Panel.zoomTarget < 0 || Game.playerTank == null || Game.playerTank.destroy || !((ScreenGame) Game.screen).playing) + if (!(Game.screen instanceof ScreenGame) || Panel.zoomTarget < 0 || + ((Game.playerTank == null || Game.playerTank.destroy) && (((ScreenGame) Game.screen).spectatingTank == null)) || !((ScreenGame) Game.screen).playing) this.zoomTimer -= 0.02 * Panel.frameFrequency; } @@ -458,14 +461,16 @@ else if (((ScreenGame) Game.screen).spectatingTank instanceof TankPlayerRemote) if (Drawing.drawing.movingCamera) { - if (!(Game.screen instanceof ScreenGame) || Panel.zoomTarget < 0 || Game.playerTank == null || Game.playerTank.destroy || !((ScreenGame) Game.screen).playing) + if (!(Game.screen instanceof ScreenGame) || Panel.zoomTarget < 0 || + ((Game.playerTank == null || Game.playerTank.destroy) && (((ScreenGame) Game.screen).spectatingTank == null)) || + !((ScreenGame) Game.screen).playing) this.zoomTimer += 0.04 * Panel.frameFrequency; double mul = Panel.zoomTarget; if (mul < 0) mul = 1; - if (ScreenPartyHost.isServer || ScreenPartyLobby.isClient) + if (Game.startTime > 0 && (ScreenPartyHost.isServer || ScreenPartyLobby.isClient)) this.zoomTimer = Math.min(this.zoomTimer, mul * (1 - Game.startTime / Game.currentLevel.startTime)); } } @@ -476,15 +481,12 @@ else if (((ScreenGame) Game.screen).spectatingTank instanceof TankPlayerRemote) this.zoomTimer = Math.min(Math.max(this.zoomTimer, 0), 1); - if (Game.screen instanceof ScreenGame && Panel.zoomTarget >= 0 && (((ScreenGame) Game.screen).spectatingTank != null || (Game.playerTank != null && !Game.playerTank.destroy)) && ((ScreenGame) Game.screen).playing) + if (Game.screen instanceof ScreenGame && Drawing.drawing.enableMovingCamera && Panel.zoomTarget >= 0 && (((ScreenGame) Game.screen).spectatingTank != null || (Game.playerTank != null && !Game.playerTank.destroy)) && ((ScreenGame) Game.screen).playing) { double speed = 0.3 * Drawing.drawing.unzoomedScale; double accel = 0.0003 * Drawing.drawing.unzoomedScale; double distDampen = 2; - if (this.zoomTimer > Panel.zoomTarget) - speed = -0.02; - if (Panel.autoZoom) { speed /= 4; @@ -501,14 +503,18 @@ else if (((ScreenGame) Game.screen).spectatingTank instanceof TankPlayerRemote) Panel.lastAutoZoomSpeed = speed; + speed *= Math.signum(Panel.zoomTarget - this.zoomTimer); + this.zoomTimer = this.zoomTimer + speed * Panel.frameFrequency; } else { - if (speed > 0) - this.zoomTimer = Math.min(this.zoomTimer + speed * Panel.frameFrequency, Panel.zoomTarget); - else if (speed < 0) - this.zoomTimer = Math.max(this.zoomTimer + speed * Panel.frameFrequency, Panel.zoomTarget); + if (this.zoomTimer > Panel.zoomTarget) + speed = -0.02; + else + speed = 0.02; + + this.zoomTimer = Math.max(this.zoomTimer + speed * Panel.frameFrequency, Panel.zoomTarget); } } diff --git a/src/main/java/tanks/event/EventLevelEndQuick.java b/src/main/java/tanks/event/EventLevelEndQuick.java new file mode 100644 index 00000000..bee21537 --- /dev/null +++ b/src/main/java/tanks/event/EventLevelEndQuick.java @@ -0,0 +1,56 @@ +package tanks.event; + +import io.netty.buffer.ByteBuf; +import tanks.Game; +import tanks.Panel; +import tanks.gui.screen.ScreenGame; +import tanks.gui.screen.ScreenPartyInterlevel; +import tanks.gui.screen.ScreenPartyLobby; +import tanks.network.NetworkUtils; + +public class EventLevelEndQuick extends PersonalEvent +{ + public String winningTeam; + + public EventLevelEndQuick() + { + + } + + public EventLevelEndQuick(String winner) + { + this.winningTeam = winner; + } + + @Override + public void execute() + { + if (this.clientID != null) + return; + + if (Game.clientID.toString().equals(winningTeam) || (Game.playerTank != null && Game.playerTank.team != null && Game.playerTank.team.name.equals(this.winningTeam))) + { + Panel.win = true; + Panel.winlose = "Victory!"; + } + else + { + Panel.win = false; + Panel.winlose = "You were destroyed!"; + } + + ScreenGame.finishedQuick = true; + } + + @Override + public void write(ByteBuf b) + { + NetworkUtils.writeString(b, this.winningTeam); + } + + @Override + public void read(ByteBuf b) + { + this.winningTeam = NetworkUtils.readString(b); + } +} diff --git a/src/main/java/tanks/gui/screen/Screen.java b/src/main/java/tanks/gui/screen/Screen.java index c7cab3f2..4816d32c 100755 --- a/src/main/java/tanks/gui/screen/Screen.java +++ b/src/main/java/tanks/gui/screen/Screen.java @@ -102,7 +102,7 @@ public void drawDefaultBackground(double size) mul * Game.game.window.absoluteWidth / Drawing.drawing.interfaceScale, mul * Game.game.window.absoluteHeight / Drawing.drawing.interfaceScale); Drawing.drawing.setColor(Level.currentColorR, Level.currentColorG, Level.currentColorB, 255.0 * size); - Drawing.drawing.fillRect(this, Drawing.drawing.sizeX / 2, Drawing.drawing.sizeY / 2, Drawing.drawing.sizeX, Drawing.drawing.sizeY); + Drawing.drawing.fillBackgroundRect(this, Drawing.drawing.sizeX / 2, Drawing.drawing.sizeY / 2, Drawing.drawing.sizeX, Drawing.drawing.sizeY); } Drawing.drawing.setColor(Level.currentColorR, Level.currentColorG, Level.currentColorB); @@ -141,7 +141,12 @@ else if (Game.game.window.shapeRenderer.supportsBatching) double frac2 = 0; if (i1 >= 0 && i1 < Game.currentSizeX && j1 >= 0 && j1 < Game.currentSizeY) - Drawing.drawing.setColor(Game.tilesR[i][j], Game.tilesG[i][j], Game.tilesB[i][j]); + { + if (Game.fancyTerrain) + Drawing.drawing.setColor(Game.tilesR[i][j], Game.tilesG[i][j], Game.tilesB[i][j]); + else + Drawing.drawing.setColor(Level.currentColorR, Level.currentColorG, Level.currentColorB); + } else { inBounds = false; @@ -159,7 +164,7 @@ else if (Game.game.window.shapeRenderer.supportsBatching) byte o = 61; - if (Game.enable3dBg && !(Drawing.drawing.scale <= 0.25 * Drawing.drawing.interfaceScale && !Game.game.window.shapeRenderer.supportsBatching)) + if (Game.enable3dBg && Game.fancyTerrain && !(Drawing.drawing.scale <= 0.25 * Drawing.drawing.interfaceScale && !Game.game.window.shapeRenderer.supportsBatching)) { z1 = Game.tilesDepth[i][j]; o = 1; diff --git a/src/main/java/tanks/gui/screen/ScreenChangelog.java b/src/main/java/tanks/gui/screen/ScreenChangelog.java index 39b6952a..0337d818 100755 --- a/src/main/java/tanks/gui/screen/ScreenChangelog.java +++ b/src/main/java/tanks/gui/screen/ScreenChangelog.java @@ -167,7 +167,7 @@ public static void setupLogs() "Max level size increased\n" + "More variation in level generator\n\n" + - "*Items:\n\n" + + "*Items:\n\n" + "New mine item\n" + "Add items and shops in individual levels\n" + "New item templates\n" + @@ -195,7 +195,7 @@ public static void setupLogs() "Updated health indicators\n" + "Flashier 3D fireworks\n\n" + - "*Audio:\n\n" + + "*Audio:\n\n" + "New volume controls\n" + "New songs for battle, crusade, and battle victory/defeat\n" + "New sound effects\n" + @@ -219,7 +219,7 @@ public static void setupLogs() "New time limit option for levels\n" + "Added lighting options to levels", - "*Options:\n\n" + + "*Options:\n\n" + "Added shadows and shadow quality option\n" + "Added option to show time elapsed\n" + "Added keybind to instantly start a level\n\n" + @@ -272,7 +272,7 @@ public static void setupLogs() "Large timed levels have longer timers\n" + "Orangered tank is now immune to explosion damage\n\n", - "*More:\n\n" + + "*More:\n\n" + "Improved the crusade editor level edit menu\n" + "Changed light block appearance\n" + "Fireworks are more varied and prettier!\n" + @@ -308,7 +308,7 @@ public static void setupLogs() "Added indicator for where arc bullets will land\n" + "Added mini tank to level editor\n", - "*Improvements:\n\n" + + "*Improvements:\n\n" + "Hovering over the item bar slots shows keybinds\n" + "Leaving and rejoining a party crusade before a new level is\n" + " loaded recovers progress\n" + @@ -333,7 +333,7 @@ public static void setupLogs() "New editor music which changes based on tanks present\n" + "New sounds for winning and losing battles", - "*User interfaces:\n\n" + + "*User interfaces:\n\n" + "Improved lists with search, sort, and jump buttons\n" + "New window options menu for resolution and fullscreen\n" + "New option to warn before closing unsaved work\n" + @@ -350,21 +350,15 @@ public static void setupLogs() "Bug fixes and other minor improvements" }); - new Changelog("v1.3.1a", new String[] + new Changelog("v1.3.1", new String[] { - "*What's new in Tanks v1.3.1a:\n\n" + + "*What's new in Tanks v1.3.1:\n\n" + "Added maximum framerate option\n" + "Scroll while holding the zoom key for manual zoom\n" + "Added keybinds to manually zoom in and out\n" + - "Bug fixes and other minor improvements" - }); - - new Changelog("v1.3.1b", new String[] - { - "*What's new in Tanks v1.3.1b:\n\n" + - "Added automatic zoom mode (can toggle with 'O')\n" + + "Added automatic zoom mode with keybind\n" + "Improved keybindings screen\n" + - "Bug fixes and other minor improvements" + "Bug fixes and other minor improvements\n" }); } } diff --git a/src/main/java/tanks/gui/screen/ScreenGame.java b/src/main/java/tanks/gui/screen/ScreenGame.java index c040eb41..a09c5ec3 100755 --- a/src/main/java/tanks/gui/screen/ScreenGame.java +++ b/src/main/java/tanks/gui/screen/ScreenGame.java @@ -168,8 +168,19 @@ public void run() } ); - Button zoom = new Button(0, -1000, 70, 70, "", () -> Drawing.drawing.movingCamera = !Drawing.drawing.movingCamera - ); + Button zoom = new Button(0, -1000, 70, 70, "", () -> + { + Panel.autoZoom = false; + Panel.zoomTarget = -1; + Drawing.drawing.movingCamera = !Drawing.drawing.movingCamera; + }); + + Button zoomAuto = new Button(0, -1000, 70, 70, "", () -> + { + Panel.autoZoom = !Panel.autoZoom; + if (!Panel.autoZoom) + Panel.zoomTarget = -1; + }); Button resume = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 - this.objYSpace * 1.5, this.objWidth, this.objHeight, "Continue playing", () -> { @@ -803,14 +814,17 @@ else if (Level.isDark()) this.prevTankMusics.addAll(this.tankMusics); this.tankMusics.clear(); - for (Movable m : Game.movables) + if (!this.paused) { - if (m instanceof Tank && !m.destroy) + for (Movable m : Game.movables) { - ArrayList s = Game.registryTank.tankMusics.get(((Tank) m).name); + if (m instanceof Tank && !m.destroy) + { + ArrayList s = Game.registryTank.tankMusics.get(((Tank) m).name); - if (s != null) - this.tankMusics.addAll(s); + if (s != null) + this.tankMusics.addAll(s); + } } } @@ -921,9 +935,10 @@ else if (Level.isDark()) } if (Game.playerTank != null && !Game.playerTank.destroy && Panel.autoZoom) - { Panel.zoomTarget = Game.playerTank.getAutoZoom(); - } + + if (spectatingTank != null && !spectatingTank.destroy && Panel.autoZoom) + Panel.zoomTarget = spectatingTank.getAutoZoom(); } if (Game.game.input.zoom.isPressed() && playing) @@ -1146,9 +1161,17 @@ else if (Game.game.window.touchscreen && !shopScreen) zoom.posX = pause.posX - hStep; zoom.posY = pause.posY + vStep; + zoomAuto.posX = zoom.posX - hStep; + zoomAuto.posY = zoom.posY + vStep; + if (Drawing.drawing.enableMovingCamera) + { zoom.update(); + if (!Panel.autoZoom) + zoomAuto.update(); + } + if (playing) { TankPlayer.controlStick.mobile = TankPlayer.controlStickMobile; @@ -1505,6 +1528,14 @@ else if (newSeconds < seconds && seconds <= 10) Panel.win = false; Drawing.drawing.playSound("lose.ogg", 1.0f, true); } + + String s = "**"; + + if (fullyAliveTeams.size() > 0) + s = fullyAliveTeams.get(0).name; + + if (ScreenPartyHost.isServer) + Game.eventsOut.add(new EventLevelEndQuick(s)); } ScreenGame.finishedQuick = true; @@ -2325,10 +2356,16 @@ else if (ScreenPartyLobby.isClient) { zoom.draw(); + if (!Panel.autoZoom) + zoomAuto.draw(); + if (Drawing.drawing.movingCamera) Drawing.drawing.drawInterfaceImage("zoom_out.png", zoom.posX, zoom.posY, 40, 40); else Drawing.drawing.drawInterfaceImage("zoom_in.png", zoom.posX, zoom.posY, 40, 40); + + if (!Panel.autoZoom) + Drawing.drawing.drawInterfaceImage("zoom_auto.png", zoomAuto.posX, zoomAuto.posY, 40, 40); } } diff --git a/src/main/java/tanks/gui/screen/ScreenOptionsGraphics.java b/src/main/java/tanks/gui/screen/ScreenOptionsGraphics.java index b7226dea..5c92ef0c 100755 --- a/src/main/java/tanks/gui/screen/ScreenOptionsGraphics.java +++ b/src/main/java/tanks/gui/screen/ScreenOptionsGraphics.java @@ -160,6 +160,9 @@ public void run() terrain.setText(terrainText, fastText); update3dGroundButton(); + + Game.resetTiles(); + Drawing.drawing.forceRedrawTerrain(); } }, "Fancy terrain enables varied block---and ground colors------May impact performance on larger levels"); @@ -220,6 +223,7 @@ public void run() update3dGroundButton(); + Game.resetTiles(); Drawing.drawing.forceRedrawTerrain(); } }, @@ -237,6 +241,7 @@ public void run() else ground3d.setText(ground3dText, ScreenOptions.offText); + Game.resetTiles(); Drawing.drawing.forceRedrawTerrain(); } }, diff --git a/src/main/java/tanks/network/ClientHandler.java b/src/main/java/tanks/network/ClientHandler.java index 3c9224b9..01b64616 100755 --- a/src/main/java/tanks/network/ClientHandler.java +++ b/src/main/java/tanks/network/ClientHandler.java @@ -95,12 +95,22 @@ else if (Client.handler.steamID != null) Client.handler.channelInactive(null); } } - + public synchronized void sendEvent(INetworkEvent e) + { + this.sendEvent(e, true); + } + + public synchronized void sendEvent(INetworkEvent e, boolean flush) { if (steamID != null) { - Game.steamNetworkHandler.send(steamID.getAccountID(), e, SteamNetworking.P2PSend.Reliable); + SteamNetworking.P2PSend sendType = SteamNetworking.P2PSend.ReliableWithBuffering; + + if (flush) + sendType = SteamNetworking.P2PSend.Reliable; + + Game.steamNetworkHandler.send(steamID.getAccountID(), e, sendType); return; } @@ -116,7 +126,11 @@ public synchronized void sendEvent(INetworkEvent e) ByteBuf b2 = ctx.channel().alloc().buffer(); b2.writeInt(b.readableBytes()); b2.writeBytes(b); - ctx.channel().writeAndFlush(b2); + + if (flush) + ctx.channel().writeAndFlush(b2); + else + ctx.channel().write(b2); ReferenceCountUtil.release(b); } @@ -202,9 +216,12 @@ public void reply() for (int i = 0; i < Game.eventsOut.size(); i++) { INetworkEvent e = Game.eventsOut.get(i); - this.sendEvent(e); + this.sendEvent(e, false); } + if (steamID == null) + this.ctx.flush(); + Game.eventsOut.clear(); } } diff --git a/src/main/java/tanks/network/ServerHandler.java b/src/main/java/tanks/network/ServerHandler.java index bf1330d3..0c78ea0e 100755 --- a/src/main/java/tanks/network/ServerHandler.java +++ b/src/main/java/tanks/network/ServerHandler.java @@ -129,18 +129,31 @@ public void reply() for (int i = 0; i < this.events.size(); i++) { INetworkEvent e = this.events.get(i); - this.sendEvent(e); + this.sendEvent(e, false); } + if (steamID == null) + this.ctx.flush(); + this.events.clear(); } } public synchronized void sendEvent(INetworkEvent e) + { + this.sendEvent(e, true); + } + + public synchronized void sendEvent(INetworkEvent e, boolean flush) { if (steamID != null) { - Game.steamNetworkHandler.send(steamID.getAccountID(), e, SteamNetworking.P2PSend.Reliable); + SteamNetworking.P2PSend sendType = SteamNetworking.P2PSend.ReliableWithBuffering; + + if (flush) + sendType = SteamNetworking.P2PSend.Reliable; + + Game.steamNetworkHandler.send(steamID.getAccountID(), e, sendType); return; } @@ -156,7 +169,11 @@ public synchronized void sendEvent(INetworkEvent e) ByteBuf b2 = ctx.channel().alloc().buffer(); b2.writeInt(b.readableBytes()); b2.writeBytes(b); - ctx.channel().writeAndFlush(b2); + + if (flush) + ctx.channel().writeAndFlush(b2); + else + ctx.channel().write(b2); ReferenceCountUtil.release(b); } diff --git a/src/main/java/tanks/obstacle/Obstacle.java b/src/main/java/tanks/obstacle/Obstacle.java index 819033ce..ec714d8c 100755 --- a/src/main/java/tanks/obstacle/Obstacle.java +++ b/src/main/java/tanks/obstacle/Obstacle.java @@ -261,6 +261,15 @@ public boolean hasLowerNeighbor() return false; } + /** + * Draws the tile under the obstacle if it needs to be drawn differently than when not covered by an obstacle + * + * @param r Red + * @param g Green + * @param b Blue + * @param d Tile height + * @param extra The deepest tile next to the current tile, used to render sides underground + */ public void drawTile(double r, double g, double b, double d, double extra) { if (Obstacle.draw_size < Game.tile_size || extra != 0) diff --git a/src/main/java/tanks/obstacle/ObstacleHole.java b/src/main/java/tanks/obstacle/ObstacleHole.java index ce808830..8c4d48d0 100755 --- a/src/main/java/tanks/obstacle/ObstacleHole.java +++ b/src/main/java/tanks/obstacle/ObstacleHole.java @@ -14,7 +14,7 @@ public ObstacleHole(String name, double posX, double posY) this.drawLevel = 1; this.destructible = false; this.bulletCollision = false; - this.replaceTiles = true; + this.replaceTiles = Game.fancyTerrain; this.enableStacking = false; @@ -29,7 +29,7 @@ public ObstacleHole(String name, double posX, double posY) @Override public void draw() { - if (!Game.enable3d) + if (!Game.enable3d || !Game.fancyTerrain) { Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, this.colorA); Drawing.drawing.fillRect(this, this.posX, this.posY, draw_size * size, draw_size * size); diff --git a/src/main/java/tanks/tank/Tank.java b/src/main/java/tanks/tank/Tank.java index 3ffe0c61..15233e0b 100755 --- a/src/main/java/tanks/tank/Tank.java +++ b/src/main/java/tanks/tank/Tank.java @@ -305,7 +305,7 @@ public void update() { this.treadAnimation += Math.sqrt(this.lastFinalVX * this.lastFinalVX + this.lastFinalVY * this.lastFinalVY) * Panel.frameFrequency; - if (this.treadAnimation > this.size * 2 / 5 && !this.destroy && !ScreenGame.finished) + if (this.treadAnimation > this.size * 2 / 5 && !this.destroy) { this.drawTread = true; @@ -420,11 +420,13 @@ else if (a.name.equals("boost_effect")) if (!(Math.abs(this.posX - this.lastPosX) < 0.01 && Math.abs(this.posY - this.lastPosY) < 0.01) && !this.destroy && !ScreenGame.finished) { + double dist = Math.sqrt(Math.pow(this.posX - this.lastPosX, 2) + Math.pow(this.posY - this.lastPosY, 2)); + double dir = Math.PI + this.getAngleInDirection(this.lastPosX, this.lastPosY); if (Movable.absoluteAngleBetween(this.orientation, dir) <= Movable.absoluteAngleBetween(this.orientation + Math.PI, dir)) - this.orientation -= Movable.angleBetween(this.orientation, dir) / 10 * Panel.frameFrequency; + this.orientation -= Movable.angleBetween(this.orientation, dir) / 20 * dist; else - this.orientation -= Movable.angleBetween(this.orientation + Math.PI, dir) / 10 * Panel.frameFrequency; + this.orientation -= Movable.angleBetween(this.orientation + Math.PI, dir) / 20 * dist; } if (!this.isRemote && this.standardUpdateEvent && ScreenPartyHost.isServer) @@ -920,7 +922,7 @@ public double getAutoZoomRaw() nearest = dist; } - if (dist <= 3 && dist > farthestInSight) + if (dist <= 3.5 && dist > farthestInSight) { Ray r = new Ray(this.posX, this.posY, 0, 0, this); r.vX = m.posX - this.posX; @@ -942,7 +944,7 @@ public double getAutoZoomRaw() public double getAutoZoom() { - double dist = Math.min(2.5, Math.max(1, getAutoZoomRaw())); + double dist = Math.min(3, Math.max(1, getAutoZoomRaw())); return 1 / dist; } } diff --git a/src/main/java/tanks/tank/TankBoss.java b/src/main/java/tanks/tank/TankBoss.java index a45e6917..7fa05380 100755 --- a/src/main/java/tanks/tank/TankBoss.java +++ b/src/main/java/tanks/tank/TankBoss.java @@ -126,6 +126,7 @@ else if (side == 3) Tank t = e.getTank(this.posX + x, this.posY + y, this.angle); t.team = this.team; + t.crusadeID = this.crusadeID; Game.eventsOut.add(new EventCreateTank(t)); this.spawned.add(t); diff --git a/src/main/java/tanks/tank/TankPink.java b/src/main/java/tanks/tank/TankPink.java index ebb29978..0776ab95 100755 --- a/src/main/java/tanks/tank/TankPink.java +++ b/src/main/java/tanks/tank/TankPink.java @@ -109,6 +109,7 @@ else if (side == 3) } TankMini t = new TankMini("mini", this.posX + x, this.posY + y, this.angle, this); + t.crusadeID = this.crusadeID; Game.eventsOut.add(new EventCreateCustomTank(t)); Game.movables.add(t); } diff --git a/src/main/resources/images/zoom_auto.png b/src/main/resources/images/zoom_auto.png new file mode 100644 index 00000000..77c9fdf5 Binary files /dev/null and b/src/main/resources/images/zoom_auto.png differ