generated from technolyceum/rocker-launch-starter
Update main.py
This commit is contained in:
47
main.py
47
main.py
@@ -1,33 +1,44 @@
|
|||||||
# Import library code
|
# Import library code
|
||||||
from p5 import *
|
from p5 import *
|
||||||
from random import randint
|
|
||||||
|
|
||||||
# Set up global variables
|
# Set up global variables
|
||||||
screen_size = 400
|
screen_size = 400
|
||||||
|
rocket_y = screen_size - 100
|
||||||
|
rocket_img = None
|
||||||
|
planet_img = None
|
||||||
|
|
||||||
# The draw_rocket function goes here
|
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)
|
||||||
|
|
||||||
|
|
||||||
# The draw_background function goes here
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
# Set up your animation here
|
global rocket_img, planet_img
|
||||||
size(screen_size, screen_size)
|
size(screen_size, screen_size)
|
||||||
image_mode(CENTER)
|
image_mode(CENTER)
|
||||||
global planet
|
|
||||||
planet = load_image('planet.png')
|
# Load images
|
||||||
|
rocket_img = load_image('rocket.png')
|
||||||
|
planet_img = load_image('planet.png')
|
||||||
|
|
||||||
def draw():
|
def draw():
|
||||||
# Things to do in every frame
|
draw_background()
|
||||||
|
draw_rocket()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user