Ejemplo n.º 1
0
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))
Ejemplo n.º 2
0
from collections import defaultdict
import math

from copanzers.scripts import get_logger
L = get_logger ("Defender")

def main (tank, game):
    gun = tank.mounts [0]
    center = Vec2d (*map (lambda x: x / 2, game.size))

    tank.throttle = 1
    tank.rotation = (center - tank.position).angle

    start = game.time
    dt = (center - tank.position).length / tank.max_speed
    yield (lambda: start + dt <= game.time)
    tank.throttle = 0

    positions = defaultdict (list)
    dealtwith = set ()
    targets   = set ()

    width = max (tank.size)
    delta = gun.reload_time

    while 1:
        incoming = set (filter (lambda x: x ["Class"] == "Bullet", tank.visible))
        incoming.difference_update (dealtwith)

        for b in incoming:
            ps = positions [b]