-
Notifications
You must be signed in to change notification settings - Fork 0
/
convoy.py
75 lines (60 loc) · 2.31 KB
/
convoy.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import pymunk
import math
import masks
import utils
import weapons
from direct.actor.Actor import Actor
from enum import Enum, auto
class State(Enum):
IDLE = auto()
RUN_L = auto()
RUN_R = auto()
WAVE = auto()
class Convoy:
def __init__(self, scene: "scene.Scene"):
self.target = None
self.space = scene.space
self.destroyed = False
self.hp = 10
self.team = 1
self.spawn_point = scene.definition.convoy_spawn_point
self.bodyNode = Actor("models/truck.dae")
self.bodyNode.reparentTo(scene.root)
self.body = pymunk.Body(10, 100)
self.shape = pymunk.Circle(self.body, 6.5/2)
self.shape.friction = 0.5
self.shape.filter = pymunk.ShapeFilter(categories=masks.CATEGORY_CONVOY)
self.shape.collision_type = masks.CATEGORY_CONVOY
self.shape.data = self
scene.space.add(self.body, self.shape)
self.crash_snd = scene.app.loader.loadSfx("sound/521377__jarusca__rocket-launch.mp3")
def destroy(self):
self.shape.data = None
self.space.remove(self.body, self.shape)
self.bodyNode.cleanup()
self.bodyNode.remove_node()
def update(self,dt):
dist = self.body.position - self.target.body.position
if abs(dist) < 40 and self.body.velocity.length < 10:
#self.body.apply_force_at_local_point((50, 0), (0,0))
self.body.apply_force_at_world_point((25, 0), (self.body.position.x,self.body.position.y + 1))
self.bodyNode.setPos(self.body.position.x, 0, self.body.position.y)
#self.bodyNode.setR(-(utils.radians_to_degrees(self.body.angle)))
def setPos(self, x, y):
self.body.position = x, y
def reset(self):
self.body.position = self.spawn_point
self.body.angle = 0
self.hp = 10
self.crash_snd.play()
def hurt(self, damage):
self.hp -= damage
if self.hp < 0:
self.reset()
def collision(self, other):
if other.shape.collision_type == masks.CATEGORY_ENEMY:
print("yep")
if other.shape.collision_type == masks.CATEGORY_ENEMY and other.hp < 1:
other.destroyed = True
elif hasattr(other, "hurt"):
other.hurt(100)