-
Notifications
You must be signed in to change notification settings - Fork 0
/
trigger.py
148 lines (124 loc) · 4.87 KB
/
trigger.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import pygame
from animation import Animation
from entity import Entity
from staticenemy import StaticEnemy
from block import Block
class Trigger(Entity):
def __init__(self, image_path, position, entity, entities):
self.entity = entity
self.entities = entities
self.entities.append(entity)
self.position = position
self.velocity = pygame.math.Vector2()
self.type = Entity.TYPE_OBJECT
self.animation = Animation([pygame.image.load(image_path)], 0)
self.reset_collider()
class ShutdownTrigger(Trigger):
def update_logic(self, input_m, entities, dt):
pass
def collide(self, other, axis, dt):
if other.type == Entity.TYPE_PLAYER_MELEE \
or other.type == Entity.TYPE_PLAYER_RANGED:
self.die()
def take_damage(self, damage, source):
print("trigger taking damage from a " + str(type(source)))
self.die()
def die(self):
if self.entity in self.entities:
print("trigger removing a " + str(type(self.entity)))
self.entities.remove(self.entity)
self.animation = Animation([pygame.image.load("mock/trigger-broken.png")],
0)
class FireTrigger(ShutdownTrigger):
FIRE_ON_TIME = 500
FIRE_OFF_TIME = 750
ANIM_GLOWY = Animation([
pygame.image.load("mock/stove-glowy.png"),
pygame.image.load("mock/stove-glowy-2.png"),
pygame.image.load("mock/stove-glowy-3.png"),
],
FIRE_OFF_TIME / 3)
ANIM_FIRE = Animation([
pygame.image.load("mock/stove-fire.png"),
pygame.image.load("mock/stove-fire-2.png"),
],
FIRE_ON_TIME / 2)
def __init__(self, image_path, position, entities):
self.entities = entities
self.fire = [
StaticEnemy("mock/stove-fire.png",
pygame.math.Vector2(20 * 26, 22 * 26 - 1), 1,
FireTrigger.ANIM_FIRE),
StaticEnemy("mock/stove-fire.png",
pygame.math.Vector2(14 * 26, 22 * 26 - 1), 1,
FireTrigger.ANIM_FIRE),
StaticEnemy("mock/stove-fire.png",
pygame.math.Vector2(17 * 26, 22 * 26 - 1), 1,
FireTrigger.ANIM_FIRE),
]
self.glowies = [
StaticEnemy("mock/stove-glowy.png",
pygame.math.Vector2(20 * 26, 25 * 26 - 1), 1,
FireTrigger.ANIM_GLOWY),
StaticEnemy("mock/stove-glowy.png",
pygame.math.Vector2(14 * 26, 25 * 26 - 1), 1,
FireTrigger.ANIM_GLOWY),
StaticEnemy("mock/stove-glowy.png",
pygame.math.Vector2(17 * 26, 25 * 26 - 1), 1,
FireTrigger.ANIM_GLOWY),
]
self.position = position
self.animation = Animation([pygame.image.load("mock/trigger.png")], 0)
self.type = Entity.TYPE_OBJECT
self.reset_collider()
self.time = 0
self.on = False
self.current = 0
self.dead = False
def update_logic(self, input_m, entities, dt):
if self.dead:
return
print("updating fire trigger")
if self.on:
if self.time > FireTrigger.FIRE_ON_TIME:
self.on = False
self.time = 0
if self.current == len(self.fire):
self.turn_off_all(self.fire)
else:
self.turn_off(self.fire[self.current])
self.current += 1
if self.current > len(self.fire):
self.current = 0
if self.current == len(self.fire):
self.turn_on_all(self.glowies)
else:
self.turn_on(self.glowies[self.current])
else:
if self.time > FireTrigger.FIRE_OFF_TIME:
self.on = True
self.time = 0
if self.current == len(self.fire):
self.turn_off_all(self.glowies)
self.turn_on_all(self.fire)
else:
self.turn_off(self.glowies[self.current])
self.turn_on(self.fire[self.current])
self.time += dt
def turn_on_all(self, entities):
for e in entities:
self.turn_on(e)
def turn_on(self, entity):
self.entities.append(entity)
def turn_off_all(self, entities):
for e in entities:
self.turn_off(e)
def turn_off(self, entity):
if entity in self.entities:
self.entities.remove(entity)
entity.animation.current_time = 0
entity.animation.frame_number = 0
def die(self):
self.dead = True
self.turn_off_all(self.fire)
self.turn_off_all(self.glowies)