Debian Codegraph @

src/jj1/level/event/jj1event.cpp

raw symbols SCIP
1
2 /**
3 *
4 * @file jj1event.cpp
5 *
6 * Part of the OpenJazz project
7 *
8 * @par History:
9 * - 23rd August 2005: Created level.c
10 * - 1st January 2006: Created events.c from parts of level.c
11 * - 3rd February 2009: Renamed events.c to events.cpp
12 * - 5th February 2009: Added parts of events.cpp and level.cpp to player.cpp
13 * - 11th February 2009: Created bullet.cpp from parts of events.cpp
14 * - 1st March 2009: Created bird.cpp from parts of events.cpp
15 * - 19th March 2009: Created sprite.cpp from parts of event.cpp and player.cpp
16 * - 19th July 2009: Created eventframe.cpp from parts of events.cpp
17 * - 19th July 2009: Renamed events.cpp to event.cpp
18 * - 2nd March 2010: Created guardians.cpp from parts of event.cpp and
19 * eventframe.cpp
20 * - 2nd March 2010: Created bridge.cpp from parts of event.cpp and eventframe.cpp
21 * - 5th February 2011: Moved parts of eventframe.cpp to event.cpp
22 * - 1st August 2012: Renamed event.cpp to jj1event.cpp
23 *
24 * @par Licence:
25 * Copyright (c) 2005-2013 AJ Thomson
26 *
27 * OpenJazz is distributed under the terms of
28 * the GNU General Public License, version 2.0
29 *
30 * @par Description:
31 * Deals with events in ordinary levels.
32 *
33 */
34
35
36 #include "../jj1level.h"cxx . . $ `<file>/src/jj1/level/jj1level.h`/
37 #include "jj1event.h"cxx . . $ `<file>/src/jj1/level/event/jj1event.h`/
38
39 #include "io/gfx/video.h"cxx . . $ `<file>/src/io/gfx/video.h`/
40 #include "io/sound.h"cxx . . $ `<file>/src/io/sound.h`/
41 #include "util.h"cxx . . $ `<file>/src/util.h`/
42
43
44 /**
45 * Create event
46 *
47 * @param gX X-coordinate
48 * @param gY Y-coordinate
49 */
50 JJ1Eventcxx . . $ JJ1Event#::JJ1Eventcxx . . $ JJ1Event#JJ1Event(8fbe6856f5410d23). (unsigned char gX, unsigned char gY) {
51
52 setcxx . . $ JJ1Event#set. = levelcxx . . $ level.->getEventcxx . . $ JJ1Level#getEvent(4d9fc4215ff36191).(gX, gY);
53
54 xcxx . . $ Movable#x. = TTOFcxx . . $ `src/level/level.h:38:9`!(gX);
55 ycxx . . $ Movable#y. = TTOFcxx . . $ `src/level/level.h:38:9`!(gY + 1);
56 dxcxx . . $ Movable#dx. = 0;
57 dycxx . . $ Movable#dy. = 0;
58
59 nextcxx . . $ JJ1Event#next. = levelcxx . . $ level.->getEventscxx . . $ JJ1Level#getEvents(31caec775bb17100).();
60 gridXcxx . . $ JJ1Event#gridX. = gX;
61 gridYcxx . . $ JJ1Event#gridY. = gY;
62 flashTimecxx . . $ JJ1Event#flashTime. = 0;
63
64 animTypecxx . . $ JJ1Event#animType. = E_NOANIMcxx . . $ `src/jj1/level/event/jj1event.h:47:9`!;
65 animcxx . . $ JJ1Event#anim. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
66 noAnimOffsetcxx . . $ JJ1Event#noAnimOffset. = false;
67
68 drawnXcxx . . $ JJ1Event#drawnX. = xcxx . . $ Movable#x.;
69 drawnYcxx . . $ JJ1Event#drawnY. = ycxx . . $ Movable#y.;
70 widthcxx . . $ JJ1Event#width. = F32cxx . . $ `src/types.h:40:9`!;
71 heightcxx . . $ JJ1Event#height. = F32cxx . . $ `src/types.h:40:9`!;
72
73 }
74
75
76 /**
77 * Delete all events
78 */
79 JJ1Eventcxx . . $ JJ1Event#::~cxx . . $ JJ1Event#`~JJ1Event`(49f6e7a06ebc5aa8).JJ1Eventcxx . . $ JJ1Event# () {
80
81 if (nextcxx . . $ JJ1Event#next.) delete nextcxx . . $ JJ1Event#next.;
82
83 }
84
85
86 /**
87 * Delete this event
88 *
89 * @param permanently Whether or not to delete the event from the level
90 *
91 * @return The next event
92 */
93 JJ1Eventcxx . . $ JJ1Event#* JJ1Eventcxx . . $ JJ1Event#::removecxx . . $ JJ1Event#remove(953c18bf09d857ef). (bool permanently) {
94
95 JJ1Eventcxx . . $ JJ1Event# *oldNext;
96
97 if (permanently) levelcxx . . $ level.->clearEventcxx . . $ JJ1Level#clearEvent(8fbe6856f5410d23).(gridXcxx . . $ JJ1Event#gridX., gridYcxx . . $ JJ1Event#gridY.);
98
99 oldNext = nextcxx . . $ JJ1Event#next.;
100 nextcxx . . $ JJ1Event#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
101 delete this;
102
103 return oldNext;
104
105 }
106
107
108 /**
109 * Get the next event
110 *
111 * @return The next event
112 */
113 JJ1Eventcxx . . $ JJ1Event# * JJ1Eventcxx . . $ JJ1Event#::getNextcxx . . $ JJ1Event#getNext(31caec775bb17100). () {
114
115 return nextcxx . . $ JJ1Event#next.;
116
117 }
118
119
120 /**
121 * Initiate the destruction of the event
122 *
123 * @param ticks Time
124 */
125 void JJ1Eventcxx . . $ JJ1Event#::destroycxx . . $ JJ1Event#destroy(cb2f890c2fdad230). (unsigned int ticks) {
126
127 setAnimTypecxx . . $ JJ1Event#setAnimType(ac50b47256ae7414).(E_LFINISHANIMcxx . . $ `src/jj1/level/event/jj1event.h:43:9`! | (animTypecxx . . $ JJ1Event#animType. & 1));
128
129 levelcxx . . $ level.->setEventTimecxx . . $ JJ1Level#setEventTime(4a4a5f1b8fcd3f2e).(gridXcxx . . $ JJ1Event#gridX., gridYcxx . . $ JJ1Event#gridY., ticks);
130
131 playSoundcxx . . $ playSound(80b838f98135e5b).(setcxx . . $ JJ1Event#set.->soundcxx . . $ $anonymous_type_e8f9ae77bbb68925_1#sound.);
132
133 }
134
135
136 /**
137 * Deal with bullet collisions
138 *
139 * @param source Source of the hit(s)
140 * @param hits Number of hits to inflict
141 * @param ticks Current time
142 *
143 * @return Whether or not the hit was successful
144 */
145 bool JJ1Eventcxx . . $ JJ1Event#::hitcxx . . $ JJ1Event#hit(a041df1a1d9c3254). (JJ1LevelPlayercxx . . $ JJ1LevelPlayer# *source, int hits, unsigned int ticks) {
146
147 // Check if event has already been destroyed
148 if (((animTypecxx . . $ JJ1Event#animType. & ~1) == E_LFINISHANIMcxx . . $ `src/jj1/level/event/jj1event.h:43:9`!) || (ticks < flashTimecxx . . $ JJ1Event#flashTime.)) return false;
149
150 int hitsRemaining = levelcxx . . $ level.->hitEventcxx . . $ JJ1Level#hitEvent(21563437c91e9cad).(gridXcxx . . $ JJ1Event#gridX., gridYcxx . . $ JJ1Event#gridY., hits, source, ticks);
151
152 // If the event cannot be hit, do not register hit
153 if (hitsRemaining < 0) return false;
154
155 // Check if the hit has destroyed the event
156 if (hitsRemaining == 0) destroycxx . . $ JJ1Event#destroy(cb2f890c2fdad230).(ticks);
157
158 // The event has been hit, so it should flash
159 flashTimecxx . . $ JJ1Event#flashTime. = ticks + T_FLASHcxx . . $ `src/jj1/level/event/jj1event.h:50:9`!;
160
161 // Register hit
162 return true;
163
164 }
165
166
167 /**
168 * Determine whether or not the event is an enemy
169 *
170 * @return Whether or not the event is an enemy
171 */
172 bool JJ1Eventcxx . . $ JJ1Event#::isEnemycxx . . $ JJ1Event#isEnemy(c9857a73d68e59ba). () {
173
174 return setcxx . . $ JJ1Event#set.->strengthcxx . . $ $anonymous_type_e8f9ae77bbb68925_1#strength. && (setcxx . . $ JJ1Event#set.->modifiercxx . . $ $anonymous_type_e8f9ae77bbb68925_1#modifier. == 0);
175
176 }
177
178
179 /**
180 * Determine whether or not the event is from the given position
181 *
182 * @return Whether or not the event is from the given position
183 */
184 bool JJ1Eventcxx . . $ JJ1Event#::isFromcxx . . $ JJ1Event#isFrom(4ed805b44025c28a). (unsigned char gX, unsigned char gY) {
185
186 return (gX == gridXcxx . . $ JJ1Event#gridX.) && (gY == gridYcxx . . $ JJ1Event#gridY.);
187
188 }
189
190
191 /**
192 * Calculate the width and height of the event
193 */
194 void JJ1Eventcxx . . $ JJ1Event#::calcDimensionscxx . . $ JJ1Event#calcDimensions(49f6e7a06ebc5aa8). () {
195
196 if (animTypecxx . . $ JJ1Event#animType. == E_NOANIMcxx . . $ `src/jj1/level/event/jj1event.h:47:9`!) {
197
198 widthcxx . . $ JJ1Event#width. = F32cxx . . $ `src/types.h:40:9`!;
199 heightcxx . . $ JJ1Event#height. = F32cxx . . $ `src/types.h:40:9`!;
200
201 } else {
202
203 widthcxx . . $ JJ1Event#width. = ITOFcxx . . $ `src/types.h:53:9`!(anim->getWidth());
204 heightcxx . . $ JJ1Event#height. = ITOFcxx . . $ `src/types.h:53:9`!(anim->getHeight());
205
206 // Blank sprites for e.g. invisible springs
207 if ((widthcxx . . $ JJ1Event#width. == F1cxx . . $ `src/types.h:31:9`!) && (heightcxx . . $ JJ1Event#height. == F1cxx . . $ `src/types.h:31:9`!)) {
208
209 widthcxx . . $ JJ1Event#width. = F32cxx . . $ `src/types.h:40:9`!;
210 heightcxx . . $ JJ1Event#height. = F32cxx . . $ `src/types.h:40:9`!;
211
212 }
213
214 }
215
216 }
217
218
219 /**
220 * Determine whether or not the event is overlapping the given area
221 *
222 * @param areaX The x-coordinate of the left of the area
223 * @param areaY The y-coordinate of the top of the area
224 * @param areaWidth The width of the area
225 * @param areaHeight The height of the area
226 *
227 * @return Whether or not there is an overlap
228 */
229 bool JJ1Eventcxx . . $ JJ1Event#::overlapcxx . . $ JJ1Event#overlap(a1642a0ee405ca20). (fixedcxx . . $ fixed# areaX, fixedcxx . . $ fixed# areaY, fixedcxx . . $ fixed# areaWidth, fixedcxx . . $ fixed# areaHeight) {
230
231 return (drawnXcxx . . $ JJ1Event#drawnX. + widthcxx . . $ JJ1Event#width. >= areaX) &&
232 (drawnXcxx . . $ JJ1Event#drawnX. < areaX + areaWidth) &&
233 (drawnYcxx . . $ JJ1Event#drawnY. + heightcxx . . $ JJ1Event#height. >= areaY) &&
234 (drawnYcxx . . $ JJ1Event#drawnY. < areaY + areaHeight);
235
236 }
237
238
239 /**
240 * Sets the animation type and updates the current animation and dimensions
241 *
242 * @param type The new animation type
243 */
244 void JJ1Eventcxx . . $ JJ1Event#::setAnimTypecxx . . $ JJ1Event#setAnimType(ac50b47256ae7414).(unsigned char type) {
245
246 if (type == animTypecxx . . $ JJ1Event#animType.) return;
247
248 animTypecxx . . $ JJ1Event#animType. = type;
249
250 if (animTypecxx . . $ JJ1Event#animType. == E_NOANIMcxx . . $ `src/jj1/level/event/jj1event.h:47:9`!) animcxx . . $ JJ1Event#anim. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
251
252 // If there is no shooting animation, use the normal animation instead
253 else if (((animTypecxx . . $ JJ1Event#animType. & ~1) == E_LSHOOTANIMcxx . . $ `src/jj1/level/event/jj1event.h:45:9`!) && (setcxx . . $ JJ1Event#set.->animscxx . . $ $anonymous_type_e8f9ae77bbb68925_1#anims.[animTypecxx . . $ JJ1Event#animType.] == 0))
254 animcxx . . $ JJ1Event#anim. = levelcxx . . $ level.->getAnimcxx . . $ JJ1Level#getAnim(e50c847d642a1093).(setcxx . . $ JJ1Event#set.->animscxx . . $ $anonymous_type_e8f9ae77bbb68925_1#anims.[animTypecxx . . $ JJ1Event#animType. & 1] & 0x7F);
255
256 else animcxx . . $ JJ1Event#anim. = levelcxx . . $ level.->getAnimcxx . . $ JJ1Level#getAnim(e50c847d642a1093).(setcxx . . $ JJ1Event#set.->animscxx . . $ $anonymous_type_e8f9ae77bbb68925_1#anims.[animTypecxx . . $ JJ1Event#animType.] & 0x7F);
257
258 calcDimensionscxx . . $ JJ1Event#calcDimensions(49f6e7a06ebc5aa8).();
259
260 }
261
262
263 /**
264 * Sets the animation frame and updates the current dimensions
265 */
266 void JJ1Eventcxx . . $ JJ1Event#::setAnimFramecxx . . $ JJ1Event#setAnimFrame(918ebd27a9ddbad3). (int frame, bool looping) {
267
268 if (!animcxx . . $ JJ1Event#anim.) return;
269
270 animcxx . . $ JJ1Event#anim.->setFramecxx . . $ Anim#setFrame(918ebd27a9ddbad3).(frame, looping);
271 calcDimensionscxx . . $ JJ1Event#calcDimensions(49f6e7a06ebc5aa8).();
272
273 }
274
275
276 /**
277 * Functionality required by all event types on each iteration
278 *
279 * @param ticks Time
280 *
281 * @return Animation
282 */
283 JJ1EventTypecxx . . $ JJ1EventType#* JJ1Eventcxx . . $ JJ1Event#::prepareStepcxx . . $ JJ1Event#prepareStep(265b63775edc5f6e). (unsigned int ticks) {
284
285 // Process the next event
286 if (nextcxx . . $ JJ1Event#next.) nextcxx . . $ JJ1Event#next. = nextcxx . . $ JJ1Event#next.->stepcxx . . $ JJ1Event#step(96f3a021ae50222d).(ticks);
287
288 // If the event has been removed from the grid, destroy it
289 if (!setcxx . . $ JJ1Event#set.) return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
290
291 // If the event and its origin are off-screen, the event is not in the
292 // process of self-destruction, remove it
293 if (((animTypecxx . . $ JJ1Event#animType. & ~1) != E_LFINISHANIMcxx . . $ `src/jj1/level/event/jj1event.h:43:9`!) &&
294 ((xcxx . . $ Movable#x. < viewXcxx . . $ viewX. - F192cxx . . $ `src/types.h:47:9`!) || (xcxx . . $ Movable#x. > viewXcxx . . $ viewX. + ITOFcxx . . $ `src/types.h:53:9`!(canvasW) + F192cxx . . $ `src/types.h:47:9`!) ||
295 (ycxx . . $ Movable#y. < viewYcxx . . $ viewY. - F160cxx . . $ `src/types.h:46:9`!) || (ycxx . . $ Movable#y. > viewYcxx . . $ viewY. + ITOFcxx . . $ `src/types.h:53:9`!(canvasH) + F160cxx . . $ `src/types.h:46:9`!)) &&
296 ((gridXcxx . . $ JJ1Event#gridX. < FTOTcxx . . $ `src/level/level.h:37:9`!(viewX) - 1) ||
297 (gridXcxx . . $ JJ1Event#gridX. > ITOTcxx . . $ `src/level/level.h:39:9`!(FTOIcxx . . $ `src/types.h:52:9`!(viewX) + canvasW) + 1) ||
298 (gridYcxx . . $ JJ1Event#gridY. < FTOTcxx . . $ `src/level/level.h:37:9`!(viewY) - 1) ||
299 (gridYcxx . . $ JJ1Event#gridY. > ITOTcxx . . $ `src/level/level.h:39:9`!(FTOIcxx . . $ `src/types.h:52:9`!(viewY) + canvasH) + 1))) return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
300
301 return setcxx . . $ JJ1Event#set.;
302
303 }
304
305
306 /**
307 * Draw the event's energy bar
308 *
309 * @param ticks Time
310 */
311 void JJ1Eventcxx . . $ JJ1Event#::drawEnergycxx . . $ JJ1Event#drawEnergy(cb2f890c2fdad230). (unsigned int ticks) {
312
313 Animcxx . . $ Anim#* miscAnim;
314 int hits;
315
316 if (!setcxx . . $ JJ1Event#set. || setcxx . . $ JJ1Event#set.->modifiercxx . . $ $anonymous_type_e8f9ae77bbb68925_1#modifier. != 8) {
317
318 if (nextcxx . . $ JJ1Event#next.) nextcxx . . $ JJ1Event#next.->drawEnergycxx . . $ JJ1Event#drawEnergy(cb2f890c2fdad230).(ticks);
319
320 return;
321
322 } else if (setcxx . . $ JJ1Event#set.->strengthcxx . . $ $anonymous_type_e8f9ae77bbb68925_1#strength.) {
323
324 // Draw boss energy bar
325
326 hits = levelcxx . . $ level.->getEventHitscxx . . $ JJ1Level#getEventHits(777233acce9323bd).(gridXcxx . . $ JJ1Event#gridX., gridYcxx . . $ JJ1Event#gridY.) * 100 / setcxx . . $ JJ1Event#set.->strengthcxx . . $ $anonymous_type_e8f9ae77bbb68925_1#strength.;
327
328
329 // Devan head
330
331 miscAnim = levelcxx . . $ level.->getMiscAnimcxx . . $ JJ1Level#getMiscAnim(e50c847d642a1093).(MA_DEVHEADcxx . . $ `src/jj1/level/jj1level.h:103:9`!);
332 miscAnim->setFramecxx . . $ Anim#setFrame(918ebd27a9ddbad3).(0, true);
333
334 if (ticks < flashTimecxx . . $ JJ1Event#flashTime.) miscAnim->flashPalettecxx . . $ Anim#flashPalette(d4f767463ce0a6b3).(0);
335
336 miscAnim->drawcxx . . $ Anim#draw(b1146eedae1e1d0b).(ITOFcxx . . $ `src/types.h:53:9`!(canvasW - 44), ITOFcxx . . $ `src/types.h:53:9`!(hits + 48));
337
338 if (ticks < flashTimecxx . . $ JJ1Event#flashTime.) miscAnim->restorePalettecxx . . $ Anim#restorePalette(49f6e7a06ebc5aa8).();
339
340
341 // Bar
342 videocxx . . $ video..drawRectcxx . . $ Video#drawRect(a4376a5627a47301).(canvasWcxx . . $ canvasW. - 40, hits + 40, 12, 100 - hits, (ticks < flashTimecxx . . $ JJ1Event#flashTime.)? 0: 32);
343
344 }
345
346 }