Flizzy Burd ๐Ÿฆ is an exciting 2D platformer ๐ŸŽฎ where players take control of a brave little bird navigating through an endless world ๐ŸŒ filled with challenges. The bird must flap its wings ๐Ÿชฝ at the right time โฑ๏ธ to avoid obstacles ๐Ÿ”๏ธ and stay alive ๐Ÿ’ฅ.
๐ŸฆBird Script๐Ÿฆ
1. VARIABLES:
- myRigidbody: A reference to the birdโ€™s Rigidbody2D component (handles the bird's physics ๐Ÿงฒ, gravity ๐ŸŒ, and movement ๐Ÿƒโ€โ™‚๏ธ).
- flapStrength: The strength ๐Ÿ’ช of the bird's flap ๐Ÿฆ… (how high the bird flies when the spacebar is pressed โฌ†๏ธ).
- logic: A reference to the LogicScript ๐Ÿ“œ, which controls the gameโ€™s logic (like checking if the game is over ๐Ÿšจ).
- birdIsAlive: A boolean ๐Ÿ”˜ that tracks whether the bird is still alive ๐Ÿฆโค๏ธ or has crashed ๐Ÿชฆ.
2. START METHOD:
- Sets logic to the LogicScript (finds the object in the scene using the "Logic" tag ๐Ÿท๏ธ) so the bird can interact with the gameโ€™s logic (like game-over checks and scoring ๐ŸŽฏ).
3. UPDATE METHOD:
- Called every frame โฑ๏ธ to check if the player presses the spacebar (flap button ๐Ÿฆ…). If the bird is still alive (birdIsAlive is true ๐Ÿฆโœ…), it applies an upward force โฌ†๏ธ to the Rigidbody2D (making the bird "flap" ๐Ÿฆ๐Ÿ’จ).
- The flapStrength determines how high the bird will fly with each flap ๐ŸŒŸ.
4. ONCOLLISIONENTER2D METHOD:
- Triggered when the bird collides ๐Ÿ›‘ with another object (e.g., a pipe ๐Ÿ—๏ธ or obstacle ๐Ÿชต).
- When a collision happens, it calls the gameOver() method from the LogicScript ๐Ÿ•น๏ธ to end the game ๐Ÿ›‘ and sets birdIsAlive to false โŒ, stopping the bird's movement ๐Ÿฆ๐Ÿ’€.
IN SUMMARY:
The BirdScript makes the bird flap ๐Ÿฆ… when the player presses the spacebar โฌ†๏ธ. If the bird crashes ๐Ÿ›‘ into anything (like an obstacle ๐Ÿ—๏ธ), it triggers a game-over sequence ๐Ÿšจ, stopping the game ๐Ÿ›‘. It's a basic script for handling player input (flapping ๐Ÿฆ) and detecting collisions (game over ๐Ÿ’€).
Logic Script
WHAT IT DOES:
- This script manages the game logic for scoring ๐ŸŽฏ, restarting ๐Ÿ”„, and handling the game over ๐Ÿ’€ state in Flizzy Burd.
FEATURES:
- addScore(int scoreToAdd): Increases the player's score ๐Ÿ’ฏ by the given amount โž• and updates the score displayed on the screen ๐Ÿ–ฅ๏ธ.
- restartGame(): Reloads the current scene ๐Ÿ”„ to restart the game, giving the player a fresh start ๐ŸŒฑ.
- gameOver(): Displays the game over screen ๐Ÿ’” when the game is over ๐Ÿ›‘, signaling the end of the bird's journey ๐Ÿšถโ€โ™‚๏ธ๐Ÿ’จ.
- The script keeps track of the playerโ€™s score ๐ŸŽฏ, displays it in the UI ๐Ÿ–ฅ๏ธ, and provides functions to restart the game ๐Ÿ”„ or show a game over screen ๐Ÿ’€ when the birdโ€™s flight ends.
Pipe Middleย Script
WHAT IT DOES:
- This script manages the scoring logic ๐Ÿ† when the bird ๐Ÿฆ passes through the middle of a pipe ๐Ÿšง in Flizzy Burd. Here's what each part does:
- Start(): It finds the LogicScript attached to the game object tagged with "Logic" ๐Ÿ” and stores it in the logic variable ๐Ÿ“ฅ.
- OnTriggerEnter2D(Collider2D collision): This method checks when the bird ๐Ÿฆ passes through the middle of the pipe ๐Ÿšง (the "trigger" area).
- If the bird (on layer 3) ๐Ÿฆ collides with the pipe ๐Ÿšง, it calls the addScore(1) function from the LogicScript ๐ŸŽฏ, increasing the score by 1 โž•.
- This script ensures that the player earns points ๐ŸŽฏ whenever the bird ๐Ÿฆ successfully passes through a pipe ๐Ÿšง, adding to the challenge and excitement of Flizzy Burd!
Pipe Move Script
WHAT IT DOES:
This script handles the movement ๐Ÿƒโ€โ™‚๏ธ and deletion ๐Ÿ’ฅ of pipes ๐Ÿšง in Flizzy Burd. Here's what each part does:
- moveSpeed: Controls how fast the pipe ๐Ÿšง moves across the screen โฉ.
- deadZone: The X position ๐Ÿ—บ๏ธ at which the pipe ๐Ÿšง is destroyed ๐Ÿ’ฅ.
KEY ACTIONS:
Update():
- Moves the pipe ๐Ÿšง to the left across the screen โฌ…๏ธ at a speed determined by moveSpeed.
- If the pipe ๐Ÿšง moves past the deadZone (a specific X position), it gets destroyed ๐Ÿ’ฅ using Destroy(gameObject).
This script ensures the pipes ๐Ÿšง move across the screen and are deleted when they exit the visible area ๐ŸŒ, preventing them from cluttering the game world ๐ŸŒช๏ธ.
Pipe Spawn Script
WHAT IT DOES:
This script spawns pipes ๐Ÿšง in Flizzy Burd at regular intervals. Here's what each part does:
- pipe: The pipe ๐Ÿšง prefab that gets instantiated (spawned) in the game world.
- spawnRate: The time ๐Ÿ•’ between each pipe spawn. Default is 2 seconds.
- timer: Keeps track of the time passed and triggers a new spawn when it reaches spawnRate.
- heightOffset: Determines how far the pipes ๐ŸŽฎ can spawn from the origin point (higher or lower).
KEY ACTIONS:
Start():
- Calls the spawnPipe() function to spawn the first pipe ๐Ÿšง when the game starts ๐ŸŽฎ.
Update():
- Checks if the timer is less than the spawnRate. If true, it adds time ๐Ÿ•’ to the timer.
- If the timer exceeds the spawnRate, it calls spawnPipe() to spawn a new pipe ๐Ÿšง and resets the timer.
spawnPipe():
- Spawns a pipe ๐Ÿšง at a random Y position within a defined range (between lowestPoint and highestPoint).
- The pipe ๐ŸŽฎ will always spawn at the same X position but at different Y heights to create variety.
- This script ensures endless pipes ๐Ÿšง are spawned at regular intervals to keep the game fun and challenging ๐Ÿƒโ€โ™‚๏ธ๐ŸŽฏ.
Come take a look!
You can find this project and many more in my Github repositories!
Back to Top