-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinvaders.py
executable file
·64 lines (51 loc) · 1.66 KB
/
invaders.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
63
64
#!env python
"""
This is the first of two starter files.
This is the one that you will run to start the program.
"""
import pyglet
class InvadersWindow(pyglet.window.Window):
"""
This class does all managing: it draws to the screen, and
updates all the bits and pieces flying around the screen!
Extends pyglet.window.Window, overwriting the on_draw method.
"""
def __init__(self):
"""
This sets everything up. Factoid: Init is short for 'initialise'.
We call up to pyglets Window init to do the heavy lifting,
specifying a width, height and caption (title).
"""
# Create pyglet window - the caption is the window title
pyglet.window.Window.__init__(
self,
caption="Invaders From Space!",
width=640,
height=480)
def on_draw(self):
"""
Overrides Window.on_draw.
"""
# First off we wipe the slate clean.
self.clear()
def update(self, elapsed_time):
"""
Perform frame-rate indepent updates of game objects.
"""
pass
def run_game():
"""
Creates an InvadersWindow, schedules the update function
and starts the main pyglet loop.
This is in a function so that we can run the game from a python
instance as well as in a script.
"""
# Make a new game window
game_window = InvadersWindow()
# Run the update function as close to 120 times a second as possible
pyglet.clock.schedule_interval(game_window.update, 1/120.0)
# And LOOP!
pyglet.app.run()
if __name__ == "__main__":
# This is triggered if being run as a script.
run_game()