Added star system map view
This commit is contained in:
parent
c6d68e36c9
commit
40925d54e1
|
@ -19,6 +19,7 @@ module SpaceTac {
|
|||
this.state.add('router', View.Router);
|
||||
this.state.add('battle', View.BattleView);
|
||||
this.state.add('universe', View.UniverseMapView);
|
||||
this.state.add('starsystem', View.StarSystemView);
|
||||
|
||||
this.state.start('boot');
|
||||
}
|
||||
|
|
|
@ -11,6 +11,9 @@ module SpaceTac.Game {
|
|||
// List of ships
|
||||
ships: Ship[];
|
||||
|
||||
// Current fleet location
|
||||
location: StarLocation;
|
||||
|
||||
// Current battle in which the fleet is engaged (null if not fighting)
|
||||
battle: Battle;
|
||||
|
||||
|
@ -20,6 +23,7 @@ module SpaceTac.Game {
|
|||
|
||||
this.player = player || new Player();
|
||||
this.ships = [];
|
||||
this.location = null;
|
||||
this.battle = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,12 +12,20 @@ module SpaceTac.Game {
|
|||
x: number;
|
||||
y: number;
|
||||
|
||||
// Radius of the star system
|
||||
radius: number;
|
||||
|
||||
// List of points of interest
|
||||
locations: StarLocation[];
|
||||
|
||||
constructor(universe: Universe, x: number, y: number) {
|
||||
super();
|
||||
|
||||
this.universe = universe;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.radius = 0.1;
|
||||
this.locations = [];
|
||||
}
|
||||
|
||||
// Get the distance to another star
|
||||
|
@ -27,5 +35,38 @@ module SpaceTac.Game {
|
|||
|
||||
return Math.sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
|
||||
// Generate the contents of this star system
|
||||
generate(random: RandomGenerator = new RandomGenerator()): void {
|
||||
var location_count = random.throwInt(2, 10);
|
||||
this.locations = this.generateLocations(location_count, random);
|
||||
}
|
||||
|
||||
// Generate points of interest (*count* doesn't include the star and warp locations)
|
||||
generateLocations(count: number, random: RandomGenerator = new RandomGenerator()): StarLocation[] {
|
||||
var result: StarLocation[] = [];
|
||||
|
||||
// Add the star
|
||||
result.push(new StarLocation(this, StarLocationType.STAR, 0, 0));
|
||||
|
||||
// Add warp locations around the star
|
||||
var warps = 3;
|
||||
while (warps--) {
|
||||
result.push(this.generateOneLocation(StarLocationType.WARP, result, this.radius * 0.3, random));
|
||||
}
|
||||
|
||||
// Add random locations
|
||||
while (count--) {
|
||||
result.push(this.generateOneLocation(StarLocationType.PLANET, result, this.radius, random));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private generateOneLocation(type: StarLocationType, others: StarLocation[], radius: number, random: RandomGenerator): StarLocation {
|
||||
var x = (random.throw(2) - 1) * radius;
|
||||
var y = (random.throw(2) - 1) * radius;
|
||||
return new StarLocation(this, type, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
35
src/app/game/StarLocation.ts
Normal file
35
src/app/game/StarLocation.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
/// <reference path="Serializable.ts"/>
|
||||
|
||||
module SpaceTac.Game {
|
||||
"use strict";
|
||||
|
||||
export enum StarLocationType {
|
||||
STAR,
|
||||
WARP,
|
||||
PLANET,
|
||||
ASTEROID,
|
||||
STATION
|
||||
}
|
||||
|
||||
// Point of interest in a star system
|
||||
export class StarLocation extends Serializable {
|
||||
// Parent star system
|
||||
star: Star;
|
||||
|
||||
// Type of location
|
||||
type: StarLocationType;
|
||||
|
||||
// Location in the star system
|
||||
x: number;
|
||||
y: number;
|
||||
|
||||
constructor(star: Star, type: StarLocationType, x: number, y: number) {
|
||||
super();
|
||||
|
||||
this.star = star;
|
||||
this.type = type;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -60,6 +60,10 @@ module SpaceTac.Game {
|
|||
|
||||
var links = this.getPotentialLinks();
|
||||
this.starlinks = this.filterCrossingLinks(links);
|
||||
|
||||
this.stars.forEach((star: Star) => {
|
||||
star.generate(random);
|
||||
});
|
||||
}
|
||||
|
||||
// Generate a given number of stars, not too crowded
|
||||
|
|
|
@ -54,6 +54,9 @@ module SpaceTac.View {
|
|||
this.loadImage("common/standard-bar-background.png");
|
||||
this.loadImage("common/standard-bar-foreground.png");
|
||||
this.loadImage("map/star-icon.png");
|
||||
this.loadImage("map/planet-icon.png");
|
||||
this.loadImage("map/warp-icon.png");
|
||||
this.loadImage("map/button-back.png");
|
||||
|
||||
// Load sounds
|
||||
this.loadSound("battle/ship-change.wav");
|
||||
|
|
63
src/app/view/map/StarSystemView.ts
Normal file
63
src/app/view/map/StarSystemView.ts
Normal file
|
@ -0,0 +1,63 @@
|
|||
module SpaceTac.View {
|
||||
"use strict";
|
||||
|
||||
// Interactive map of a star system
|
||||
export class StarSystemView extends Phaser.State {
|
||||
|
||||
// Displayed star system
|
||||
star: Game.Star;
|
||||
|
||||
// Interacting player
|
||||
player: Game.Player;
|
||||
|
||||
// Group for the locations diplay
|
||||
locations: Phaser.Group;
|
||||
|
||||
// Scaling used to transform game coordinates in screen ones
|
||||
private scaling: number;
|
||||
|
||||
|
||||
// Init the view, binding it to a universe
|
||||
init(star: Game.Star, player: Game.Player) {
|
||||
this.star = star;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
// Create view graphics
|
||||
create() {
|
||||
this.locations = this.add.group();
|
||||
|
||||
this.scaling = 720 / (this.star.radius * 2);
|
||||
this.locations.position.set(this.star.radius * this.scaling, this.star.radius * this.scaling);
|
||||
this.locations.scale.set(this.scaling);
|
||||
|
||||
this.drawLocations();
|
||||
|
||||
// Back button
|
||||
this.add.button(0, 0, "map-button-back", this.onBackClicked, this);
|
||||
}
|
||||
|
||||
// Leaving the view, unbind and destroy
|
||||
shutdown() {
|
||||
this.star = null;
|
||||
this.player = null;
|
||||
}
|
||||
|
||||
// Redraw the locations map
|
||||
drawLocations(): void {
|
||||
console.log(this.star.locations);
|
||||
this.locations.removeAll(true, true);
|
||||
this.star.locations.forEach((location: Game.StarLocation) => {
|
||||
var key = "map-" + Game.StarLocationType[location.type].toLowerCase() + "-icon";
|
||||
var sprite = this.add.sprite(location.x, location.y, key, 0, this.locations);
|
||||
sprite.scale.set(1.0 / this.scaling, 1.0 / this.scaling);
|
||||
sprite.anchor.set(0.5, 0.5);
|
||||
});
|
||||
}
|
||||
|
||||
// Called when "Back" is clicked, go back to universe map
|
||||
onBackClicked(): void {
|
||||
this.game.state.start("universe", true, false, this.star.universe, this.player);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,7 +11,10 @@ module SpaceTac.View {
|
|||
player: Game.Player;
|
||||
|
||||
// Group for the stars and links
|
||||
stars: Phaser.Group;
|
||||
private stars: Phaser.Group;
|
||||
|
||||
// Scaling used to transform game coordinates in screen ones
|
||||
private scaling: number;
|
||||
|
||||
// Init the view, binding it to a universe
|
||||
init(universe: Game.Universe, player: Game.Player) {
|
||||
|
@ -23,9 +26,9 @@ module SpaceTac.View {
|
|||
create() {
|
||||
this.stars = this.add.group();
|
||||
|
||||
var scale = 720 / (this.universe.radius * 2);
|
||||
this.stars.position.set(this.universe.radius * scale, this.universe.radius * scale);
|
||||
this.stars.scale.set(scale);
|
||||
this.scaling = 720 / (this.universe.radius * 2);
|
||||
this.stars.position.set(this.universe.radius * this.scaling, this.universe.radius * this.scaling);
|
||||
this.stars.scale.set(this.scaling);
|
||||
|
||||
this.drawStars();
|
||||
|
||||
|
@ -52,9 +55,15 @@ module SpaceTac.View {
|
|||
});
|
||||
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);
|
||||
var sprite = new Phaser.Button(this.game, star.x, star.y, "map-star-icon");
|
||||
sprite.scale.set(1.0 / this.scaling, 1.0 / this.scaling);
|
||||
sprite.anchor.set(0.5, 0.5);
|
||||
|
||||
sprite.onInputUp.add(() => {
|
||||
this.game.state.start("starsystem", true, false, star, this.player);
|
||||
});
|
||||
|
||||
this.stars.addChild(sprite);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
BIN
src/assets/images/map/button-back.png
Normal file
BIN
src/assets/images/map/button-back.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
BIN
src/assets/images/map/planet-icon.png
Normal file
BIN
src/assets/images/map/planet-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2 KiB |
BIN
src/assets/images/map/warp-icon.png
Normal file
BIN
src/assets/images/map/warp-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3 KiB |
Loading…
Reference in a new issue