diff --git a/src/entities/Player.ts b/src/entities/Player.ts index 15472e2..fd6f2a4 100644 --- a/src/entities/Player.ts +++ b/src/entities/Player.ts @@ -91,17 +91,8 @@ export class Player extends Phaser.GameObjects.Container { // Listen for goal events this.scene.events.on('goal', this.onGoal, this); - // Add to scene - scene.add.existing(this); - scene.physics.add.existing(this); - - this.body = this.body as Phaser.Physics.Arcade.Body; - - // Set physics body (circular, centered on container) - const radius = this.playerPosition === 'G' ? PLAYER_RADIUS_GOALIE : PLAYER_RADIUS_SKATER; - this.body.setCircle(radius); - this.body.setOffset(-radius, -radius); // Center the body on the container - this.body.setCollideWorldBounds(true); + // Note: Player must be added to scene via scene.add.existing(player) and scene.physics.add.existing(player) + // This is handled by GameScene.addPlayer() method, which also sets up the physics body this.createSprite(); diff --git a/src/game/GameScene.ts b/src/game/GameScene.ts index eadfad3..84c80d1 100644 --- a/src/game/GameScene.ts +++ b/src/game/GameScene.ts @@ -18,6 +18,8 @@ import { SHOT_SPEED, TACKLE_SUCCESS_MODIFIER, TACKLE_PUCK_LOOSE_CHANCE, + PLAYER_RADIUS_GOALIE, + PLAYER_RADIUS_SKATER, TACKLE_MIN_SPEED, TACKLE_ANGLE_HEAD_ON_THRESHOLD, TACKLE_ANGLE_SIDE_THRESHOLD, @@ -89,20 +91,20 @@ export class GameScene extends Phaser.Scene { { speed: 70, skill: 75, tackling: 70, balance: 75, handling: 80 } ); - // Create one away defender at (15, 0) - right side for defending - const awayDefender = new Player( - this, - 'away-LD', - 'away', - 'LD', - -15, - 0, - { speed: 80, skill: 70, tackling: 85, balance: 80, handling: 65 } - ); - // Add players to tracking array and physics group this.addPlayer(homeCenter); - this.addPlayer(awayDefender); + + // Commented out for testing single player + // const awayDefender = new Player( + // this, + // 'away-LD', + // 'away', + // 'LD', + // -15, + // 0, + // { speed: 80, skill: 70, tackling: 85, balance: 80, handling: 65 } + // ); + // this.addPlayer(awayDefender); // Setup player-player collisions for entire group this.physics.add.collider(this.playerGroup, this.playerGroup, (obj1, obj2) => { @@ -114,6 +116,18 @@ export class GameScene extends Phaser.Scene { * Add a player to the scene (can be called at any time for debugging) */ addPlayer(player: Player) { + // Add to scene and enable physics + this.add.existing(player); + this.physics.add.existing(player); + + // Setup physics body + player.body = player.body as Phaser.Physics.Arcade.Body; + const radius = player.playerPosition === 'G' ? PLAYER_RADIUS_GOALIE : PLAYER_RADIUS_SKATER; + player.body.setCircle(radius); + player.body.setOffset(-radius, -radius); + player.body.setCollideWorldBounds(true); + + // Add to tracking arrays and groups this.players.push(player); this.playerGroup.add(player); this.behaviorTrees.set(player.id, new BehaviorTree(player));