This commit is contained in:
Martin
2022-11-16 12:26:20 +01:00
parent 3dd10f13ef
commit 0eb9cc907f
23 changed files with 1312 additions and 485 deletions

View File

@@ -3,6 +3,7 @@ import { GroupType } from "../GroupType";
import { Player } from "../Player/Player";
import { GameTimer } from "../../Services/GameTimer";
import { Enemy } from "../Enemy/Enemy";
import { XP } from "../XP/XP";
export class PlayerCollisionSystem {
private playerContacts: Collider2D[] = [];
@@ -20,6 +21,7 @@ export class PlayerCollisionSystem {
this.collisionTimer = new GameTimer(collisionDelay);
this.groupToResolver.set(GroupType.ENEMY, this.resolveEnemyContact.bind(this));
this.groupToResolver.set(GroupType.XP, this.resolveXpContact.bind(this));
}
public gameTick(deltaTime: number): void {
@@ -60,4 +62,12 @@ export class PlayerCollisionSystem {
console.log("Collided with enemy: Damage: " + damage);
this.player.Health.damage(damage);
}
private resolveXpContact(xpCollider: Collider2D): void {
const xp: XP = xpCollider.node.getComponent(XP);
this.player.addXp(xp.Value);
xp.pickup();
console.log("Collided with xp: " + xp);
}
}