-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhunter.py
More file actions
55 lines (45 loc) · 2.04 KB
/
hunter.py
File metadata and controls
55 lines (45 loc) · 2.04 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
import math, random, geom
from agent import Agent
from soldier import SoldierAgent
from vector import Vector
from entity import Entity
SHOOT_SPEED = 100
SHOOT_TEST_DIST = 150
SPEED = 0.1
class HunterAgent(Agent):
def __init__(self, loc):
self.maxBullets = 1
self.shootTimer = SHOOT_SPEED
self.wanderVector = Vector(random.randint(-3, 3), random.randint(-3, 3))
Agent.__init__(self, 7, loc)
def ai(self, level, player):
if not random.randint(0, 100):
for bId in Entity.bulletIds:
b = Entity.entities[bId]
if b.ownerId != self.ID and geom.circCircCollision(b.circle, (self.getX(), self.getY(), 100)) and self.onCollisionPath(b):
bangle = math.degrees(math.atan2(self.getY()- b.getY(), self.getX()- b.getX()))
self.setTurretAngle(bangle)
self.shoot(1)
break
self.randomWander()
playerAngle = math.degrees(math.atan2(self.getY()- player.getY(), self.getX()- player.getX()))
self.turnTo(playerAngle)
if self.shootTimer == 0:
if self.bulletsFired < self.maxBullets and self.safeToShoot(level, player, 50, bounces = 0):
self.shoot(1)
self.getRandShootTime(100, 150)
return
self.getRandShootTime(4, 7)
else:
self.shootTimer -= 1
def randomWander(self):
if self.velocity.length() == 0:
velocity = Vector(0.1,0.1)
final = self.velocity.getNorm()
final.mul(Vector(SoldierAgent.wanderDist, SoldierAgent.wanderDist))
self.wanderVector.add(Vector(random.randint(-3, 3), random.randint(-3, 3)))
self.wanderVector.norm()
self.wanderVector.mul(Vector(SoldierAgent.wanderRadius, SoldierAgent.wanderRadius))
self.velocity.add(final)
self.velocity.add(self.wanderVector)
self.velocity.trunc(SPEED)