-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek18.py
More file actions
45 lines (38 loc) · 1.17 KB
/
week18.py
File metadata and controls
45 lines (38 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Week 18: Game Jam Template (start screen + game over)
# Goal: pick one of your games and add:
# - Start screen
# - Gameplay
# - Game over screen
# - Restart (press R)
WIDTH = 700
HEIGHT = 500
state = "start" # "start" -> "play" -> "gameover"
score = 0
def start_game():
global state, score
state = "play"
score = 0
def end_game():
global state
state = "gameover"
def update():
if state != "play":
return
# TODO: put your game update logic here
pass
def draw():
screen.clear()
if state == "start":
screen.draw.text("MY GAME", center=(WIDTH//2, HEIGHT//2 - 40), fontsize=70)
screen.draw.text("Press SPACE to start", center=(WIDTH//2, HEIGHT//2 + 20), fontsize=40)
elif state == "play":
screen.draw.text(f"Score: {score}", (20, 20))
# TODO: draw your game here
else:
screen.draw.text("GAME OVER", center=(WIDTH//2, HEIGHT//2 - 40), fontsize=70)
screen.draw.text("Press R to restart", center=(WIDTH//2, HEIGHT//2 + 20), fontsize=40)
def on_key_down(key):
if key == keys.SPACE and state == "start":
start_game()
if key == keys.R and state == "gameover":
start_game()