31 Commits

Author SHA1 Message Date
Pierre Wessman
581574fa1c Move goal-scored logic to behavior system with faceoff positioning
- Add isGoalScored flag to GameState for behavior tree decision-making
- Update SkaterBehavior to skate to center ice (0,0) when goal scored
- Update GoalieBehavior to return to center of goal when goal scored
- Remove update loop freeze from GameScene, now handled by behaviors
- Update CLAUDE.md with comprehensive subsystem documentation

All player logic now contained within the behavior system instead of
GameScene update loop, improving separation of concerns and making
post-goal behavior more realistic (players skate to faceoff positions).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-06 07:24:35 +02:00
Pierre Wessman
29885d1992 Add pause-aware goal reset timer with proper scene cleanup
- Add 3-second countdown timer after goal that resets the scene
- Timer pauses when game is paused, respecting pause state
- Freeze all game updates (puck, players, goals) during countdown
- Properly reset timer flags in create() to fix post-restart state
- Add safety checks in Player and Puck update to handle destroyed entities
- Remove player goal deceleration behavior (superseded by scene freeze)
- Add destroy() method to Player for proper resource cleanup
- Clean up goal event listeners before scene restart

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-04 16:12:21 +02:00
Pierre Wessman
ca6a444dec Add physics-based player detection with field-of-view filtering
Replace distance-based opponent detection with physics sensors and
angle filtering for more realistic spatial awareness. Players now
detect nearby opponents/teammates through Phaser overlap zones with
180° forward field-of-view.

Key changes:
- Add detection sensor to Player with physics overlap tracking
- Add NEAR_PLAYER_DETECTION_ANGLE constant for FOV filtering
- Refactor PuckCarrierBehavior to use physics-based detection
- Add debug visualization showing detection arc (wedge shape)
- Fix TypeScript unused variable errors for production build

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 14:03:26 +02:00
Pierre Wessman
c749308b49 Refactor THREAT_DETECTION_RADIUS to NEAR_PLAYER_DETECTION_RADIUS for general use
- Renamed constant to reflect general-purpose nature (can be used by any behavior, not just puck carriers)
- Moved detection circle rendering from PuckCarrierBehavior to Player class
- Detection circle now renders for all players in DEBUG mode, not just puck carriers
- Updated all references and comments to use new naming

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 13:25:33 +02:00
Pierre Wessman
1aa18376d5 Fix coordinate system to use rink center instead of canvas center
When the pause button was added below the rink, it increased the canvas
height (RINK_HEIGHT + UI_BOTTOM_PADDING). The coordinate conversion was
incorrectly using the full canvas center (including UI padding) instead
of just the rink center, causing y=0 to shift 30 pixels below the actual
center of the rink.

Now CoordinateUtils.gameToScreen/screenToGame correctly use RINK_WIDTH
for centerY calculation, ensuring y=0 is always at the rink center
regardless of UI elements.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 13:11:59 +02:00
Pierre Wessman
43ff271582 Add puck deceleration with drag and bounce reduction
Implemented ice friction physics for puck:
- Added PUCK_DRAG (200 px/s²) to simulate ice friction
- Reduced PUCK_BOUNCE from 1.0 to 0.6 for energy loss on collisions
- Puck now naturally decelerates when loose instead of bouncing forever

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 13:09:43 +02:00
Pierre Wessman
a8daedf53b Centralize player initialization to single addPlayer() method
Moved all player scene/physics setup from Player constructor to GameScene.addPlayer() to create a single source of truth for adding players. This prevents players from auto-rendering when instantiated and gives better control over when/how players are added to the scene.

Changes:
- Remove scene.add.existing() and physics setup from Player constructor
- Move physics body initialization to GameScene.addPlayer()
- Comment out second test player for single-player debugging

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 13:07:01 +02:00
Pierre Wessman
71082f713a Refactor player and goal collision handling using Phaser physics groups
- Add playerGroup for dynamic collision management between all players
- Add goalPostsGroup for centralized goal post collision handling
- Add addPlayer() and removePlayer() methods for runtime player management
- Reduce collision setup from 15+ lines to 2 group-based colliders
- Adjust threat detection radius from 8m to 4m for more realistic evasion

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 12:58:43 +02:00
Pierre Wessman
f26d8a3189 Add pause/resume button for match engine debugging
Implements a clickable pause button centered at the bottom of the screen that allows freezing and resuming the match engine. When paused, physics stops and the game loop exits early. Button changes color and text to indicate state (PAUSE/RESUME).

- Add UI_BOTTOM_PADDING constant and increase canvas height to show UI below rink
- Add pause state tracking and toggle functionality in GameScene
- Pause button positioned at bottom center with visual feedback

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 12:52:55 +02:00
Pierre Wessman
db16ec2a04 Add player collision with goal posts to prevent skating through goals
- Add physics colliders between all players and goal post structures
- Players now collide with left/right posts and back bars of both goals
- Prevents unrealistic behavior of skating through goal frames

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 14:41:53 +02:00
Pierre Wessman
2e2f065838 Implement skill-based puck reception with speed penalty mechanics
- Add handling attribute to PlayerAttributes (0-100 skill rating)
- Add puck reception constants: base chance, speed thresholds, check interval
- Replace instant pickup with skill-based reception probability calculation
- Reception chance factors: handling skill and puck speed
- Slow pucks (< 5 m/s) easy to receive, fast pucks (> 20 m/s) very difficult
- Add reception cooldown (100ms) to prevent spammy attempts
- Add comprehensive logging for reception success/failure with stats
- Adjust shooting logic: check shots before evasion, prevent behind-goal shots
- Add close-range shooting (≤3m) with wider angle threshold (120° vs 60°)
- Update Claude settings to simplified permission patterns

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 14:25:40 +02:00
Pierre Wessman
f342688143 Add randomized bounce angle and speed reduction for goal post collisions
When the puck hits a goal post, it now:
- Loses 30% of its speed (reduces to 70%)
- Bounces at a slightly randomized angle (±17 degrees variation)

This creates more realistic and unpredictable post bounces.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 14:21:20 +02:00
Pierre Wessman
1d257a5757 Add realistic tackle mechanics with approach angle and velocity modifiers
- Calculate approach angle between tackler velocity and target direction
- Apply angle-based modifiers: head-on (100%) > side (70%) > behind (40%) > opposite (20%)
- Calculate closing speed from relative velocity differential
- Apply velocity modifiers: weak <1 m/s (0.3x), solid >3 m/s (1.5x)
- Combine modifiers: finalSuccess = base × angleModifier × velocityModifier
- Enhanced debug logging shows all components of tackle calculation
- Head-on charges now much less effective (~15-30% vs previous ~50%)
- Rewards proper positioning, blindside hits, and high closing speeds

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 13:48:27 +02:00
Pierre Wessman
549ac400e0 Add minimum speed requirement for tackle execution
- Players must be moving at least 2 m/s to execute a tackle
- Add TACKLE_MIN_SPEED constant (2 m/s) in constants.ts
- Add Player.getCurrentSpeed() method to expose current speed
- Check tackler speed in executeTackle() before attempting tackle
- Log speed in tackle debug output for tuning

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 12:59:35 +02:00
Pierre Wessman
00d3a0a4ea Implement collision avoidance for puck carrier with debug visualization
- Add threat detection system that detects opponents within 3m radius
- Puck carrier automatically evades when opponent is in path to goal
- Evasion direction (left/right) persists while opponent in threat zone
- Fix behavior tree instantiation to reuse trees per player
- Add comprehensive debug visualization (magenta circle, threat indicators)
- Fix DefensiveBehavior type errors (carrierTeam -> possession)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 12:50:31 +02:00
Pierre Wessman
999003b012 Add player fall mechanic after successful tackles
When a player is successfully tackled, they now experience a realistic fall animation:
- Immediately decelerate to 0 velocity
- Stay down for 500ms (configurable via TACKLE_FALL_DURATION)
- Resume normal movement after recovery period

Changes:
- Added TACKLE_FALL_DURATION constant (500ms)
- Added fall state tracking to Player class (isFallen, fallRecoveryTime)
- Implemented fall() method to trigger the fall state
- Updated update() to handle fallen state and prevent movement during recovery
- Modified executeTackle() to call fall() instead of just reducing velocity

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 11:14:53 +02:00
Pierre Wessman
c81e500e18 Implement player tackling system with collision detection
Added a realistic tackling system where players can physically contest for the puck:
- Player-player collisions trigger tackle calculations based on tackling vs balance attributes
- Tackle success uses skill-based formula with configurable modifier
- Successful tackles can steal puck or knock it loose (60% chance)
- Cooldown system prevents rapid successive tackles (1s between attempts)
- Tackled players experience significant momentum loss on successful tackles

Also improved player movement physics:
- Added smooth acceleration/deceleration with ease-out curves
- Players now gradually build up speed (10 m/s²) and brake quickly (20 m/s²)
- More realistic stopping behavior when reaching target positions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 10:50:35 +02:00
Pierre Wessman
9e81619637 Implement defensive chase behavior and increase rotation speed
- Add defensive AI: players now chase puck carriers on opposing team
- Update DefensiveBehavior to check opponent possession and target puck position
- Increase player rotation speed from 3 to 10 rad/s for more responsive turning
- Update Claude settings permissions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 10:20:00 +02:00
Pierre Wessman
ff97b227c2 Add player enhancements and debug features
- Add away team defender (LD) for testing behaviors
- Add direction indicator (white line) showing player facing direction
- Initialize player facing angle based on team (home faces right, away faces left)
- Implement speed-based turning physics (faster = wider turns, rotation drops to 30% at max speed)
- Add debug visualizations for player targets (line and X marker) when DEBUG is true
- Increase rotation speed constant from 1 to 3 rad/s for more responsive turning

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 10:08:00 +02:00
Pierre Wessman
a3ffc94916 Restructure behavior tree for scalability
- Separate base behavior nodes into BehaviorNodes.ts (fixes circular dependency)
- Organize behaviors by role (goalie) and context (offensive/defensive/transition)
- Add modular behavior subtrees:
  - GoalieBehavior: Track puck position near net
  - SkaterBehavior: Route to context-specific behaviors
  - PuckCarrierBehavior: Shoot/carry logic (Phase 4)
  - OffensiveSupportBehavior: Placeholder for Phase 5
  - DefensiveBehavior: Placeholder for Phase 6
  - TransitionBehavior: Chase loose puck
- Maintain backward compatibility with static evaluatePlayer()

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 09:42:20 +02:00
Pierre Wessman
92a7b44ca9 puck diameter 2025-10-02 08:33:39 +02:00
Pierre Wessman
d17d5c594b centralised types 2025-10-02 08:29:43 +02:00
Pierre Wessman
30d7d95ccc review 2025-10-02 08:22:33 +02:00
Pierre Wessman
40d07ee68c ... 2025-10-02 08:11:21 +02:00
Pierre Wessman
8ec240333c player turning speed 2025-10-02 08:06:08 +02:00
3d15dc716b player 2025-10-01 14:54:58 +00:00
d2fb60df8d init player 2025-10-01 14:51:24 +00:00
93cb732110 goal events 2025-10-01 14:31:51 +00:00
30f2d99716 puck - circle body 2025-10-01 14:13:48 +00:00
1990d98aa2 puck 1 2025-10-01 14:12:40 +00:00
92b2d30d2b rink 2025-10-01 13:57:42 +00:00