Skip to content

Commit

Permalink
Tanks v1.3.1 - Camera and more
Browse files Browse the repository at this point in the history
  • Loading branch information
Aehmttw committed Mar 15, 2022
1 parent c163e0b commit 9b23361
Show file tree
Hide file tree
Showing 17 changed files with 255 additions and 115 deletions.
52 changes: 26 additions & 26 deletions src/main/java/tanks/Drawing.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down
44 changes: 12 additions & 32 deletions src/main/java/tanks/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}

Expand Down
18 changes: 14 additions & 4 deletions src/main/java/tanks/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
28 changes: 17 additions & 11 deletions src/main/java/tanks/Panel.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ public void setUp()

for (Extension e: Game.extensionRegistry.extensions)
e.loadResources();

Game.resetTiles();
}

public void update()
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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));
}
}
Expand All @@ -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;
Expand All @@ -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);
}
}

Expand Down
56 changes: 56 additions & 0 deletions src/main/java/tanks/event/EventLevelEndQuick.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
11 changes: 8 additions & 3 deletions src/main/java/tanks/gui/screen/Screen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 9b23361

Please sign in to comment.