Add game
This commit is contained in:
parent
d36e98ad0b
commit
c071b286af
23 changed files with 713 additions and 11 deletions
26
src/services/game/location.ts
Normal file
26
src/services/game/location.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import {
|
||||
locationFarlands,
|
||||
locations,
|
||||
type ILocation,
|
||||
type Location,
|
||||
} from "./structures/locations.js";
|
||||
|
||||
const getLocation = (id: Location): ILocation => {
|
||||
const location = locations.find((location) => location.id === id);
|
||||
|
||||
return location ? location : locationFarlands;
|
||||
};
|
||||
|
||||
const getLocationDistance = (
|
||||
locationA: ILocation,
|
||||
locationB: ILocation,
|
||||
): number => {
|
||||
const deltaX = Math.abs(locationA.X - locationB.X);
|
||||
const deltaY = Math.abs(locationA.Y - locationB.Y);
|
||||
|
||||
const deltaPow = Math.pow(deltaX, 2) + Math.pow(deltaY, 2);
|
||||
|
||||
return Math.sqrt(deltaPow);
|
||||
};
|
||||
|
||||
export { getLocation, getLocationDistance };
|
||||
Loading…
Add table
Add a link
Reference in a new issue