1.8 SCRATCH - Nave Espacial
Game Development Basics: Creating a Space Shooter
Introduction to the Game Concept
- The game involves collecting stars while avoiding a ghost that can destroy the spaceship, leading to game over. The initial step is to remove the Scratch cat and find a rocket object in the library.
Setting Up the Rocket
- The rocket is resized to 40% and rotated 180 degrees so it faces right. It will be positioned on the left side of the screen, with controls set for vertical movement using keyboard arrows.
Programming Movement Controls
- The rocket's upward and downward movements are programmed using events, allowing it to move up when pressing the up arrow and down by 10 steps when pressing down. This establishes basic navigation for the player’s ship.
Adding Shooting Mechanics
- A new object (a ball) is introduced as ammunition, scaled down to 30%. The background is selected from space-themed options, enhancing visual appeal while programming shooting mechanics for this ball.
Implementing Bullet Behavior
- Bullets are programmed to appear at the rocket's position and move forward upon pressing spacebar. Cloning techniques are used for bullet creation, ensuring they disappear upon hitting screen edges or after traveling a certain distance.
Designing Collectible Stars
- Stars are drawn as five-pointed shapes filled with yellow color; their size is reduced by 30%. These stars will spawn on the right edge of the screen and move leftward across it, simulating lateral movement of objects in space.
Star Spawning Logic
- Stars are hidden initially and created at random intervals on starting conditions; they appear at specific coordinates before moving leftward until disappearing off-screen or reaching designated limits. Each star's behavior is controlled through cloning mechanisms as well.
Scoring System Implementation
- A scoring variable is established that increments each time the rocket touches a star; if contact occurs, both objects disappear from play while points accumulate based on interactions with collectibles throughout gameplay sessions. Initial score resets occur when starting anew with green flag activation.
Creating a Ghost Game in Scratch
Setting Up the Game Mechanics
- The game involves setting a timer for ghost appearances, with values ranging from 1 to 4 seconds. This controls how often ghosts appear on the screen.
- A ghost character is selected and resized appropriately. Adjustments are made to ensure the ghost faces the correct direction using a horizontal flip tool.
- Positioning of the ghost is defined within specific coordinates: X-axis limits are set between -254 and 263, while Y-axis values range from -140 to 136.
- The programming includes hiding the ghost at the start and creating clones that will appear randomly after waiting between 4 to 10 seconds.
- Movement logic is established for ghosts, which move left across the screen. If they collide with the player's spaceship, it results in a loss.
Collision Detection and Game Over Logic
- Programming checks if the spaceship touches a ghost; if so, it triggers a game over scenario where an explosion effect occurs.
- An event message labeled "destroy" is sent when collision happens, indicating that both visual effects (explosion animation) and gameplay consequences (game over) should occur simultaneously.
- Visual effects include removing propulsion from the spaceship and adding fire animations to simulate destruction effectively.
Enhancing Visual Effects
- Additional visual elements like flames are added around where the spaceship was destroyed to enhance realism during explosions.
- The explosion effect is designed simply yet effectively conveys that the spaceship has been destroyed each time it collides with a ghost.
Resetting Game State
- Upon starting or restarting, it's crucial to reset all elements including ensuring that sprites begin with their initial costumes before any interactions occur.
- When receiving a "destroy" message, different costume changes are programmed along with timed delays before transitioning back to hidden states for smooth gameplay flow.
Final Adjustments and Player Engagement
- A condition checks if ghosts go off-screen (X position < -250), ensuring they disappear properly without lingering on screen unnecessarily.
- Additional programming ensures that when destroying objects like spaceships or ghosts, all related actions cease immediately for clarity in gameplay mechanics.
- Players are encouraged to create their own versions of space games by modifying elements such as spaceships or enemies and adding features like lives or power-ups.