|
6 | 6 |
|
7 | 7 | # Setup global variables |
8 | 8 | screen_size = 400 |
9 | | -rocket_y = screen_size # start at the bottom |
10 | | -burn = 100 # how much fuel is burned in each frame |
| 9 | +rocket_y = 400 |
| 10 | +burn = 100 |
11 | 11 | orbit_radius = 250 |
12 | 12 | orbit_y = screen_size - orbit_radius |
13 | 13 |
|
| 14 | + |
14 | 15 | # The draw_rocket function goes here |
15 | 16 | def draw_rocket(): |
| 17 | + global rocket_y, fuel, burn |
16 | 18 |
|
17 | | - global rocket_y, fuel, burn |
18 | | - |
19 | | - if fuel >= burn and rocket_y > orbit_y: # still flying |
20 | | - rocket_y -= 1 # move the rocket |
21 | | - fuel -= burn # burn fuel |
22 | | - print('Fuel left: ', fuel) |
23 | | - |
24 | | - no_stroke() # Turn off the stroke |
25 | | - |
26 | | - for i in range(25): # draw 25 burning exhaust ellipses |
27 | | - fill(255, 255 - i*10, 0) # yellow |
28 | | - ellipse(width/2, rocket_y + i, 8, 3) # i increases each time the loop repeats |
| 19 | + if fuel >= burn and rocket_y > orbit_y: |
| 20 | + rocket_y -= 1 |
| 21 | + fuel -= burn |
| 22 | + print('Fuel left: ', fuel) |
| 23 | + |
| 24 | + no_stroke() |
| 25 | + |
| 26 | + for i in range(25): |
| 27 | + fill(255, 255 - i * 10, 0) |
| 28 | + ellipse(width/2, rocket_y + i, 8, 3) |
29 | 29 |
|
30 | | - fill(200, 200, 200, 100) # transparent grey |
31 | | - for i in range(20): # draw 20 random smoke ellipses |
32 | | - ellipse(width/2 + randint(-5, 5), rocket_y + randint(20, 50), randint(5, 10), randint(5, 10)) |
33 | | - |
34 | | - if fuel < burn and rocket_y > orbit_y: # No more fuel and not in orbit |
35 | | - tint(255, 0, 0) # Failure |
36 | | - elif fuel < 1000 and rocket_y <= orbit_y: |
37 | | - tint(0, 255, 0) # Success |
38 | | - elif fuel >= 1000 and rocket_y <= orbit_y: |
39 | | - tint(255, 200, 0) # Too much fuel |
40 | | - |
41 | | - image(rocket, width/2, rocket_y, 64, 64) |
42 | | - no_tint() |
43 | | - |
| 30 | + fill(200, 200, 200, 100) #Transparent grey |
| 31 | + for i in range(20): #Draw 20 random smoke ellipses |
| 32 | + ellipse(width/2 + randint(-5, 5), rocket_y + randint(20, 50), randint(5, 10), randint(5, 10)) |
| 33 | + |
| 34 | + if fuel < burn and rocket_y > orbit_y: |
| 35 | + tint(255, 0, 0) |
| 36 | + elif fuel < 1000 and rocket_y <= orbit_y: |
| 37 | + tint(0, 255, 0) |
| 38 | + elif fuel >= 1000 and rocket_y <= orbit_y: |
| 39 | + tint(255, 200, 0) |
| 40 | + |
| 41 | + image(rocket, width/2, rocket_y, 64, 64) |
| 42 | + no_tint() |
| 43 | + |
44 | 44 |
|
45 | 45 | # The draw_background function goes here |
46 | 46 | def draw_background(): |
47 | | - background(0) # short for background(0, 0, 0) - black |
48 | | - image(planet, width/2, height, 300, 300) # draw the image |
49 | | - |
50 | | - no_fill() # Turn off any fill |
51 | | - stroke(255) # Set a white stroke |
52 | | - stroke_weight(2) |
53 | | - ellipse(width/2, height, orbit_radius*2, orbit_radius*2) |
54 | | - |
| 47 | + background(0) |
| 48 | + image(planet, width/2, height, 300, 300) |
| 49 | + |
| 50 | + no_fill() |
| 51 | + stroke(255) |
| 52 | + stroke_weight(2) |
| 53 | + ellipse(width/2, height, orbit_radius * 2, orbit_radius * 2) |
55 | 54 |
|
56 | 55 | def setup(): |
57 | | - # Setup your animation here |
58 | | - size(screen_size, screen_size) |
59 | | - image_mode(CENTER) |
60 | | - global planet, rocket |
61 | | - planet = load_image('planet.png') # your chosen planet |
62 | | - rocket = load_image('rocket.png') |
| 56 | + # Setup your animation here |
| 57 | + size(screen_size, screen_size) |
| 58 | + image_mode(CENTER) |
| 59 | + global planet, rocket |
| 60 | + planet = load_image('planet.png') |
| 61 | + rocket = load_image('rocket.png') |
63 | 62 |
|
64 | 63 |
|
65 | 64 | def draw(): |
66 | | - # Things to do in every frame |
67 | | - draw_background() |
68 | | - draw_rocket() |
69 | | - |
| 65 | + # Things to do in every frame |
| 66 | + draw_background() |
| 67 | + draw_rocket() |
70 | 68 |
|
71 | 69 | fuel = int(input('How many kilograms of fuel do you want to use?')) |
72 | 70 | run() |
0 commit comments