summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/tankontank/game/Hud.java5
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java20
-rw-r--r--core/src/ch/asynk/tankontank/game/hud/Engagement.java115
3 files changed, 94 insertions, 46 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java
index f1e6424..fd63d03 100644
--- a/core/src/ch/asynk/tankontank/game/Hud.java
+++ b/core/src/ch/asynk/tankontank/game/Hud.java
@@ -81,6 +81,7 @@ public class Hud implements Disposable
{
msg.animate(delta);
playerInfo.animate(delta);
+ engagement.animate(delta);
}
public void draw(Batch batch)
@@ -251,9 +252,9 @@ public class Hud implements Disposable
pushDialog(okCancel);
}
- public void engagementSummary(Map.Engagement e)
+ public void engagementSummary(Map.Engagement e, float volume)
{
- engagement.show(e, Position.BOTTOM_CENTER);
+ engagement.show(e, Position.BOTTOM_CENTER, volume);
pushDialog(engagement);
}
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index 3381518..1e4aef3 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -51,6 +51,9 @@ public abstract class Map extends Board
public class Engagement
{
+ public Army attacker;
+ public Army defender;
+ public boolean success;
public int d1;
public int d2;
public int unitCount;
@@ -60,9 +63,8 @@ public abstract class Map extends Board
public int weatherDefense;
public int attack;
public int defense;
- public String msg;
- public void set(int d1, int d2, int cnt, int flk, int def, int tdf, int wdf, String msg)
+ public void set(int d1, int d2, int cnt, int flk, int def, int tdf, int wdf)
{
this.d1 = d1;
this.d2 = d2;
@@ -71,12 +73,10 @@ public abstract class Map extends Board
this.unitDefense = def;
this.terrainDefense = tdf;
this.weatherDefense = wdf;
- this.msg = msg;
this.attack = (d1 + d2 + unitCount + flankBonus);
this.defense = (unitDefense + terrainDefense + weatherDefense);
}
}
-
private Engagement engagement;
public int d6()
@@ -349,10 +349,10 @@ public abstract class Map extends Board
boolean success = false;
if (die == 2) {
- engagement.set(d1, d2, 0, 0, 0, 0, 0, target.toString() + " is destroyed");
+ engagement.set(d1, d2, 0, 0, 0, 0, 0);
success = false;
} else if (die == 12) {
- engagement.set(d1, d2, 0, 0, 0, 0, 0, target.toString() + " resisted the assault");
+ engagement.set(d1, d2, 0, 0, 0, 0, 0);
success = true;
} else {
@@ -389,11 +389,13 @@ public abstract class Map extends Board
int s1 = (die + cnt + flk);
int s2 = (def + tdf + wdf);
success = (s1 >= s2);
-
- engagement.set(d1, d2, cnt, flk, def, tdf, wdf, target.toString() + (success ? " is destroyed" : " resisted the assault"));
+ engagement.set(d1, d2, cnt, flk, def, tdf, wdf);
}
- ctrl.hud.engagementSummary(engagement);
+ engagement.success = success;
+ engagement.attacker = ctrl.player.army;
+ engagement.defender = ctrl.opponent.army;
+ ctrl.hud.engagementSummary(engagement, ctrl.cfg.fxVolume);
return success;
}
diff --git a/core/src/ch/asynk/tankontank/game/hud/Engagement.java b/core/src/ch/asynk/tankontank/game/hud/Engagement.java
index 9a06a42..2f6565b 100644
--- a/core/src/ch/asynk/tankontank/game/hud/Engagement.java
+++ b/core/src/ch/asynk/tankontank/game/hud/Engagement.java
@@ -1,66 +1,98 @@
package ch.asynk.tankontank.game.hud;
import com.badlogic.gdx.graphics.g2d.Batch;
+import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
-import ch.asynk.tankontank.game.Player;
import ch.asynk.tankontank.game.Map;
+import ch.asynk.tankontank.game.Army;
+import ch.asynk.tankontank.engine.gfx.animations.DiceAnimation;
public class Engagement extends Bg
{
+ public static int FLAG_HEIGHT = 24;
public float padding;
+ private Sprite usFlag;
+ private Sprite geFlag;
+ private Sprite winner;
private Label attack;
private Label defense;
- private Label attackV;
- private Label defenseV;
- private Label msg;
+ private Label attackR;
+ private Label defenseR;
private Bg okBtn;
+ private DiceAnimation d1Animation;
+ private DiceAnimation d2Animation;
public Engagement(BitmapFont font, TextureRegion region, TextureAtlas atlas, float padding)
{
super(region);
+ usFlag = new Sprite(atlas.findRegion("us-flag"));
+ geFlag = new Sprite(atlas.findRegion("ge-flag"));
+ winner = new Sprite();
+ usFlag.setSize(usFlag.getWidth() * (FLAG_HEIGHT / usFlag.getHeight()), FLAG_HEIGHT);
+ geFlag.setSize(geFlag.getWidth() * (FLAG_HEIGHT / geFlag.getHeight()), FLAG_HEIGHT);
this.attack = new Label(font);
this.defense = new Label(font);
- this.attackV = new Label(font);
- this.defenseV = new Label(font);
- this.msg = new Label(font);
+ this.attackR = new Label(font);
+ this.defenseR = new Label(font);
this.okBtn = new Bg(atlas.findRegion("ok"));
- this.attack.write("Attack: \n 2D6\n units\n flank");
- this.defense.write("Defense: \n defense\n terrain \n weather");
this.visible = false;
this.padding = padding;
+ this.d1Animation = new DiceAnimation();
+ this.d2Animation = new DiceAnimation();
}
- public void show(Map.Engagement e, Position position)
+ public void show(Map.Engagement e, Position position, float volume)
{
- attackV.write(String.format("%d\n%d + %d\n%d\n%d", e.attack, e.d1, e.d2, e.unitCount, e.flankBonus));
- defenseV.write(String.format("%d\n%d\n%d\n%d", e.defense, e.unitDefense, e.terrainDefense, e.weatherDefense));
- msg.write(e.msg);
+ DiceAnimation.initSound(volume);
+ attack.write(String.format(" + %d + %d", e.unitCount, e.flankBonus));
+ defense.write(String.format("%d + %d + %d = %d", e.unitDefense, e.terrainDefense, e.weatherDefense, e.defense));
+ attackR.write(String.format("= %d", e.attack));
+ defenseR.write(String.format("= %d", e.defense));
+ if (e.success)
+ winner.set((e.attacker == Army.US) ? usFlag : geFlag);
+ else
+ winner.set((e.attacker == Army.US) ? geFlag : usFlag);
- float height = (attack.getHeight() + okBtn.getHeight() + msg.getHeight() + (4 * padding));
- float width = (attack.getWidth() + defense.getWidth() + attackV.getWidth() + defenseV.getWidth() + (5 * padding));
- float w2 = (msg.getWidth() + (2 * padding));
- if (w2 > width) width = w2;
+ float resultW = attackR.getWidth();
+ float w = defenseR.getWidth();
+ if (w > resultW)
+ resultW = w;
+ float height = (okBtn.getHeight() + (2 * usFlag.getHeight()) + (4 * padding));
+ float width = (usFlag.getWidth() + (2 * d1Animation.getWidth()) + attack.getWidth() + resultW + (6 * padding));
float x = position.getX(width);
float y = position.getY(height);
set(x, y, width, height);
- x += padding;
y += padding;
okBtn.setPosition((x + width - okBtn.getWidth() - padding), y);
+ winner.setPosition((getX() + ((okBtn.getX() - getX()) / 2.0f) - (winner.getWidth() / 2.0f)), y);
+ x += padding;
y += (okBtn.getHeight() + padding);
- msg.setPosition(x, y);
- y += msg.getHeight() + padding;
- attack.setPosition(x, y);
- x += attack.getWidth() + padding;
- attackV.setPosition(x, y);
- x += attackV.getWidth() + padding;
+
+ Sprite flag = ((e.defender == Army.US) ? usFlag : geFlag);
+ flag.setPosition(x, y);
+ x += (flag.getWidth() + padding);
+ y = (y + (flag.getHeight() / 2.0f) - (defense.getHeight() / 2.0f));
defense.setPosition(x, y);
- x += defense.getWidth() + padding;
- defenseV.setPosition(x, y);
+ defenseR.setPosition((getX() + width - resultW- padding), y);
+
+ x = getX() + padding;
+ y += flag.getHeight() + padding;
+ flag = ((flag == geFlag) ? usFlag : geFlag);
+ flag.setPosition(x, y);
+ x += (flag.getWidth() + padding);
+ d1Animation.set(e.d1, x, y);
+ x += (d1Animation.getWidth() + padding);
+ d2Animation.set(e.d2, x, (y));
+ x += (d1Animation.getWidth() + padding);
+ y = (y + (flag.getHeight() / 2.0f) - (attack.getHeight() / 2.0f));
+ attack.setPosition(x, y);
+ attackR.setPosition(defenseR.getX(), y);
+
visible = true;
}
@@ -71,15 +103,23 @@ public class Engagement extends Bg
return false;
}
+ public void animate(float delta)
+ {
+ if (!visible) return;
+ d1Animation.animate(delta);
+ d2Animation.animate(delta);
+ }
+
@Override
public void dispose()
{
super.dispose();
attack.dispose();
defense.dispose();
- attackV.dispose();
- defenseV.dispose();
- msg.dispose();
+ attackR.dispose();
+ defenseR.dispose();
+ d1Animation.dispose();
+ d2Animation.dispose();
okBtn.dispose();
}
@@ -90,10 +130,16 @@ public class Engagement extends Bg
super.draw(batch);
attack.draw(batch);
defense.draw(batch);
- attackV.draw(batch);
- defenseV.draw(batch);
- msg.draw(batch);
+ defenseR.draw(batch);
+ geFlag.draw(batch);
+ usFlag.draw(batch);
+ d1Animation.draw(batch);
+ d2Animation.draw(batch);
okBtn.draw(batch);
+ if (d1Animation.isDone() && d2Animation.isDone()) {
+ attackR.draw(batch);
+ winner.draw(batch);
+ }
}
@Override
@@ -103,9 +149,8 @@ public class Engagement extends Bg
super.drawDebug(shapes);
attack.drawDebug(shapes);
defense.drawDebug(shapes);
- attackV.drawDebug(shapes);
- defenseV.drawDebug(shapes);
- msg.drawDebug(shapes);
+ attackR.drawDebug(shapes);
+ defenseR.drawDebug(shapes);
okBtn.drawDebug(shapes);
}
}