-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
121 lines (115 loc) · 4.45 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
@namespace
class SpriteKind:
Segment = SpriteKind.create()
def on_up_pressed():
Head.set_velocity(0, -100)
Head.set_image(assets.image("""
Head0
"""))
controller.up.on_event(ControllerButtonEvent.PRESSED, on_up_pressed)
def on_left_pressed():
Head.set_velocity(-100, 0)
Head.set_image(assets.image("""
Head1
"""))
addSegment()
controller.left.on_event(ControllerButtonEvent.PRESSED, on_left_pressed)
def on_right_pressed():
Head.set_velocity(100, 0)
Head.set_image(assets.image("""
Head2
"""))
controller.right.on_event(ControllerButtonEvent.PRESSED, on_right_pressed)
def on_down_pressed():
Head.set_velocity(0, 100)
Head.set_image(assets.image("""
Head
"""))
controller.down.on_event(ControllerButtonEvent.PRESSED, on_down_pressed)
def on_on_destroyed(sprite):
game.game_over(False)
sprites.on_destroyed(SpriteKind.player, on_on_destroyed)
def addSegment():
global lastSegment, depth, newSegment
if len(segments) > 0:
lastSegment = segments[len(segments)]
else:
lastSegment = Head
depth += -1
newSegment = sprites.create(assets.image("""
segmentB
"""), SpriteKind.Segment)
newSegment.set_position(lastSegment.x, lastSegment.y)
newSegment.z = depth
animation.run_image_animation(newSegment,
[img("""
. . . . . . . f . . . . . . . .
. . . . . . . f . . . . . . . .
. . . e f f f f f f f e . . . .
. . e f 4 4 4 4 4 4 4 f e . . .
. . f 4 4 b b b b b 4 4 f . . .
. . f 4 b 8 8 8 8 8 b 4 f . . .
. . f 4 3 2 2 2 2 2 3 4 f . . .
. . f 9 8 8 a a a 8 8 9 f . . .
. . f 4 3 2 2 2 2 2 3 4 f . . .
. . f 4 b 8 8 8 8 8 b 4 f . . .
. . f 4 4 b b b b b 4 4 f . . .
. . e f 4 4 4 4 4 4 4 f e . . .
. . . e f f f f f f f e . . . .
. . . . . . . f . . . . . . . .
. . . . . . . f . . . . . . . .
. . . . . . . . . . . . . . . .
"""),
img("""
. . . . . f . . . . . . . . . .
. . . . . . f . . . . . . . . .
. . . e f f f f f f f e . . . .
. . e f 4 4 4 4 4 4 4 f e . . .
. . f 4 4 b b b b b 4 4 f . . .
. . f 4 b 8 8 8 8 8 b 4 f . . .
. . f 4 3 2 2 2 2 2 3 4 f . . .
. . f 9 8 8 a a a 8 8 9 f . . .
. . f 4 3 2 2 2 2 2 3 4 f . . .
. . f 4 b 8 8 8 8 8 b 4 f . . .
. . f 4 4 b b b b b 4 4 f . . .
. . e f 4 4 4 4 4 4 4 f e . . .
. . . e f f f f f f f e . . . .
. . . . . . f . . . . . . . . .
. . . . . f . . . . . . . . . .
. . . . . . . . . . . . . . . .
"""),
img("""
. . . . . . . . . f . . . . . .
. . . . . . . . f . . . . . . .
. . . e f f f f f f f e . . . .
. . e f 4 4 4 4 4 4 4 f e . . .
. . f 4 4 b b b b b 4 4 f . . .
. . f 4 b 8 8 8 8 8 b 4 f . . .
. . f 4 3 2 2 2 2 2 3 4 f . . .
. . f 9 8 8 a a a 8 8 9 f . . .
. . f 4 3 2 2 2 2 2 3 4 f . . .
. . f 4 b 8 8 8 8 8 b 4 f . . .
. . f 4 4 b b b b b 4 4 f . . .
. . e f 4 4 4 4 4 4 4 f e . . .
. . . e f f f f f f f e . . . .
. . . . . . . . f . . . . . . .
. . . . . . . . . f . . . . . .
. . . . . . . . . . . . . . . .
""")],
100,
True)
segments.append(newSegment)
newSegment: Sprite = None
lastSegment: Sprite = None
segments: List[Sprite] = []
Head: Sprite = None
depth = 0
depth = 100
scene.set_background_color(12)
Head = sprites.create(assets.image("""
Head0
"""), SpriteKind.player)
Head.set_position(80, 61)
Head.z = depth
Head.set_flag(SpriteFlag.AUTO_DESTROY, True)
segments = []