Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add drag & drop to choose soldier

  • Loading branch information...
commit ece560fb191bf9633acad5e05f12ef28c2064d02 1 parent 4e92e8e
@atapie authored
View
BIN  flashpunk/assets/battle_icon_boss_strength.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  flashpunk/assets/battle_icon_knightlance.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  flashpunk/assets/battle_icon_knightrobo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  flashpunk/assets/robo_knight.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  flashpunk/bin/flashpunk.swf
Binary file not shown
View
4 flashpunk/flashpunk.as3proj
@@ -65,6 +65,10 @@
<library>
<asset path="assets\avatar.jpg" />
<asset path="assets\dragon_knight.png" />
+ <asset path="assets\robo_knight.png" />
+ <asset path="assets\battle_icon_boss_strength.png" />
+ <asset path="assets\battle_icon_knightlance.png" />
+ <asset path="assets\battle_icon_knightrobo.png" />
</library>
<!-- Class files to compile (other referenced classes will automatically be included) -->
<compileTargets>
View
2  flashpunk/obj/flashpunkConfig.old
@@ -14,7 +14,7 @@
</define>
<define append="true">
<name>CONFIG::timeStamp</name>
- <value>'4/14/2012'</value>
+ <value>'4/21/2012'</value>
</define>
<source-path append="true">
<path-element>C:\Moving\Repositories\warone\flashpunk\src</path-element>
View
2  flashpunk/obj/flashpunkConfig.xml
@@ -14,7 +14,7 @@
</define>
<define append="true">
<name>CONFIG::timeStamp</name>
- <value>'4/14/2012'</value>
+ <value>'4/21/2012'</value>
</define>
<source-path append="true">
<path-element>C:\Moving\Repositories\warone\flashpunk\src</path-element>
View
70 flashpunk/src/common/Config.as
@@ -0,0 +1,70 @@
+package common
+{
+ import common.config.SoldierConfig;
+ import logic.soldier.BaseSoldier;
+ import logic.soldier.KnightRobo;
+ /**
+ * ...
+ * @author ...
+ */
+ public class Config
+ {
+ private static var _instance:Config;
+
+ private var soldierConfig:Array;
+
+ public function Config()
+ {
+ soldierConfig = new Array();
+
+ var knightRoboConfig:SoldierConfig = new SoldierConfig();
+ knightRoboConfig.id = BaseSoldier.SOLDIER_KNIGHT_ROBO_ID;
+ knightRoboConfig.sizeWidth = 1;
+ knightRoboConfig.sizeHeight = 1;
+ knightRoboConfig.baseHealth = 100;
+ knightRoboConfig.damage = 25;
+ knightRoboConfig.moveSpeed = 1; // px per frame
+ knightRoboConfig.attackSpeed = 25; // frame per hit
+ knightRoboConfig.attackRange = 0; // attack range in pixels
+ knightRoboConfig.rowAttack = 1;
+ soldierConfig[knightRoboConfig.id] = knightRoboConfig;
+
+ var knightLanceConfig:SoldierConfig = new SoldierConfig();
+ knightLanceConfig.id = BaseSoldier.SOLDIER_KNIGHT_LANCE_ID;
+ knightLanceConfig.sizeWidth = 2;
+ knightLanceConfig.sizeHeight = 1;
+ knightLanceConfig.baseHealth = 200;
+ knightLanceConfig.damage = 40;
+ knightLanceConfig.moveSpeed = 1; // px per frame
+ knightLanceConfig.attackSpeed = 25; // frame per hit
+ knightLanceConfig.attackRange = 0; // attack range in pixels
+ knightLanceConfig.rowAttack = 2; // number of unit can attack in a row
+ soldierConfig[knightLanceConfig.id] = knightLanceConfig;
+
+ var bossStrengthConfig:SoldierConfig = new SoldierConfig();
+ bossStrengthConfig.id = BaseSoldier.SOLDIER_BOSS_STRENGTH_ID;
+ bossStrengthConfig.sizeWidth = 2;
+ bossStrengthConfig.sizeHeight = 2;
+ bossStrengthConfig.baseHealth = 1000;
+ bossStrengthConfig.damage = 20;
+ bossStrengthConfig.moveSpeed = 1; // px per frame
+ bossStrengthConfig.attackSpeed = 25; // frame per hit
+ bossStrengthConfig.attackRange = 0; // attack range in pixels
+ bossStrengthConfig.rowAttack = 1; // number of unit can attack in a row
+ soldierConfig[bossStrengthConfig.id] = bossStrengthConfig;
+ }
+
+ public static function instance():Config
+ {
+ if (_instance == null) _instance = new Config();
+ return _instance;
+ }
+
+ public function getConfig(soldierId:int):SoldierConfig
+ {
+ return soldierConfig[soldierId] as SoldierConfig;
+ }
+
+ }
+
+}
View
7 flashpunk/src/common/Constants.as
@@ -7,9 +7,10 @@ package common
public class Constants
{
public static const LAYER_GUI:int = 0;
- public static const LAYER_GAME:int = 1;
- public static const LAYER_BG2:int = 2;
- public static const LAYER_BG1:int = 3;
+ public static const LAYER_MOUSE:int = 100;
+ public static const LAYER_GAME:int = 200;
+ public static const LAYER_BG2:int = 300;
+ public static const LAYER_BG1:int = 400;
public static const TEAM_1:int = 1;
public static const TEAM_2:int = -1;
View
31 flashpunk/src/common/Utils.as
@@ -1,6 +1,7 @@
package common
{
import flash.display.BitmapData;
+ import flash.geom.Point;
import net.flashpunk.FP;
/**
* ...
@@ -8,6 +9,9 @@ package common
*/
public class Utils
{
+ public static const CELL_START_POINT:Point = new Point(60, 230);
+ public static const BASE_ZONE_DISTANCE:int = 50;
+
public static function getFlippedBitmap(source:BitmapData):BitmapData
{
var flip:BitmapData = new BitmapData(source.width, source.height, true, 0);
@@ -20,7 +24,32 @@ package common
public static function getCellFrom(row:int, col:int):int
{
- return row * Constants.CELL_COLUMN + col;
+ if (row < 0 || row >= Constants.CELL_ROW || col < 0 || col >= Constants.CELL_COLUMN) return -1;
+ else return row * Constants.CELL_COLUMN + col;
+ }
+
+ public static function getCellFromPos(x:Number, y:Number):int
+ {
+ var col:int = Math.floor((x - CELL_START_POINT.x) / Constants.CELL_SIZE);
+ var row:int = Math.floor((y - CELL_START_POINT.y) / Constants.CELL_SIZE);
+
+ if (col >= Constants.CELL_COLUMN / 2)
+ {
+ var newCol:int = Math.floor((x - CELL_START_POINT.x - BASE_ZONE_DISTANCE) / Constants.CELL_SIZE);
+ if (newCol >= Constants.CELL_COLUMN / 2) col = newCol;
+ else col = -1;
+ }
+
+ return getCellFrom(row, col);
+ }
+
+ public static function getPosFrom(row:int, col:int):Point
+ {
+ var result:Point = new Point();
+ result.x = CELL_START_POINT.x + col * Constants.CELL_SIZE + Constants.CELL_SIZE / 2;
+ if (col >= Constants.CELL_COLUMN / 2) result.x += BASE_ZONE_DISTANCE;
+ result.y = CELL_START_POINT.y + row * Constants.CELL_SIZE;
+ return result;
}
}
View
26 flashpunk/src/common/config/SoldierConfig.as
@@ -0,0 +1,26 @@
+package common.config
+{
+ /**
+ * ...
+ * @author ...
+ */
+ public class SoldierConfig
+ {
+ public var id:int;
+ public var sizeWidth:int;
+ public var sizeHeight:int;
+ public var baseHealth:int;
+ public var damage:int;
+ public var moveSpeed:int;
+ public var attackSpeed:int;
+ public var attackRange:int;
+ public var rowAttack:int;
+
+ public function SoldierConfig()
+ {
+
+ }
+
+ }
+
+}
View
18 flashpunk/src/logic/BattleLogic.as
@@ -12,8 +12,10 @@ package logic
public class BattleLogic
{
private static var _instance:BattleLogic;
- public static const BATTLE_STATE_STOPPED:int = 0;
- public static const BATTLE_STATE_STARTED:int = 1;
+ public static const BATTLE_STATE_NORMAL:int = 0;
+ public static const BATTLE_STATE_CHOOSE_SOLDIER:int = 1;
+ public static const BATTLE_STATE_STARTED:int = 2;
+ public static const BATTLE_STATE_STOPPED:int = 3;
public var state:int;
public var time:int; // by frames
@@ -24,7 +26,7 @@ package logic
private function init():void
{
- state = BATTLE_STATE_STOPPED;
+ state = BATTLE_STATE_NORMAL;
}
public static function instance():BattleLogic
@@ -41,7 +43,7 @@ package logic
{
switch(state)
{
- case BATTLE_STATE_STOPPED:
+ case BATTLE_STATE_NORMAL:
if (Input.released(Key.ENTER))
{
reset();
@@ -79,8 +81,8 @@ package logic
var soldier:BaseSoldier = troops[Utils.getCellFrom(r, c)];
if (soldier != null)
{
- if (soldier.row <= row && row < soldier.row + soldier.sizeHeight &&
- soldier.column <= col && col < soldier.column + soldier.sizeWidth)
+ if (soldier.row <= row && row < soldier.row + soldier.config.sizeHeight &&
+ soldier.column <= col && col < soldier.column + soldier.config.sizeWidth)
return false;
}
}
@@ -90,9 +92,9 @@ package logic
public function addTroop(troop:BaseSoldier):Boolean
{
- for (var c:int = troop.column; c < troop.column + troop.sizeWidth; c++)
+ for (var c:int = troop.column; c < troop.column + troop.config.sizeWidth; c++)
{
- for (var r:int = troop.row; r < troop.row + troop.sizeHeight; r++)
+ for (var r:int = troop.row; r < troop.row + troop.config.sizeHeight; r++)
{
if (!cellAvailable(troop.team, r, c)) return false;
}
View
93 flashpunk/src/logic/soldier/BaseSoldier.as
@@ -1,12 +1,15 @@
package logic.soldier
{
+ import common.config.SoldierConfig;
import common.Constants;
import common.FloatingText;
import common.Utils;
+ import flash.display.Bitmap;
import flash.geom.Point;
import logic.BattleLogic;
import net.flashpunk.Entity;
import net.flashpunk.FP;
+ import net.flashpunk.graphics.Image;
import net.flashpunk.graphics.Spritemap;
import scene.BattleScene;
/**
@@ -15,7 +18,10 @@ package logic.soldier
*/
public class BaseSoldier extends Entity
{
- public static const START_POINT:Point = new Point(60, 230);
+ public static const SOLDIER_KNIGHT_ROBO_ID:int = 0;
+ public static const SOLDIER_KNIGHT_LANCE_ID:int = 1;
+ public static const SOLDIER_BOSS_STRENGTH_ID:int = 2;
+
public static const ANIM_STAND:String = "stand";
public static const ANIM_WALK:String = "walk";
public static const ANIM_ATTACK:String = "attack";
@@ -30,17 +36,15 @@ package logic.soldier
public var row:int;
public var column:int;
- public var sizeWidth:int;
- public var sizeHeight:int;
+ public var config:SoldierConfig;
public var health:int;
- public var damage:int;
- public var moveSpeed:int;
- public var attackSpeed:int;
- public var attackRange:int;
- public var rowAttack:int;
private var lastAttack:int;
+ // View related
+ protected var offsetX:int;
+ protected var offsetY:int;
+
public function BaseSoldier(team:int, cell:int, startAnim:String)
{
this.layer = Constants.LAYER_GAME;
@@ -51,22 +55,16 @@ package logic.soldier
this.column = cell % Constants.CELL_COLUMN;
(graphic as Spritemap).play(startAnim);
- var pos:Point = getPosFromCell();
+ var pos:Point = Utils.getPosFrom(row, column);
this.x = pos.x;
this.y = pos.y;
- if (column >= Constants.CELL_COLUMN / 2) graphic.x -= ((graphic as Spritemap).scaledWidth - Constants.CELL_SIZE / 2);
+ if (team == Constants.TEAM_2) graphic.x -= ((graphic as Spritemap).scaledWidth - Constants.CELL_SIZE / 2);
else graphic.x -= Constants.CELL_SIZE / 2;
graphic.y -= ((graphic as Spritemap).scaledHeight - Constants.CELL_SIZE);
- }
-
- public function getPosFromCell():Point
- {
- var result:Point = new Point();
- result.x = START_POINT.x + column * Constants.CELL_SIZE + Constants.CELL_SIZE / 2;
- if (column >= Constants.CELL_COLUMN / 2) result.x += 50;
- result.y = START_POINT.y + row * Constants.CELL_SIZE;
- return result;
+ graphic.x += offsetX;
+ graphic.y += offsetY;
+ layer = Constants.LAYER_GAME - cell;
}
override public function update():void
@@ -90,12 +88,12 @@ package logic.soldier
private function move():void
{
- if (BattleLogic.instance().time - lastAttack >= attackSpeed)
+ if (BattleLogic.instance().time - lastAttack >= config.attackSpeed)
{
if (canMove())
{
- if (team == Constants.TEAM_1) x += moveSpeed;
- else x -= moveSpeed;
+ if (team == Constants.TEAM_1) x += config.moveSpeed;
+ else x -= config.moveSpeed;
(graphic as Spritemap).play(ANIM_WALK);
}
else
@@ -107,7 +105,7 @@ package logic.soldier
private function canMove():Boolean
{
- if (BattleLogic.instance().time - lastAttack >= attackSpeed)
+ if (BattleLogic.instance().time - lastAttack >= config.attackSpeed)
{
var startCol:int = column + 1;
var endCol:int = Constants.CELL_COLUMN / 2 - 1;
@@ -120,14 +118,15 @@ package logic.soldier
}
for (var c:int = startCol; c * direction <= endCol * direction; c += direction)
{
- for (var r:int = row; r < row + sizeHeight; r++)
+ for (var r:int = row - Constants.MAX_SOLDIER_SIZE + 1; r <= row; r++)
{
+ if (r < 0) continue;
var comrade:BaseSoldier = BattleLogic.instance().getTroop(Utils.getCellFrom(r, c));
- if (comrade == null) continue;
+ if (comrade == null || (comrade.row + comrade.config.sizeHeight - 1) < row) continue;
var minDistance:Number;
- if (team == Constants.TEAM_1) minDistance = Constants.CELL_SIZE * sizeWidth;
- else minDistance = Constants.CELL_SIZE * comrade.sizeWidth;
- if (Math.abs(comrade.x - x) < moveSpeed + minDistance)
+ if (team == Constants.TEAM_1) minDistance = Constants.CELL_SIZE * config.sizeWidth;
+ else minDistance = Constants.CELL_SIZE * comrade.config.sizeWidth;
+ if (Math.abs(comrade.x - x) < config.moveSpeed + minDistance)
{
return false;
}
@@ -139,7 +138,7 @@ package logic.soldier
private function attack(enemies:Array):void
{
- if (BattleLogic.instance().time - lastAttack >= attackSpeed)
+ if (BattleLogic.instance().time - lastAttack >= config.attackSpeed)
{
// View
(graphic as Spritemap).play(ANIM_ATTACK, true);
@@ -152,8 +151,8 @@ package logic.soldier
for (var i:int = 0; i < enemies.length; i++)
{
var enemy:BaseSoldier = enemies[i] as BaseSoldier;
- (world.create(FloatingText) as FloatingText).reset(enemy.x, enemy.y, ( -damage).toString(), 10, 0xFF0000);
- enemy.health -= damage;
+ (world.create(FloatingText) as FloatingText).reset(enemy.x, enemy.y, ( -config.damage).toString(), 10, 0xFF0000);
+ enemy.health -= config.damage;
if (enemy.health <= 0)
{
enemy.state = STATE_DEAD;
@@ -162,7 +161,7 @@ package logic.soldier
}
else
{
- BattleLogic.instance().castleHealth[ -team] -= damage;
+ BattleLogic.instance().castleHealth[ -team] -= config.damage;
(world as BattleScene).updateHpInfo( -team, (BattleLogic.instance().castleHealth[ -team] * 100 / BattleLogic.instance().castleHealthOrigin[ -team]));
if (BattleLogic.instance().castleHealth[ -team] <= 0)
@@ -193,23 +192,22 @@ package logic.soldier
var lastTargetX:Number = -1;
for (var c:int = startCol; c*direction <= endCol*direction; c+=direction)
{
- for (var r:int = row; r < row + sizeHeight; r++)
+ for (var r:int = row - Constants.MAX_SOLDIER_SIZE + 1; r < row + config.sizeHeight; r++)
{
+ if (r < 0) continue;
var enemy:BaseSoldier = BattleLogic.instance().getTroop(Utils.getCellFrom(r, c));
- if (enemy != null)
+ if (enemy == null || (enemy.row + enemy.config.sizeHeight - 1) < row) continue;
+ var distance:Number;
+ if (team == Constants.TEAM_1) distance = Math.abs(enemy.x - x) - Constants.CELL_SIZE * config.sizeWidth;
+ else distance = Math.abs(enemy.x - x) - Constants.CELL_SIZE * enemy.config.sizeWidth;
+ if (distance <= config.attackRange || (lastTargetX >= 0 && Math.abs(enemy.x - lastTargetX) <= Constants.CELL_SIZE))
{
- var distance:Number;
- if (team == Constants.TEAM_1) distance = Math.abs(enemy.x - x) - Constants.CELL_SIZE * sizeWidth;
- else distance = Math.abs(enemy.x - x) - Constants.CELL_SIZE * enemy.sizeWidth;
- if (distance <= attackRange || (lastTargetX >= 0 && Math.abs(enemy.x - lastTargetX) <= Constants.CELL_SIZE))
+ if (targetRow == -1 || r == targetRow)
{
- if (targetRow == -1 || r == targetRow)
- {
- targetRow = r;
- lastTargetX = enemy.x;
- result.push(enemy);5
- if (result.length == rowAttack) return result;
- }
+ targetRow = r;
+ lastTargetX = enemy.x;
+ result.push(enemy);5
+ if (result.length == config.rowAttack) return result;
}
}
}
@@ -219,8 +217,8 @@ package logic.soldier
if (result.length == 0)
{
if (
- (team == Constants.TEAM_1 && (x + attackRange + Constants.CELL_SIZE * sizeWidth - Constants.CELL_SIZE / 2) >= (FP.width - 60)) ||
- (team == Constants.TEAM_2 && (x - attackRange - Constants.CELL_SIZE / 2) <= 60)
+ (team == Constants.TEAM_1 && (x + config.attackRange + Constants.CELL_SIZE * config.sizeWidth - Constants.CELL_SIZE / 2) >= (FP.width - 60)) ||
+ (team == Constants.TEAM_2 && (x - config.attackRange - Constants.CELL_SIZE / 2) <= 60)
)
{
return result;
@@ -230,5 +228,4 @@ package logic.soldier
else return result;
}
}
-
}
View
41 flashpunk/src/logic/soldier/BossStrength.as
@@ -0,0 +1,41 @@
+package logic.soldier
+{
+ import common.Config;
+ import common.Constants;
+ import common.Utils;
+ import flash.display.BitmapData;
+ import flash.geom.Rectangle;
+ import net.flashpunk.FP;
+ import net.flashpunk.graphics.Image;
+ import net.flashpunk.graphics.Spritemap;
+ /**
+ * ...
+ * @author ...
+ */
+ public class BossStrength extends BaseSoldier
+ {
+ [Embed(source = "../../../assets/dragon_knight.png")] private static const BOSS_STRENGTH_SRC:Class;
+ private static const BOSS_STRENGTH_IMG:BitmapData = FP.getBitmap(BOSS_STRENGTH_SRC);
+ private static const BOSS_STRENGTH_IMG_FLIPPED:BitmapData = Utils.getFlippedBitmap(BOSS_STRENGTH_IMG);
+ public static const DISPLAY_IMG:Image = new Image(BOSS_STRENGTH_IMG, new Rectangle(0, 0, 64, 64));
+
+ public function BossStrength(team:int, cell:int, startAnim:String)
+ {
+ // Init sprite map
+ var sprBossStrength:Spritemap = new Spritemap(BOSS_STRENGTH_IMG, 64, 64);
+ sprBossStrength.add(ANIM_STAND, [4], 1, false);
+ sprBossStrength.add(ANIM_WALK, [0,1,2,3], 0.4, true);
+ sprBossStrength.add(ANIM_ATTACK, [4,5,6,7], 0.6, false);
+ if (team == Constants.TEAM_2) sprBossStrength.setFlipped(true, BOSS_STRENGTH_IMG_FLIPPED);
+ graphic = sprBossStrength;
+
+ // Init base info
+ config = Config.instance().getConfig(BaseSoldier.SOLDIER_BOSS_STRENGTH_ID);
+ health = config.baseHealth;
+
+ super(team, cell, startAnim);
+ }
+
+ }
+
+}
View
14 flashpunk/src/logic/soldier/KnightLance.as
@@ -1,9 +1,12 @@
package logic.soldier
{
+ import common.Config;
import common.Constants;
import common.Utils;
import flash.display.BitmapData;
+ import flash.geom.Rectangle;
import net.flashpunk.FP;
+ import net.flashpunk.graphics.Image;
import net.flashpunk.graphics.Spritemap;
/**
* ...
@@ -14,6 +17,7 @@ package logic.soldier
[Embed(source = "../../../assets/dragon_knight.png")] private static const KNIGHT_LANCE_SRC:Class;
private static const KNIGHT_LANCE_IMG:BitmapData = FP.getBitmap(KNIGHT_LANCE_SRC);
private static const KNIGHT_LANCE_IMG_FLIPPED:BitmapData = Utils.getFlippedBitmap(KNIGHT_LANCE_IMG);
+ public static const DISPLAY_IMG:Image = new Image(KNIGHT_LANCE_IMG, new Rectangle(0, 0, 64, 64));
public function KnightLance(team:int, cell:int, startAnim:String)
{
@@ -26,14 +30,8 @@ package logic.soldier
graphic = sprKnightLance;
// Init base info
- sizeWidth = 2;
- sizeHeight = 1;
- health = 200;
- damage = 40;
- moveSpeed = 1; // px per frame
- attackSpeed = 25; // frame per hit
- attackRange = 0; // attack range in pixels
- rowAttack = 2; // number of unit can attack in a row
+ config = Config.instance().getConfig(BaseSoldier.SOLDIER_KNIGHT_LANCE_ID);
+ health = config.baseHealth;
super(team, cell, startAnim);
}
View
33 flashpunk/src/logic/soldier/KnightRobo.as
@@ -1,10 +1,13 @@
package logic.soldier
{
+ import common.Config;
import common.Constants;
import common.Utils;
+ import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.geom.Point;
+ import flash.geom.Rectangle;
import logic.BattleLogic;
import net.flashpunk.FP;
import net.flashpunk.graphics.Image;
@@ -12,35 +15,33 @@ package logic.soldier
/**
* ...
* @author
- */
+ */
public class KnightRobo extends BaseSoldier
{
- [Embed(source = "../../../assets/dragon_knight.png")] private static const KNIGHT_ROBO_SRC:Class;
+ [Embed(source = "../../../assets/robo_knight.png")] private static const KNIGHT_ROBO_SRC:Class;
private static const KNIGHT_ROBO_IMG:BitmapData = FP.getBitmap(KNIGHT_ROBO_SRC);
private static const KNIGHT_ROBO_IMG_FLIPPED:BitmapData = Utils.getFlippedBitmap(KNIGHT_ROBO_IMG);
+ public static const DISPLAY_IMG:Image = new Image(KNIGHT_ROBO_IMG_FLIPPED, new Rectangle(KNIGHT_ROBO_IMG_FLIPPED.width - 72, 0, 72, 68));
public function KnightRobo(team:int, cell:int, startAnim:String)
{
// Init sprite map
- var sprKnightRobo:Spritemap = new Spritemap(KNIGHT_ROBO_IMG, 64, 64);
- sprKnightRobo.add(ANIM_STAND, [4], 1, false);
- sprKnightRobo.add(ANIM_WALK, [0,1,2,3], 0.4, true);
- sprKnightRobo.add(ANIM_ATTACK, [4,5,6,7], 0.6, false);
- if (team == Constants.TEAM_2) sprKnightRobo.setFlipped(true, KNIGHT_ROBO_IMG_FLIPPED);
+ var sprKnightRobo:Spritemap = new Spritemap(KNIGHT_ROBO_IMG, 72, 68);
+ sprKnightRobo.add(ANIM_STAND, [0, 1], 0.11, true);
+ sprKnightRobo.add(ANIM_WALK, [11, 12], 0.2, true);
+ sprKnightRobo.add(ANIM_ATTACK, [33, 34, 35, 36, 37, 38], 0.4, false);
+ //sprKnightRobo.add(ANIM_ATTACK, [22,23,24,25,26,27,28,29,30,31,32], 0.4, false);
+ if (team == Constants.TEAM_1) sprKnightRobo.setFlipped(true, KNIGHT_ROBO_IMG_FLIPPED);
graphic = sprKnightRobo;
+ offsetX = -25 * team;
+ offsetY = + 3;
+
// Init base info
- sizeWidth = 1;
- sizeHeight = 1;
- health = 100;
- damage = 25;
- moveSpeed = 1; // px per frame
- attackSpeed = 25; // 10 frame per hit
- attackRange = 0; // attack range in pixels
- rowAttack = 1;
+ config = Config.instance().getConfig(BaseSoldier.SOLDIER_KNIGHT_ROBO_ID);
+ health = config.baseHealth;
super(team, cell, startAnim);
}
}
-
}
View
210 flashpunk/src/scene/BattleScene.as
@@ -1,12 +1,18 @@
package scene
{
+ import common.Config;
+ import common.config.SoldierConfig;
import common.Constants;
+ import common.Utils;
+ import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
import flash.events.MouseEvent;
+ import flash.geom.Point;
import flash.geom.Rectangle;
import logic.BattleLogic;
import logic.soldier.BaseSoldier;
+ import logic.soldier.BossStrength;
import logic.soldier.KnightLance;
import logic.soldier.KnightRobo;
import net.flashpunk.Entity;
@@ -14,9 +20,13 @@ package scene
import net.flashpunk.graphics.Canvas;
import net.flashpunk.graphics.Image;
import net.flashpunk.utils.Draw;
+ import net.flashpunk.utils.Input;
import net.flashpunk.World;
import org.aswing.AbstractButton;
+ import org.aswing.AssetIcon;
+ import org.aswing.event.DragAndDropEvent;
import org.aswing.FlowLayout;
+ import org.aswing.Icon;
import org.aswing.JButton;
import org.aswing.JFrame;
import org.aswing.JLabel;
@@ -33,8 +43,12 @@ package scene
private var enemyHp:Canvas = null;
private var groundGrid:Image = null;
- // AsWingGUI
- private var closeDialog:JFrame;
+ // choose soldier by drag & drop action
+ private var choosingSoldierEntity:Entity;
+ private var cellStatusEntity:Entity;
+ private var choosingSoldier:SoldierConfig;
+ private var lastOveringCell:int;
+ private var canPlaceSoldier:Boolean;
public function BattleScene()
{
@@ -42,65 +56,195 @@ package scene
addHpInfo();
addBattleGround();
addLogicEngities();
- //initGUI();
+ initGUI();
+ initChoosingSoldier();
}
+ private function initChoosingSoldier():void
+ {
+ cellStatusEntity = this.addGraphic(null, Constants.LAYER_MOUSE);
+ cellStatusEntity.visible = false;
+ choosingSoldierEntity = this.addGraphic(null, Constants.LAYER_MOUSE);
+ choosingSoldierEntity.visible = false;
+ }
+
+ [Embed(source = "../../assets/battle_icon_knightrobo.png")] private static const KNIGHT_ROBO_ICON_SRC:Class;
+ private static const KNIGHT_ROBO_ICON:BitmapData = FP.getBitmap(KNIGHT_ROBO_ICON_SRC);
+ [Embed(source = "../../assets/battle_icon_knightlance.png")] private static const KNIGHT_LANCE_ICON_SRC:Class;
+ private static const KNIGHT_LANCE_ICON:BitmapData = FP.getBitmap(KNIGHT_LANCE_ICON_SRC);
+ [Embed(source = "../../assets/battle_icon_boss_strength.png")] private static const BOSS_STRENGTH_ICON_SRC:Class;
+ private static const BOSS_STRENGTH_ICON:BitmapData = FP.getBitmap(BOSS_STRENGTH_ICON_SRC);
private function initGUI():void
{
// create components
- closeDialog = new JFrame(FP.engine, "Close Dialog");
- var panel:JPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
- var label:JLabel = new JLabel("This is a dialog with one close button only");
- var button:JButton = new JButton(" Đóng ");
+ var bottomGUI:JFrame = new JFrame(FP.engine);
// size the frame
- closeDialog.setSizeWH(300, 150);
- closeDialog.x = FP.halfWidth - closeDialog.width / 2;
- closeDialog.y = FP.halfHeight - closeDialog.height;
+ bottomGUI.setSizeWH(FP.width, 100);
+ bottomGUI.y = FP.height - bottomGUI.getHeight();
// frame config
- closeDialog.setClosable(false);
- closeDialog.setDragable(false);
- closeDialog.setResizable(false);
-
- // button config
- button.addEventListener(MouseEvent.CLICK, onCloseDialog);
-
- // add the label and button to the panel
- panel.appendAll(label, button);
+ bottomGUI.setClosable(false);
+ bottomGUI.setDragable(false);
+ bottomGUI.setResizable(false);
+ bottomGUI.setBackgroundDecorator(null);
// add the panel to the frame
- closeDialog.getContentPane().append(panel);
+ var panel:JPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ var knightRoboButton:JButton = new JButton("", new AssetIcon(new Bitmap(KNIGHT_ROBO_ICON)));
+ knightRoboButton.name = "knightRoboButton";
+ knightRoboButton.setDragEnabled(true);
+ knightRoboButton.addEventListener(DragAndDropEvent.DRAG_RECOGNIZED, onChooseSoldier);
+ var knightLanceButton:JButton = new JButton("", new AssetIcon(new Bitmap(KNIGHT_LANCE_ICON)));
+ knightLanceButton.name = "knightLanceButton";
+ knightLanceButton.setDragEnabled(true);
+ knightLanceButton.addEventListener(DragAndDropEvent.DRAG_RECOGNIZED, onChooseSoldier);
+ var bossStrengthButton:JButton = new JButton("", new AssetIcon(new Bitmap(BOSS_STRENGTH_ICON)));
+ bossStrengthButton.name = "bossStrengthButton";
+ bossStrengthButton.setDragEnabled(true);
+ bossStrengthButton.addEventListener(DragAndDropEvent.DRAG_RECOGNIZED, onChooseSoldier);
+ panel.appendAll(knightRoboButton, knightLanceButton, bossStrengthButton);
+ bottomGUI.getContentPane().append(panel);
// display the frame
- closeDialog.show();
+ bottomGUI.show();
}
- private function onCloseDialog(e:Event):void
+ private function onChooseSoldier(e:DragAndDropEvent):void
{
- closeDialog.hide();
+ if (BattleLogic.instance().state != BattleLogic.BATTLE_STATE_NORMAL) return;
+ BattleLogic.instance().state = BattleLogic.BATTLE_STATE_CHOOSE_SOLDIER;
+ lastOveringCell = -1;
+ canPlaceSoldier = false;
+ switch(e.target.name)
+ {
+ case "knightRoboButton":
+ choosingSoldierEntity.graphic = KnightRobo.DISPLAY_IMG;
+ choosingSoldier = Config.instance().getConfig(BaseSoldier.SOLDIER_KNIGHT_ROBO_ID);
+ break;
+ case "knightLanceButton":
+ choosingSoldierEntity.graphic = KnightLance.DISPLAY_IMG;
+ choosingSoldier = Config.instance().getConfig(BaseSoldier.SOLDIER_KNIGHT_LANCE_ID);
+ break;
+ case "bossStrengthButton":
+ choosingSoldierEntity.graphic = BossStrength.DISPLAY_IMG;
+ choosingSoldier = Config.instance().getConfig(BaseSoldier.SOLDIER_BOSS_STRENGTH_ID);
+ break;
+ default:
+ break;
+ }
+ (choosingSoldierEntity.graphic as Image).centerOrigin();
+ choosingSoldierEntity.x = mouseX;
+ choosingSoldierEntity.y = mouseY;
+ choosingSoldierEntity.visible = true;
+
+ cellStatusEntity.graphic = new Canvas(choosingSoldier.sizeWidth * Constants.CELL_SIZE, choosingSoldier.sizeHeight * Constants.CELL_SIZE);
}
override public function update():void
{
BattleLogic.instance().update();
- super.update();
+ super.update();
+
+ switch(BattleLogic.instance().state)
+ {
+ case BattleLogic.BATTLE_STATE_CHOOSE_SOLDIER:
+ // Check finish choose soldier
+ if (Input.mouseReleased)
+ {
+ choosingSoldierEntity.visible = false;
+ cellStatusEntity.visible = false;
+
+ if (canPlaceSoldier)
+ {
+ var soldier:BaseSoldier;
+ switch(choosingSoldier.id)
+ {
+ case BaseSoldier.SOLDIER_KNIGHT_ROBO_ID:
+ soldier = new KnightRobo(Constants.TEAM_1, lastOveringCell, BaseSoldier.ANIM_STAND);
+ break;
+ case BaseSoldier.SOLDIER_KNIGHT_LANCE_ID:
+ soldier = new KnightLance(Constants.TEAM_1, lastOveringCell, BaseSoldier.ANIM_STAND);
+ break;
+ case BaseSoldier.SOLDIER_BOSS_STRENGTH_ID:
+ soldier = new BossStrength(Constants.TEAM_1, lastOveringCell, BaseSoldier.ANIM_STAND);
+ break;
+ }
+ if (BattleLogic.instance().addTroop(soldier))
+ {
+ add(soldier);
+ }
+ }
+
+ BattleLogic.instance().state = BattleLogic.BATTLE_STATE_NORMAL;
+ }
+ else
+ {
+ choosingSoldierEntity.x = mouseX;
+ choosingSoldierEntity.y = mouseY;
+
+ // Detect overing cell
+ var cell:int = Utils.getCellFromPos(mouseX, mouseY);
+ if (cell != lastOveringCell)
+ {
+ lastOveringCell = cell;
+ if (cell == -1)
+ {
+ cellStatusEntity.visible = false;
+ canPlaceSoldier = false;
+ }
+ else
+ {
+ var cellStatusCanvas:Canvas = cellStatusEntity.graphic as Canvas;
+ // clear canvas
+ cellStatusCanvas.fill(new Rectangle(0, 0, cellStatusCanvas.width, cellStatusCanvas.height), 0, 0);
+
+ var row:int = cell / Constants.CELL_COLUMN;
+ var col:int = cell % Constants.CELL_COLUMN;
+ var cellPos:Point = Utils.getPosFrom(row, col);
+ cellStatusEntity.x = cellPos.x - Constants.CELL_SIZE / 2;
+ cellStatusEntity.y = cellPos.y;
+ // Check cell available
+ canPlaceSoldier = true;
+ for (var i:int = 0; i < choosingSoldier.sizeWidth; i++)
+ {
+ for (var j:int = 0; j < choosingSoldier.sizeHeight; j++)
+ {
+ var color:uint = 0x00FF00;
+ if (!BattleLogic.instance().cellAvailable(Constants.TEAM_1, row + j, col + i))
+ {
+ color = 0xFF0000;
+ canPlaceSoldier = false;
+ }
+ cellStatusCanvas.drawRect(new Rectangle(i * Constants.CELL_SIZE, j * Constants.CELL_SIZE, Constants.CELL_SIZE, Constants.CELL_SIZE), color, 0.5);
+ }
+ }
+ cellStatusEntity.visible = true;
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
}
private function addLogicEngities():void
{
- var knightLance1:KnightLance = new KnightLance(Constants.TEAM_1, 5, BaseSoldier.ANIM_STAND);
- if (BattleLogic.instance().addTroop(knightLance1)) add(knightLance1);
- var knightLance2:KnightLance = new KnightLance(Constants.TEAM_1, 3, BaseSoldier.ANIM_STAND);
- if (BattleLogic.instance().addTroop(knightLance2)) add(knightLance2);
- var knightLance3:KnightLance = new KnightLance(Constants.TEAM_2, 21, BaseSoldier.ANIM_STAND);
- if (BattleLogic.instance().addTroop(knightLance3)) add(knightLance3);
- var knightLance4:KnightLance = new KnightLance(Constants.TEAM_2, 23, BaseSoldier.ANIM_STAND);
- if(BattleLogic.instance().addTroop(knightLance4)) add(knightLance4);
+ //var bossStrength:BossStrength = new BossStrength(Constants.TEAM_1, 5, BaseSoldier.ANIM_STAND);
+ //if (BattleLogic.instance().addTroop(bossStrength)) add(bossStrength);
+ //var knightLance2:KnightLance = new KnightLance(Constants.TEAM_1, 3, BaseSoldier.ANIM_STAND);
+ //if (BattleLogic.instance().addTroop(knightLance2)) add(knightLance2);
+ //var knightLance1:KnightLance = new KnightLance(Constants.TEAM_1, 5, BaseSoldier.ANIM_STAND);
+ //if (BattleLogic.instance().addTroop(knightLance1)) add(knightLance1);
+ //var knightLance3:KnightLance = new KnightLance(Constants.TEAM_2, 21, BaseSoldier.ANIM_STAND);
+ //if (BattleLogic.instance().addTroop(knightLance3)) add(knightLance3);
+ //var knightLance4:KnightLance = new KnightLance(Constants.TEAM_2, 23, BaseSoldier.ANIM_STAND);
+ //if (BattleLogic.instance().addTroop(knightLance4)) add(knightLance4);
for (var row:int = 0; row < 6; row++)
{
- for (var col:int = 0; col < 14; col++)
+ for (var col:int = 7; col < 14; col++)
{
var cell:int = row * 14 + col;
var knightRobo:KnightRobo;
Please sign in to comment.
Something went wrong with that request. Please try again.