enemy projectile

This commit is contained in:
Martin
2022-12-21 11:30:21 +01:00
parent 9158085b58
commit b8c40c4053
9 changed files with 534 additions and 192 deletions

View File

@@ -7,6 +7,7 @@ import { Gold } from "../Items/Gold/Gold";
import { HealthPotion } from "../Items/HealthPotion/HealthPotion";
import { ItemManager } from "../Items/ItemManager";
import { XP } from "../Items/XP/XP";
import { Projectile } from "../Projectile/Projectile";
import { Enemy } from "../Unit/Enemy/Enemy";
import { Player } from "../Unit/Player/Player";
@@ -27,6 +28,7 @@ export class PlayerCollisionSystem {
this.collisionTimer = new GameTimer(collisionDelay);
this.groupToResolver.set(GroupType.ENEMY, this.resolveEnemyContact.bind(this));
this.groupToResolver.set(GroupType.ENEMY_PROJECTILE, this.resolveEnemyProjectileContact.bind(this));
this.groupToResolver.set(GroupType.XP, this.resolveXpContact.bind(this));
this.groupToResolver.set(GroupType.GOLD, this.resolveGoldContact.bind(this));
this.groupToResolver.set(GroupType.HEALTH_POTION, this.resolveHealthPotionContact.bind(this));
@@ -75,6 +77,15 @@ export class PlayerCollisionSystem {
this.player.Health.damage(damage);
}
private resolveEnemyProjectileContact(enemyCollider: Collider2D): void {
const projectile = enemyCollider.node.getComponent(Projectile);
const damage: number = projectile.Damage;
projectile.pierce();
console.log("Collided with enemy projectile: Damage: " + damage);
this.player.Health.damage(damage);
}
private resolveXpContact(xpCollider: Collider2D): void {
console.log("Collided with XP");
this.itemManager.pickupXP(xpCollider.node.getComponent(XP));