Skip to content

Commit

Permalink
Tanks v0.4.0 - Added the level creator, and saved levels!
Browse files Browse the repository at this point in the history
  • Loading branch information
aehmttw committed Sep 16, 2018
1 parent d926ac2 commit 01d4b22
Show file tree
Hide file tree
Showing 76 changed files with 3,232 additions and 1,091 deletions.
95 changes: 65 additions & 30 deletions src/tanks/Bullet.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,33 @@

public class Bullet extends Movable
{
public static enum BulletEffect {none, fire, fireTrail, trail};
public static enum BulletEffect {none, fire, darkFire, fireTrail, trail};

public static int bullet_size = 10;

public int age = 0;
public double size;
public int bounces;
public Color color;
public Color baseColor;
public Color outlineColor;
public double destroyTimer = 0;
public Tank tank;
public double damage = 1;
public BulletEffect effect = BulletEffect.none;
public boolean useCustomWallCollision = false;
public double wallCollisionSize = 10;

public Bullet(double x, double y, Color color, int bounces, Tank t)
public Bullet(double x, double y, int bounces, Tank t)
{
super(x, y);
this.vX = 0;
this.vY = 0;
this.size = bullet_size;
this.color = color;
this.baseColor = t.color;
this.outlineColor = Team.getObjectColor(t.turret.color, t);
this.bounces = bounces;
this.tank = t;
this.team = t.team;
t.liveBullets++;
}

Expand All @@ -50,7 +53,7 @@ public void checkCollision()
{
double prevX = this.posX;
double prevY = this.posY;

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

double horizontalDist = Math.abs(this.posX - o.posX);
Expand All @@ -62,7 +65,7 @@ public void checkCollision()
double s = this.size;
if (useCustomWallCollision)
s = this.wallCollisionSize;

double bound = s / 2 + Obstacle.obstacle_size / 2;

if (horizontalDist < bound && verticalDist < bound)
Expand Down Expand Up @@ -138,29 +141,33 @@ else if (dy >= 0 && dy < bound && horizontalDist < verticalDist)
double verticalDist = Math.abs(this.posY - o.posY);

Tank t = ((Tank) o);

double bound = this.size / 2 + t.size / 2;

if (horizontalDist < bound && verticalDist < bound)
{
t.flashAnimation = 1;
this.destroy = true;
this.vX = 0;
this.vY = 0;
t.lives -= this.damage;

if (t.lives <= 0)
if (!(Team.isAllied(this, t) && !this.team.friendlyFire))
{
t.flashAnimation = 0;
o.destroy = true;
if (o.equals(Game.player))
Game.coins -= 5;
if (this.tank.equals(Game.player))
Game.coins += t.coinValue;
t.flashAnimation = 1;
this.vX = 0;
this.vY = 0;
t.lives -= this.damage;

if (t.lives <= 0)
{
t.flashAnimation = 0;
o.destroy = true;
if (o.equals(Game.player))
Game.coins -= 5;
if (this.tank.equals(Game.player))
Game.coins += t.coinValue;
}
}
}
}
else if ((o instanceof Bullet || o instanceof Mine) && o != this && !o.destroy && !(o instanceof Flame || this instanceof Flame))
else if ((o instanceof Bullet || o instanceof Mine) && o != this && !o.destroy && !(o instanceof BulletFlame || this instanceof BulletFlame))
{
if (!o.destroy)
{
Expand Down Expand Up @@ -195,12 +202,18 @@ else if ((o instanceof Bullet || o instanceof Mine) && o != this && !o.destroy &

if (collided)
{

if (this.bounces <= 0)
{
Window.playSound("resources/bullet_explode.wav");

this.destroy = true;
this.vX = 0;
this.vY = 0;
}
else
Window.playSound("resources/bounce.wav");

this.bounces--;
}
}
Expand All @@ -217,36 +230,54 @@ public void update()
{
if (destroy)
{
if (this.destroyTimer <= 0 && Game.graphicalEffects && !(this instanceof Flame))
if (this.destroyTimer <= 0 && Game.graphicalEffects && !(this instanceof BulletFlame))
{
for (int i = 0; i < this.size * 4; i++)
{
Effect e = new Effect(this.posX, this.posY, Effect.EffectType.piece);
Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece);
int var = 50;
e.maxAge /= 2;
e.col = new Color((int) Math.min(255, Math.max(0, this.color.getRed() + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, this.color.getGreen() + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, this.color.getBlue() + Math.random() * var - var / 2)));
e.col = new Color((int) Math.min(255, Math.max(0, this.baseColor.getRed() + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, this.baseColor.getGreen() + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, this.baseColor.getBlue() + Math.random() * var - var / 2)));
e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 50.0 * 4);
Game.effects.add(e);
}
}

this.destroyTimer += Panel.frameFrequency;
this.vX = 0;
this.vY = 0;
}

else
{
if (Game.graphicalEffects)
{
if (this.effect.equals(BulletEffect.trail) || this.effect.equals(BulletEffect.fire))
Game.effects.add(new Effect(this.posX, this.posY, Effect.EffectType.trail));
if (this.effect.equals(BulletEffect.trail) || this.effect.equals(BulletEffect.fire) || this.effect.equals(BulletEffect.darkFire))
Game.effects.add(Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.trail));

if (this.effect.equals(BulletEffect.fireTrail))
Game.effects.add(new Effect(this.posX, this.posY, Effect.EffectType.smokeTrail));
{
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));
}

if (this.effect.equals(BulletEffect.fire) || this.effect.equals(BulletEffect.fireTrail))
Game.effects.add(new Effect(this.posX, this.posY, Effect.EffectType.fire));
{
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));
}

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));
}
}
}

Expand All @@ -265,8 +296,12 @@ public void update()
public void draw(Graphics p)
{
double opacity = ((60 - destroyTimer) / 60.0);
p.setColor(new Color(this.color.getRed(), this.color.getGreen(), this.color.getBlue(), (int)(opacity * opacity * opacity * 255.0)));
Window.fillOval(p, posX, posY, size + destroyTimer * (size / Bullet.bullet_size), size + destroyTimer * (size / Bullet.bullet_size));
double sizeModifier = destroyTimer * (size / Bullet.bullet_size);
p.setColor(new Color(this.outlineColor.getRed(), this.outlineColor.getGreen(), this.outlineColor.getBlue(), (int)(opacity * opacity * opacity * 255.0)));
Window.fillOval(p, posX, posY, size + sizeModifier, size + sizeModifier);
p.setColor(new Color(this.baseColor.getRed(), this.baseColor.getGreen(), this.baseColor.getBlue(), (int)(opacity * opacity * opacity * 255.0)));
Window.fillOval(p, posX, posY, (size + sizeModifier) * 0.6, (size + sizeModifier) * 0.6);

}

}
6 changes: 3 additions & 3 deletions src/tanks/Flame.java → src/tanks/BulletFlame.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import java.awt.Color;
import java.awt.Graphics;

public class Flame extends Bullet
public class BulletFlame extends Bullet
{
double life = 100;
double age = 0;
double frequency = Panel.frameFrequency;

public Flame(double x, double y, Color color, int bounces, Tank t)
public BulletFlame(double x, double y, int bounces, Tank t)
{
super(x, y, color, bounces, t);
super(x, y, bounces, t);
t.liveBullets--;
this.useCustomWallCollision = true;
}
Expand Down
39 changes: 39 additions & 0 deletions src/tanks/BulletLaser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package tanks;

import java.awt.Color;

public class BulletLaser extends Bullet
{
public BulletLaser(double x, double y, int bounces, Tank t)
{
super(x, y, bounces, t);
t.liveBullets--;
this.baseColor = Color.red;
}

public void shoot()
{
while(!this.destroy)
{
if (ScreenGame.finished)
this.destroy = true;

this.update();
Game.effects.add(Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.laser));
}

if (Game.graphicalEffects)
{
for (int i = 0; i < this.size * 4; i++)
{
Effect e = Effect.createNewEffect(this.posX, this.posY, Effect.EffectType.piece);
int var = 50;
e.maxAge /= 2;
e.col = new Color((int) Math.min(255, Math.max(0, this.baseColor.getRed() + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, this.baseColor.getGreen() + Math.random() * var - var / 2)), (int) Math.min(255, Math.max(0, this.baseColor.getBlue() + Math.random() * var - var / 2)));
e.setPolarMotion(Math.random() * 2 * Math.PI, Math.random() * this.size / 50.0 * 4);
Game.effects.add(e);
}
}
}

}
81 changes: 45 additions & 36 deletions src/tanks/Button.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tanks;

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

public class Button
Expand All @@ -12,77 +11,87 @@ public class Button
public double sizeX;
public double sizeY;
public String text;

public boolean enableHover = false;
public String[] hoverText;

public boolean selected = false;

public boolean clicked = false;

Color unselectedCol = new Color(255, 255, 255);
Color selectedCol = new Color(240, 240, 255);

public Button(double sX, double sY, String text, Runnable f)
public Button(double x, double y, double sX, double sY, String text, Runnable f)
{
this.function = f;


this.posX = x;
this.posY = y;
this.sizeX = sX;
this.sizeY = sY;
this.text = text;
}
public Button(double sX, double sY, String text, Runnable f, String hoverText)

public Button(double x, double y, double sX, double sY, String text, Runnable f, String hoverText)
{
this(sX, sY, text, f);
this(x, y, sX, sY, text, f);
this.enableHover = true;
this.hoverText = hoverText.split("---");
}
public void draw(Graphics g, int x, int y)

public void draw(Graphics g)
{
this.posX = x;
this.posY = y;

g.setFont(g.getFont().deriveFont(Font.BOLD, (float) (24 * Window.scale)));

Window.setInterfaceFontSize(g, 24);

if (selected)
g.setColor(this.selectedCol);
else
g.setColor(this.unselectedCol);
Window.fillRect(g, posX, posY, sizeX, sizeY);

Window.fillInterfaceRect(g, posX, posY, sizeX, sizeY);

g.setColor(Color.black);
Window.drawText(g, posX, posY + 5, text);
if (selected && enableHover)
Window.drawInterfaceText(g, posX, posY + 5, text);

if (enableHover)
{
Window.drawTooltip(g, this.hoverText);
if (selected)
{
g.setColor(Color.blue);
Window.fillInterfaceOval(g, this.posX + this.sizeX / 2 - this.sizeY / 2, this.posY, this.sizeY * 3 / 4, this.sizeY * 3 / 4);
g.setColor(Color.white);
Window.drawInterfaceText(g, this.posX + this.sizeX / 2 - this.sizeY / 2, this.posY + 5, "i");
Window.drawTooltip(g, this.hoverText);
}
else
{
g.setColor(new Color(0, 150, 255));
Window.fillInterfaceOval(g, this.posX + this.sizeX / 2 - this.sizeY / 2, this.posY, this.sizeY * 3 / 4, this.sizeY * 3 / 4);
g.setColor(Color.white);
Window.drawInterfaceText(g, this.posX + this.sizeX / 2 - this.sizeY / 2, this.posY + 5, "i");
}
}
}
public void update(int x, int y)

public void update()
{
this.posX = x;
this.posY = y;
double mx = Game.window.getInterfaceMouseX();
double my = Game.window.getInterfaceMouseY();

double mx = Game.window.getMouseX();
double my = Game.window.getMouseY();

if (mx > posX - sizeX/2 && mx < posX + sizeX/2 && my > posY - sizeY/2 && my < posY + sizeY/2)
selected = true;
else
selected = false;
if (selected && MouseInputListener.lClickValid && !clicked)

if (selected && InputMouse.lClickValid && !clicked)
{
function.run();
clicked = true;
MouseInputListener.lClickValid = false;
InputMouse.lClickValid = false;
}
if (!(selected && MouseInputListener.lClick))

if (!(selected && InputMouse.lClick))
clicked = false;
}
}
Loading

0 comments on commit 01d4b22

Please sign in to comment.