Group Details Private

Best Forum Helpers

This group is for users who have assisted others by answering or helping with at least 5 situations. Eligible users may request to join the group.

  • Game AI for Flappy Bird (Difficulty: 2)

    Introduction


    Flappy Bird is a simple and fun game, where the player controls the bird to fly through a few obstacles to reach its nest. There is only one control: press the SPACE key to make the bird flap.

    In this tutorial, you will learn to build a simple AI program to control the bird instead of manually.

    Note that this AI will be based on programming logic, rather than large language models (LLMs). That is due to 3 reasons:

    • LLMs are too slow for such tasks: it usually takes a few seconds for LLMs to respond to each request, but we need to make the bird react and flap with a precision of milliseconds.
    • LLMs are too unpredictable: LLMs are inherently random, and it is often hard to control them to generate precisely the same output every single time. In contrast, programming logic is much more predictable and reliable.
    • LLMs are too expensive: It takes a lot of computation, and hence energy, to generate even a very simple output. To avoid such waste, when we can use programming logic to make a decision, we should do so.

    The same argument also applies in many other situations, and that’s why a significant portion of AI systems will continue to be implemented using programming logic.

    Now let’s get started with this simple AI program.


    Step 1 - Remix the Starter Project


    Open this link and remix the project:

    play.creaticode.com/projects/684dbd401c49cae4509533bd


    Step 2 - Read the Existing Code for “AI”


    In the “AI” sprite, there are 2 stacks of code.

    First, when the green flag is clicked, 3 parameters are set:

    • How many columns (green pipes) are placed before the nest.
    • The gravity for the bird’s falling speed;
    • How much the bird rises up on each flap.

    AI parameters

    Below that, when the “start” message is received, this AI program will simply send out the “flap” message every 0.3 seconds. Each “flap” message will make the bird flap once. This is the most basic AI program, which we will improve in the next few steps.

    Flap loop


    Step 3 - Adjust the Game Settings


    When you click the green flag, you will find that the bird will fall to the ground. The falling speed will depend on your computer, but it will look similar to this:

    Bird falls


    This is because the “gravity” and “flap strength” are not fine-tuned yet. As an exercise, please adjust these 2 values. In general, “gravity” should be a number between 0 and -2 (such as -0.5), and “flap strength” should be a number between 4 and 20. Your goal should be to make the bird fly horizontally with a nice waveform trail like this:

    Wave flight


     

     

    Step 4 - A Shorter Wait Interval

     

    Currently, in the forever loop, we send out the “flap” message every 0.3 seconds, and the bird will stay at the same height. Suppose we want the bird to fly higher, then we need to use a shorter interval.

    Instead of 0.3 seconds, let’s use an interval of 0.03 seconds. This may be necessary if the bird needs to rise up very quickly.

    Change delay

    As a result, when you run again, the bird should reach the ceiling very quickly and stay there:

    Bird at top

     
     

    Step 5 - Skip some flaps

     

    Obviously, the current AI always makes the bird fly too high. A simple solution is to skip some flaps, so the bird will do a free fall to reach nests that are below its level.

    In general, to make smart decisions, an AI needs relevant sensing data. In this case, to determine whether the bird needs to fall a bit, we can compare these 2 variables:

    • The bird’s Y position
    • The Y position of the nest

    Your AI can access these 2 values using these 2 reporter blocks:

    Y sensing
     

    Now, can you change the forever loop so that the bird would not flap if it is already above the nest?

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    Here is one way to do it: we put the broadcast block inside an “if-then” block, so only when the nest is above the bird would the bird make a flap:

    If nest is above

    Try to run the program a few times. The nest is placed at random heights, but the bird will almost always rise or fall to its level quickly:

    Bird matches nest

     
     

    Step 6 - Add a few columns

     

    Now let’s move on to the next challenge: make the bird fly through the columns (pipes). Change the “columns” variable to 4, which will add 4 columns:

    Set to 4 columns

    Obviously the bird will crash with the columns and fail. What can we do?

     
     

    Step 7 - Fly through all columns

     

    Similar to above, we need to provide data to the AI. Specifically, here are information about the columns:

    1. Each column has an opening at its center, and the Y positions of these openings are stored in the list named “columnYs”.
    2. The number of columns is given in the variable “columns”.
    3. The upcoming column has an index of “nextColumnIndex” in the list. For example, when the bird is facing the first column, nextColumnIndex is equal 1. After the bird flies through it, nextColumnIndex will automatically increase to 2.

    With these information, can you try to make the bird fly through all the columns? Don’t worry about the nest for now.

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    In fact, all that we need to do is to replace “nestY” with the Y position of the upcoming column:

    Use columnY

     

    The bird should have no problem flying through all columns:

    Success with pipes

     

     

    Step 8 - Fly to the nest after all the columns

     

    For our last step, we need to combine our solution for columns and the nest. When the bird has passed the last column, the nextColumnIndex will be more than the columns variable, and that’s when we should target the nest instead. Can you implement this change?

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    Here is an example solution:

    Switch to nest after pipes

    Here is the final demo:

    Final full run

     
     

    Extra Practices

     

    To practice what you have learned, here is an additional challenge for you.

    Currently, the bird would only start flapping if it is below the target height (of the nest or the center of the opening), so it might fall too much below the target. If the target is very low, then the bird might touch the ground before flying back up.

    Bird too low

    To ensure the bird is always safe, it should start to flap if it is too close to the ground (Y of -240).

    posted in Tutorials
  • RE: Scroll wheel should be use as zoom instead of scroll in Creaticode Create

    @the_true_odst left click is always used to highlight, left click is the primary function for your mouse (mouse button 1 in the system) and interacting with your costumes is your main intent, and right click is secondary (mouse button 2) so its for moving around wtih is a lesser but still big intent

    posted in Feedback
  • RE: Sneak Peak for my next game!

    (weapons have been switched from modern to futuristic.)

    a9954dd4-6926-4061-ab35-3d71cf29641c-Screen-recording-2025-06-12-7.04.01-PM.gif

    posted in Project Showcase
  • Catch the Cookies! - ChatGPT Scratch Challenge 1

    I was required to make a “catch the falling cookies game” (suggested by CHATGPT) in under 20 minutes (my goal). Here is the finished product:

    https://play.creaticode.com/projects/684b55c73d952dd83a793d22

    Tell me if you think I should continue on with this

    posted in Project Showcase
  • RE: Scroll wheel should be use as zoom instead of scroll in Creaticode Create

    @tyller_ Yeah I tried it and it works on both coding and costume editor. The only problem is is that left click highlights in costume editor and I feel like right click should do that while left click scrolls.

    posted in Feedback
  • RE: Scroll wheel should be use as zoom instead of scroll in Creaticode Create

    @info-creaticode Thats good to know! @The_True_Odst do you have anything to add?

    posted in Feedback
  • RE: Scroll wheel should be use as zoom instead of scroll in Creaticode Create

    @tyller_

    Currently, the playground already supports both:

    • Ctrl + Wheel: zoom in or out
    • Shift + Wheel: scroll left or right

    And these are the same for MIT Scratch.

    posted in Feedback
  • RE: Scroll wheel should be use as zoom instead of scroll in Creaticode Create

    @info-creaticode an idea is to have control + scroll or shift + scroll (dont remember if there’s any browser keybinds for control and scroll) zooms it, it would make navigation quicker without removing the original functionality

    posted in Feedback