summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/game/Factory.java4
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java36
-rw-r--r--core/src/ch/asynk/tankontank/game/MapA.java5
-rw-r--r--core/src/ch/asynk/tankontank/game/MapB.java5
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateAttack.java6
5 files changed, 42 insertions, 14 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Factory.java b/core/src/ch/asynk/tankontank/game/Factory.java
index 5c70563..66c19c9 100644
--- a/core/src/ch/asynk/tankontank/game/Factory.java
+++ b/core/src/ch/asynk/tankontank/game/Factory.java
@@ -120,10 +120,10 @@ public class Factory implements Board.TileBuilder, Disposable
Map m = null;
switch(t) {
case MAP_A:
- m = new MapA(ctrl, this, config(), manager.get("data/map_a.png", Texture.class));
+ m = new MapA(ctrl, this, config(), manager, "data/map_a.png");
break;
case MAP_B:
- m = new MapB(ctrl, this, config(), manager.get("data/map_b.png", Texture.class));
+ m = new MapB(ctrl, this, config(), manager, "data/map_b.png");
break;
}
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index e36b143..4df7077 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
+import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Vector2;
@@ -14,6 +15,8 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import ch.asynk.tankontank.engine.Pawn;
import ch.asynk.tankontank.engine.Board;
import ch.asynk.tankontank.engine.Orientation;
+import ch.asynk.tankontank.engine.gfx.animations.AnimationSequence;
+import ch.asynk.tankontank.engine.gfx.animations.SpriteAnimation;
import ch.asynk.tankontank.engine.gfx.animations.RunnableAnimation;
public abstract class Map extends Board
@@ -30,12 +33,17 @@ public abstract class Map extends Board
private final ArrayList<Pawn> activablePawns = new ArrayList<Pawn>(7);
private final ArrayList<Pawn> activatedPawns = new ArrayList<Pawn>(7);
+ private final SpriteAnimation explosion;
+ private final SpriteAnimation explosions;
+
protected abstract void setup();
- public Map(Ctrl ctrl, Factory factory, Board.Config cfg, Texture texture)
+ public Map(Ctrl ctrl, Factory factory, Board.Config cfg, AssetManager manager, String textureName)
{
- super(factory, cfg, texture);
+ super(factory, cfg, manager.get(textureName, Texture.class));
this.ctrl = ctrl;
+ this.explosion = new SpriteAnimation(manager.get("data/explosion.png", Texture.class), 10, 4, 40);
+ this.explosions = new SpriteAnimation(manager.get("data/explosions.png", Texture.class), 16, 8, 15);
setup();
}
@@ -275,13 +283,13 @@ public abstract class Map extends Board
clearPointVector(possibleTargets);
}
- public boolean attackPawn(Pawn pawn, Pawn target, GridPoint2 from, GridPoint2 to, int dice)
+ public boolean attackPawn(Pawn pawn, final Pawn target, GridPoint2 from, GridPoint2 to, int dice)
{
Hex hex = getHex(to.x, to.y);
int activatedUnits = activatedPawns.size();
- boolean success;
+ final boolean success;
if (dice == 2) {
success = false;
} else if (dice == 12) {
@@ -304,6 +312,26 @@ public abstract class Map extends Board
activablePawns.clear();
activatedPawns.clear();
+ AnimationSequence seq = AnimationSequence.get(2);
+ if (success) {
+ explosions.init(1, target.getCenter().x, target.getCenter().y);
+ seq.addAnimation(explosions);
+ } else {
+ explosion.init(1, target.getCenter().x, target.getCenter().y);
+ seq.addAnimation(explosion);
+ }
+ seq.addAnimation(RunnableAnimation.get(pawn, new Runnable() {
+ @Override
+ public void run() {
+ if (success) {
+ removePawn(target);
+ }
+ ctrl.animationDone();
+ }
+ }));
+
+ addAnimation(seq);
+
return success;
}
diff --git a/core/src/ch/asynk/tankontank/game/MapA.java b/core/src/ch/asynk/tankontank/game/MapA.java
index ea3c964..3600079 100644
--- a/core/src/ch/asynk/tankontank/game/MapA.java
+++ b/core/src/ch/asynk/tankontank/game/MapA.java
@@ -1,5 +1,6 @@
package ch.asynk.tankontank.game;
+import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
@@ -8,9 +9,9 @@ import ch.asynk.tankontank.engine.Orientation;
public class MapA extends Map
{
- public MapA(Ctrl ctrl, Factory factory, Board.Config cfg, Texture texture)
+ public MapA(Ctrl ctrl, Factory factory, Board.Config cfg, AssetManager manager, String textureName)
{
- super(ctrl, factory, cfg, texture);
+ super(ctrl, factory, cfg, manager, textureName);
}
@Override
diff --git a/core/src/ch/asynk/tankontank/game/MapB.java b/core/src/ch/asynk/tankontank/game/MapB.java
index 34f8fe9..073f653 100644
--- a/core/src/ch/asynk/tankontank/game/MapB.java
+++ b/core/src/ch/asynk/tankontank/game/MapB.java
@@ -1,5 +1,6 @@
package ch.asynk.tankontank.game;
+import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
@@ -8,9 +9,9 @@ import ch.asynk.tankontank.engine.Orientation;
public class MapB extends Map
{
- public MapB(Ctrl ctrl, Factory factory, Board.Config cfg, Texture texture)
+ public MapB(Ctrl ctrl, Factory factory, Board.Config cfg, AssetManager manager, String textureName)
{
- super(ctrl, factory, cfg, texture);
+ super(ctrl, factory, cfg, manager, textureName);
}
@Override
diff --git a/core/src/ch/asynk/tankontank/game/states/StateAttack.java b/core/src/ch/asynk/tankontank/game/states/StateAttack.java
index 9005def..d68afe0 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateAttack.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateAttack.java
@@ -82,11 +82,9 @@ public class StateAttack extends StateCommon
int d1 = ctrl.currentPlayer().d6();
int d2 = ctrl.currentPlayer().d6();
System.err.print(" attack (" + from.x + ";" + from.y + ") -> (" + to.x + ";" + to.y + ") : 2D6 -> (" + d1 + " + " + d2 + ")");
- if (map.attackPawn(selectedPawn, activePawn, from, to, d1 + d2)) {
- map.removePawnFrom(activePawn, to);
+ if (map.attackPawn(selectedPawn, activePawn, from, to, d1 + d2))
ctrl.currentPlayer().casualty(activePawn);
- // TODO free move for infantry
- }
+ ctrl.setState(StateType.ANIMATION);
super.done();
}