From 0a0d9874181c28750924dfda36a39dbbc8a42e3d Mon Sep 17 00:00:00 2001 From: Brian Fertig Date: Sat, 26 Jul 2025 23:05:24 -0600 Subject: [PATCH] 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. --- src/scenes/gulch.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/scenes/gulch.js b/src/scenes/gulch.js index b15159c..53ea1a5 100644 --- a/src/scenes/gulch.js +++ b/src/scenes/gulch.js @@ -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) => {