- Overview
- Architectural Approach
- Level Manager Enhancements
- Level Data Structure
- Level Transition System
- Collectibles System
- Moving Platforms
- Level Completion Triggers
- Integration with Event System
- Implementation Plan
This document outlines the architectural approach for implementing the level system in WynIsBuff2. The goal is to create a flexible, data-driven level system that supports the 5 focused levels described in the MVP Level Design Guide, while enabling easy level transitions, collectibles, and completion triggers.
The level implementation will follow these key architectural principles:
- Data-Driven Design: Level layouts and properties will be defined in data structures, separating level design from implementation logic.
- Event-Based Communication: Level events (completion, collectibles, transitions) will use the existing Event System.
- Modular Components: Each level element (platforms, collectibles, triggers) will be implemented as modular components.
- Progressive Loading: Levels will be loaded and unloaded as needed to optimize performance.
- Visual Feedback: Clear visual cues will indicate level progression, collectibles, and completion.
The existing LevelManager class will be enhanced with the following capabilities:
// Load a specific level by ID
loadLevel(levelId);
// Transition to the next level
nextLevel();
// Reset the current level
resetLevel();
// Create collectibles for the current level
createCollectibles(collectibleConfigs);
// Create moving platforms
createMovingPlatforms(movingPlatformConfigs);
// Create level completion trigger
createLevelCompletionTrigger(triggerConfig);
// Check if all collectibles have been collected
areAllCollectiblesCollected();// Store the current level ID
currentLevelId;
// Store level configurations
levelConfigs;
// Track collectibles
collectibles;
// Track moving platforms
movingPlatforms;
// Track completion trigger
completionTrigger;Each level will be defined using a consistent data structure:
{
id: 'level1',
name: 'First Steps',
description: 'Learn basic movement and single jumps',
// Player starting position
playerStart: { x: 100, y: 600 },
// Ground configuration
ground: { width: 1024, height: 50, y: 700 },
// Static platforms
platforms: [
{ x: 200, y: 500, width: 200, height: 20, color: 0x00AA00 },
// More platforms...
],
// Moving platforms
movingPlatforms: [
{
x: 400, y: 300, width: 100, height: 20, color: 0xAA00AA,
movement: { type: 'horizontal', distance: 200, speed: 100 }
},
// More moving platforms...
],
// Collectibles
collectibles: [
{ x: 300, y: 450, type: 'protein', value: 10 },
// More collectibles...
],
// Level completion trigger
completionTrigger: {
x: 800, y: 200, width: 50, height: 50,
requireAllCollectibles: true
},
// Background elements
background: {
color: 0x87CEEB,
elements: [
{ type: 'image', key: 'gym_background', x: 512, y: 384, alpha: 0.5 }
]
},
// UI elements specific to this level
ui: {
instructionText: 'Use WASD to move and SPACE to jump!'
}
}The level transition system will handle smooth transitions between levels:
- Transition Trigger: When a player reaches the level completion trigger, a transition sequence begins.
- Transition Sequence:
- Fade out the current level
- Display level completion UI
- Load the next level data
- Initialize the next level
- Position the player at the start position
- Fade in the new level
- Level Persistence: The system will track which levels have been completed.
Collectibles will enhance the gameplay experience and provide additional objectives:
-
Types of Collectibles:
- Protein shakes (standard collectibles)
- Dumbbells (special collectibles with gameplay effects)
- Gym badges (achievement collectibles)
-
Collectible Behavior:
- Visual feedback on collection (particles, sound)
- Counter in UI showing collected/total
- Optional requirement for level completion
-
Implementation:
- Physics-based collision detection
- Event emission on collection
- Tracking via the LevelManager
Moving platforms will add dynamic elements to levels:
-
Movement Types:
- Horizontal (left-right)
- Vertical (up-down)
- Circular (around a point)
- Path-based (following a series of points)
-
Platform Properties:
- Movement distance
- Movement speed
- Pause duration at endpoints
-
Implementation:
- Physics-based movement using Rapier
- Kinematic bodies that can carry the player
- Smooth interpolation between positions
Level completion triggers will determine when a level is finished:
-
Trigger Types:
- Area trigger (player enters a specific area)
- Collection trigger (player collects all required items)
- Time trigger (player completes level within time limit)
-
Visual Representation:
- Clear visual indicator (flag, portal, etc.)
- Particle effects to draw attention
- Optional animation
-
Implementation:
- Physics-based collision detection
- Event emission on trigger
- Optional conditions (all collectibles, time limit)
The level system will integrate with the existing Event System using these events:
// Add to EventNames.js
LEVEL_LOAD: 'level:load',
LEVEL_LOADED: 'level:loaded',
LEVEL_RESET: 'level:reset',
LEVEL_COMPLETE: 'level:complete', // Already exists
COLLECTIBLE_COLLECTED: 'level:collectibleCollected',
COLLECTIBLE_EFFECT: 'level:collectibleEffect',
PLATFORM_MOVE: 'level:platformMove',
LEVEL_TRANSITION_START: 'level:transitionStart',
LEVEL_TRANSITION_COMPLETE: 'level:transitionComplete'The level implementation will be broken down into these steps:
-
Enhance LevelManager (1 day)
- Add support for level configurations
- Implement level loading/unloading
- Add methods for level transitions
-
Implement Collectibles (0.5 day)
- Create collectible objects
- Implement collection logic
- Add UI for tracking collectibles
-
Implement Moving Platforms (0.5 day)
- Create moving platform logic
- Implement different movement patterns
- Ensure proper physics interactions
-
Create Level Completion System (0.5 day)
- Implement completion triggers
- Create level transition effects
- Add completion UI
-
Design and Implement 5 Levels (1.5 days)
- Create level data for each level
- Test and refine each level
- Ensure proper progression
This implementation plan aligns with the 2-day estimate for Phase 2.2 in the Revised MVP Implementation Plan.