-
Notifications
You must be signed in to change notification settings - Fork 0
/
move.py
executable file
·189 lines (145 loc) · 4.91 KB
/
move.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/python
import os
import glob
import math
import random
import rabbyt
import pyglet
pyglet.resource.path = [
".",
"art",
"alpha",
"shapes",
"bosses",
"bullets",
"costumes",
"backgrounds",
]
pyglet.resource.reindex()
from pyglet.gl import *
from fshelper import *
from playersprite import PlayerSprite
from factories import ParaFactory
from shots import Shot1, Shot2
from const import *
random.seed(0)
# Modify this scheduled method to pause, probably.
# Put it inside MainWindow and have it run off of MainWindow's time.
pyglet.clock.schedule(rabbyt.add_time)
class MainWindow(pyglet.window.Window):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.viewport = FixedResolutionViewport(
self, WIDTH, HEIGHT,
filtered=FILTERED
)
self.set_mouse_visible(False)
self.sprite = PlayerSprite()
self.sprite.xyf = (WIDTH/4, HEIGHT/2)
#PlayerSprite.truncate(self.sprite)
self.sprite.truncate_coords()
self.fps_display = pyglet.clock.ClockDisplay()
#self.factory = ParaFactory(
# lambda t: 10*t,
# lambda t: 0,
# self.sprite,
# 2,
# #16
# 64
#)
self.text_colorf = (0.50, 0.50, 0.50, 0.75)
self.text_colori = ( 128, 128, 128, 224)
self.bg = pyglet.resource.image("bg.png")
self.time = 0
self.collisions = 0
self.coll_ctr = pyglet.text.Label(
anchor_x="right",
anchor_y="bottom",
halign="right",
font_name=None,
x=WIDTH - 10,
y=5,
bold=True,
font_size=24,
color=self.text_colori
)
self.fps_display.label.color = self.text_colorf
#self.fps_display.label.color = self.text_colori
pyglet.clock.schedule_interval(self.update_coll_ctr, 0.10)
def update(self, dt):
self.time += dt
self.sprite.update(dt)
self.detect_collisions()
def update_coll_ctr(self, dt):
self.coll_ctr.text = "%i" % self.collisions
def detect_collisions(self):
collisions = rabbyt.collisions.collide_single(
self.sprite,
self.sprite.bullets()
)
self.collisions += len(collisions)
#self.update_coll_ctr()
def on_draw(self):
if self.scale_needed(): self.viewport.begin()
rabbyt.clear()
self.reset_color_hack()
self.bg.blit(0, 0, 0)
self.sprite.render()
for shot in self.sprite.shots:
for factory in shot.factories:
rabbyt.render_unsorted(factory.bullets)
self.fps_display.label.draw()
self.coll_ctr.draw()
if self.scale_needed(): self.viewport.end()
def reset_color_hack(self):
glColor3f(1.0, 1.0, 1.0)
def scale_needed(self):
return not (self.width == WIDTH and self.height == HEIGHT)
def on_key_press(self, symbol, modifiers):
from pyglet.window import key
# Simple value toggles
if symbol == key.F:
self.set_fullscreen(not self.fullscreen)
elif symbol == key.V:
self.set_vsync(not self.vsync)
elif symbol == key.ESCAPE:
self.close()
elif symbol == key.UP: self.sprite.go_up()
elif symbol == key.LEFT: self.sprite.go_left()
elif symbol == key.DOWN: self.sprite.go_down()
elif symbol == key.RIGHT: self.sprite.go_right()
elif symbol == key.A: self.sprite.try_shot1()
elif symbol == key.S: self.sprite.try_shot2()
def on_key_release(self, symbol, modifiers):
from pyglet.window import key
if symbol == key.UP: self.sprite.stop_up()
elif symbol == key.LEFT: self.sprite.stop_left()
elif symbol == key.DOWN: self.sprite.stop_down()
elif symbol == key.RIGHT: self.sprite.stop_right()
elif symbol == key.A: self.sprite.stop_shot1()
elif symbol == key.S: self.sprite.stop_shot2()
def main():
window_w = WIDTH
window_h = HEIGHT
#window_w = 1280
#window_h = 720
#window_w = 1024
#window_h = 576
#window_w = 800
#window_h = 450
window = MainWindow(width=window_w, height=window_h, vsync=False)
#window = MainWindow(vsync=False, fullscreen=True)
window.set_caption(
"moving magic!"
)
rabbyt.set_default_attribs()
#window.push_handlers(pyglet.window.event.WindowEventLogger())
#pyglet.clock.schedule_interval(window.update, 1.0/70.0)
#pyglet.clock.schedule_interval(window.update, 1.0/4.0)
#pyglet.clock.schedule_interval(window.update, 1.0/60.0)
pyglet.clock.schedule(window.update)
#pyglet.clock.schedule_interval(window.update, 4.0)
#pyglet.clock.schedule_interval(window.update, 1.0/120)
#window.update(0)
pyglet.app.run()
main()