diff --git a/assets/proedge-enemies.png b/assets/proedge-enemies.png index 29168c9..8cc3265 100644 Binary files a/assets/proedge-enemies.png and b/assets/proedge-enemies.png differ diff --git a/assets/proedge.json b/assets/proedge.json new file mode 100644 index 0000000..e2282d1 --- /dev/null +++ b/assets/proedge.json @@ -0,0 +1,134 @@ +{ "compressionlevel":-1, + "height":9, + "infinite":false, + "layers":[ + { + "data":[1, 2, 3, 4, 5, 2684354612, 2684354612, 2684354602, 2147483653, 2147483652, 2147483653, 2147483652, 2147483651, 2147483650, 2147483650, 2147483649, + 11, 12, 13, 14, 13, 14, 13, 14, 13, 14, 13, 14, 13, 14, 2147483660, 2147483659, + 21, 22, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 2147483670, 2147483669, + 31, 32, 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 2147483680, 2147483679, + 42, 22, 24, 33, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 2147483670, 2147483690, + 42, 32, 24, 23, 24, 24, 24, 24, 24, 24, 24, 24, 3221225506, 3221225505, 3221225504, 3221225503, + 52, 22, 34, 33, 34, 34, 34, 34, 34, 34, 34, 34, 3221225496, 3221225495, 3221225494, 3221225493, + 52, 1610612748, 1073741838, 1073741837, 1073741838, 1073741837, 1073741838, 1073741837, 1073741838, 1073741837, 1073741838, 1073741837, 3221225486, 3221225485, 3221225484, 3221225483, + 62, 3221225477, 3221225476, 3221225475, 3221225474, 3221225477, 3221225476, 3221225475, 3221225474, 3221225477, 3221225474, 3221225477, 3221225476, 3221225475, 3221225474, 3221225473], + "height":9, + "id":1, + "name":"main", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":16, + "x":0, + "y":0 + }, + { + "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "height":9, + "id":2, + "name":"objects", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":16, + "x":0, + "y":0 + }, + { + "draworder":"topdown", + "id":3, + "name":"enemies", + "objects":[ + { + "gid":101, + "height":100, + "id":1, + "name":"", + "properties":[ + { + "name":"fire", + "type":"bool", + "value":true + }, + { + "name":"patrolX", + "type":"int", + "value":-700 + }], + "rotation":0, + "type":"", + "visible":true, + "width":100, + "x":1096, + "y":498 + }, + { + "gid":111, + "height":100, + "id":2, + "name":"", + "properties":[ + { + "name":"follow", + "type":"bool", + "value":true + }], + "rotation":0, + "type":"", + "visible":true, + "width":100, + "x":904, + "y":702 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + }], + "nextlayerid":4, + "nextobjectid":3, + "orientation":"orthogonal", + "renderorder":"right-down", + "tiledversion":"1.11.2", + "tileheight":100, + "tilesets":[ + { + "columns":10, + "firstgid":1, + "image":"proedge-tiles.png", + "imageheight":1000, + "imagewidth":1000, + "margin":0, + "name":"proedge-tiles", + "spacing":0, + "tilecount":100, + "tileheight":100, + "tilewidth":100 + }, + { + "columns":10, + "firstgid":101, + "image":"proedge-enemies.png", + "imageheight":1000, + "imagewidth":1000, + "margin":0, + "name":"proedge-enemies", + "spacing":0, + "tilecount":100, + "tileheight":100, + "tilewidth":100 + }], + "tilewidth":100, + "type":"map", + "version":"1.10", + "width":16 +} \ No newline at end of file diff --git a/raw/Tile-Project-Legends.tiled-session b/raw/Tile-Project-Legends.tiled-session index b6d24d4..7b2c8d5 100644 --- a/raw/Tile-Project-Legends.tiled-session +++ b/raw/Tile-Project-Legends.tiled-session @@ -15,9 +15,9 @@ }, "NNDungeon.tmx": { "expandedObjectLayers": [ + 5, 3, - 4, - 5 + 4 ], "scale": 0.5, "selectedLayer": 1, @@ -50,8 +50,8 @@ "scale": 0.25, "selectedLayer": 1, "viewCenter": { - "x": 4146, - "y": 4180 + "x": 2466, + "y": 4800 } }, "gulch.tmx#99boy-tiles": { @@ -86,7 +86,7 @@ ], "tileset.embedInMap": true, "tileset.tileSize": { - "height": 200, - "width": 200 + "height": 100, + "width": 100 } } diff --git a/raw/proedge-enemies.psd b/raw/proedge-enemies.psd index 8b5c598..c117563 100644 Binary files a/raw/proedge-enemies.psd and b/raw/proedge-enemies.psd differ diff --git a/raw/proedge.tmx b/raw/proedge.tmx new file mode 100644 index 0000000..811b1d6 --- /dev/null +++ b/raw/proedge.tmx @@ -0,0 +1,51 @@ + + + + + + + + + + + + + +1,2,3,4,5,2684354612,2684354612,2684354602,2147483653,2147483652,2147483653,2147483652,2147483651,2147483650,2147483650,2147483649, +11,12,13,14,13,14,13,14,13,14,13,14,13,14,2147483660,2147483659, +21,22,23,23,24,24,24,24,24,24,24,24,24,24,2147483670,2147483669, +31,32,33,33,34,34,34,34,34,34,34,34,34,34,2147483680,2147483679, +42,22,24,33,34,34,34,34,34,34,34,34,34,34,2147483670,2147483690, +42,32,24,23,24,24,24,24,24,24,24,24,3221225506,3221225505,3221225504,3221225503, +52,22,34,33,34,34,34,34,34,34,34,34,3221225496,3221225495,3221225494,3221225493, +52,1610612748,1073741838,1073741837,1073741838,1073741837,1073741838,1073741837,1073741838,1073741837,1073741838,1073741837,3221225486,3221225485,3221225484,3221225483, +62,3221225477,3221225476,3221225475,3221225474,3221225477,3221225476,3221225475,3221225474,3221225477,3221225474,3221225477,3221225476,3221225475,3221225474,3221225473 + + + + +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + + + + + + + + + + + + + + + diff --git a/src/characters/proEdge.js b/src/characters/proEdge.js new file mode 100644 index 0000000..e027fe8 --- /dev/null +++ b/src/characters/proEdge.js @@ -0,0 +1,385 @@ +export class ProEdgeEnemy extends Phaser.GameObjects.Sprite { + constructor(scene, x, y, texture, frame) { + super(scene, x, y, texture, frame); + + // Add the enemy to the scene + scene.add.existing(this); + + // Enable physics for the enemy (if using Arcade Physics) + scene.physics.world.enable(this); + + this.speed = 100; + this.isFollowing = false; + this.onPatrol = false; + this.leftBoundary = 0; + this.rightBoundary = 0; + this.topBoundary = 0; + this.bottomBoundary = 0; + + this.shoots = false; + this.shootTimer = 0; + this.scytheSpeed = 550; + this.fireballSpeed = 300; + this.exploding = false; + this.reloadVariance = 4000; + this.reloadCalc = 1000; + this.reload = 0; + this.bulletsGroup = scene.add.group(); + this.dropHeartOneIn = 3; + this.garbage = false; + this.onPause = false; + this.health = 1; + this.takingDamage = false; + this.boss = false; + this.follows = false; + + // Create animations + this.anims.create({ + key: 'walk99', + frames: this.anims.generateFrameNumbers(texture, { start: frame, end: frame+1 }), + frameRate: 5, + repeat: -1 + }); + } + + setPatrolX(leftBoundary, rightBoundary) { + this.onPatrol = true; + this.leftBoundary = leftBoundary; + this.rightBoundary = rightBoundary; + } + + setPatrolY(topBoundary, bottomBoundary) { + this.onPatrol = true; + this.topBoundary = topBoundary; + this.bottomBoundary = bottomBoundary; + } + + setSpeed(spd) { + this.speed = spd; + } + + // Example: Basic patrolling movement + patrol() { + if (this.onPause === true) { + return; + } + // Horizontal boundaries + if (this.leftBoundary !== 0) { + if (this.body.blocked.left || this.body.x <= this.leftBoundary) { + this.flipX = true; + this.body.setVelocityX(this.speed); + } else if (this.body.blocked.right || this.body.x >= this.rightBoundary) { + this.flipX = false; + this.body.setVelocityX(-this.speed); + } + } + + // Vertical boundaries + if (this.topBoundary !== 0) { + if (this.body.touching.up || this.body.y <= this.topBoundary) { + this.body.setVelocityY(this.speed); + } else if (this.body.touching.down || this.body.y >= this.bottomBoundary) { + this.body.setVelocityY(-this.speed); + } + } + + // Prevent falling off the platform + if (this.body.velocity.x === 0 && this.leftBoundary!== 0) { + this.body.setVelocityX(this.speed); + this.flipX = true; + } + if (this.body.velocity.y === 0 && this.bottomBoundary!== 0) { + this.body.setVelocityY(this.speed); + } + } + + // Example: Following the player + follow() { + const camera = this.scene.cameras.main; + + // Only follow if enemy is visible on screen + if (camera.worldView.contains(this.x, this.y)) { + this.isFollowing = true; + this.scene.physics.moveToObject(this, player, this.speed); + } else { + this.isFollowing = false; + this.body.setVelocity(0); + } + } + + // Example: Enemy taking damage + takeDamage() { + if (this.takingDamage === true) { + return; + } + + this.takingDamage = true; + + // Set takingDamage back to false after 2000ms + this.scene.time.delayedCall(500, () => { + this.takingDamage = false; + }); + + if (this.health === 1) { + if (this.boss === true) { + //BOSS DEFEAT + this.scene.game.globalState.addScore(100); + this.scene.interface.showScore(); + this.shoots = false; + this.garbage = false; + this.onPatrol = false; + this.anims.stop('walk99'); + this.onPause = true; + this.setTexture('boss-tiles', 2); + this.scene.tweens.add({ + targets: this, + scale: 1.5, + ease: 'Power1', + yoyo: true, + repeat: 2, + duration: 200, + onComplete: () => { + this.setTexture('boss-tiles', 3); + this.scene.tweens.add({ + targets: this, + ease: 'Power1', + scale: 1.1, + duration: 200, + onComplete: () => { + this.setTexture('boss-tiles', 4); + this.scene.tweens.add({ + targets: this, + ease: 'Power1', + scale: 0, + duration: 2000, + delay: 2000, + onComplete: () => { + this.destroy(); + } + }); + } + }); + } + }); + } else { + this.scene.game.globalState.addScore(25); + this.scene.interface.showScore(); + //REGULAR ENEMY DEFEAT + let dropHeart = Math.floor(Math.random() * this.dropHeartOneIn); + if (dropHeart === 1) { + let heart = this.scene.physics.add.image(this.x, this.y, 'heart-full').setScale(.5); + this.scene.hearts.add(heart); + this.scene.tweens.add({ + targets: heart, + scale: 0.8, + duration: 1000, + ease: 'Power1', + yoyo: true, + repeat: -1 + }); + } + // Create a tween that scales the enemy's body on Y-axis to 10 + let variance = Math.floor(Math.random() * 2); + this.scene.tweens.add({ + targets: this, + scaleY: .2, + duration: 200, // Duration of the animation in milliseconds + ease: 'Power1', + onComplete: () => { + // Destroy the enemy after the animation completes + this.destroy(); + } + }); + } + } else { + this.body.setVelocity(0, 0); + this.health --; + if (this.health === 2) { + this.shoots = true; + this.bottleReload = 1200; + this.speed += 200; + } + if (this.health === 1) { + this.bottleReload = 800; + this.speed += 200; + this.bottleReloadVariance = 1000; + } + if (this.boss === true) { + this.anims.stop('walk99'); + this.setTexture('boss-tiles', 2); + } + } + } + + fireBullet() { + // Fire the bottle + let variance = Math.floor(Math.random() * 2); + if (variance === 0) { + this.fireScythe(); + } else { + this.fireBalls(); + } + } + + fireScythe() { + const player = this.scene.player; + const scythe = this.scene.physics.add.sprite(this.x, this.y, 'proedge-enemies', 3); + scythe.setSize(75, 75); + this.scene.attacks.add(scythe); + const angle = Phaser.Math.Angle.Between(this.x, this.y, player.x, player.y); + scythe.setVelocity(Math.cos(angle) * this.scytheSpeed, Math.sin(angle) * this.scytheSpeed); + this.scene.physics.world.enable(scythe); + this.scene.sound.play('swoosh'); + this.scene.tweens.add({ + targets: scythe, + angle: 1080, + duration: 1500, + ease: 'Power1', + onComplete: () => { + scythe.destroy(); + } + }); + } + + fireBalls() { + // Get the player from the scene + const player = this.scene.player; + + // Fire three garbage projectiles with different angles + const baseAngle = Phaser.Math.Angle.Between(this.x, this.y, player.x, player.y); + + // Create and fire garbage at 0.5 radians less than the base angle + this.createFireballProjectile(baseAngle - 0.8); + + // Create and fire garbage at 0.5 radians more than the base angle + this.createFireballProjectile(baseAngle + 0.8); + } + + createFireballProjectile(angle) { + const player = this.scene.player; + const fireball = this.scene.physics.add.sprite(this.x, this.y, 'proedge-enemies', 2); + fireball.setSize(50, 50).setScale(.75); + this.scene.attacks.add(fireball); + fireball.setVelocity(Math.cos(angle) * this.scytheSpeed, Math.sin(angle) * this.scytheSpeed); + this.scene.physics.world.enable(fireball); + this.scene.tweens.add({ + targets: fireball, + angle: 720, + duration: 800, + ease: 'Power1', + onComplete: () => { + const baseAngle = Phaser.Math.Angle.Between(fireball.x, fireball.y, player.x, player.y); + fireball.setVelocity(Math.cos(baseAngle) * this.fireballSpeed, Math.sin(baseAngle) * this.fireballSpeed); + this.scene.tweens.add({ + targets: fireball, + angle: 720, + duration: 1500, + ease: 'Power1', + onComplete: () => { + fireball.destroy(); + } + }); + } + }); + } + + explode() { + const player = this.scene.player; + this.prepShot(); + this.scene.time.delayedCall(1000, () => { + const explosion = this.scene.physics.add.image(this.x, this.y, 'explosion'); + this.scene.explosions.add(explosion); + this.scene.physics.world.enable(explosion); + this.scene.tweens.add({ + targets: explosion, + angle: 120, + duration: 500, + ease: 'Power1', + alpha: .3, + scale: 3, + onComplete: () => { + explosion.destroy(); + } + }); + this.destroy(); + }); + + } + + prepShot() { + this.scene.time.delayedCall(500, () => { + if(!this.body) { + return; + } + this.onPause = true; + const originalVelocity = this.body.velocity.clone(); + this.body.setVelocity(0, 0); + + this.scene.time.delayedCall(500, () => { + if(!this.body) { + return; + } + this.body.setVelocity(originalVelocity.x, originalVelocity.y); + this.onPause = false; + }); + }); + this.scene.tweens.add({ + targets: this, + tint: 0xaaaaff, + duration: 1000, + repeat: 0, + yoyo: true, + ease: 'Power1' + }); + } + + // + update(time, delta) { + if (this.takingDamage === true) { + this.body.setVelocity(0, 0); + return; + } + + if (this.follows === true) { + const camera = this.scene.cameras.main; + if (camera.worldView.contains(this.x, this.y)) { + this.isFollowing = true; + if (Phaser.Math.Distance.Between(this.x, this.y, this.scene.player.x, this.scene.player.y) < 200 && this.exploding === false) { + this.exploding = true; + this.explode(); + } else { + this.scene.physics.moveToObject(this, this.scene.player, this.speed); + this.anims.play('walk99', true); + } + } else { + this.isFollowing = false; + this.body.setVelocity(0); + } + } + + if (this.onPatrol === true) { + this.patrol(); + this.anims.play('walk99', true); + } + + const camera = this.scene.cameras.main; + + if (this.shoots) { + if (camera.worldView.contains(this.x, this.y)) { + this.shootTimer += delta; + if (this.shootTimer >= this.reloadCalc) { + this.shootTimer = 0; + let variance = Math.floor(Math.random() * this.reloadVariance); + this.reloadCalc = this.reload + variance; + this.prepShot(); + this.scene.time.delayedCall(1000, () => { + if(!this.body) { + return; + } + this.fireBullet(); + }); + } + } + } + } +} \ No newline at end of file diff --git a/src/globalState.js b/src/globalState.js index 6c6e0e4..6c6b90c 100644 --- a/src/globalState.js +++ b/src/globalState.js @@ -10,6 +10,8 @@ export class GlobalState { startGulchY: 4250, startNNX: 2400, startNNY: 3350, + startProX: 350, + startProY: 250, }; } @@ -104,6 +106,22 @@ export class GlobalState { return this.playerData.startNNY; } + set startProX(value) { + this.playerData.startProX = value; + } + + get startProX() { + return this.playerData.startProX; + } + + set startProY(value) { + this.playerData.startProY = value; + } + + get startProY() { + return this.playerData.startProY; + } + // Add safe score increment method (replaces manual score updates) addScore(amount) { if (amount < 0) throw new Error("Cannot add negative score"); diff --git a/src/main.js b/src/main.js index ef2e459..32669ff 100644 --- a/src/main.js +++ b/src/main.js @@ -2,6 +2,7 @@ import { MenuScene } from './scenes/MenuScene.js'; import { Gulch } from './scenes/gulch.js'; import { NNDungeon } from './scenes/NNDungeon.js'; import { GlobalState } from './globalState.js'; +import { ProEdge } from './scenes/proedge.js'; const config = { type: Phaser.AUTO, @@ -25,6 +26,7 @@ const config = { MenuScene, Gulch, NNDungeon, + ProEdge, ] }; diff --git a/src/scenes/NNDungeon.js b/src/scenes/NNDungeon.js index 8fd9821..0287c27 100644 --- a/src/scenes/NNDungeon.js +++ b/src/scenes/NNDungeon.js @@ -44,11 +44,15 @@ export class NNDungeon extends Phaser.Scene { this.load.audio('dungeonMusic', 'assets/music/99Dungeon.mp3'); this.load.audio('gunShot', 'assets/sounds/gun-shot.mp3'); this.load.audio('axeThrow', 'assets/sounds/axe.mp3'); + this.load.audio('health-pickup', 'assets/sounds/health-pickup.mp3'); + this.load.audio('player-damage', 'assets/sounds/player-damage.mp3'); + // 99 Boy Sounds this.load.audio('99boy-defeat-0', 'assets/sounds/zombie-death-1.mp3'); this.load.audio('99boy-defeat-1', 'assets/sounds/zombie-death-2.mp3'); this.load.audio('99boy-defeat-2', 'assets/sounds/zombie-death-3.mp3'); - this.load.audio('health-pickup', 'assets/sounds/health-pickup.mp3'); - this.load.audio('player-damage', 'assets/sounds/player-damage.mp3'); + this.load.audio('crumple', 'assets/sounds/crumple.mp3'); + this.load.audio('glass-break', 'assets/sounds/glass-break.mp3'); + this.load.audio('swoosh', 'assets/sounds/swoosh.mp3'); } create() { @@ -213,7 +217,7 @@ export class NNDungeon extends Phaser.Scene { enemy.takeDamage(1); // Assuming your NNBoy class has a takeDamage function }); - this.physics.add.collider(this.axes, this.enemies, (axe, enemy) => { + this.physics.add.overlap(this.axes, this.enemies, (axe, enemy) => { // Handle collision here (e.g., damage the enemy or destroy the bullet) axe.destroy(); enemy.takeDamage(1); // Assuming your NNBoy class has a takeDamage function diff --git a/src/scenes/proedge.js b/src/scenes/proedge.js new file mode 100644 index 0000000..997f74a --- /dev/null +++ b/src/scenes/proedge.js @@ -0,0 +1,271 @@ +import { Player } from '../characters/player.js'; +import { ProEdgeEnemy } from '../characters/proEdge.js'; +//import { NNBoy } from '../characters/99boy.js'; +import { Interface } from '../interface.js'; + +export class ProEdge extends Phaser.Scene { + + constructor() { + super({ key: 'ProEdge' }); + + this.cameras; + this.player; + this.cursors = null; + this.wide = 1600; + this.tall = 900; + this.topBound = 1100; + this.leftBound = 800; + } + + preload() { + this.load.image('proedge-tiles', 'assets/proedge-tiles.png'); + this.load.image('heart-full', 'assets/heart-full.png'); + this.load.image('heart-empty', 'assets/heart-empty.png'); + this.load.image('heart-upgrade', 'assets/heart-upgrade.png'); + this.load.image('explosion', 'assets/explosion.png'); + this.load.tilemapTiledJSON('proedgeMap', 'assets/proedge.json'); + this.load.spritesheet('player-tiles', 'assets/player-tiles.png', { + frameWidth: 100, + frameHeight: 100 + }); + this.load.spritesheet('proedge-enemies', 'assets/proedge-enemies.png', { + frameWidth: 100, + frameHeight: 100 + }); + this.load.spritesheet('boss-tiles', 'assets/boss-tiles.png', { + frameWidth: 200, + frameHeight: 200 + }); + + this.load.audio('dungeonMusic', 'assets/music/99Dungeon.mp3'); + this.load.audio('gunShot', 'assets/sounds/gun-shot.mp3'); + this.load.audio('axeThrow', 'assets/sounds/axe.mp3'); + this.load.audio('health-pickup', 'assets/sounds/health-pickup.mp3'); + this.load.audio('player-damage', 'assets/sounds/player-damage.mp3'); + + // Enemy Sounds + this.load.audio('swoosh', 'assets/sounds/swoosh.mp3'); + } + + create() { + // Load the map and tileset + const proedgeMap = this.make.tilemap({ key: 'proedgeMap' }); + const proedgeTiles = proedgeMap.addTilesetImage('proedge-tiles', 'proedge-tiles'); + //const NNTiles = proedgeMap.addTilesetImage('99boy-tiles', '99boy-tiles'); + const mainLayer = proedgeMap.createLayer('main', proedgeTiles, 0, 0) + .setCollisionByProperty({ collides: true }); + //const objectsLayer = proedgeMap.createLayer('objects', dungeonTiles, 0, 0) + // .setCollisionByProperty({ collides: true }); + const enemiesLayer = proedgeMap.getObjectLayer('enemies'); + //const interactiveLayer = proedgeMap.getObjectLayer('interactive'); + //const zoneLayer = proedgeMap.getObjectLayer('zones'); + + // Show Score + this.interface = new Interface(this); + this.interface.showScore(); + + // Add a player + this.player = new Player(this, this.game.globalState.startProX, this.game.globalState.startProY); + //this.player = new Player(this, 3550, 350); + this.player.healthBars(true, 1, 3); + + // zoneLayer.objects.forEach(object => { + // if (object.name === 'gulchExit') { + // const Gulch = this.add.rectangle(object.x, object.y, object.width, object.height); + // this.Gulch = this.physics.add.existing(Gulch); + // } + // if (object.name === 'bossSave') { + // const bossSave = this.add.rectangle(object.x, object.y, object.width, object.height); + // this.bossSave = this.physics.add.existing(bossSave); + // } + // }); + + // Add Interactive + // this.interactive = this.physics.add.group(); + // interactiveLayer.objects.forEach(object => { + // if (object.gid) { + // let inter = this.interactive.create(object.x+50, object.y-50, '99Dungeon-tiles', object.gid-1); + // inter.properties = object.properties; + // } else { + // let inter = this.physics.add.existing(this.add.rectangle(object.x, object.y, object.width, object.height)); + // this.interactive.add(inter); + // if (object.properties) { + // inter.properties = object.properties; + // } + // } + // }); + + // Add Enemies + this.enemies = this.physics.add.group({ + classType: ProEdgeEnemy, + runChildUpdate: true + }); + enemiesLayer.objects.forEach(object => { + let aProEdge; + console.log(object.gid); + if (object.gid > 300) { + aProEdge = this.enemies.create(object.x-50, object.y-50, 'boss-tiles', object.gid-301); + } else { + aProEdge = this.enemies.create(object.x-50, object.y-50, 'proedge-enemies', object.gid-101); + } + if (object.properties) { + object.properties.forEach(prop => { + if (prop.name === 'patrolX') { + let to = object.x + prop.value; + if (to < object.x) { + aProEdge.setPatrolX(to, object.x); + } else { + aProEdge.setPatrolX(object.x, to); + } + } + if (prop.name === 'patrolY') { + let to = object.y + prop.value; + if (to < object.y) { + aProEdge.setPatrolY(to-100, object.y-100); + } else { + aProEdge.setPatrolY(object.y-100, to-100); + } + } + if (prop.name === 'follow' && prop.value === true) { + aProEdge.follows = true; + } + if (prop.name === 'fire') { + aProEdge.shoots = true; + aProEdge.bottleReload = prop.value; + } + if (prop.name === 'speed') { + aProEdge.speed = prop.value; + } + if (prop.name === 'garbage') { + aProEdge.garbage = prop.value; + } + if (prop.name === 'fastShot' && prop.value === true) { + aProEdge.bottleReload = 2000; + aProEdge.bottleReloadVariance = 500; + } + if (prop.name === 'NNBoss' && prop.value === true) { + aProEdge.boss = true; + } + if (prop.name === 'health') { + aProEdge.health = prop.value; + } + }); + } + }); + + // Create a group for bullets + this.bullets = this.physics.add.group(); + this.attacks = this.physics.add.group(); + this.explosions = this.physics.add.group(); + this.axes = this.physics.add.group(); + this.hearts = this.physics.add.group(); + + // Input + this.cursors = this.input.keyboard.createCursorKeys(); + + this.physics.add.collider(this.player, mainLayer); + // 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.interactive, touchInteractive); + this.physics.add.collider(this.player, this.enemies, (player, enemy) => { + player.takeDamage(); + }); + // this.physics.add.collider(this.player, this.Gulch, (player, zone) => { + // this.game.globalState.startNNX = 2400; + // this.game.globalState.startNNY = 3350; + // this.bgMusic.stop(); + // this.scene.start('Gulch'); + // }); + // this.physics.add.collider(this.player, this.bossSave, (player, zone) => { + // this.game.globalState.startNNX = 2350; + // this.game.globalState.startNNY = 550; + // }); + + // function touchInteractive(player, interactive) { + // interactive.properties.forEach(prop => { + // if (prop.name === 'key' && prop.value === true) { + // player.addItemToInventory('key'); + // interactive.destroy(); + // } + // if (prop.name === 'lock' && prop.value === true) { + // if (player.hasItem('key')) { + // player.removeItemFromInventory('key'); + // let checkTiles = objectsLayer.getTilesWithin(interactive.x/100-5, interactive.y/100-5, 15, 15); + // checkTiles.forEach(frameTile => { + // if (frameTile.properties.lockedDoor === true) { + // objectsLayer.removeTileAt(frameTile.x, frameTile.y); + // } + // interactive.destroy(); + // }); + // } + // } + // }); + // }; + + // Collision between bullets and enemies + this.physics.add.collider(this.bullets, this.enemies, (bullet, enemy) => { + bullet.destroy(); + enemy.takeDamage(1); + }); + + this.physics.add.overlap(this.axes, this.enemies, (axe, enemy) => { + axe.destroy(); + enemy.takeDamage(1); + }); + + this.physics.add.collider(this.player, this.attacks, (player, attack) => { + player.takeDamage(attack); + attack.destroy(); + }); + + this.physics.add.collider(this.player, this.explosions, (player, attack) => { + player.takeDamage(attack); + }); + + this.physics.add.collider(this.player, this.hearts, (player, heart) => { + player.addHealth(1); + heart.destroy(); + }); + + // Add level heart upgrade + // if (this.game.globalState.hasInventory('99-heart') === 0) { + // this.upgrade = this.physics.add.image(5600, 500, 'heart-upgrade').setScale(0.2); + // this.physics.add.collider(this.player, this.upgrade, (player, upgrade) => { + // this.game.globalState.addToInventory('99-heart', 1); + // this.player.maxHearts ++; + // this.player.numHearts ++; + // this.game.globalState.maxHearts = this.player.maxHearts; + // this.game.globalState.hearts = this.player.numHearts; + // this.player.updateHealth(); + // upgrade.destroy(); + // }); + // } + + //this.cameras.main.setScroll(800, 1100); + this.cameras.main.setBounds(1600, 2700, 1600, 900); + + // Background Music + this.bgMusic = this.sound.add('dungeonMusic', { volume: 0.5 }); + this.bgMusic.loop = true; + this.bgMusic.play(); + } + + update(time, delta) { + this.player.update(); + + const onBounds = this.cameras.main.getBounds(); + if (this.player.body.y <= onBounds.y) { + this.cameras.main.setBounds(onBounds.x, onBounds.y-900, 1600, 900); + } + if (this.player.body.y >= onBounds.y+900) { + this.cameras.main.setBounds(onBounds.x, onBounds.y+900, 1600, 900); + } + if (this.player.body.x <= onBounds.x) { + this.cameras.main.setBounds(onBounds.x-1600, onBounds.y, 1600, 900); + } + if (this.player.body.x >= onBounds.x+1600) { + this.cameras.main.setBounds(onBounds.x+1600, onBounds.y, 1600, 900); + } + } +} \ No newline at end of file