Skip to content

Commit

Permalink
(Tanks v0.3.6) Menu system rewrite.
Browse files Browse the repository at this point in the history
  • Loading branch information
aehmttw committed Jul 14, 2018
1 parent d3c99df commit 6c10766
Show file tree
Hide file tree
Showing 26 changed files with 1,256 additions and 929 deletions.
10 changes: 5 additions & 5 deletions src/tanks/Bullet.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ else if (dy >= 0 && dy < bound && horizontalDist < verticalDist)

}

if (this.posX + this.size/2 > Screen.sizeX)
if (this.posX + this.size/2 > Window.sizeX)
{
collided = true;
this.posX = Screen.sizeX - this.size/2 - (this.posX + this.size/2 - Screen.sizeX);
this.posX = Window.sizeX - this.size/2 - (this.posX + this.size/2 - Window.sizeX);
this.vX = -Math.abs(this.vX);
}
if (this.posX - this.size/2 < 0)
Expand All @@ -115,10 +115,10 @@ else if (dy >= 0 && dy < bound && horizontalDist < verticalDist)
this.posX = this.size/2 - (this.posX - this.size / 2);
this.vX = Math.abs(this.vX);
}
if (this.posY + this.size/2 > Screen.sizeY)
if (this.posY + this.size/2 > Window.sizeY)
{
collided = true;
this.posY = Screen.sizeY - this.size/2 - (this.posY + this.size/2 - Screen.sizeY);
this.posY = Window.sizeY - this.size/2 - (this.posY + this.size/2 - Window.sizeY);
this.vY = -Math.abs(this.vY);
}
if (this.posY - this.size/2 < 0)
Expand Down Expand Up @@ -266,7 +266,7 @@ 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)));
Screen.fillOval(p, posX, posY, size + destroyTimer * (size / Bullet.bullet_size), size + destroyTimer * (size / Bullet.bullet_size));
Window.fillOval(p, posX, posY, size + destroyTimer * (size / Bullet.bullet_size), size + destroyTimer * (size / Bullet.bullet_size));
}

}
46 changes: 26 additions & 20 deletions src/tanks/Button.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,37 @@ public Button(double sX, double sY, String text, Runnable f, String hoverText)
this.hoverText = hoverText.split("---");
}

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

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

double mx = Game.gamescreen.getMouseX();
double my = Game.gamescreen.getMouseY();
g.setFont(g.getFont().deriveFont(Font.BOLD, (float) (24 * Window.scale)));

if (selected)
g.setColor(this.selectedCol);
else
g.setColor(this.unselectedCol);

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

g.setColor(Color.black);
Window.drawText(g, posX, posY + 5, text);

if (selected && enableHover)
{
Window.drawTooltip(g, this.hoverText);
}
}

public void update(int x, int y)
{
this.posX = x;
this.posY = y;

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
Expand All @@ -63,20 +84,5 @@ public void drawUpdate(Graphics g, int x, int y)

if (!(selected && MouseInputListener.lClick))
clicked = false;

if (selected)
g.setColor(selectedCol);
else
g.setColor(unselectedCol);

Screen.fillRect(g, posX, posY, sizeX, sizeY);

g.setColor(Color.black);
Screen.drawText(g, posX, posY + 5, text);

if (selected && enableHover)
{
Screen.drawTooltip(g, this.hoverText);
}
}
}
26 changes: 13 additions & 13 deletions src/tanks/Effect.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public Effect(double x, double y, EffectType type)
@Override
public void checkCollision() {}

public void drawWithoutUpdate(Graphics p)
@Override
public void draw(Graphics p)
{
//p.setColor(Color.red);
//Screen.fillRect(p, this.posX, this.posY, 4, 4);
Expand All @@ -53,7 +54,7 @@ public void drawWithoutUpdate(Graphics p)
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);
Window.fillOval(p, this.posX, this.posY, size, size);

}
else if (this.type == EffectType.smokeTrail)
Expand All @@ -74,7 +75,7 @@ else if (this.type == EffectType.smokeTrail)
}

p.setColor(col);
Screen.fillOval(p, this.posX, this.posY, size, size);
Window.fillOval(p, this.posX, this.posY, size, size);
}
else if (this.type == EffectType.trail)
{
Expand All @@ -91,13 +92,13 @@ else if (this.type == EffectType.trail)
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);
Window.fillOval(p, this.posX, this.posY, size, size);
}
else if (this.type == EffectType.ray)
{
int size = 6;
p.setColor(new Color(0, 0, 0, 50));
Screen.fillOval(p, this.posX, this.posY, size, size);
Window.fillOval(p, this.posX, this.posY, size, size);

Game.removeEffects.add(this);
}
Expand All @@ -112,7 +113,7 @@ else if (this.type == EffectType.mineExplosion)
int size = Game.tank_size * 4;
int opacity = (int) (100 - this.age * 5);
p.setColor(new Color(255, 0, 0, opacity));
Screen.fillOval(p, this.posX, this.posY, size, size);
Window.fillOval(p, this.posX, this.posY, size, size);
}
else if (this.type == EffectType.laser)
{
Expand All @@ -126,7 +127,7 @@ else if (this.type == EffectType.laser)
//double size = (int) (255 - this.age * 12);
double size = Bullet.bullet_size - this.age / 2;
p.setColor(new Color(255, 0, 0));
Screen.fillOval(p, this.posX, this.posY, size, size);
Window.fillOval(p, this.posX, this.posY, size, size);
}
else if (this.type == EffectType.piece)
{
Expand All @@ -138,7 +139,7 @@ else if (this.type == EffectType.piece)

int size = 1 + (int) (Bullet.bullet_size * (1 - this.age / this.maxAge));
p.setColor(col);
Screen.fillOval(p, this.posX, this.posY, size, size);
Window.fillOval(p, this.posX, this.posY, size, size);
}
else if (this.type == EffectType.obstaclePiece)
{
Expand All @@ -150,7 +151,7 @@ else if (this.type == EffectType.obstaclePiece)

int size = 1 + (int) (Bullet.bullet_size * (1 - this.age / this.maxAge));
p.setColor(col);
Screen.fillRect(p, this.posX, this.posY, size, size);
Window.fillRect(p, this.posX, this.posY, size, size);
}
else if (this.type == EffectType.charge)
{
Expand All @@ -162,7 +163,7 @@ else if (this.type == EffectType.charge)

int size = 1 + (int) (Bullet.bullet_size * (this.age / this.maxAge));
p.setColor(col);
Screen.fillOval(p, this.posX, this.posY, size, size);
Window.fillOval(p, this.posX, this.posY, size, size);
}
else if (this.type == EffectType.tread)
{
Expand All @@ -183,14 +184,13 @@ else if (this.type == EffectType.tread)

int opacity = (int) (255 - this.age / opacityFactor) / 4;
p.setColor(new Color(0, 0, 0, opacity));
Screen.fillRect(p, this.posX, this.posY, size * Obstacle.draw_size / Obstacle.obstacle_size, size * Obstacle.draw_size / Obstacle.obstacle_size);
Window.fillRect(p, this.posX, this.posY, size * Obstacle.draw_size / Obstacle.obstacle_size, size * Obstacle.draw_size / Obstacle.obstacle_size);
}
}

@Override
public void draw(Graphics p)
public void update()
{
this.drawWithoutUpdate(p);
this.posX += this.vX * Panel.frameFrequency;
this.posY += this.vY * Panel.frameFrequency;
this.age += Panel.frameFrequency;
Expand Down
2 changes: 1 addition & 1 deletion src/tanks/EnemyTankWhite.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void draw(Graphics g)
for (int i = 0; i < Game.tank_size * 2 - this.age; i++)
{
g.setColor(new Color(255, 255, 255, (int)((Game.tank_size * 2 - i - this.age) * 2.55)));
Screen.fillOval(g, this.posX, this.posY, i, i);
Window.fillOval(g, this.posX, this.posY, i, i);
}

if (this.drawTread)
Expand Down
6 changes: 3 additions & 3 deletions src/tanks/Firework.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void drawUpdate(Graphics g)
this.vY += 0.0625 * Panel.frameFrequency;

g.setColor(this.color);
Screen.fillOval(g, posX, posY, this.size, this.size);
Window.fillOval(g, posX, posY, this.size, this.size);

Firework f = new Firework(FireworkType.trail, this.posX, this.posY, this.list, this.removeList);
f.maxAge = 30;
Expand Down Expand Up @@ -115,7 +115,7 @@ public void drawUpdate(Graphics g)
else if (type == FireworkType.trail)
{
g.setColor(new Color(this.color.getRed(), this.color.getGreen(), this.color.getBlue(), Math.max(0, Math.min(255, 255 - (int) (this.age * 255.0 / this.maxAge)))));
Screen.fillOval(g, posX, posY, this.size, this.size);
Window.fillOval(g, posX, posY, this.size, this.size);

if (this.age >= this.maxAge)
{
Expand All @@ -128,7 +128,7 @@ else if (type == FireworkType.particle)

int opacity = Math.min(255, Math.max(0, (int) (255 - this.age * 255.0 / this.maxAge)));
g.setColor(new Color(this.color.getRed(), this.color.getGreen(), this.color.getBlue(), opacity));
Screen.fillOval(g, posX, posY, this.size, this.size);
Window.fillOval(g, posX, posY, this.size, this.size);

/*Firework f = new Firework(FireworkType.trail, this.posX, this.posY, this.list, this.removeList);
f.maxAge = opacity / 50;
Expand Down
2 changes: 1 addition & 1 deletion src/tanks/Flame.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void draw(Graphics g)
Color col = new Color(255, green, 0, opacity);

g.setColor(col);
Screen.fillOval(g, this.posX, this.posY, size, size);
Window.fillOval(g, this.posX, this.posY, size, size);
}

}
Loading

0 comments on commit 6c10766

Please sign in to comment.