10. Game Progression & Mechanics

Defold Platformer Framework
# 10. Game Progression & Mechanics ## Introduction Game progression and mechanics are fundamental aspects that drive player engagement and provide a sense of accomplishment. In this section, we'll explore how to implement progression systems and core mechanics in the Defold Platformer Framework. ## Level Progression ### Level Structure The framework supports a sequential level progression system where players advance through increasingly challenging levels. Each level is defined as a separate collection in Defold. ```mermaid graph LR A[Main Menu] --> B[Level 1] B --> C[Level 2] C --> D[Level 3] D --> E[...] E --> F[Final Level] F --> G[End Game Screen] ``` ### Level Unlocking System Levels can be unlocked based on various conditions: 1. **Sequential Unlocking**: Complete the previous level to unlock the next 2. **Star-based Unlocking**: Collect a certain number of stars across levels 3. **Achievement-based Unlocking**: Complete specific challenges Example level unlocking implementation: ```lua function unlock_next_level(current_level) local next_level = current_level + 1 local max_levels = 10 if next_level <= max_levels then -- Save the unlocked level to player preferences save_game_progress("unlocked_level", next_level) return true else -- Player has completed all levels return false end end ``` ## Score and Reward Systems ### Point System The framework includes a flexible point system that can reward players for: - Collecting items - Defeating enemies - Completing levels quickly - Finding secrets The score calculation can be customized based on your game's specific needs: $$Score = basePoints + (collectibles \times collectibleValue) + (enemies \times enemyValue) + timeBonus$$ ### Star Rating Each level can have a 3-star rating system based on performance: ```mermaid graph TD A[Level Completion] --> B{Score Evaluation} B -->|Score >= 90%| C[3 Stars] B -->|Score >= 70%| D[2 Stars] B -->|Score >= 50%| E[1 Star] B -->|Score < 50%| F[0 Stars] ``` Implementation example: ```lua function calculate_stars(score, max_score) local percentage = (score / max_score) * 100 if percentage >= 90 then return 3 elseif percentage >= 70 then return 2 elseif percentage >= 50 then return 1 else return 0 end end ``` ## Player Progression ### Character Upgrades The framework supports character progression through upgrades: 1. **Health Upgrades**: Increase maximum health 2. **Speed Upgrades**: Enhance movement speed 3. **Jump Upgrades**: Improve jump height or enable double jump 4. **Special Abilities**: Unlock new abilities like wall jump, dash, etc. ### Skill Tree For more complex games, a skill tree can be implemented: ```mermaid graph TD A[Base Character] --> B[Double Jump] A --> C[Speed Boost] A --> D[Health+] B --> E[Triple Jump] B --> F[Wall Jump] C --> G[Dash] D --> H[Shield] ``` ## Game Mechanics ### Core Mechanics The framework includes several core mechanics: 1. **Movement**: Walking, running, and jumping 2. **Combat**: Basic attacks, special moves 3. **Interaction**: Buttons, levers, platforms 4. **Collection**: Items, power-ups, coins ### Physics-Based Mechanics Defold's physics engine enables various mechanics: - **Momentum-based jumps**: Jump height varies with speed - **Moving platforms**: Platforms that follow paths - **Swinging objects**: Ropes, vines, pendulums - **Bouncy surfaces**: Springs, trampolines Example physics parameters: ```lua -- Physics properties for the player local physics_properties = { gravity = -980, -- Gravity force (pixels/second²) jump_power = 500, -- Initial jump velocity max_velocity = 250, -- Maximum horizontal velocity ground_friction = 0.8, -- Friction when on ground air_friction = 0.95, -- Friction when in air acceleration = 2000 -- Movement acceleration } ``` ## Save System ### Progress Saving The framework includes a comprehensive save system to track: - Unlocked levels - Collected items and achievements - Player upgrades and abilities - High scores Example save data structure: ```json { "player": { "health_level": 2, "speed_level": 1, "jump_level": 3, "abilities": ["double_jump", "wall_slide"] }, "levels": { "unlocked": 5, "stars": [3, 2, 3, 1, 2, 0, 0, 0, 0, 0] }, "collectibles": { "coins": 347, "gems": 12, "secrets": ["secret1", "secret3", "secret4"] } } ``` ### Save Implementation ```lua function save_game_progress(data) local encoded_data = json.encode(data) sys.save(SAVE_FILE_PATH, encoded_data) end function load_game_progress() local saved_data = sys.load(SAVE_FILE_PATH) if saved_data then return json.decode(saved_data) else return create_default_save_data() end end ``` ## Difficulty Scaling ### Dynamic Difficulty The framework supports dynamic difficulty adjustment based on player performance: - Adjusting enemy spawn rates and patterns - Modifying platform distances - Changing timing windows for precision jumps - Altering collectible placement The difficulty can be calculated using: $$Difficulty = baseLevel + playerPerformanceFactor + levelProgressionFactor$$ Where: - `baseLevel` is the starting difficulty - `playerPerformanceFactor` adjusts based on deaths, time spent, etc. - `levelProgressionFactor` increases as players advance through levels ## Conclusion Implementing well-designed progression systems and game mechanics is crucial for creating an engaging platformer. The Defold Platformer Framework provides the foundation for these systems, but you should customize them to match your specific game design and player experience goals. In the next section, we'll explore how to implement advanced features and polish to elevate your platformer game.