-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo_tank.py
57 lines (41 loc) · 1.43 KB
/
demo_tank.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
# Copyright (C) 2014 Marvin Poul <ponder@creshal.de>
import math
from copanzers.scripts import get_logger
def destroy_target (w, target):
if w.till_reloaded <= 0:
w.shoot ()
return target.destroyed
def drive_circle (t, game, length):
start = game.time
while start + length > game.time:
t.rotation = (game.time - start) / length * math.pi * 2
yield (lambda: True)
def main (tank, game):
x, y = tank.position
tank.throttle = 1
tank.rotation = - math.pi / 2
yield (lambda: tank.position.y <= 50)
tank.rotation = 0
yield (lambda: tank.position.x >= 500)
tank.rotation = math.pi / 2
yield (lambda: tank.position.y >= 250)
tank.rotation = - 5/6 * math.pi
tank.throttle = 1
yield (lambda: tank.position.x <= x)
diff = y - tank.position.y
tank.rotation = math.pi / 2 * diff / abs (diff)
log = get_logger ("DemoTank")
log.info ("Imma driving a circle!")
tank.throttle = .5
yield from drive_circle (tank, game, 4)
tank.throttle = 0
tank.rotation = 0
log.info ("I'll be shooting everything in a radius of 200px.")
cannon = tank.mounts [0]
radar = tank.mounts [1]
for o in radar.visible:
d = o.position - tank.position
if abs (d) <= 200 and o != tank and o not in tank.mounts:
log.info ("Aiming at %s", o.e)
cannon.rotation = d.angle
yield (lambda: destroy_target(cannon, o))