1
0
Fork 0

Added ship sprite moving on move actions

This commit is contained in:
Michaël Lemaire 2015-01-06 01:00:00 +01:00 committed by Michaël Lemaire
parent 9d55c8d085
commit 8870b8839e
6 changed files with 53 additions and 9 deletions

View file

@ -46,6 +46,10 @@ module SpaceTac.Game {
this.fleet = fleet;
this.name = name;
this.initiative_level = 1;
this.ap_current = 10;
this.ap_maximal = 20;
this.ap_recover = 5;
this.movement_cost = 0.1;
if (fleet) {
fleet.addShip(this);

View file

@ -17,6 +17,7 @@ module SpaceTac.Game {
protected customApply(battle: Battle, ship: Ship, target: Target): boolean {
ship.moveTo(target.x, target.y);
battle.log.add(new MoveEvent(ship, target.x, target.y));
return true;
}
}

View file

@ -2,10 +2,22 @@ module SpaceTac.View {
// Graphical representation of a battle
// This is the area in the BattleView that will display ships with their real positions
export class Arena extends Phaser.Group {
// Arena background
background: Phaser.Button;
// Input callback to receive mouse move events
private input_callback: any;
// Link to battleview
private battleview: BattleView;
// List of ship sprites
private ship_sprites: ShipArenaSprite[];
constructor(battleview: BattleView) {
this.battleview = battleview;
this.ship_sprites = [];
super(battleview.game);
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) => {
var point = new Phaser.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);
this.add(this.background);
this.init();
}
destroy() {
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;
}
}
}

View file

@ -67,11 +67,6 @@ module SpaceTac.View {
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
this.log_processor = new LogProcessor(this);
}

View file

@ -37,7 +37,11 @@ module SpaceTac.View {
this.view.action_bar.setShip(event.target.ship);
break;
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;
}
}

View file

@ -1,15 +1,18 @@
module SpaceTac.View {
// Ship sprite in the arena (BattleView)
export class ShipArenaSprite extends Phaser.Button {
// Link to displayed ship
ship: Game.Ship;
constructor(battleview: BattleView, ship: Game.Ship) {
this.ship = ship;
super(battleview.game, ship.arena_x, ship.arena_y, "arena-ship");
this.scale.set(0.1, 0.1);
this.rotation = ship.arena_angle;
this.anchor.set(0.5, 0.5);
battleview.arena.add(this);
this.input.useHandCursor = true;
this.onInputOver.add(() => {
battleview.cursorOnShip(ship);