Files
rocket-launch/main.py
2026-05-29 19:06:21 +00:00

45 lines
999 B
Python

# Import library code
from p5 import *
# Set up global variables
screen_size = 400
rocket_y = screen_size - 100
rocket_img = None
planet_img = None
def draw_rocket():
'''Draw the rocket at its current position'''
global rocket_y, rocket_img
if rocket_img:
# Draw rocket at current position
image(rocket_img, width / 2, rocket_y, 50, 50) # Width=50, Height=50
rocket_y = rocket_y - 5
if rocket_y < -50:
rocket_y = screen_size + 50
def draw_background():
'''Draw the space background with planet'''
background(0, 0, 0)
if planet_img:
# Draw planet at bottom center (size 150x150)
image(planet_img, width / 2, height - 50, 150, 150)
def setup():
global rocket_img, planet_img
size(screen_size, screen_size)
image_mode(CENTER)
# Load images
rocket_img = load_image('rocket.png')
planet_img = load_image('planet.png')
def draw():
draw_background()
draw_rocket()
run()