Skip to content

Commit

Permalink
Merge pull request #14 from QazCetelic/master
Browse files Browse the repository at this point in the history
Use JavaDoc to document classes and a few tweaks.
  • Loading branch information
aehmttw authored Feb 23, 2022
2 parents 543c3ca + 3c1cdc0 commit 78e35d5
Show file tree
Hide file tree
Showing 36 changed files with 168 additions and 55 deletions.
48 changes: 28 additions & 20 deletions src/main/java/main/Tanks.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import tanksonline.TanksOnlineServer;

import java.io.File;
import java.util.Arrays;

public class Tanks
{
Expand All @@ -17,27 +18,27 @@ public static void main(String[] args)
Game.framework = Game.Framework.lwjgl;
int port = 8080;

// Relaunches the .jar if Mac OS X is detected.
boolean relaunch = System.getProperties().toString().contains("Mac OS X");

for (int i = 0; i < args.length; i++)
// Goes through arguments and applies specified settings.
for (String arg : args)
{
if (args[i].equals("online_server"))
if (arg.equals("online_server"))
Game.isOnlineServer = true;

if (args[i].startsWith("port="))
port = Integer.parseInt(args[i].split("=")[1]);

if (args[i].equals("debug"))
if (arg.matches("port=\\d+"))
port = Integer.parseInt(arg.split("=")[1]);
if (arg.equals("debug"))
Game.debug = true;

if (args[i].equals("mac") || args[i].equals("no_relaunch"))
if (arg.equals("mac") || arg.equals("no_relaunch"))
relaunch = false;
}

if (!Game.isOnlineServer)
{
if (relaunch && Game.framework == Game.Framework.lwjgl)
{
// Attempts to relaunch from the .jar file.
try
{
String path = new File(Tanks.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getPath();
Expand All @@ -63,7 +64,14 @@ public static void main(String[] args)

if (Game.framework == Game.Framework.lwjgl)
{
Game.game.window = new LWJGLWindow("Tanks", 1400, 900 + Drawing.drawing.statsHeight, Game.absoluteDepthBase, new GameUpdater(), new GameDrawer(), new GameWindowHandler(), Game.vsync, !Panel.showMouseTarget);
// Creates and configures the LWJGL window.
Game.game.window = new LWJGLWindow(
"Tanks",
1400, 900 + Drawing.drawing.statsHeight,
Game.absoluteDepthBase,
new GameUpdater(), new GameDrawer(), new GameWindowHandler(),
Game.vsync, !Panel.showMouseTarget
);
Game.game.window.antialiasingEnabled = Game.antialiasing;
}

Expand All @@ -81,21 +89,21 @@ public static void main(String[] args)
}
}

/*
Call this method to launch Tanks with extensions directly instead of loading them from a jar file!
This is useful if you want to test an extension without exporting it as a jar file.
The integer array passed determines the order in which these extensions will be added to the full list
(which includes extensions loaded from separate jar files traditionally)
/**
* Call this method to launch Tanks with extensions directly instead of loading them from a jar file!
* This is useful if you want to test an extension without exporting it as a jar file.
* The integer array passed determines the order in which these extensions will be added to the full list
* (which includes extensions loaded from separate jar files traditionally)
*/
public static void launchWithExtensions(String[] args, Extension[] extensions, int[] order)
{
Game.extraExtensions = extensions;
Game.extraExtensionOrder = order;

// Append "no_relaunch" to the arguments.
String[] newArgs = Arrays.copyOf(args, args.length + 1);
newArgs[args.length] = "no_relaunch";

String[] args2 = new String[args.length + 1];
System.arraycopy(args, 0, args2, 0, args.length);
args2[args.length] = "no_relaunch";

main(args2);
main(newArgs);
}
}
5 changes: 1 addition & 4 deletions src/main/java/tanks/IGameObject.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
package tanks;

public interface IGameObject
{

}
public interface IGameObject {}
31 changes: 15 additions & 16 deletions src/main/java/tanks/Movable.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@ public void update()
double vY2 = this.vY;
double vZ2 = this.vZ;

ArrayList<AttributeModifier> removeAttributes = new ArrayList<>();
for (int i = 0; i < this.attributes.size(); i++)
ArrayList<AttributeModifier> toRemove = new ArrayList<>();
for (AttributeModifier a : attributes)
{
AttributeModifier a = this.attributes.get(i);

if (a.expired)
removeAttributes.add(a);

{
// Adds attribute to list to later get removed.
toRemove.add(a);
}

a.update();

if (!a.expired && a.type.equals("velocity"))
{
vX2 = a.getValue(vX2);
Expand All @@ -90,13 +91,11 @@ public void update()
}
}

for (int i = 0; i < removeAttributes.size(); i++)
for (AttributeModifier a : toRemove)
{
this.attributes.remove(removeAttributes.get(i));
attributes.remove(a);
}

removeAttributes.clear();

this.lastFinalVX = vX2 * ScreenGame.finishTimer / ScreenGame.finishTimerMax;
this.lastFinalVY = vY2 * ScreenGame.finishTimer / ScreenGame.finishTimerMax;
this.lastFinalVZ = vZ2 * ScreenGame.finishTimer / ScreenGame.finishTimerMax;
Expand Down Expand Up @@ -234,7 +233,7 @@ public void setPolarMotion(double angle, double velocity)
double velX = velocity * Math.cos(angle);
double velY = velocity * Math.sin(angle);
this.vX = velX;
this.vY = velY;
this.vY = velY;
}

public void set3dPolarMotion(double angle1, double angle2, double velocity)
Expand All @@ -253,7 +252,7 @@ public void addPolarMotion(double angle, double velocity)
double velX = velocity * Math.cos(angle);
double velY = velocity * Math.sin(angle);
this.vX += velX;
this.vY += velY;
this.vY += velY;
}

public void add3dPolarMotion(double angle1, double angle2, double velocity)
Expand All @@ -270,7 +269,7 @@ public void add3dPolarMotion(double angle1, double angle2, double velocity)
public void moveInDirection(double x, double y, double amount)
{
this.posX += amount * x;
this.posY += amount * y;
this.posY += amount * y;
}

public double getSpeed()
Expand Down Expand Up @@ -318,9 +317,9 @@ public void addUnduplicateAttribute(AttributeModifier m)
{
this.attributes.remove(i);
i--;
}
}
}

this.attributes.add(m);
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/tanks/bullet/BulletLaser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import tanks.hotbar.item.ItemBullet;
import tanks.tank.Tank;

/**
* A laser which can be fired by a Tank.
* @see tanks.tank.TankRed
*/
public class BulletLaser extends BulletInstant
{
public static String bullet_name = "laser";
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tanks/obstacle/ObstacleTeleporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import java.util.ArrayList;

/**
* A teleporter which randomly transports the player to another teleporter in the level
*/
public class ObstacleTeleporter extends Obstacle
{
public double cooldown;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tanks/tank/TankBlack.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import tanks.Game;
import tanks.bullet.Bullet;

/**
* A smart, very fast tank which fires rockets
*/
public class TankBlack extends TankAIControlled
{
public double strafeDirection = Math.PI / 2;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tanks/tank/TankBlue.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import tanks.Game;
import tanks.bullet.BulletElectric;

/**
* A stationary tank which shoots stunning electricity that arcs between targets
*/
public class TankBlue extends TankAIControlled
{
public TankBlue(String name, double x, double y, double angle)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tanks/tank/TankBoss.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import java.util.ArrayList;

/**
* A big boss tank which spawns other tanks and takes 5 regular bullets to destroy
*/
public class TankBoss extends TankAIControlled
{
public ArrayList<Tank> spawned = new ArrayList<>();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/tanks/tank/TankBrown.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import tanks.Game;

/**
* A primitive stationary tank
*/
public class TankBrown extends TankAIControlled
{

public TankBrown(String name, double x, double y, double angle)
{
super(name, x, y, Game.tile_size, 150, 80, 0, angle, ShootAI.wander);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tanks/tank/TankCyan.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import java.util.Arrays;

/**
* A support tank which shoots freezing bullets that deal low damage
*/
public class TankCyan extends TankAIControlled
{
public TankCyan(String name, double x, double y, double angle)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tanks/tank/TankDarkGreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import tanks.Game;
import tanks.bullet.Bullet;

/**
* A fast tank which rapidly fires many small, low-damage bullets
*/
public class TankDarkGreen extends TankAIControlled
{
public TankDarkGreen(String name, double x, double y, double angle)
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/tanks/tank/TankDummy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import tanks.Game;

/**
* A dummy tank used to practice your aim
* @see TankDummyLoadingScreen
*/
public class TankDummy extends Tank
{
public TankDummy(String name, double x, double y, double angle)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tanks/tank/TankDummyLoadingScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import tanks.Game;

/**
* A spinning tank shown on the loading screen
*/
public class TankDummyLoadingScreen extends Tank
{
public static final double size_multiplier = 1.5;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tanks/tank/TankGold.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import tanks.event.EventShootBullet;
import tanks.event.EventTankUpdateColor;

/**
* A tank which speeds up its allies and becomes explosive as a last stand
*/
public class TankGold extends TankAIControlled
{
boolean suicidal = false;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/tanks/tank/TankGray.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import tanks.Game;

/**
* A primitive mobile tank
* @see TankBrown
*/
public class TankGray extends TankAIControlled
{
public TankGray(String name, double x, double y, double angle)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tanks/tank/TankGreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import tanks.Game;
import tanks.bullet.Bullet;

/**
* A deadly stationary tank which shoots rockets that bounce twice
*/
public class TankGreen extends TankAIControlled
{
public TankGreen(String name, double x, double y, double angle)
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/tanks/tank/TankLightPink.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import tanks.event.EventTankLightPinkAngry;
import tanks.event.EventTankUpdateColor;

/**
* A tank which gets angry on line of sight
*/
public class TankLightPink extends TankAIControlled
{
public double angerTimer = 0;
Expand All @@ -30,6 +33,7 @@ public TankLightPink(String name, double x, double y, double angle)
this.description = "A tank which gets angry---on line of sight";
}

@Override
public void postUpdate()
{
double prevTimer = this.angerTimer;
Expand Down Expand Up @@ -87,6 +91,7 @@ public void postUpdate()
}
}

@Override
public void shoot()
{
if (this.angerTimer <= 0)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tanks/tank/TankMagenta.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import tanks.Game;

/**
* A medium-speed smart tank
*/
public class TankMagenta extends TankAIControlled
{
public TankMagenta(String name, double x, double y, double angle)
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/tanks/tank/TankMaroon.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import tanks.Game;
import tanks.bullet.Bullet;

/**
* A tank which shoots huge bullets which bounce 3 times and can't be stopped
*/
public class TankMaroon extends TankAIControlled
{
public TankMaroon(String name, double x, double y, double angle)
Expand Down Expand Up @@ -31,6 +34,7 @@ public TankMaroon(String name, double x, double y, double angle)
this.description = "A tank which shoots huge bullets which---bounce 3 times and can't be stopped";
}

@Override
public void reactToTargetEnemySight()
{
this.currentlySeeking = false;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/tanks/tank/TankMedic.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import tanks.event.EventLayMine;
import tanks.event.EventTankUpdateColor;

/**
* A tank which adds extra health to its allies and becomes explosive as a last stand
*/
public class TankMedic extends TankAIControlled
{
boolean suicidal = false;
Expand Down Expand Up @@ -153,6 +156,7 @@ public void updateTarget()
this.targetEnemy = nearest;
}

@Override
public void reactToTargetEnemySight()
{
if (this.suicidal && this.targetEnemy != null)
Expand All @@ -162,6 +166,7 @@ public void reactToTargetEnemySight()
}
}

@Override
public boolean isInterestingPathTarget(Movable m)
{
return m instanceof Tank && Team.isAllied(m, this) && m != this && ((Tank) m).health - ((Tank) m).baseHealth < 1 && !(m instanceof TankMedic);
Expand Down
Loading

0 comments on commit 78e35d5

Please sign in to comment.