Rocket Landing Simulator

Gate Check #2 - Basic Animation
Go Back to the Assignment Description

Part 1 (Overview) - Part 2 (Boat Animation) - Part 3 (Rocket Animation) - Part 4 (Thrusters)

Let's Move the Rocket!

The next thing we are going to do is implement the "Boost" phase of the rocket. That's a really complicated way to say "we're going to make the rocket go up and turn to the right."

In order to better understand what we are trying to accomplish, here is a picture that outlines the major steps in the "Boost" phase:

At the start of the simulation, our rocket is sitting at rest on the ground. It then begins to take off (Step 1, Above) and continues to accelerate using its thrusters until it is at some preprogrammed height (e.g., Step 2 - 1/2 the screen height). Once this happens, the rocket begins thrusting to the right until it is over the water (Step 3). Finally (Step 4), the rocket stops boosting and starts falling to the ground.

From this basic description, we can infer that we need some variables. What do you think we need variables for?

In addition to the above, we also need to make some slight modifications to our initialize_rocket() function, and add code to our update_rocket() function. Let's tackle each of these problems separately!

Step 1: Update initialize_rocket()

This step is easy! All we need to do in this function is set our boosting variable (i.e., the variable that determines if the rocket is boosting) to True.

You might be wondering to yourself: "Why are we setting this variable to True when we already did it in the previous section?!?"

Step 2: Implement update_rocket()

In this function, we are going to implement the update_rocket() function so that it launches the rocket into the air. The first thing we need to do is to add some code that modifies the rocket's velocities based on which thrusters are firing. Use the following logic design to achieve this.

def update_rocket():
    global 
    
    # Updating Rocket Position
    1.  rocket x coordinate = rocket x coordinate + rocket's x velocity
    2.  rocket y coordinate = rocket y coordinate + rocket's y velocity

If you were to press play, nothing would happen! This is because the rocket's initial velocities in both the x and y-direction were initialized to 0. In order to change the velocity, we are going to use the thruster variables that we created earlier in this section. Specifically, we are going to:

Use the following logic design to accomplish the above steps:

def update_rocket():
    global 
    
    # (NEW!!!) Updating Velocity
    1.  rocket's y velocity = rocket's y velocity - up thruster amount + gravity
    2.  rocket's x velocity = rocket's x velocity + right thruster amount
    3.  rocket's x velocity = rocket's x velocity + left thruster amount
        
    # (OLD) Updating Rocket Position
    1.  rocket x coordinate = rocket x coordinate + rocket's x velocity
    2.  rocket y coordinate = rocket y coordinate + rocket's y velocity

NOW, if you were to press play, the rocket would sadly fall through the Earth (if it doesn't, make sure you remember that +y is DOWN in pythonGraph). This is normal! The rocket thrusters are never fired by your code, so the up, left, and right thruster values are all equal to 0.0. To make the rocket actually Boost, we need to include some logic that lets the rocket take off on its own!

Here is the final logic design for update_rocket():

def update_rocket():
    global 
    
    # (NEW) Boost Phase
    1.  if boosting = True:                               <--------- Your variable may have a different name
        1a.  Set up, right, and left thruster amounts to 0.0
        2a.  If the rocket is not halfway up the screen:
                 - set up thruster to 0.35                
             else:
                 - set right thruster amount fo 0.25      
        3a.  If the rocket is over the water
                 - boosting = false
    
    # (OLD) Updating Velocity
    1.  rocket's y velocity = rocket's y velocity + up thruster amount + gravity
    2.  rocket's x velocity = rocket's x velocity + right thruster amount
    3.  rocket's x velocity = rocket's x velocity + left thruster amount
    
    # (OLD) Updating Rocket Position
    1.  rocket x coordinate = rocket x coordinate + rocket's x velocity
    2.  rocket y coordinate = rocket y coordinate + rocket's y velocity

Testing

Once you have completed this phase, you should see the rocket boosting and flying off the screen. It should look something like this:

It is okay if the rocket goes off the top of the screen. Assuming that you see this, you are free to move onto the next page.

Proceed to the next section.