Add KD stats and joystick deadzone

This commit is contained in:
schmelczerandras 2020-10-23 22:10:39 +02:00
parent c74b2f14a0
commit 1cd8f5fbe6
10 changed files with 123 additions and 44 deletions

View file

@ -95,12 +95,14 @@ export class PlayerCharacterPhysical
constructor(
name: string,
killCount: number,
deathCount: number,
public readonly colorIndex: number,
team: CharacterTeam,
private readonly container: PhysicalContainer,
startPosition: vec2,
) {
super(id(), name, colorIndex, team, settings.playerMaxHealth);
super(id(), name, killCount, deathCount, colorIndex, team, settings.playerMaxHealth);
this.head = new CirclePhysical(
vec2.add(vec2.create(), startPosition, PlayerCharacterPhysical.headOffset),
@ -133,7 +135,13 @@ export class PlayerCharacterPhysical
}
public calculateUpdates(): UpdateObjectMessage {
return new UpdateGameObjectMessage(this, ['head', 'leftFoot', 'rightFoot', 'health']);
return new UpdateGameObjectMessage(this, [
'head',
'leftFoot',
'rightFoot',
'health',
'killCount',
]);
}
public handleMovementAction(c: MoveActionCommand) {
@ -141,11 +149,16 @@ export class PlayerCharacterPhysical
}
public onCollision(other: GameObject) {
if (other instanceof ProjectilePhysical && other.team !== this.team) {
if (
other instanceof ProjectilePhysical &&
other.team !== this.team &&
other.isAlive
) {
other.destroy();
this.health -= other.strength;
if (this.health <= 0) {
this.destroy();
other.originator.killCount++;
}
}
}
@ -167,6 +180,7 @@ export class PlayerCharacterPhysical
strength,
this.team,
velocity,
this,
this.container,
);
this.container.addObject(projectile);

View file

@ -38,6 +38,7 @@ export class ProjectilePhysical
public strength: number,
public team: CharacterTeam,
private velocity: vec2,
public readonly originator: PlayerCharacterPhysical,
readonly container: PhysicalContainer,
) {
super(id(), center, radius, colorIndex, strength);
@ -46,6 +47,10 @@ export class ProjectilePhysical
this.moveOutsideOfObject();
}
public get isAlive(): boolean {
return !this.isDestroyed;
}
private moveOutsideOfObject() {
let wasCollision = true;
const delta = vec2.scale(

View file

@ -37,6 +37,9 @@ export class Player extends CommandReceiver {
private aspectRatio: number = 16 / 9;
private isActive = true;
private sumKills = 0;
private sumDeaths = 0;
private objectsPreviouslyInViewArea: Array<GameObject> = [];
private pingTime?: number;
@ -64,17 +67,20 @@ export class Player extends CommandReceiver {
};
private findEmptyPositionForPlayer(): vec2 {
let possibleCenter = this.players.find((p) => p.team === this.team)?.center;
let possibleCenter = this.players.find(
(p) => p.character?.isAlive && p.team === this.team,
)?.center;
if (!possibleCenter) {
possibleCenter = vec2.create();
}
let rotation = Math.atan2(possibleCenter.y, possibleCenter.x);
let radius = vec2.length(possibleCenter);
let rotation = 0;
let radius = 0;
for (;;) {
const playerPosition = vec2.fromValues(
radius * Math.cos(rotation),
radius * Math.sin(rotation),
radius * Math.cos(rotation) + possibleCenter.x,
radius * Math.sin(rotation) + possibleCenter.y,
);
const playerBoundingCircle = new Circle(
@ -121,6 +127,8 @@ export class Player extends CommandReceiver {
private createCharacter() {
this.character = new PlayerCharacterPhysical(
this.playerInfo.name.slice(0, 20),
this.sumKills,
this.sumDeaths,
this.colorIndex,
this.team,
this.objects,
@ -143,6 +151,9 @@ export class Player extends CommandReceiver {
this.center = this.character?.center;
if (!this.character.isAlive) {
this.sumDeaths++;
this.sumKills = this.character.killCount;
this.socket.emit(
TransportEvents.ServerToPlayer,
serialize(new PlayerDiedCommand(settings.playerDiedTimeout)),