Update gameplay

This commit is contained in:
schmelczerandras 2020-10-23 15:19:04 +02:00
parent 49c410d8ff
commit 23fa7646d6
10 changed files with 165 additions and 33 deletions

View file

@ -17,10 +17,11 @@ import {
Circle,
PlayerInformation,
CharacterTeam,
UpdatePlanetOwnershipCommand,
UpdateGameState,
GameObject,
Command,
UpdateObjectMessage,
OtherPlayerDirection,
} from 'shared';
import { getTimeInMilliseconds } from '../helper/get-time-in-milliseconds';
import { BoundingBox } from '../physics/bounding-boxes/bounding-box';
@ -189,14 +190,46 @@ export class Player extends CommandReceiver {
);
this.sendToPlayer(
new UpdatePlanetOwnershipCommand(
new UpdateGameState(
PlanetPhysical.declaPlanetCount,
PlanetPhysical.redPlanetCount,
PlanetPhysical.neutralPlanetCount,
this.getOtherPlayers(),
),
);
}
private getOtherPlayers(): Array<OtherPlayerDirection> {
if (!this.character) {
return [];
}
const viewArea = calculateViewArea(this.center, this.aspectRatio, 0.9);
const bb = new BoundingBox();
bb.topLeft = viewArea.topLeft;
bb.size = viewArea.size;
const playersInViewArea = this.objects
.findIntersecting(bb)
.map((o) => o.gameObject)
.filter((g) => g instanceof PlayerCharacterPhysical);
const otherPlayers = this.players.filter(
(p) => playersInViewArea.indexOf(p.character!) < 0,
);
return otherPlayers.map(
(p) =>
new OtherPlayerDirection(
vec2.normalize(
vec2.create(),
vec2.subtract(vec2.create(), p.center, this.character!.center),
),
p.team,
),
);
}
private sendToPlayer(command: Command) {
this.socket.emit(TransportEvents.ServerToPlayer, serialize(command));
}