File: simple_aimer.py

package info (click to toggle)
balder2d 1.0-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 12,552 kB
  • ctags: 1,226
  • sloc: cpp: 8,623; xml: 398; python: 364; ansic: 214; makefile: 79; sh: 9
file content (28 lines) | stat: -rw-r--r-- 798 bytes parent folder | download | duplicates (3)
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
import balder
from balderutil import entity
from balderutil import probe
import math
try:
  import psyco
except ImportError:
  # no psyco, so don't use it
  pass
else:
  psyco.full()

def DoProbeControl(probe_id, probe_dict, projectile_list, powerup_list):
    # don't try to do AI for non existant probes
    if not probe_id in probe_dict:
        return 0
    inputs = 0
    # first, lets find out where we are and where we are aiming]
    # aim for the closest probe
    target = entity.FindClosestProbe(probe_id, probe_dict)
    if not target in probe_dict:
        return 0
    xtarget = probe_dict[target]['x']
    ytarget = probe_dict[target]['y']
    inputs = probe.AimProbeAt(probe_dict[probe_id], xtarget, ytarget)
    if inputs == 0:
        inputs = balder.INPUT_FIRE
    return inputs