Added minimal distance between star locations
This commit is contained in:
parent
cb278959a9
commit
f204bc4321
4
TODO
4
TODO
|
@ -1,3 +1,5 @@
|
|||
* Add a cheat system, to use for development
|
||||
* Display active effects on ships
|
||||
* Add a cheat system, to use for development (win battle, revive killed ship ...)
|
||||
* Add a defeat screen (game over for now)
|
||||
* Add a victory screen, with looting
|
||||
* Add retreat from battle
|
||||
|
|
|
@ -159,10 +159,22 @@ module SpaceTac.Game {
|
|||
return result;
|
||||
}
|
||||
|
||||
// Check if a location is far enough from all other ones
|
||||
private checkMinDistance(loc: StarLocation, others: StarLocation[]): boolean {
|
||||
return others.every((iloc: StarLocation): boolean => {
|
||||
return iloc.getDistanceTo(loc) > this.radius * 0.1;
|
||||
});
|
||||
}
|
||||
|
||||
// Generate a single location
|
||||
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);
|
||||
do {
|
||||
var x = (random.throw(2) - 1) * radius;
|
||||
var y = (random.throw(2) - 1) * radius;
|
||||
var result = new StarLocation(this, type, x, y);
|
||||
} while (!this.checkMinDistance(result, others));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,5 +80,13 @@ module SpaceTac.Game {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the distance to another location
|
||||
getDistanceTo(other: StarLocation): number {
|
||||
var dx = this.x - other.x;
|
||||
var dy = this.y - other.y;
|
||||
|
||||
return Math.sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue