Skip to content

Commit

Permalink
Tanks v0.3.3 - Tank AI Improvements and full support for higher fps t…
Browse files Browse the repository at this point in the history
…han 100. Tank Rebalancing. Recolored Dark Red tank to Dark Green
  • Loading branch information
aehmttw committed Jul 8, 2018
1 parent 43d98fe commit d71f076
Show file tree
Hide file tree
Showing 28 changed files with 758 additions and 550 deletions.
5 changes: 5 additions & 0 deletions src/tanks/Bullet.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public void checkCollision()

for (int i = 0; i < Game.obstacles.size(); i++)
{
double prevX = this.posX;
double prevY = this.posY;

Obstacle o = Game.obstacles.get(i);

double horizontalDist = Math.abs(this.posX - o.posX);
Expand Down Expand Up @@ -93,6 +96,8 @@ else if (dy >= 0 && dy < bound && horizontalDist < verticalDist)
if (collided && this.age == 0)
{
this.destroy = true;
this.posX = prevX;
this.posY = prevY;
return;
}

Expand Down
8 changes: 4 additions & 4 deletions src/tanks/Effect.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class Effect extends Movable
{
static enum EffectType {fire, smokeTrail, trail, ray, mineExplosion, laser, piece, obstaclePiece, charge, tread}
public enum EffectType {fire, smokeTrail, trail, ray, mineExplosion, laser, piece, obstaclePiece, charge, tread}
public EffectType type;
double age = 0;
public Color col;
Expand Down Expand Up @@ -50,7 +50,7 @@ public void drawWithoutUpdate(Graphics p)
int opacity = (int)(rawOpacity * 255);

int green = Math.min(255, (int)(127 + 128.0*(this.age / 20.0)));
Color col = new Color(255, green, 0, (int) (opacity * opacityMultiplier * ffOpacityMultiplier));
Color col = new Color(255, green, 0, Math.min(255, Math.max(0, (int) (opacity * opacityMultiplier * ffOpacityMultiplier))));

p.setColor(col);
Screen.fillOval(p, this.posX, this.posY, size, size);
Expand All @@ -65,7 +65,7 @@ else if (this.type == EffectType.smokeTrail)
rawOpacity *= rawOpacity * rawOpacity;
int opacity = (int)(rawOpacity * 100);

Color col = new Color(0, 0, 0, (int) (opacity * opacityMultiplier * opacityModifier * ffOpacityMultiplier));
Color col = new Color(0, 0, 0, Math.min(255, Math.max(0, (int) (opacity * opacityMultiplier * opacityModifier * ffOpacityMultiplier))));

if (opacity <= 0)
{
Expand All @@ -88,7 +88,7 @@ else if (this.type == EffectType.trail)
rawOpacity *= rawOpacity * rawOpacity;
int opacity = (int)(rawOpacity * 25);

Color col = new Color(127, 127, 127, (int) (opacity * opacityMultiplier * ffOpacityMultiplier));
Color col = new Color(127, 127, 127, Math.min(255, Math.max(0, (int) (opacity * opacityMultiplier * ffOpacityMultiplier))));

p.setColor(col);
Screen.fillOval(p, this.posX, this.posY, size, size);
Expand Down
20 changes: 12 additions & 8 deletions src/tanks/EnemyTankDynamic.java → src/tanks/EnemyTank.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/** This class is the skeleton tank class.
* It can be extended and values can be changed to easily produce an AI for another tank.
* Also, the behavior is split into many methods which are intended to be overridden easily.*/
public class EnemyTankDynamic extends Tank
public class EnemyTank extends Tank
{

/** Determines which type of AI the tank will use when shooting.
Expand Down Expand Up @@ -155,7 +155,7 @@ protected enum RotationPhase {clockwise, counterClockwise, aiming}
/** Time until the tank will continue motion*/
protected double motionTimer = 0;

public EnemyTankDynamic(double x, double y, int size, Color color, double angle, ShootAI ai)
public EnemyTank(double x, double y, int size, Color color, double angle, ShootAI ai)
{
super(x, y, size, color);

Expand Down Expand Up @@ -202,7 +202,7 @@ public void launchBullet(double offset)
{
Bullet b = new Bullet(this.posX, this.posY, this.bulletColor, this.bulletBounces, this);
b.setPolarMotion(angle + offset, this.bulletSpeed);
b.moveOut((int) (25 / this.bulletSpeed * 2));
b.moveOut((int) (25 / this.bulletSpeed * 2 * this.size / Game.tank_size));
b.effect = this.bulletEffect;
b.size = this.bulletSize;
b.damage = this.bulletDamage;
Expand Down Expand Up @@ -442,6 +442,10 @@ else if (this.enablePredictiveFiring)
{
this.aimAngle = this.getAngleInDirection(Game.player.posX + Game.player.vX * Movable.distanceBetween(this, Game.player) / this.bulletSpeed, Game.player.posY + Game.player.vY * Movable.distanceBetween(this, Game.player) / this.bulletSpeed);
}
else
{
this.aimAngle = this.getAngleInDirection(Game.player.posX, Game.player.posY);
}
}
else
{
Expand All @@ -463,13 +467,13 @@ else if (this.enablePredictiveFiring)
if ((this.angle - this.aimAngle + Math.PI * 3) % (Math.PI*2) - Math.PI < 0)
this.angle += this.aimTurretSpeed * Panel.frameFrequency;
else
this.angle -= this.aimTurretSpeed * Panel.frameFrequency;

if (Math.abs(this.angle - this.aimAngle) < this.aimThreshold && !this.disableOffset)
this.angle = this.aimAngle;
this.angle -= this.aimTurretSpeed * Panel.frameFrequency;

this.angle = this.angle % (Math.PI * 2);
}

if (Math.abs(this.angle - this.aimAngle) < this.aimThreshold && !this.disableOffset)
this.angle = this.aimAngle;
}

public void updateTurretReflect()
Expand Down Expand Up @@ -636,7 +640,7 @@ public void updateMineAI()

if (nearest != null)
{
if (this.enableMineAvoidance)
if (this.enableMineAvoidance && this.enableMovement)
this.setMotionAwayFromDirection(nearest.posX, nearest.posY, speed);
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/tanks/EnemyTankBlack.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.awt.Color;

public class EnemyTankBlack extends EnemyTankDynamic
public class EnemyTankBlack extends EnemyTank
{
public double strafeDirection = Math.PI / 2;

Expand Down
2 changes: 1 addition & 1 deletion src/tanks/EnemyTankBrown.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.awt.Color;

public class EnemyTankBrown extends EnemyTankDynamic
public class EnemyTankBrown extends EnemyTank
{
public EnemyTankBrown(double x, double y, double angle)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.awt.Color;

public class EnemyTankDarkRed extends EnemyTankDynamic
public class EnemyTankDarkGreen extends EnemyTank
{
public EnemyTankDarkRed(double x, double y, double angle)
public EnemyTankDarkGreen(double x, double y, double angle)
{
super(x, y, Game.tank_size, new Color(100, 0, 0), angle, ShootAI.straight);
super(x, y, Game.tank_size, new Color(85, 107, 47), angle, ShootAI.straight);
this.cooldownBase = 5;
this.cooldownRandom = 0;
this.speed = 2.5;
Expand Down
2 changes: 1 addition & 1 deletion src/tanks/EnemyTankGray.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.awt.Color;

public class EnemyTankGray extends EnemyTankDynamic
public class EnemyTankGray extends EnemyTank
{
public EnemyTankGray(double x, double y, double angle)
{
Expand Down
2 changes: 1 addition & 1 deletion src/tanks/EnemyTankGreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.awt.Color;

public class EnemyTankGreen extends EnemyTankDynamic
public class EnemyTankGreen extends EnemyTank
{
public EnemyTankGreen(double x, double y, double angle)
{
Expand Down
2 changes: 1 addition & 1 deletion src/tanks/EnemyTankMagenta.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.awt.Color;

public class EnemyTankMagenta extends EnemyTankDynamic
public class EnemyTankMagenta extends EnemyTank
{
public EnemyTankMagenta(double x, double y, double angle)
{
Expand Down
14 changes: 11 additions & 3 deletions src/tanks/EnemyTankMini.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.awt.Color;

public class EnemyTankMini extends EnemyTankDynamic
public class EnemyTankMini extends EnemyTank
{
public EnemyTankPink tank;
public boolean previousDestroy = false;
Expand All @@ -28,8 +28,6 @@ public EnemyTankMini(double x, double y, double angle)
this.enableLookingAtPlayer = false;
this.motionChangeChance = 0.001;
this.enableBulletAvoidance = false;

this.coinValue = 2;
}

public EnemyTankMini(double x, double y, double angle, EnemyTankPink t)
Expand All @@ -54,5 +52,15 @@ public void update()
}

super.update();


if (this.tank != null)
{
if (!this.tank.destroy && Math.sqrt(Math.pow(this.posX - this.tank.posX, 2) + Math.pow(this.posY - this.tank.posY, 2)) > 300)
{
this.setMotionInDirection(this.tank.posX, this.tank.posY, this.speed);
}
}

}
}
4 changes: 2 additions & 2 deletions src/tanks/EnemyTankMint.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.awt.Color;

public class EnemyTankMint extends EnemyTankDynamic
public class EnemyTankMint extends EnemyTank
{
public EnemyTankMint(double x, double y, double angle)
{
Expand All @@ -14,7 +14,7 @@ public EnemyTankMint(double x, double y, double angle)
this.enablePredictiveFiring = false;
this.liveBulletMax = 1;
this.cooldownRandom = 60;
this.cooldownBase = 120;
this.cooldownBase = 240;
this.idleTurretSpeed = 0.02;
this.bulletBounces = 0;
this.bulletColor = Color.red;
Expand Down
77 changes: 25 additions & 52 deletions src/tanks/EnemyTankOrange.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,46 @@

import java.awt.Color;

public class EnemyTankOrange extends Tank
public class EnemyTankOrange extends EnemyTank
{
int moveTime = 0;
double aimAngle = 0;

public EnemyTankOrange(double x, double y, int size)
public EnemyTankOrange(double x, double y, double angle)
{
super(x, y, size, new Color(230, 120, 0));
this.liveBulletMax = 1;
}
super(x, y, Game.tank_size, new Color(230, 120, 0), angle, ShootAI.straight);

public EnemyTankOrange(double x, double y, int size, double a)
{
this(x, y, size);
this.angle = a;
this.coinValue = 5;
this.enableMovement = true;
this.speed = 1.5;

this.enableMineLaying = false;
this.enablePredictiveFiring = false;
this.idleTurretSpeed = 0.01;
this.aimAccuracyOffset = 0;

this.motionChangeChance = 0.0005;

this.coinValue = 6;
}

@Override
public void shoot()
{
Flame b = new Flame(this.posX, this.posY, Color.blue, 0, this);
b.setPolarMotion(this.angle, 25.0/4);
b.moveOut(8);
Game.movables.add(b);
this.cooldown = 0;
}

@Override
public void update()
{

if (Movable.distanceBetween(this, Game.player) < 400)
if (Movable.distanceBetween(this, Game.player) < 400 && this.cooldown <= 0)
{
Ray a = new Ray(this.posX, this.posY, this.angle, 0, this);
Movable m = a.getTarget();
//if (m != null)
// System.out.println(((Tank)m).color);

if (!(m == null))
{
if(m.equals(Game.player))
this.shoot();
{
Flame b = new Flame(this.posX, this.posY, Color.blue, 0, this);
b.setPolarMotion(this.angle, 25.0/4);
b.moveOut(8);
Game.movables.add(b);
this.cooldown = 0;
}
}
}

if (this.moveTime <= 0 || hasCollided)
{
double angleV = Math.random() * Math.PI * 2;
this.setPolarMotion(angleV, 1.5);
this.moveTime = (int) (Math.random() * 100 + 25);
}

//this.moveTime--;

this.aimAngle = this.getAngleInDirection(Game.player.posX, Game.player.posY);


if ((this.angle - this.aimAngle + Math.PI * 3) % (Math.PI*2) - Math.PI < 0)
//if ((this.aimAngle - this.angle) % (Math.PI * 2) < (this.angle - this.aimAngle) % (Math.PI * 2))
this.angle+=0.02;
else
this.angle-=0.02;

if (Math.abs(this.aimAngle - this.angle) < 0.02)
this.angle = this.aimAngle;

this.angle = this.angle % (Math.PI * 2);

super.update();
}
}
Loading

0 comments on commit d71f076

Please sign in to comment.