Added visited status on star locations
This commit is contained in:
parent
69762a0a07
commit
cacef3cea8
|
@ -229,7 +229,7 @@
|
|||
inkscape:cx="1424.0698"
|
||||
inkscape:cy="540.88968"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:current-layer="g7289"
|
||||
inkscape:current-layer="layer5"
|
||||
showgrid="false"
|
||||
units="px"
|
||||
inkscape:snap-bbox="false"
|
||||
|
@ -413,24 +413,30 @@
|
|||
id="tspan7271"
|
||||
sodipodi:role="line">?</tspan></text>
|
||||
</g>
|
||||
<use
|
||||
style=""
|
||||
x="0"
|
||||
y="0"
|
||||
xlink:href="#path7269"
|
||||
id="use7291"
|
||||
transform="translate(54.323607)"
|
||||
width="100%"
|
||||
height="100%" />
|
||||
<path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#2b8443;stroke-width:1.10821939;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 401.15031,150.22836 1.78335,1.65025 2.68829,-3.35372"
|
||||
id="path7294"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="ccc"
|
||||
<g
|
||||
id="g4573"
|
||||
inkscape:export-filename="/home/michael/workspace/perso/spacetac/out/assets/images/map/state-clear.png"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-ydpi="96" />
|
||||
inkscape:export-ydpi="96">
|
||||
<use
|
||||
height="100%"
|
||||
width="100%"
|
||||
transform="translate(54.323607)"
|
||||
id="use7291"
|
||||
xlink:href="#path7269"
|
||||
y="0"
|
||||
x="0"
|
||||
style="" />
|
||||
<path
|
||||
inkscape:export-ydpi="96"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-filename="/home/michael/workspace/perso/spacetac/out/assets/images/map/state-clear.png"
|
||||
sodipodi:nodetypes="ccc"
|
||||
inkscape:connector-curvature="0"
|
||||
id="path7294"
|
||||
d="m 401.15031,150.22836 1.78335,1.65025 2.68829,-3.35372"
|
||||
style="fill:none;fill-rule:evenodd;stroke:#2b8443;stroke-width:1.10821939;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
</g>
|
||||
<use
|
||||
x="0"
|
||||
y="0"
|
||||
|
|
Before Width: | Height: | Size: 123 KiB After Width: | Height: | Size: 123 KiB |
Binary file not shown.
Before Width: | Height: | Size: 631 B After Width: | Height: | Size: 1.5 KiB |
|
@ -1 +1 @@
|
|||
Subproject commit c8b1e60af539304ea82abed99ff9500895318f99
|
||||
Subproject commit 6d16fc0a5b50aa53c68c09fda2d0d3c5ec22b02d
|
|
@ -28,7 +28,7 @@ module TS.SpaceTac.Game {
|
|||
// Set the current location of the fleet
|
||||
setLocation(location: StarLocation): void {
|
||||
this.location = location;
|
||||
this.player.setVisited(this.location.star);
|
||||
this.player.setVisited(this.location);
|
||||
|
||||
// Check encounter
|
||||
var battle = this.location.enterLocation(this.player.fleet);
|
||||
|
|
40
src/game/Player.spec.ts
Normal file
40
src/game/Player.spec.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
module TS.SpaceTac.Game {
|
||||
describe("Player", function () {
|
||||
it("keeps track of visited locations", function () {
|
||||
let player = new Player();
|
||||
let star1 = new Star();
|
||||
let star2 = new Star();
|
||||
let loc1a = new StarLocation(star1);
|
||||
let loc1b = new StarLocation(star1);
|
||||
let loc2a = new StarLocation(star2);
|
||||
let loc2b = new StarLocation(star2);
|
||||
|
||||
function checkVisited(s1 = false, s2 = false, v1a = false, v1b = false, v2a = false, v2b = false) {
|
||||
expect(player.hasVisitedSystem(star1)).toBe(s1);
|
||||
expect(player.hasVisitedSystem(star2)).toBe(s2);
|
||||
expect(player.hasVisitedLocation(loc1a)).toBe(v1a);
|
||||
expect(player.hasVisitedLocation(loc1b)).toBe(v1b);
|
||||
expect(player.hasVisitedLocation(loc2a)).toBe(v2a);
|
||||
expect(player.hasVisitedLocation(loc2b)).toBe(v2b);
|
||||
}
|
||||
|
||||
checkVisited();
|
||||
|
||||
player.setVisited(loc1b);
|
||||
|
||||
checkVisited(true, false, false, true, false, false);
|
||||
|
||||
player.setVisited(loc1a);
|
||||
|
||||
checkVisited(true, false, true, true, false, false);
|
||||
|
||||
player.setVisited(loc2a);
|
||||
|
||||
checkVisited(true, true, true, true, true, false);
|
||||
|
||||
player.setVisited(loc2a);
|
||||
|
||||
checkVisited(true, true, true, true, true, false);
|
||||
});
|
||||
});
|
||||
}
|
|
@ -13,7 +13,7 @@ module TS.SpaceTac.Game {
|
|||
ai: AI.AbstractAI;
|
||||
|
||||
// List of visited star systems
|
||||
visited: Star[];
|
||||
visited: StarLocation[] = [];
|
||||
|
||||
// Create a player, with an empty fleet
|
||||
constructor(universe: Universe = new Universe()) {
|
||||
|
@ -22,7 +22,6 @@ module TS.SpaceTac.Game {
|
|||
this.universe = universe;
|
||||
this.fleet = new Fleet(this);
|
||||
this.ai = null;
|
||||
this.visited = [];
|
||||
}
|
||||
|
||||
// Create a quick random player, with a fleet, for testing purposes
|
||||
|
@ -50,16 +49,25 @@ module TS.SpaceTac.Game {
|
|||
return player;
|
||||
}
|
||||
|
||||
// Check if the player has visited a given star system
|
||||
hasVisited(star: Star): boolean {
|
||||
return this.visited.indexOf(star) >= 0;
|
||||
/**
|
||||
* Return true if the player has visited at least one location in a given system.
|
||||
*/
|
||||
hasVisitedSystem(system: Star): boolean {
|
||||
return any(this.visited, location => location.star == system);
|
||||
}
|
||||
|
||||
// Set a star system as visited
|
||||
setVisited(star: Star): void {
|
||||
if (!this.hasVisited(star)) {
|
||||
this.visited.push(star);
|
||||
}
|
||||
/**
|
||||
* Return true if the player has visited a given star location.
|
||||
*/
|
||||
hasVisitedLocation(location: StarLocation): boolean {
|
||||
return contains(this.visited, location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a star location as visited.
|
||||
*/
|
||||
setVisited(location: StarLocation): void {
|
||||
add(this.visited, location);
|
||||
}
|
||||
|
||||
// Get currently played battle, null when none is in progress
|
||||
|
|
|
@ -28,7 +28,7 @@ module TS.SpaceTac.Game {
|
|||
encounter: Fleet;
|
||||
encounter_gen: boolean;
|
||||
|
||||
constructor(star: Star, type: StarLocationType, x: number = 0, y: number = 0) {
|
||||
constructor(star: Star, type: StarLocationType = StarLocationType.PLANET, x: number = 0, y: number = 0) {
|
||||
super();
|
||||
|
||||
this.star = star || new Star();
|
||||
|
|
|
@ -17,14 +17,21 @@ module TS.SpaceTac.View {
|
|||
|
||||
// Show locations
|
||||
starsystem.locations.forEach(location => {
|
||||
let location_sprite: Phaser.Image | null = null;
|
||||
|
||||
if (location.type == Game.StarLocationType.STAR) {
|
||||
this.addImage(location.x, location.y, "map-location-star");
|
||||
location_sprite = this.addImage(location.x, location.y, "map-location-star");
|
||||
} else if (location.type == Game.StarLocationType.PLANET) {
|
||||
let planet = this.addImage(location.x, location.y, "map-location-planet");
|
||||
planet.rotation = Math.atan2(location.y, location.x);
|
||||
location_sprite = this.addImage(location.x, location.y, "map-location-planet");
|
||||
location_sprite.rotation = Math.atan2(location.y, location.x);
|
||||
this.addCircle(Math.sqrt(location.x * location.x + location.y * location.y), 1);
|
||||
} else if (location.type == Game.StarLocationType.WARP) {
|
||||
let warp = this.addImage(location.x, location.y, "map-location-warp");
|
||||
location_sprite = this.addImage(location.x, location.y, "map-location-warp");
|
||||
}
|
||||
|
||||
if (location_sprite) {
|
||||
let key = parent.player.hasVisitedLocation(location) ? (location.encounter ? "map-state-enemy" : "map-state-clear") : "map-state-unknown";
|
||||
this.addImage(location.x + 0.005, location.y + 0.005, key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -67,8 +67,10 @@ module TS.SpaceTac.View {
|
|||
|
||||
// Reveal the whole map (this is a cheat)
|
||||
revealAll(): void {
|
||||
this.universe.stars.forEach((star: Game.Star) => {
|
||||
this.player.setVisited(star);
|
||||
this.universe.stars.forEach(star => {
|
||||
star.locations.forEach(location => {
|
||||
this.player.setVisited(location);
|
||||
});
|
||||
});
|
||||
// TODO Redraw
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue