1
0
Fork 0

Added minimal distance between star locations

This commit is contained in:
Michaël Lemaire 2015-04-21 23:40:15 +02:00
parent cb278959a9
commit f204bc4321
3 changed files with 26 additions and 4 deletions

4
TODO
View file

@ -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

View file

@ -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;
}
}
}

View file

@ -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);
}
}
}