Skip to content

Commit

Permalink
Tanks v0.5.1 - Fixed mouse pointer in odd-sized large levels, and add…
Browse files Browse the repository at this point in the history
…ed shrubs, which you can hide in, and added the Wii Crusade
  • Loading branch information
aehmttw committed Jan 7, 2019
1 parent 8c27a75 commit c613f3d
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 15 deletions.
8 changes: 7 additions & 1 deletion src/tanks/Bullet.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void checkCollision()
{
Obstacle o = Game.obstacles.get(i);

if (!o.bulletCollision)
if (!o.bulletCollision && !o.checkForObjects)
continue;

double horizontalDist = Math.abs(this.posX - o.posX);
Expand All @@ -145,6 +145,12 @@ public void checkCollision()

if (horizontalDist < bound && verticalDist < bound)
{
if (o.checkForObjects)
o.onObjectEntry(this);

if (!o.bulletCollision)
continue;

if (dx <= 0 && dx > 0 - bound && horizontalDist > verticalDist)
{
this.posX += horizontalDist - bound;
Expand Down
7 changes: 3 additions & 4 deletions src/tanks/Crusade.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ else if (parsing == 1)
}
else if (parsing == 2)
{
String[] args = levelArray.get(i).split("-");
this.remainingLives = Integer.parseInt(args[0].split(",")[0]);
this.bonusLifeFrequency = Integer.parseInt(args[0].split(",")[1]);
this.remainingLives = Integer.parseInt(s.split(",")[0]);
this.bonusLifeFrequency = Integer.parseInt(s.split(",")[1]);
}
}

Expand All @@ -108,7 +107,7 @@ public void levelFinished(boolean win)
}
else
{
if ((this.currentLevel + 1) % 3 == 0 && !replay)
if ((this.currentLevel + 1) % this.bonusLifeFrequency == 0 && !replay)
remainingLives++;

if (this.currentLevel >= levels.size() - 1)
Expand Down
4 changes: 2 additions & 2 deletions src/tanks/Drawing.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,14 @@ public static double getPlayerMouseOffsetX()
if (!enableMovingCamera || !movingCamera || !enableMovingCameraX)
return 0;

return getPlayerOffsetX() + Drawing.interfaceSizeX / 2;
return getPlayerOffsetX() + (Game.currentSizeX / 28.0 - 1) * Drawing.interfaceSizeX / 2;
}

public static double getPlayerMouseOffsetY()
{
if (!enableMovingCamera || !movingCamera || !enableMovingCameraY)
return 0;

return getPlayerOffsetY() + Drawing.interfaceSizeY / 2;
return getPlayerOffsetY() + (Game.currentSizeY / 18.0 - 1) * Drawing.interfaceSizeY / 2;
}
}
1 change: 1 addition & 0 deletions src/tanks/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public static void initScript()
defaultObstacles.add(new RegistryObstacle.DefaultObstacleEntry(Obstacle.class, "normal"));
defaultObstacles.add(new RegistryObstacle.DefaultObstacleEntry(ObstacleIndestructible.class, "hard"));
defaultObstacles.add(new RegistryObstacle.DefaultObstacleEntry(ObstacleHole.class, "hole"));
defaultObstacles.add(new RegistryObstacle.DefaultObstacleEntry(ObstacleShrubbery.class, "shrub"));

defaultTanks.add(new RegistryTank.DefaultTankEntry(TankBrown.class, "brown", 1));
defaultTanks.add(new RegistryTank.DefaultTankEntry(TankGray.class, "gray", 1));
Expand Down
7 changes: 7 additions & 0 deletions src/tanks/Movable.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public abstract class Movable
public boolean destroy = false;
public boolean drawBelow = false;
public boolean drawAbove = false;
public boolean canHide = false;

public double hiddenTimer = 0;

public ArrayList<AttributeModifier> attributes = new ArrayList<AttributeModifier>();

Expand All @@ -28,6 +31,8 @@ public void update()
{
if (!destroy)
{
this.hiddenTimer = Math.max(0, this.hiddenTimer - Panel.frameFrequency);

double vX2 = this.vX;
double vY2 = this.vY;

Expand All @@ -50,6 +55,8 @@ public void update()

this.posX += vX2 / 2 * ScreenGame.finishTimer / ScreenGame.finishTimerMax * Panel.frameFrequency;
this.posY += vY2 / 2 * ScreenGame.finishTimer / ScreenGame.finishTimerMax * Panel.frameFrequency;

this.canHide = false;
this.checkCollision();
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/tanks/Obstacle.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class Obstacle
public boolean tankCollision = true;
public boolean bulletCollision = true;
public boolean drawBelow = false;

public boolean checkForObjects = false;

public double posX;
public double posY;
public Color color;
Expand Down Expand Up @@ -59,6 +60,11 @@ public void drawOutline(Graphics g)
drawing.fillRect(g, this.posX, this.posY + Obstacle.obstacle_size * 0.4, Obstacle.obstacle_size, Obstacle.obstacle_size * 0.2);
}

public void onObjectEntry(Movable m)
{

}

public static Color getRandomColor()
{
double colorMul = Math.random() * 0.5 + 0.5;
Expand Down
37 changes: 37 additions & 0 deletions src/tanks/ObstacleShrubbery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package tanks;

import java.awt.Color;
import java.awt.Graphics;

public class ObstacleShrubbery extends Obstacle
{

public double opacity = 255;
public ObstacleShrubbery(String name, double posX, double posY)
{
super(name, posX, posY);

this.destructible = true;
this.tankCollision = false;
this.bulletCollision = false;
this.checkForObjects = true;
this.color = new Color((int) (Math.random() * 20), (int) (Math.random() * 50) + 150, (int) (Math.random() * 20));
}

public void draw(Graphics g)
{
this.opacity = Math.min(this.opacity + Panel.frameFrequency, 255);
this.color = new Color(this.color.getRed(), this.color.getGreen(), this.color.getBlue(), (int) opacity);
g.setColor(this.color);
Drawing.window.fillRect(g, this.posX, this.posY, draw_size, draw_size);
}

@Override
public void onObjectEntry(Movable m)
{
this.opacity = Math.max(this.opacity - Panel.frameFrequency * Math.pow(Math.abs(m.vX) + Math.abs(m.vY), 2), 127);
m.hiddenTimer = Math.min(100, m.hiddenTimer + (this.opacity - 127) / 255);
m.canHide = true;
}

}
2 changes: 1 addition & 1 deletion src/tanks/Panel.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void paint(Graphics g)

g.setFont(g.getFont().deriveFont(Font.BOLD, 12));

g.drawString("Tanks v0.5.0", 2, (int) (Panel.windowHeight - 40 + 12));
g.drawString("Tanks v0.5.1", 2, (int) (Panel.windowHeight - 40 + 12));
g.drawString("FPS: " + lastFPS, 2, (int) (Panel.windowHeight - 40 + 24));

//g.drawString("Coins: " + Game.coins, 2, (int) (Panel.windowHeight - 40 + 36 - Window.yOffset));
Expand Down
23 changes: 23 additions & 0 deletions src/tanks/ScreenCrusades.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,29 @@ public void run()
}
));

buttons.add(new Button(0, 0, 350, 40, "Wii crusade", new Runnable()
{
@Override
public void run()
{
Scanner s = new Scanner(new InputStreamReader(getClass().getResourceAsStream("resources/wii_crusade.tanks")));
ArrayList<String> al = new ArrayList<String>();

while (s.hasNext())
{
al.add(s.nextLine());
}

s.close();

Crusade.currentCrusade = new Crusade(al, "Wii Crusade");
Crusade.crusadeMode = true;
Crusade.currentCrusade.loadLevel();
Game.screen = new ScreenGame(Crusade.currentCrusade.getShop());
}
}
));

for (Path l: levels)
{
String[] pathSections = l.toString().replaceAll("\\\\", "/").split("/");
Expand Down
23 changes: 23 additions & 0 deletions src/tanks/resources/wii_crusade.tanks
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
properties
3,5
levels
{22,17,235,207,166,20,20,20|11-5...6,0...21-12-hard,5-3...4-hard,5-7...8-hard,8-13-hard,11-3...4-hard,11-7...8-hard,13-13-hard|2-6-player-0-ally,19-6-brown-2-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|6...9-11,12...15-4,4...11-4-hard,10...17-11-hard|2-13-player-0-ally,19-2-gray-2-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|5...10-3,11...16-13,3...4-3-hard,10-8...13-hard,11-3...8-hard,17...18-13-hard|2-9-player-0-ally,5-1-gray-1-enemy,18-15-gray-3-enemy,19-8-brown-2-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|0...5-5-hole,0...12-11-hole,7-0...9-hole,7-13...16-hole,9...21-5-hole,14-0...3-hole,14-7...16-hole,16...21-11-hole|3-14-player-3-ally,10-8-gray-0-enemy,18-8-brown-2-enemy,11-2-brown-1-enemy,18-2-gray-1-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|2-11,3-12,18-4,19-5,3-11-hard,18-5-hard|2-13-player-0-ally,14-0-mint-1-enemy,20-9-mint-2-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|5-3,7-3,9-3,12-13,14-13,16-13,4-3-hard,4...11-13-hard,6-3-hard,8-3-hard,10...17-3-hard,13-13-hard,15-13-hard,17-13-hard,10-4...8-hole,11-8...12-hole|2-8-player-0-ally,17-4-gray-2-enemy,19-8-mint-2-enemy,20-13-mint-2-enemy,17-15-gray-3-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|3-4,3-10,18-5,18-12,0...2-4-hard,0...2-10-hard,4...8-4-hard,4...8-10-hard,13...17-5-hard,13...17-12-hard,19...21-5-hard,19...21-12-hard|2-14-player-0-ally,19-15-mint-3-enemy,19-2-mint-2-enemy,2-7-mint-0-enemy,1-1-mint-0-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|3-3...5,3-11...13,4-5...6,4-10...11,8...9-3,8...9-13,12...13-3,12...13-13,17...18-5,17-6,17-10...11,18-3...4,18-11...13,4-7...9-hard,10...11-3-hard,10...11-13-hard,17-7...9-hard|1-9-player-0-ally,15-4-yellow-1-enemy,14-12-yellow-3-enemy,20-9-yellow-2-enemy,21-2-mint-2-enemy,21-14-mint-2-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|10-4...8,11-8...12,0...6-8-hard,10...11-3-hard,10...11-13-hard,15...21-8-hard|2-13-player-0-ally,14-15-gray-3-enemy,13-5-gray-1-enemy,19-3-gray-2-enemy,7-1-gray-1-enemy,3-3-yellow-0-enemy,19-13-yellow-2-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|2...5-8,10-5,11-11,16...19-8,2...5-2-hard,2...5-14-hard,8...9-5-hard,8...10-11-hard,11...13-5-hard,12...13-11-hard,16...19-2-hard,16...19-14-hard|1-12-player-0-ally,11-1-magenta-1-enemy,20-4-magenta-2-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|5-11...12,6-0...1,6-12,15...16-4,15-15...16,16-5,5-6...10-hard,6-2...6-hard,7...8-12-hard,13...14-4-hard,15-10...14-hard,16-6...10-hard|2-3-player-0-ally,3-13-gray-0-enemy,7-0-mint-1-enemy,9-8-magenta-0-enemy,14-1-gray-1-enemy,19-4-magenta-2-enemy,19-14-mint-2-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|10...11-8,10-9,11-7,6...7-12-hard,6-13-hard,7...8-11-hard,8...9-10-hard,9-9-hard,12...13-6-hard,12-7-hard,13...14-5-hard,14...15-4-hard,15-3-hard,6...7-3-hole,6...7-4-hole,14...15-12-hole,14...15-13-hole|0-0-player-0-ally,17-15-green-3-enemy,10-14-magenta-3-enemy,19-4-green-2-enemy,12-1-magenta-1-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|3...4-8,5...6-3,5...6-13,7...8-8,9...10-3,9...10-13,11...12-8,13...14-3,13...14-13,15...16-8,17...18-3,17...18-13,3...4-3-hard,3...4-13-hard,5...6-8-hard,7...8-3-hard,7...8-13-hard,9...10-8-hard,11...12-3-hard,11...12-13-hard,13...14-8-hard,15...16-3-hard,15...16-13-hard,17...18-8-hard|0-0-player-0-ally,8-1-yellow-1-enemy,20-1-mint-2-enemy,21-8-mint-2-enemy,20-15-mint-2-enemy,5-15-yellow-3-enemy,12-10-yellow-3-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|1-13,3-13,18-3,20-3,0-13-hard,2-13-hard,3...11-3-hard,3-4...9-hard,4...7-9-hard,4-13-hard,6-13-hard,8-13-hard,10...18-13-hard,13-3-hard,14...18-7-hard,15-3-hard,17-3-hard,18-8...12-hard,19-3-hard,21-3-hard,5-13-hole,7-13-hole,9-13-hole,12-3-hole,14-3-hole,16-3-hole|1-15-player-0-ally,20-10-magenta-2-enemy,15-1-magenta-1-enemy,20-1-green-2-enemy,15-10-green-2-enemy,6-6-green-0-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|5-3,5-10,7-3,7-10,14-6,14-13,16-6,16-13,4-3...6-hard,4-10-hard,6-3-hard,6-10-hard,8-3-hard,8-10...13-hard,13-3...6-hard,13-13-hard,15-6-hard,15-13-hard,17-6-hard,17-10...13-hard|2-14-player-0-ally,6-5-purple-0-enemy,19-2-purple-2-enemy,19-15-purple-3-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|4-10,7-3,8-13,9-3,10-13,11-3,12-13,13-3,14-13,17-6,3-3...10-hard,5...6-10-hard,6-11...13-hard,7-13-hard,8-3-hard,9-13-hard,10-3-hard,11-13-hard,12-3-hard,13-13-hard,14...15-3-hard,15-4...6-hard,16-6-hard,18-6...13-hard|1-15-player-0-ally,20-11-purple-2-enemy,20-1-green-2-enemy,9-1-purple-1-enemy,13-8-purple-2-enemy,8-11-green-3-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|7...8-6,7...8-10,8-5,8-11,13-5...6,13...14-10,13-11,14-6,0...6-10-hard,4...6-6-hard,8-0...4-hard,8-12...13-hard,13-3...4-hard,13-12...16-hard,15...21-6-hard,15...17-10-hard|1-13-player-0-ally,10-8-green-0-enemy,3-2-green-1-enemy,20-3-green-2-enemy,1-8-green-0-enemy,20-8-green-2-enemy,19-14-green-2-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|9...12-6,9...12-10,4...8-6-hard,4...8-10-hard,10-0...2-hard,10-11...14-hard,11-2...5-hard,11-14...16-hard,13...17-6-hard,13...17-10-hard|2-13-player-0-ally,11-8-green-2-enemy,14-2-purple-1-enemy,14-15-purple-3-enemy,19-14-mint-2-enemy,4-2-mint-1-enemy,7-4-magenta-1-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20|1...2-3,1...2-13,3...4-8,5...6-3,5...6-13,7...8-8,9...10-3,9...10-13,11...12-8,13...14-3,13...14-13,15...16-8,17...18-3,17...18-13,19...20-8,0-3-hard,0-13-hard,3...4-3-hard,3...4-13-hard,5...6-8-hard,7...8-3-hard,7...8-13-hard,9...10-8-hard,11...12-3-hard,11...12-13-hard,13...14-8-hard,15...16-3-hard,15...16-13-hard,17...18-8-hard,21-8-hard|1-15-player-0-ally,17-15-purple-3-enemy,20-11-purple-2-enemy,1-8-purple-0-enemy,9-5-purple-1-enemy,19-6-purple-2-enemy,17-1-purple-1-enemy,8-1-purple-1-enemy,1-1-purple-0-enemy|ally-true,enemy-true}
{22,17,235,207,166,20,20,20||2-9-player-0-ally,19-9-white-2-enemy,17-7-white-2-enemy|ally-true,enemy-true}
8 changes: 7 additions & 1 deletion src/tanks/tank/Tank.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void checkCollision()
{
Obstacle o = Game.obstacles.get(i);

if (!o.tankCollision)
if (!o.tankCollision && !o.checkForObjects)
continue;

double horizontalDist = Math.abs(this.posX - o.posX);
Expand All @@ -91,6 +91,12 @@ public void checkCollision()

if (horizontalDist < bound && verticalDist < bound)
{
if (o.checkForObjects)
o.onObjectEntry(this);

if (!o.tankCollision)
continue;

if (dx <= 0 && dx > 0 - bound && horizontalDist > verticalDist)
{
hasCollided = true;
Expand Down
37 changes: 32 additions & 5 deletions src/tanks/tank/TankAIControlled.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ protected enum RotationPhase {clockwise, counterClockwise, aiming}
/** Range which rays will be used to detect a tank after being locked on to it. Larger values detect motion better but are less accurate.*/
public double searchRange = 0.3;

/** Multiplier of time the tank will hide in a shrub*/
public double hideAmount = 350;

/** Type of shooting AI to use*/
public ShootAI shootAIType;

Expand Down Expand Up @@ -171,7 +174,10 @@ protected enum RotationPhase {clockwise, counterClockwise, aiming}

/** Normally the nearest tank not on this tank's team. This is the tank that this tank will fight*/
protected Movable targetEnemy;


/** True if can find an enemy*/
protected boolean hasTarget = true;

public TankAIControlled(String name, double x, double y, int size, Color color, double angle, ShootAI ai)
{
super(name, x, y, size, color);
Expand Down Expand Up @@ -266,16 +272,18 @@ public void updateTarget()
{
double nearestDist = Double.MAX_VALUE;
Movable nearest = this;
this.hasTarget = false;

for (int i = 0; i < Game.movables.size(); i++)
{
Movable m = Game.movables.get(i);

if (m instanceof Tank && !Team.isAllied(this, m))
if (m instanceof Tank && !Team.isAllied(this, m) && m.hiddenTimer <= 0)
{
double dist = Movable.distanceBetween(this, m);
if (dist < nearestDist)
{
this.hasTarget = true;
nearestDist = dist;
nearest = m;
}
Expand Down Expand Up @@ -321,7 +329,7 @@ public void reactToTargetEnemySight()
public void updateIdleMotion()
{
if (Math.random() < this.motionChangeChance || this.hasCollided)
{
{
this.overrideDirection = false;

double prevDirection = this.direction;
Expand Down Expand Up @@ -353,6 +361,9 @@ public void updateIdleMotion()

if (this.direction != prevDirection)
this.motionPauseTimer = this.directionChangeCooldown;

if (this.canHide)
this.motionPauseTimer += this.hideAmount * (Math.random() + 1);
}

if (this.motionPauseTimer > 0)
Expand Down Expand Up @@ -466,7 +477,7 @@ public void updateTurretWander()
Movable m = a.getTarget();

if (!(m == null))
if (!Team.isAllied(m, this) && m instanceof Tank)
if (!Team.isAllied(m, this) && m instanceof Tank && m.hiddenTimer <= 0)
this.shoot();

if (this.idlePhase == RotationPhase.clockwise)
Expand All @@ -490,6 +501,9 @@ public void updateTurretWander()

public void updateTurretStraight()
{
if (!this.hasTarget)
return;

if (this.avoidTimer > 0 && this.enableDefensiveFiring && !this.nearestBullet.destroy)
{
this.aimAngle = this.getAngleInDirection(this.nearestBullet.posX + this.nearestBullet.vX * Movable.distanceBetween(this, this.nearestBullet) / this.bulletSpeed, this.nearestBullet.posY + this.nearestBullet.vY * Movable.distanceBetween(this, nearestBullet) / this.bulletSpeed);
Expand Down Expand Up @@ -553,7 +567,7 @@ public void updateTurretReflect()
this.aimAngle = this.getAngleInDirection(this.nearestBullet.posX + this.nearestBullet.vX * Movable.distanceBetween(this, this.nearestBullet) / this.bulletSpeed, this.nearestBullet.posY + this.nearestBullet.vY * Movable.distanceBetween(this, nearestBullet) / this.bulletSpeed);
this.disableOffset = true;
}
else if (aim)
else if (aim && this.hasTarget)
{
this.updateAimingTurret();
}
Expand Down Expand Up @@ -592,17 +606,30 @@ else if (this.searchPhase == RotationPhase.counterClockwise)

Movable target = ray.getTarget();
if (target != null)
{
if (target.equals(this.targetEnemy))
{
this.lockedAngle = this.angle;
this.searchPhase = RotationPhase.aiming;
this.aim = true;
this.aimAngle = this.searchAngle % (Math.PI * 2);
}
else if (target instanceof Tank && target.hiddenTimer <= 0 && Team.isAllied(target, this))
{
this.targetEnemy = target;
this.lockedAngle = this.angle;
this.searchPhase = RotationPhase.aiming;
this.aim = true;
this.aimAngle = this.searchAngle % (Math.PI * 2);
}
}
}

public void lookAtTargetEnemy()
{
if (!this.hasTarget)
return;

double a;

if (this.enablePredictiveFiring)
Expand Down

0 comments on commit c613f3d

Please sign in to comment.