forked from noxious/server
Fix character movement speed, fix for diagonal movement and disabled it by default
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import config from '../config'
|
||||
|
||||
type Position = { x: number; y: number }
|
||||
export type Node = Position & { parent?: Node; g: number; h: number; f: number }
|
||||
|
||||
@ -13,7 +15,7 @@ export class AStar {
|
||||
{ x: 1, y: 1 }
|
||||
]
|
||||
|
||||
static findPath(start: Position, end: Position, grid: number[][], allowDiagonal = false): Node[] {
|
||||
static findPath(start: Position, end: Position, grid: number[][]): Node[] {
|
||||
const openList: Node[] = [{ ...start, g: 0, h: 0, f: 0 }]
|
||||
const closedSet = new Set<string>()
|
||||
const getKey = (p: Position) => `${p.x},${p.y}`
|
||||
@ -25,7 +27,7 @@ export class AStar {
|
||||
openList.splice(openList.indexOf(current), 1)
|
||||
closedSet.add(getKey(current))
|
||||
|
||||
const neighbors = this.DIRECTIONS.slice(0, allowDiagonal ? 8 : 4)
|
||||
const neighbors = this.DIRECTIONS.slice(0, config.ALLOW_DIAGONAL_MOVEMENT ? 8 : 4)
|
||||
.map((dir) => ({ x: current.x + dir.x, y: current.y + dir.y }))
|
||||
.filter((pos) => this.isValidPosition(pos, grid, end))
|
||||
|
||||
|
@ -1,25 +1,35 @@
|
||||
import config from '../config'
|
||||
|
||||
class Rotation {
|
||||
static calculate(X1: number, Y1: number, X2: number, Y2: number): number {
|
||||
let rotation = 0
|
||||
if (X1 > X2 && Y1 > Y2) {
|
||||
rotation = 7
|
||||
} else if (X1 < X2 && Y1 < Y2) {
|
||||
rotation = 3
|
||||
} else if (X1 > X2 && Y1 < Y2) {
|
||||
rotation = 5
|
||||
} else if (X1 < X2 && Y1 > Y2) {
|
||||
rotation = 1
|
||||
} else if (X1 > X2) {
|
||||
rotation = 6
|
||||
} else if (X1 < X2) {
|
||||
rotation = 2
|
||||
} else if (Y1 < Y2) {
|
||||
rotation = 4
|
||||
} else if (Y1 > Y2) {
|
||||
rotation = 0
|
||||
|
||||
if (config.ALLOW_DIAGONAL_MOVEMENT) {
|
||||
if (X1 > X2 && Y1 > Y2) {
|
||||
rotation = 7
|
||||
} else if (X1 < X2 && Y1 < Y2) {
|
||||
rotation = 3
|
||||
} else if (X1 > X2 && Y1 < Y2) {
|
||||
rotation = 5
|
||||
} else if (X1 < X2 && Y1 > Y2) {
|
||||
rotation = 1
|
||||
}
|
||||
}
|
||||
|
||||
if (rotation === 0) {
|
||||
if (X1 > X2) {
|
||||
rotation = 6
|
||||
} else if (X1 < X2) {
|
||||
rotation = 2
|
||||
} else if (Y1 < Y2) {
|
||||
rotation = 4
|
||||
} else if (Y1 > Y2) {
|
||||
rotation = 0
|
||||
}
|
||||
}
|
||||
|
||||
return rotation
|
||||
}
|
||||
}
|
||||
|
||||
export default Rotation
|
||||
export default Rotation
|
@ -8,6 +8,8 @@ class config {
|
||||
static PORT: number = process.env.PORT ? parseInt(process.env.PORT) : 6969
|
||||
static JWT_SECRET: string = process.env.JWT_SECRET || 'secret'
|
||||
|
||||
static ALLOW_DIAGONAL_MOVEMENT: boolean = process.env.ALLOW_DIAGONAL_MOVEMENT === 'true'
|
||||
|
||||
static DEFAULT_CHARACTER_ZONE: number = parseInt(process.env.DEFAULT_CHARACTER_ZONE || '1')
|
||||
static DEFAULT_CHARACTER_X: number = parseInt(process.env.DEFAULT_CHARACTER_POS_X || '0')
|
||||
static DEFAULT_CHARACTER_Y: number = parseInt(process.env.DEFAULT_CHARACTER_POS_Y || '0')
|
||||
|
Reference in New Issue
Block a user