-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototype.py
More file actions
64 lines (48 loc) · 1.44 KB
/
prototype.py
File metadata and controls
64 lines (48 loc) · 1.44 KB
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
# coding: utf-8
"""
This file contains code that is to be revised and split in parts later.
Purely a playground.
"""
from math import sin, pi, cos
import pyglet
from pyglet.gl import GL_TRIANGLES, GL_POINTS
from world import World
__author__ = 'iljich'
class Drawer(object):
def tick(self, creeps):
for creep in creeps:
self.draw(creep)
self._draw_target(creep)
def draw(self, creep):
# creep is a triangle
x, y = creep.location
s = creep.size
r = creep.rotation
pyglet.graphics.draw(
3, GL_TRIANGLES,
('v2f',
(x + s * cos(r + 0), y + s * sin(r + 0),
x + s * cos(r + 4 * pi / 3), y + s * sin(r + 4 * pi / 3),
x + s * cos(r + 8 * pi / 3), y + s * sin(r + 8 * pi / 3))),
('c3B', creep.color * 3)
)
def _draw_target(self, creep):
pyglet.graphics.draw(
1, GL_POINTS,
('v2f', creep.target),
('c3B', creep.color)
)
window = pyglet.window.Window(1024, 768)
world = World()
drawer = Drawer()
world.spawn_creep([10, 10], 0.1, 40, (250, 25, 25))
world.spawn_creep([1000, 10], 2, 40, (25, 250, 25))
world.spawn_creep([10, 700], 6, 40, (25, 25, 250))
def update(dt):
window.clear()
for creep in world.creeps:
creep.move()
world.tick()
drawer.tick(world.creeps)
pyglet.clock.schedule_interval(update, 1/60.0)
pyglet.app.run()