Geometry Dash #2 | Platform Collisions | Scratch Tutorial
How to Recreate Geometry Dash in Scratch - Part 2
Introduction to Multi-Level Platforming
- Griffpatch introduces the second part of the series, focusing on multi-level platforming and enhancing player mechanics.
- Emphasizes the importance of saving a backup copy of the project before making changes, ensuring safety against mistakes.
Adding Platforms to the Level
- Begins by adding platforms represented as a grid of black squares within the Level sprite.
- Details how to create a new costume for platforms with specific color settings (black fill and white outline for collision detection).
- Explains using selection tools and keyboard shortcuts (alt + shift) for duplicating shapes efficiently, allowing rapid construction of large platforms.
Testing Platform Integration
- After creating platforms, tests them in-game but finds that jumping code does not recognize them yet.
- Stops the project to prepare for implementing gravity and collision detection in jumping mechanics.
Implementing Jumping & Gravity Mechanics
- Discusses deleting old jumping scripts to introduce gravity simulation; creates a variable named "speed y" for tracking vertical movement.
- Sets initial upward speed and applies downward force over time to simulate realistic jump arcs, adjusting values based on game physics.
Collision Detection with Platforms
- Describes testing jump functionality but realizes an error in initiating jumps; correct sequence involves setting "speed y" first.
- Introduces collision detection logic using color checks (white for solid surfaces), enabling player interaction with platforms.
Finalizing Player Movement Dynamics
- Implements a loop that moves the player upwards until they are no longer colliding with white, refining control after collisions.
Fixing Collision Issues in Scratch
Addressing Player Animation During Collisions
- The player character dips below the ground during gameplay, which is undesirable. The screen refreshes every time a loop occurs, causing visible animation issues.
Implementing "Run Without Screen Refresh"
- A new block named "Move Out of Level" is created under My Blocks, allowing code execution without refreshing the screen. This helps prevent unwanted animations during collisions.
Testing Gravity and Collision Mechanics
- After implementing the new block, testing shows that there are no overlaps or rising effects when jumping; everything appears instantaneously due to single screen refresh.
Game Loop Adjustments for Gravity
- The script is modified to reset the player's speed to 0 at game start and introduces a Repeat Until loop that checks for collision with spikes instead of using a wait until block.
Enhancing Code Clarity with Custom Blocks
- A custom block called "Player Movement" is created to keep code organized and readable. It runs without screen refresh for smooth gameplay mechanics.
Reintroducing Jump Mechanics
Conditions for Jumping
- Players should only be able to jump when touching the ground. An IF check is added after detecting floor collision to allow jumping when the space key or mouse button is pressed.
Making Gameplay Mobile-Friendly
- To accommodate mobile users, an additional check for mouse down events is included, enabling jumps via touch input as well as keyboard input.
Testing New Jump Functionality
- Upon testing, players can now bounce off floors and platforms effectively. However, challenges arise with avoiding spikes due to new gravity mechanics making it more difficult.
Handling Ceiling Collisions
Identifying Ceiling Collision Issues
- When jumping into platforms from below, players currently pass through them instead of colliding properly. This issue arises from upward movement not being handled correctly in collision detection.
Modifying Collision Logic
- The existing downward collision handling code needs adjustment. An IF ELSE structure will differentiate between upward and downward movements during collisions.
Reusing Existing Code Efficiently
Collision Handling in Game Development
Progress on Ground Collisions
- Ground collisions are functioning correctly, preventing players from bouncing through surfaces and instead sending them back to the ground.
- The team is making significant progress, but issues remain with face-on collisions.
Identifying Collision Types
- Differentiating between wall, ceiling, and floor collisions can be complex; it often depends on the player's movement into the collision.
- The "Speed y" variable is crucial for determining collision types: if a player can move out of a collision within their previous speed range, it's a platform collision; otherwise, it's a wall collision leading to game over.
Addressing Level Design Issues
- Hand-drawn levels may have alignment issues that cause unintended collisions, resulting in game over scenarios. This necessitates adjustments to avoid frustrating gameplay experiences.
- A proposed solution involves widening the safe zone by 4 pixels above and below to accommodate minor misalignments in level design. This adjustment aims to enhance player experience by reducing frustration during gameplay.
Coding Adjustments for Collision Detection
- To implement the safe zone adjustment, start by modifying the "Move out of Level" block to include an additional 4-pixel buffer when detecting collisions. This involves changing y values accordingly within a loop structure.
- Utilize the absolute value function ("abs") to handle both positive and negative speed values effectively during calculations for distance covered in collisions. This ensures accurate detection regardless of directionality in movement.
Finalizing Game Over Logic
- Implement checks within loops to determine when players are no longer touching designated colors (e.g., white) indicating they are out of collision zones; if not detected within set iterations, trigger game over conditions.
- Ensure that upon triggering game over events, players do not end up slightly sunk into floors by duplicating necessary scripts for consistency across different states of play (e.g., normal vs game over). Broadcast messages will signal these events appropriately throughout the game's logic flow.
Testing and Debugging Gameplay Mechanics
- After implementing changes, testing reveals that while most mechanics work well (e.g., floor/platform interactions), there are still issues with player movement synchronization during game overs due to script execution order changes made earlier in development processes. Adjustments need to be made here as well for optimal performance post-collision detection events.
Future Developments and Enhancements