1 /*
2 Copyright (C) 2009-2021 Parallel Realities
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 */
19
20 #include "../headers.h"
21
22 #include "../audio/audio.h"
23 #include "../collisions.h"
24 #include "../entity.h"
25 #include "../game.h"
26 #include "../graphics/animation.h"
27 #include "../item/key_items.h"
28 #include "../system/error.h"
29 #include "../system/properties.h"
30
31 extern Entity *self, player;
32 extern Game game;
33
34 static void entityWait(void);
35 static void explodeInit(void);
36 static void explode(void);
37 static void touch(Entity *);
38 static void throwGazerEye(int);
39 static void explodeWait(void);
40
addExplodingGazerEyeDud(int x,int y,char * name)41 Entity *addExplodingGazerEyeDud(int x, int y, char *name)
42 {
43 Entity *e = getFreeEntity();
44
45 if (e == NULL)
46 {
47 showErrorAndExit("No free slots to add an Exploding Gazer Eye Dud");
48 }
49
50 loadProperties(name, e);
51
52 e->x = x;
53 e->y = y;
54
55 e->type = KEY_ITEM;
56
57 e->action = &entityWait;
58 e->activate = &throwGazerEye;
59
60 e->draw = &drawLoopingAnimationToMap;
61
62 setEntityAnimation(e, "STAND");
63
64 return e;
65 }
66
entityWait()67 static void entityWait()
68 {
69 checkToMap(self);
70
71 if ((self->flags & ON_GROUND) || self->standingOn != NULL)
72 {
73 self->dirX = 0;
74
75 if (self->active == FALSE)
76 {
77 self->touch = &keyItemTouch;
78 }
79
80 else
81 {
82 self->touch = &touch;
83
84 self->thinkTime = 30;
85 }
86 }
87 }
88
throwGazerEye(int val)89 static void throwGazerEye(int val)
90 {
91 Entity *e;
92
93 if (game.status == IN_GAME && player.element != WATER)
94 {
95 setEntityAnimation(self, "STAND");
96
97 self->active = TRUE;
98
99 e = addEntity(*self, player.x + (player.face == RIGHT ? player.w : 0), player.y);
100
101 e->touch = &touch;
102
103 e->action = &explodeWait;
104
105 e->fallout = &entityDieNoDrop;
106
107 e->flags |= DO_NOT_PERSIST;
108
109 e->dirX = player.face == LEFT ? -8 : 8;
110
111 e->dirY = ITEM_JUMP_HEIGHT;
112
113 playSoundToMap("sound/common/throw", -1, player.x, player.y, 0);
114
115 self->inUse = FALSE;
116 }
117 }
118
explodeWait()119 static void explodeWait()
120 {
121 long onGround;
122
123 onGround = self->flags & ON_GROUND;
124
125 checkToMap(self);
126
127 if (landedOnGround(onGround) == TRUE)
128 {
129 self->dirX = 0;
130
131 self->thinkTime--;
132
133 if (self->thinkTime <= 0)
134 {
135 setEntityAnimation(self, "WALK");
136
137 self->thinkTime = 15;
138
139 self->action = &explodeInit;
140 }
141 }
142 }
143
explodeInit()144 static void explodeInit()
145 {
146 self->thinkTime--;
147
148 if (self->thinkTime <= 0)
149 {
150 self->thinkTime = 15;
151
152 setEntityAnimation(self, "JUMP");
153
154 self->action = &explode;
155 }
156 }
157
explode()158 static void explode()
159 {
160 Entity *temp;
161
162 self->thinkTime--;
163
164 if (self->thinkTime <= 0)
165 {
166 playSoundToMap("sound/enemy/gazer/flash", -1, self->x, self->y, 0);
167
168 fadeFromColour(255, 255, 255, 60);
169
170 if (self->head != NULL)
171 {
172 temp = self;
173
174 self = self->head;
175
176 self->activate(100);
177
178 self = temp;
179 }
180
181 self->inUse = FALSE;
182 }
183 }
184
touch(Entity * other)185 static void touch(Entity *other)
186 {
187
188 }
189