Skip to content

Commit

Permalink
Add drag & drop to choose soldier
Browse files Browse the repository at this point in the history
  • Loading branch information
atapie committed Apr 21, 2012
1 parent 4e92e8e commit ece560f
Show file tree
Hide file tree
Showing 18 changed files with 432 additions and 119 deletions.
Binary file added 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.
Binary file added 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.
Binary file added 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.
Binary file added 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.
Binary file modified flashpunk/bin/flashpunk.swf
Binary file not shown.
4 changes: 4 additions & 0 deletions flashpunk/flashpunk.as3proj
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion flashpunk/obj/flashpunkConfig.old
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion flashpunk/obj/flashpunkConfig.xml
Expand Up @@ -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>
Expand Down
70 changes: 70 additions & 0 deletions 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;
}

}

}
7 changes: 4 additions & 3 deletions flashpunk/src/common/Constants.as
Expand Up @@ -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;
Expand Down
31 changes: 30 additions & 1 deletion flashpunk/src/common/Utils.as
@@ -1,13 +1,17 @@
package common
{
import flash.display.BitmapData;
import flash.geom.Point;
import net.flashpunk.FP;
/**
* ...
* @author ...
*/
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);
Expand All @@ -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;
}
}

Expand Down
26 changes: 26 additions & 0 deletions 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()
{

}

}

}
18 changes: 10 additions & 8 deletions flashpunk/src/logic/BattleLogic.as
Expand Up @@ -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
Expand All @@ -24,7 +26,7 @@ package logic

private function init():void
{
state = BATTLE_STATE_STOPPED;
state = BATTLE_STATE_NORMAL;
}

public static function instance():BattleLogic
Expand All @@ -41,7 +43,7 @@ package logic
{
switch(state)
{
case BATTLE_STATE_STOPPED:
case BATTLE_STATE_NORMAL:
if (Input.released(Key.ENTER))
{
reset();
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
Expand Down

0 comments on commit ece560f

Please sign in to comment.