Add zone collision detection and garbage shooting functionality for enemies

- Introduced a new 'zone' object layer to detect when the player enters specific areas (e.g., "99Dungeon").
- Added logic to trigger actions when the player collides with these zones.
- Implemented garbage shooting mechanics for enemies, including:
  - A new `fireGarbage()` method that fires multiple projectiles in different directions.
  - A `createGarbageProjectile()` helper method to create and manage garbage projectiles.
  - Updated enemy behavior to use garbage shooting when enabled (`this.garbage`).
- Updated Tiled map configuration and JSON data to include new zone objects and properties.
This commit is contained in:
Brian Fertig 2025-07-26 23:05:24 -06:00
parent a91f6ad525
commit 0a0d987418
1 changed files with 18 additions and 1 deletions

View File

@ -50,11 +50,19 @@ export class Gulch extends Phaser.Scene {
const objectsLayer = gulchMap.createLayer('objects', gulchTiles, 0, 0)
.setCollisionByProperty({ collides: true });
const enemiesLayer = gulchMap.getObjectLayer('enemies');
const zoneLayer = gulchMap.getObjectLayer('zone');
// Add a player
this.player = new Player(this, 950, 3650);
this.player.healthBars(true, 1, 3);
zoneLayer.objects.forEach(object => {
if (object.name === '99Dungeon') {
const NNDungeon = this.add.rectangle(object.x, object.y, object.width, object.height);
this.NNDungeon = this.physics.add.existing(NNDungeon);
}
});
// Add Enemies
this.enemies = this.physics.add.group({
classType: NNBoy,
@ -87,6 +95,10 @@ export class Gulch extends Phaser.Scene {
if (prop.name === 'speed') {
a99Boy.speed = prop.value;
}
if (prop.name === 'garbage') {
a99Boy.garbage = prop.value;
a99Boy.reloadCalc = 5000;
}
});
}
});
@ -104,7 +116,12 @@ export class Gulch extends Phaser.Scene {
this.physics.add.collider(this.player, objectsLayer);
this.physics.add.collider(this.enemies, mainLayer);
this.physics.add.collider(this.enemies, objectsLayer);
this.physics.add.collider(this.player, this.enemies);
this.physics.add.collider(this.player, this.enemies, (player, enemy) => {
player.takeDamage();
});
this.physics.add.collider(this.player, this.NNDungeon, (player, zone) => {
console.log('Hit');
});
// Collision between bullets and enemies
this.physics.add.collider(this.bullets, this.enemies, (bullet, enemy) => {