client/src/engine/Map/Map.ts

37 lines
1.0 KiB
TypeScript

import type IMap from '@/engine/Map/IMap';
import Player from '@/engine/Player/Player';
export default class Map implements IMap {
id: number;
name: string;
width: number;
height: number;
data: any;
players: Array<Player>|[];
constructor(id: number, name: string, width: number, height: number, data: any, players: Array<Player>|[]) {
this.id = id;
this.name = name;
this.width = width;
this.height = height;
this.data = data;
this.players = players;
}
public addPlayer(player: Player) {
// @ts-ignore
this.players.push(player);
}
public removePlayer(player: Player) {
this.players = this.players.filter(p => p.id !== player.id);
}
public movePlayer(player: Player, x: number, y: number) {
const playerIndex = this.players.findIndex(p => p.id === player.id);
if (playerIndex !== -1) {
this.players[playerIndex].coords.x = x;
this.players[playerIndex].coords.y = y;
}
}
}