Skip to content

Commit

Permalink
Tanks v0.6.1 - Added tutorial, improved the level generator to make m…
Browse files Browse the repository at this point in the history
…ore appealing levels with newer obstacles, improved tank AI, tweaked motion, changed the firework animation, changed how your levels are deleted - there is now a delete button, and empty levels will no longer be deleted automatically. Also includes other improvements.
  • Loading branch information
aehmttw committed Apr 11, 2019
1 parent a2e1b8b commit 25a4c69
Show file tree
Hide file tree
Showing 29 changed files with 1,083 additions and 306 deletions.
8 changes: 4 additions & 4 deletions src/lwjglwindow/FontRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public void drawString(double x, double y, double sX, double sY, String s)
}
}

public int getStringSizeX(double sX, String s)
public double getStringSizeX(double sX, String s)
{
int w = 0;
double w = 0;
char[] c = s.toCharArray();

for (int i = 0; i < c.length; i++)
Expand All @@ -72,8 +72,8 @@ public int getStringSizeX(double sX, String s)
return w;
}

public int getStringSizeY(double sY, String s)
public double getStringSizeY(double sY, String s)
{
return (int) (sY * 32);
return (sY * 32);
}
}
12 changes: 9 additions & 3 deletions src/lwjglwindow/LWJGLWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class LWJGLWindow

public boolean validScrollUp;
public boolean validScrollDown;

public boolean vsync;

protected ArrayList<Long> framesList = new ArrayList<Long>();
protected ArrayList<Double> frameFrequencies = new ArrayList<Double>();
Expand All @@ -50,7 +52,7 @@ public class LWJGLWindow
public Drawer drawer;
public Updater updater;

public LWJGLWindow(String name, int x, int y, Updater u, Drawer d)
public LWJGLWindow(String name, int x, int y, Updater u, Drawer d, boolean vsync)
{
this.name = name;
this.absoluteWidth = x;
Expand Down Expand Up @@ -155,8 +157,12 @@ else if (action == GLFW_RELEASE)
// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable v-sync
glfwSwapInterval(1);


if (vsync)
GLFW.glfwSwapInterval(1);
else
GLFW.glfwSwapInterval(0);

// Make the window visible
glfwShowWindow(window);
}
Expand Down
20 changes: 10 additions & 10 deletions src/tanks/Bullet.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,26 +371,26 @@ public void update()

if (this.effect.equals(BulletEffect.fireTrail))
{
Game.effects.add(Effect.createNewEffect(this.posX - this.vX * Panel.frameFrequency / 8, this.posY - this.vY * Panel.frameFrequency / 8, Effect.EffectType.smokeTrail, 0.25, 0.75));
Game.effects.add(Effect.createNewEffect(this.posX - this.vX * Panel.frameFrequency / 4, this.posY - this.vY * Panel.frameFrequency / 4, Effect.EffectType.smokeTrail, 0.25, 0.50));
Game.effects.add(Effect.createNewEffect(this.posX - this.vX * Panel.frameFrequency / 8 * 3, this.posY - this.vY * Panel.frameFrequency / 8 * 3, Effect.EffectType.smokeTrail, 0.25, 0.25));
Game.effects.add(Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.smokeTrail, 0.25, 0));
Game.effects.add(Effect.createNewEffect(this.posX - this.vX / 8, this.posY - this.vY * Panel.frameFrequency / 8, Effect.EffectType.smokeTrail, 0.25, 0.25 * Panel.frameFrequency));
Game.effects.add(Effect.createNewEffect(this.posX - this.vX / 4, this.posY - this.vY * Panel.frameFrequency / 4, Effect.EffectType.smokeTrail, 0.25, 0.50 * Panel.frameFrequency));
Game.effects.add(Effect.createNewEffect(this.posX - this.vX / 8 * 3, this.posY - this.vY * Panel.frameFrequency / 8 * 3, Effect.EffectType.smokeTrail, 0.25, 0.75 * Panel.frameFrequency));
}

if (this.effect.equals(BulletEffect.fire) || this.effect.equals(BulletEffect.fireTrail))
{
Game.effects.add(Effect.createNewEffect(this.posX - this.vX * Panel.frameFrequency / 8, this.posY - this.vY * Panel.frameFrequency / 8, Effect.EffectType.fire, 0.25, 0.75));
Game.effects.add(Effect.createNewEffect(this.posX - this.vX * Panel.frameFrequency / 4, this.posY - this.vY * Panel.frameFrequency / 4, Effect.EffectType.fire, 0.25, 0.50));
Game.effects.add(Effect.createNewEffect(this.posX - this.vX * Panel.frameFrequency / 8 * 3, this.posY - this.vY * Panel.frameFrequency / 8 * 3, Effect.EffectType.fire, 0.25, 0.25));
Game.effects.add(Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.fire, 0.25, 0));
Game.effects.add(Effect.createNewEffect(this.posX - this.vX / 8, this.posY - this.vY * Panel.frameFrequency / 8, Effect.EffectType.fire, 0.25, 0.25 * Panel.frameFrequency));
Game.effects.add(Effect.createNewEffect(this.posX - this.vX / 4, this.posY - this.vY * Panel.frameFrequency / 4, Effect.EffectType.fire, 0.25, 0.50 * Panel.frameFrequency));
Game.effects.add(Effect.createNewEffect(this.posX - this.vX / 8 * 3, this.posY - this.vY * Panel.frameFrequency / 8 * 3, Effect.EffectType.fire, 0.25, 0.75 * Panel.frameFrequency));
}

if (this.effect.equals(BulletEffect.darkFire))
{
Game.effects.add(Effect.createNewEffect(this.posX - this.vX * Panel.frameFrequency / 8, this.posY - this.vY * Panel.frameFrequency / 8, Effect.EffectType.darkFire, 0.25, 0.75));
Game.effects.add(Effect.createNewEffect(this.posX - this.vX * Panel.frameFrequency / 4, this.posY - this.vY * Panel.frameFrequency / 4, Effect.EffectType.darkFire, 0.25, 0.50));
Game.effects.add(Effect.createNewEffect(this.posX - this.vX * Panel.frameFrequency / 8 * 3, this.posY - this.vY * Panel.frameFrequency / 8 * 3, Effect.EffectType.darkFire, 0.25, 0.25));
Game.effects.add(Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.darkFire, 0.25, 0));
Game.effects.add(Effect.createNewEffect(this.posX - this.vX * Panel.frameFrequency / 8, this.posY - this.vY / 8, Effect.EffectType.darkFire, 0.25, 0.25 * Panel.frameFrequency));
Game.effects.add(Effect.createNewEffect(this.posX - this.vX * Panel.frameFrequency / 4, this.posY - this.vY / 4, Effect.EffectType.darkFire, 0.25, 0.50 * Panel.frameFrequency));
Game.effects.add(Effect.createNewEffect(this.posX - this.vX * Panel.frameFrequency / 8 * 3, this.posY - this.vY / 8 * 3, Effect.EffectType.darkFire, 0.25, 0.75 * Panel.frameFrequency));
}

if (this.effect.equals(BulletEffect.ice))
Expand Down Expand Up @@ -419,7 +419,7 @@ public void update()
}

super.update();

this.checkCollision();
this.age += Panel.frameFrequency;
}

Expand Down
28 changes: 14 additions & 14 deletions src/tanks/Drawing.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,21 +268,21 @@ public void drawInterfaceImage(String img, double x, double y, double sizeX, dou

public void drawInterfaceRect(double x, double y, double sizeX, double sizeY)
{
int drawX = (int) Math.round(interfaceScale * (x - sizeX / 2) + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2);
int drawY = (int) Math.round(interfaceScale * (y - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2);
int drawSizeX = (int) Math.round(sizeX * interfaceScale);
int drawSizeY = (int) Math.round(sizeY * interfaceScale);
double drawX = Math.round(interfaceScale * (x - sizeX / 2) + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2);
double drawY = Math.round(interfaceScale * (y - sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2);
double drawSizeX = Math.round(sizeX * interfaceScale);
double drawSizeY = Math.round(sizeY * interfaceScale);

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

public void drawText(double x, double y, String text)
{
double sizeX = Game.game.window.fontRenderer.getStringSizeX(this.fontSize, text);
double sizeY = Game.game.window.fontRenderer.getStringSizeY(this.fontSize, text);
double sizeX = Game.game.window.fontRenderer.getStringSizeX(this.fontSize, text) / scale;
double sizeY = Game.game.window.fontRenderer.getStringSizeY(this.fontSize, text) / scale;

int drawX = (int) (scale * x - sizeX / 2 + Math.max(0, Panel.windowWidth - this.sizeX * scale) / 2);
int drawY = (int) (scale * (y + sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - this.sizeY * scale) / 2);
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);

Game.game.window.fontRenderer.drawString(drawX, drawY, this.fontSize, this.fontSize, text);
}
Expand All @@ -292,8 +292,8 @@ public void drawInterfaceText(double x, double y, String text)
double sizeX = Game.game.window.fontRenderer.getStringSizeX(this.fontSize, text);
double sizeY = Game.game.window.fontRenderer.getStringSizeY(this.fontSize, text);

int drawX = (int) (interfaceScale * x - sizeX / 2 + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2);
int drawY = (int) (interfaceScale * y - sizeY / 2 + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2);
double drawX = (interfaceScale * x - sizeX / 2 + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2);
double drawY = (interfaceScale * y - sizeY / 2 + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2);

Game.game.window.fontRenderer.drawString(drawX, drawY, this.fontSize, this.fontSize, text);
}
Expand All @@ -310,15 +310,15 @@ public void drawInterfaceText(double x, double y, String text, boolean rightAlig
if (!rightAligned)
offX = 0;

int drawX = (int) (interfaceScale * x - offX + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2);
int drawY = (int) (interfaceScale * (y + sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2);
double drawX = (interfaceScale * x - offX + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2);
double drawY = (interfaceScale * (y + sizeY / 2) + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2);
Game.game.window.fontRenderer.drawString(drawX, drawY, this.fontSize, this.fontSize, text);
}

public void drawUncenteredInterfaceText(double x, double y, String text)
{
int drawX = (int) (interfaceScale * x + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2);
int drawY = (int) (interfaceScale * y + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2);
double drawX = (interfaceScale * x + Math.max(0, Panel.windowWidth - interfaceSizeX * interfaceScale) / 2);
double drawY = (interfaceScale * y + Math.max(0, Panel.windowHeight - statsHeight - interfaceSizeY * interfaceScale) / 2);
Game.game.window.fontRenderer.drawString(drawX, drawY, this.fontSize, this.fontSize, text);
}

Expand Down
8 changes: 4 additions & 4 deletions src/tanks/Firework.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void drawUpdate()
{
if (type == FireworkType.rocket)
{
this.vY += 0.0625 * Panel.frameFrequency;
this.vY += 0.0625 * Panel.frameFrequency / 2;

Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB);
Drawing.drawing.fillOval(posX, posY, this.size, this.size);
Expand Down Expand Up @@ -116,15 +116,15 @@ public void drawUpdate()
e.vX = this.vX;
e.vY = this.vY;
e.addPolarMotion(Math.random() * 2 * Math.PI, Math.random() * power);
e.maxAge = 100;
e.maxAge = 2 * 100;
this.list.add(e);
}
}
}
else if (type == FireworkType.trail)
{
Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, Math.max(0, Math.min(255, 255 - (int) (this.age * 255.0 / this.maxAge))));
double s = this.size - (int) (this.age * this.size / this.maxAge);
double s = Math.max(0, this.size - (int) (this.age * this.size / this.maxAge));
Drawing.drawing.fillOval(posX, posY, s, s);

if (this.age >= this.maxAge)
Expand All @@ -134,7 +134,7 @@ else if (type == FireworkType.trail)
}
else if (type == FireworkType.particle)
{
this.vY += 0.0625 * Panel.frameFrequency;
this.vY += 0.0625 * Panel.frameFrequency / 2;

int opacity = Math.min(255, Math.max(0, (int) (255 - this.age * 255.0 / this.maxAge)));
Drawing.drawing.setColor(this.colorR, this.colorG, this.colorB, opacity);
Expand Down
12 changes: 9 additions & 3 deletions src/tanks/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class Game

public static boolean bulletLocked = false;

public static boolean vsync = true;

public static String crashMessage = "Yay! The game hasn't crashed yet!";

public static Screen screen;
Expand Down Expand Up @@ -77,6 +79,7 @@ public class Game
public static final String tankRegistryPath = directoryPath + "/tank-registry.txt";
public static final String obstacleRegistryPath = directoryPath + "/obstacle-registry.txt";
public static final String optionsPath = directoryPath + "/options.txt";
public static final String tutorialPath = directoryPath + "/tutorial.txt";

public static String homedir;

Expand Down Expand Up @@ -119,8 +122,6 @@ public static void initScript()
defaultTanks.add(new RegistryTank.DefaultTankEntry(TankPink.class, "pink", 1.0 / 15));
defaultTanks.add(new RegistryTank.DefaultTankEntry(TankBoss.class, "boss", 1.0 / 25));

//defaultTanks.add(new RegistryTank.DefaultTankEntry(TankCustom.class, "custom", 1));

homedir = System.getProperty("user.home");

if (Files.exists(Paths.get(homedir + "/.tanks.d")))
Expand Down Expand Up @@ -154,6 +155,11 @@ public static void initScript()
}
}

if (!Files.exists(Paths.get(homedir + tutorialPath)))
{
Game.screen = new ScreenTutorial();
}

if (!Files.exists(Paths.get(homedir + tankRegistryPath)))
{
RegistryTank.initRegistry(homedir);
Expand Down Expand Up @@ -187,7 +193,7 @@ public static void initScript()
public static void main(String[] args)
{
Game.initScript();
Game.game.window = new LWJGLWindow("Tanks", 1400, 940, new GameUpdater(), new GameDrawer());
Game.game.window = new LWJGLWindow("Tanks", 1400, 940, new GameUpdater(), new GameDrawer(), Game.vsync);
Game.game.window.run();
}

Expand Down
Loading

0 comments on commit 25a4c69

Please sign in to comment.