-
Notifications
You must be signed in to change notification settings - Fork 0
/
rocketship.py
71 lines (56 loc) · 1.96 KB
/
rocketship.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
65
66
67
68
69
70
71
import math
class TurtleActor(object):
def __init__(self, *args, **kwargs):
self.__dict__['_actor'] = Actor(*args, **kwargs)
def __getattr__(self, attr):
if attr in self.__dict__:
return object.__getattribute__(self, attr)
else:
return getattr(self.__dict__['_actor'], attr)
def __setattr__(self, attr, value):
if attr in self.__dict__:
return object.__setattribute__(self, attr, value)
else:
return setattr(self._actor, attr, value)
def forward(self, distance):
the_angle = math.radians(self._actor.angle)
self._actor.x += distance * math.cos(the_angle)
# We subtract the y as our y gets bigger heading downward
self._actor.y -= distance * math.sin(the_angle)
def backward(self, distance):
self.forward(-distance)
def left(self, angle):
self._actor.angle += angle
def right(self, angle):
self._actor.angle -= angle
def draw():
#screen.fill((173, 216, 230))
screen.fill('lightblue')
rocketship.draw()
def forward(actor, distance):
the_angle = math.radians(actor.angle)
actor.x += distance * math.cos(the_angle)
# We subtract the y as our y gets bigger heading downward
actor.y -= distance * math.sin(the_angle)
def backward(actor, distance):
forward(actor, -distance)
def on_key_down(key):
if key == keys.SPACE:
rocketship.pos = rocketship.width / 2, rocketship.height / 2
rocketship.angle = 0
if key == keys.A:
rocketship.angle = -45
def update():
if keyboard[keys.LEFT]:
rocketship.left(10)
elif keyboard[keys.RIGHT]:
rocketship.right(10)
if keyboard[keys.UP]:
rocketship.forward(10)
elif keyboard[keys.DOWN]:
rocketship.backward(10)
rocketship = TurtleActor('rocketship')
rocketship.angle = 0
WIDTH = 600
HEIGHT = 600
trail = []