This repository has been archived by the owner on Apr 20, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmain.py
62 lines (47 loc) · 1.71 KB
/
main.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import sys
from pathlib import Path
try:
import wclib
except ImportError:
# wclib may not be in the path because of the architecture
# of all the challenges and the fact that there are many
# way to run them (through the showcase, or on their own)
ROOT_FOLDER = Path(__file__).parent.parent.parent
sys.path.append(str(ROOT_FOLDER))
import wclib
# This line tells python how to handle the relative imports
# when you run this file directly.
__package__ = "02-particle-system." + Path(__file__).parent.name
# ---- Recommended: don't modify anything above this line ---- #
# Metadata about your submission
__author__ = "CozyFractal#0042" # Put yours!
__achievements__ = [ # Uncomment the ones you've done
# "Casual",
# "Ambitious",
# "Adventurous",
]
# To import the modules in yourname/, you need to use relative imports,
# otherwise your project will not be compatible with the showcase.
# noinspection PyPackages
from .objects import *
BACKGROUND = 0x0F1012
def mainloop():
pygame.init()
player = Player((SIZE[0] / 2, SIZE[1] / 2), (0, 0))
# The state is just a collection of all the objects in the game
state = State(player, FpsCounter(60), *Asteroid.generate_many())
while True:
screen, events = yield
for event in events:
if event.type == pygame.QUIT:
return
else:
state.handle_event(event)
# Note: the logic for collisions is in the Asteroids class.
# This may seem arbitrary, but the only collisions that we consider
# are with asteroids.
state.logic()
screen.fill(BACKGROUND)
state.draw(screen)
if __name__ == "__main__":
wclib.run(mainloop())