Universe map only displays visited systems
This commit is contained in:
parent
74d302b64c
commit
d562acb409
|
@ -11,12 +11,16 @@ module SpaceTac.Game {
|
|||
// AI playing (null for human player)
|
||||
ai: AI.AbstractAI;
|
||||
|
||||
// List of visited star systems
|
||||
visited: Star[];
|
||||
|
||||
// Create a player, with an empty fleet
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.fleet = new Fleet(this);
|
||||
this.ai = null;
|
||||
this.visited = [];
|
||||
}
|
||||
|
||||
// Create a quick random player, with a fleet, for testing purposes
|
||||
|
@ -43,5 +47,17 @@ module SpaceTac.Game {
|
|||
|
||||
return player;
|
||||
}
|
||||
|
||||
// Check if the player has visited a given star system
|
||||
hasVisited(star: Star): boolean {
|
||||
return this.visited.indexOf(star) >= 0;
|
||||
}
|
||||
|
||||
// Set a star system as visited
|
||||
setVisited(star: Star): void {
|
||||
if (!this.hasVisited(star)) {
|
||||
this.visited.push(star);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,15 @@ module SpaceTac.Game {
|
|||
return <Universe>serializer.unserialize(serialized);
|
||||
}
|
||||
|
||||
// Generate a real single player game
|
||||
static newGame(): Universe {
|
||||
var universe = new Universe();
|
||||
universe.generate();
|
||||
universe.player = new Game.Player();
|
||||
universe.player.setVisited(universe.stars[0]);
|
||||
return universe;
|
||||
}
|
||||
|
||||
// Start a new "quick battle" game
|
||||
startQuickBattle(with_ai: boolean = false): void {
|
||||
this.battle = Game.Battle.newQuickRandom(with_ai);
|
||||
|
|
|
@ -29,8 +29,7 @@ module SpaceTac.View {
|
|||
onNewGame(): void {
|
||||
var gameui = <GameUI>this.game;
|
||||
|
||||
gameui.universe = new Game.Universe();
|
||||
gameui.universe.generate();
|
||||
gameui.universe = Game.Universe.newGame();
|
||||
|
||||
this.game.state.start("router");
|
||||
}
|
||||
|
|
|
@ -27,17 +27,10 @@ module SpaceTac.View {
|
|||
this.stars.position.set(this.universe.radius * scale, this.universe.radius * scale);
|
||||
this.stars.scale.set(scale);
|
||||
|
||||
this.universe.starlinks.forEach((link: Game.StarLink) => {
|
||||
var line = this.add.graphics(0, 0, this.stars);
|
||||
line.lineStyle(0.3, 0xA0A0A0);
|
||||
line.moveTo(link.first.x, link.first.y);
|
||||
line.lineTo(link.second.x, link.second.y);
|
||||
});
|
||||
this.universe.stars.forEach((star: Game.Star) => {
|
||||
var sprite = this.add.sprite(star.x, star.y, "map-star-icon", 0, this.stars);
|
||||
sprite.scale.set(0.1, 0.1);
|
||||
sprite.anchor.set(0.5, 0.5);
|
||||
});
|
||||
this.drawStars();
|
||||
|
||||
// Inputs
|
||||
this.input.keyboard.addKey(Phaser.Keyboard.R).onUp.addOnce(this.revealAll, this);
|
||||
}
|
||||
|
||||
// Leaving the view, unbind and destroy
|
||||
|
@ -45,5 +38,34 @@ module SpaceTac.View {
|
|||
this.universe = null;
|
||||
this.player = null;
|
||||
}
|
||||
|
||||
// Redraw the star map
|
||||
drawStars(): void {
|
||||
this.stars.removeAll(true, true);
|
||||
this.universe.starlinks.forEach((link: Game.StarLink) => {
|
||||
if (this.player.hasVisited(link.first) || this.player.hasVisited(link.second)) {
|
||||
var line = this.add.graphics(0, 0, this.stars);
|
||||
line.lineStyle(0.3, 0xA0A0A0);
|
||||
line.moveTo(link.first.x, link.first.y);
|
||||
line.lineTo(link.second.x, link.second.y);
|
||||
}
|
||||
});
|
||||
this.universe.stars.forEach((star: Game.Star) => {
|
||||
if (this.player.hasVisited(star)) {
|
||||
var sprite = this.add.sprite(star.x, star.y, "map-star-icon", 0, this.stars);
|
||||
sprite.scale.set(0.1, 0.1);
|
||||
sprite.anchor.set(0.5, 0.5);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Reveal the whole map (this is a cheat)
|
||||
revealAll(): void {
|
||||
console.warn("Cheat : reveal whole map");
|
||||
this.universe.stars.forEach((star: Game.Star) => {
|
||||
this.player.setVisited(star);
|
||||
});
|
||||
this.drawStars();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue