Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
y=ly, color=(200, 200, 200, 255))
self.tilesets_label.x = w
h = max(h, self.tilesets_label.content_height)
w += self.tilesets_label.content_width
self._width = (int(w) // self.TILE_SIZE) * self.TILE_SIZE + 8
if int(w) % self.TILE_SIZE: self._width += self.TILE_SIZE
self._height = h + 16 + self.TILE_SIZE * 8
# set up the background
bg = pyglet.image.SolidColorImagePattern((0, 0, 0, 200))
bg = pyglet.image.create(self._width, self._height, pattern=bg)
# set up the tiles
self.active_batch = self.tiles_batch = pyglet.graphics.Batch()
self.bg = pyglet.sprite.Sprite(bg, group=pyglet.graphics.OrderedGroup(0),
batch=self.active_batch)
self.tile_sprites = []
x = y = 4
for n, k in enumerate(self.tileset):
s = pyglet.sprite.Sprite(self.tileset[k].image, y=y, x=x,
batch=self.tiles_batch)
if not n:
self.current = s
s.tile_id = k
self.tile_sprites.append(s)
s.scale = self.TILE_SIZE / s.width
if not n % 8:
y = 4; x += self.TILE_SIZE
else:
y += self.TILE_SIZE
return get_feedback(lambda: pyglet.graphics.draw(self.n_vertices, GL_TRIANGLES, *data))
def init_load(self):
self.load_fraction = 0.0
self.load_batch = pyglet.graphics.Batch()
img = pyglet.resource.image('actors/a_train_in_spain/badge.png')
img.anchor_x = img.width/2
img.anchor_y = img.height/2
self.load_sprite = pyglet.sprite.Sprite(
img, x=self.width/2, y=self.height*0.7, batch=self.load_batch
)
img = pyglet.resource.image('actors/a_train_in_spain/train.png')
img.anchor_x = img.width
img.anchor_y = 0
self.crawler_sprite = pyglet.sprite.Sprite(img, x=0, y=self.height*0.12,
batch=self.load_batch)
img = pyglet.resource.image('ui/track.png')
img.anchor_x = img.width/2
img.anchor_y = img.height
for layer in data["layers"]:
# TODO: test this!
if layer['name'] in (self.tilelayers, self.objectgroups):
raise ValueError("Duplicated layer name %s" % layer["name"])
if layer["type"] == "tilelayer":
self.layers.append(TileLayer(layer, self))
self.tilelayers[layer["name"]] = self.layers[-1]
elif layer["type"] == "objectgroup":
self.layers.append(ObjectGroup(layer, self))
self.objectgroups[layer["name"]] = self.layers[-1]
else:
raise ValueError("unsupported layer type %s, skipping" % layer["type"])
self.batch = pyglet.graphics.Batch()
# viewport
self.x = 0
self.y = 0
self.w = 0
self.h = 0
# focus
self.fx = None
self.fy = None
# useful (size in pixels)
self.p_width = self.data["width"]*self.data["tilewidth"]
self.p_height = self.data["height"]*self.data["tileheight"]
# build a texture index converting pyglet indexing of the texture grid
self.normals = np.dot(self.normals, rotmat.T)
# for i, vertex in enumerate(self.vertices):
# self.vertices[i] = np.dot(rotmat, vertex) - self.start
# self.normals[i] = np.dot(rotmat, self.normals[i])
# Now for the indices let's generate triangle stuff
n = self.cloves * 2 + 2
# Draw each triangle in order to form the cylinder
a0 = np.array([0,1,2, 2,1,3]) # first two triangles
a = np.concatenate([a0 + 2*i for i in xrange(self.cloves)])
self.indices = a
n = self.cloves * 2 * 3
self.tri_vertex = self.vertices[a].flatten()
self.tri_normals = self.normals[a].flatten()
self.vertex_list = pyglet.graphics.vertex_list(n,
("v3f", self.tri_vertex),
("n3f", self.tri_normals),
("c3B", self.tri_color))
def __init__(self, **k):
pyglet.graphics.Batch.__init__(self)
Control.__init__(
self, x=0, y=0,
width=0, height=0, zindex=2,
**k
)
self.animations = []
def __init__(self, order):
super().__init__(order)
def set_state(self):
# Toggle smooth lines
gl.glEnable(gl.GL_POLYGON_SMOOTH)
gl.glEnable(gl.GL_BLEND)
def unset_state(self):
gl.glDisable(gl.GL_POLYGON_SMOOTH)
gl.glDisable(gl.GL_BLEND)
uiGroup = UIGroup(-1)
linesGroup = LinesGroup(0)
baseGroup = pyglet.graphics.OrderedGroup(1)
labelsGroup = pyglet.graphics.OrderedGroup(2)
class Line:
def __init__(self, batch):
self.id = batch.add_indexed(
4, gl.GL_TRIANGLES, linesGroup,
[0, 1, 2, 2, 3, 0],
('v2f', (0.0, 0.0,
0.0, 0.0,
0.0, 0.0,
0.0, 0.0)),
('c3B', (100, 100, 100) * 4)
)
def redraw(self, p1, p2):
angle = atan2(p2[1] - p1[1], p2[0] - p1[0])
def __hash__(self):
return hash(self.shader)
def __eq__(self, other):
return (
self.__class__ is other.__class__ and
self.shader == other.shader and
self.parent == other.parent
)
def __repr__(self):
return '%s(%d)' % (self.__class__.__name__, self.shader)
class ShaderUniformGroup(pyglet.graphics.Group):
def __init__(self, args, parent):
pyglet.graphics.Group.__init__(self, parent)
self.args = args
while parent and not isinstance(parent, ShaderGroup):
parent = parent.parent
if not parent:
raise Exception('Should be child group of ShaderGroup!')
self.shader = parent.shader
def set_state(self):
ua = self.shader.uniform
for k, v in self.args:
setattr(ua, k, v)
def on_draw():
pyglet.gl.glClearColor(240,240,240,255)
window.clear()
fps_display.draw()
# static attach points
pyglet.gl.glColor3f(1,0,1)
pyglet.gl.glPointSize(6)
a = []
for b in static_bs:
a += [b.position.x, b.position.y]
pyglet.graphics.draw(len(a)//2, pyglet.gl.GL_POINTS, ('v2f',a))
# web crossings / bodies
pyglet.gl.glColor3f(.8,.8,.8)
a = []
for b in bs:
a += [b.position.x, b.position.y]
pyglet.gl.glPointSize(4)
pyglet.graphics.draw(len(a)//2, pyglet.gl.GL_POINTS, ('v2f',a))
# web net / constraints
a = []
for j in space.constraints:
a += [j.a.position.x, j.a.position.y, j.b.position.x, j.b.position.y]
pass
y = s * t + c * y
mode = pyglet.gl.GL_TRIANGLE_STRIP
ps2 = [ps[0]]
for i in range(1, int(len(ps)+1/2)):
ps2.append(ps[i])
ps2.append(ps[-i])
ps = ps2
vs = []
for p in [ps[0]] + ps + [ps[-1]]:
vs += [p.x, p.y]
c = circle_center + Vec2d(radius, 0).rotated(angle)
cvs = [circle_center.x, circle_center.y, c.x, c.y]
bg = pyglet.graphics.OrderedGroup(0)
fg = pyglet.graphics.OrderedGroup(1)
l = len(vs)//2
self.batch.add(len(vs)//2, mode, bg,
('v2f', vs),
('c4B', fill_color.as_int()*l))
self.batch.add(2, pyglet.gl.GL_LINES, fg,
('v2f', cvs),
('c4B', outline_color.as_int()*2))