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