Yellow Fish Code Breakdown:

Underwater Shark Game – Project Explanation
This is a fun Scratch-style chasing game where a shark follows the mouse and eats spawning fish to increase the score. Below is a clear, structured explanation of how your project works.
Sprites in Your Project
You used 3 main elements:
-
Stage – Underwater background
-
Yellow Fish – Food that keeps spawning
-
Shark 011 – Player-controlled shark
Yellow Fish – Code Explanation
🟢 When Green Flag Clicked (Main Script)
-
Set Score = 0
-
Hide the original fish
-
Set size to 30%
-
Start a forever loop
Inside the loop:
-
Go to x: -230 (left side of screen)
-
Set y to random (-180 to 180) → fish spawns at random heights
-
Create a clone
-
Wait 1 second
-
Switch costume (adds animation effect)
Result: A new fish appears every second from random positions on the left side.
When I Start as a Clone
Each clone:
-
Becomes visible
-
Points in direction 90° (right)
-
Sets rotation style to left-right
-
Enters a forever loop
Inside that loop:
-
Turn random (-10 to 10 degrees) → makes movement natural
-
Move 5 steps
-
Bounce if on edge
-
Check collision with Shark
When Fish Touches Shark
If touching Shark 011:
-
Increase Score by 1
-
Play "Chomp" sound
-
Broadcast message "Food"
-
Hide (fish disappears)
This creates the “eating” effect.
Shark 011 – Code Explanation
When Green Flag Clicked
-
Switch costume to "Shark 13"
-
Set size to 100%
-
Enter a forever loop
Inside loop:
-
Point toward mouse pointer
-
Set rotation style to left-right
-
If distance to mouse > 10:
-
Move 10 steps toward mouse
-
Result: Shark smoothly follows your cursor.
When I Receive "Food"
This is the eating animation.
Repeat 3 times:
-
Switch to costume "Shark 08"
-
Wait 0.1 seconds
-
Switch to costume "Shark 12"
-
Wait 0.1 seconds
-
Change color effect by 25
After loop:
-
Clear graphic effects
This creates:
-
Mouth opening & closing animation
-
Flashing effect
-
Visual feedback of eating
How Everything Works Together
-
Fish continuously spawn from the left.
-
Shark follows the mouse.
-
When shark touches a fish:
-
Score increases
-
Fish disappears
-
Shark performs eating animation
-
-
Game runs endlessly.
Game Logic Summary
| Element | Function |
|---|---|
| Fish | Spawns, moves randomly, detects collision |
| Shark | Follows mouse, plays animation |
| Broadcast "Food" | Connects fish collision to shark animation |
| Score Variable | Tracks points |
Why This Is a Good Game Design
Possible Improvements
You can upgrade the game by adding:
-
Timer (Game Over after 60 seconds)
-
Lives system
-
Enemy fish that reduce score
-
Background ocean sound
-
High score saving
-
Speed increase over time
-
Bubble particle effects


Comments
Post a Comment