Added ship sprite moving on move actions
This commit is contained in:
parent
9d55c8d085
commit
8870b8839e
|
@ -46,6 +46,10 @@ module SpaceTac.Game {
|
||||||
this.fleet = fleet;
|
this.fleet = fleet;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.initiative_level = 1;
|
this.initiative_level = 1;
|
||||||
|
this.ap_current = 10;
|
||||||
|
this.ap_maximal = 20;
|
||||||
|
this.ap_recover = 5;
|
||||||
|
this.movement_cost = 0.1;
|
||||||
|
|
||||||
if (fleet) {
|
if (fleet) {
|
||||||
fleet.addShip(this);
|
fleet.addShip(this);
|
||||||
|
|
|
@ -17,6 +17,7 @@ module SpaceTac.Game {
|
||||||
|
|
||||||
protected customApply(battle: Battle, ship: Ship, target: Target): boolean {
|
protected customApply(battle: Battle, ship: Ship, target: Target): boolean {
|
||||||
ship.moveTo(target.x, target.y);
|
ship.moveTo(target.x, target.y);
|
||||||
|
battle.log.add(new MoveEvent(ship, target.x, target.y));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,22 @@ module SpaceTac.View {
|
||||||
// Graphical representation of a battle
|
// Graphical representation of a battle
|
||||||
// This is the area in the BattleView that will display ships with their real positions
|
// This is the area in the BattleView that will display ships with their real positions
|
||||||
export class Arena extends Phaser.Group {
|
export class Arena extends Phaser.Group {
|
||||||
|
// Arena background
|
||||||
background: Phaser.Button;
|
background: Phaser.Button;
|
||||||
|
|
||||||
|
// Input callback to receive mouse move events
|
||||||
private input_callback: any;
|
private input_callback: any;
|
||||||
|
|
||||||
|
// Link to battleview
|
||||||
|
private battleview: BattleView;
|
||||||
|
|
||||||
|
// List of ship sprites
|
||||||
|
private ship_sprites: ShipArenaSprite[];
|
||||||
|
|
||||||
constructor(battleview: BattleView) {
|
constructor(battleview: BattleView) {
|
||||||
|
this.battleview = battleview;
|
||||||
|
this.ship_sprites = [];
|
||||||
|
|
||||||
super(battleview.game);
|
super(battleview.game);
|
||||||
|
|
||||||
var background = new Phaser.Button(battleview.game, 0, 0, 'ui-arena-background');
|
var background = new Phaser.Button(battleview.game, 0, 0, 'ui-arena-background');
|
||||||
|
@ -21,15 +33,40 @@ module SpaceTac.View {
|
||||||
this.input_callback = this.game.input.addMoveCallback((pointer) => {
|
this.input_callback = this.game.input.addMoveCallback((pointer) => {
|
||||||
var point = new Phaser.Point();
|
var point = new Phaser.Point();
|
||||||
if (battleview.game.input.hitTest(background, pointer, point)) {
|
if (battleview.game.input.hitTest(background, pointer, point)) {
|
||||||
battleview.cursorInSpace(point.x, point.y);
|
battleview.cursorInSpace(point.x * background.scale.x, point.y * background.scale.y);
|
||||||
}
|
}
|
||||||
}, null);
|
}, null);
|
||||||
|
|
||||||
this.add(this.background);
|
this.add(this.background);
|
||||||
|
|
||||||
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.game.input.deleteMoveCallback(this.input_callback);
|
this.game.input.deleteMoveCallback(this.input_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize state (create sprites)
|
||||||
|
init(): void {
|
||||||
|
var arena = this;
|
||||||
|
|
||||||
|
// Add ship sprites
|
||||||
|
this.battleview.battle.play_order.forEach(function (ship: Game.Ship) {
|
||||||
|
var sprite = new ShipArenaSprite(arena.battleview, ship);
|
||||||
|
arena.add(sprite);
|
||||||
|
arena.ship_sprites.push(sprite);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the sprite for a ship
|
||||||
|
findShipSprite(ship: Game.Ship): ShipArenaSprite {
|
||||||
|
var result: ShipArenaSprite = null;
|
||||||
|
this.ship_sprites.forEach((sprite: ShipArenaSprite) => {
|
||||||
|
if (sprite.ship === ship) {
|
||||||
|
result = sprite;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,11 +67,6 @@ module SpaceTac.View {
|
||||||
new ShipListItem(battleview, 0, rank * 50, ship, ship.getPlayer() === player);
|
new ShipListItem(battleview, 0, rank * 50, ship, ship.getPlayer() === player);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add ship sprites to arena
|
|
||||||
this.battle.play_order.forEach(function (ship: Game.Ship) {
|
|
||||||
new ShipArenaSprite(battleview, ship);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Start processing the battle log
|
// Start processing the battle log
|
||||||
this.log_processor = new LogProcessor(this);
|
this.log_processor = new LogProcessor(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,11 @@ module SpaceTac.View {
|
||||||
this.view.action_bar.setShip(event.target.ship);
|
this.view.action_bar.setShip(event.target.ship);
|
||||||
break;
|
break;
|
||||||
case "move":
|
case "move":
|
||||||
// TODO A ship moved
|
var sprite = this.view.arena.findShipSprite(event.ship);
|
||||||
|
if (sprite) {
|
||||||
|
sprite.x = event.target.x;
|
||||||
|
sprite.y = event.target.y;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
module SpaceTac.View {
|
module SpaceTac.View {
|
||||||
// Ship sprite in the arena (BattleView)
|
// Ship sprite in the arena (BattleView)
|
||||||
export class ShipArenaSprite extends Phaser.Button {
|
export class ShipArenaSprite extends Phaser.Button {
|
||||||
|
// Link to displayed ship
|
||||||
|
ship: Game.Ship;
|
||||||
|
|
||||||
constructor(battleview: BattleView, ship: Game.Ship) {
|
constructor(battleview: BattleView, ship: Game.Ship) {
|
||||||
|
this.ship = ship;
|
||||||
|
|
||||||
super(battleview.game, ship.arena_x, ship.arena_y, "arena-ship");
|
super(battleview.game, ship.arena_x, ship.arena_y, "arena-ship");
|
||||||
|
|
||||||
this.scale.set(0.1, 0.1);
|
this.scale.set(0.1, 0.1);
|
||||||
this.rotation = ship.arena_angle;
|
this.rotation = ship.arena_angle;
|
||||||
this.anchor.set(0.5, 0.5);
|
this.anchor.set(0.5, 0.5);
|
||||||
|
|
||||||
battleview.arena.add(this);
|
|
||||||
|
|
||||||
this.input.useHandCursor = true;
|
this.input.useHandCursor = true;
|
||||||
this.onInputOver.add(() => {
|
this.onInputOver.add(() => {
|
||||||
battleview.cursorOnShip(ship);
|
battleview.cursorOnShip(ship);
|
||||||
|
|
Loading…
Reference in a new issue