Debian Codegraph @

src/jj1/level/event/jj1standardevent.cpp

raw symbols SCIP
1
2 /**
3 *
4 * @file jj1standardevent.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 * - 19th July 2009: Created eventframe.cpp from parts of events.cpp
13 * - 2nd March 2010: Created guardians.cpp from parts of event.cpp and eventframe.cpp
14 * - 2nd March 2010: Created bridge.cpp from parts of event.cpp and eventframe.cpp
15 * - 5th February 2011: Moved parts of eventframe.cpp to event.cpp
16 * - 5th February 2011: Renamed eventframe.cpp to standardevent.cpp
17 * - 1st August 2012: Renamed standardevent.cpp to jj1standardevent.cpp
18 *
19 * @par Licence:
20 * Copyright (c) 2005-2013 AJ Thomson
21 *
22 * OpenJazz is distributed under the terms of
23 * the GNU General Public License, version 2.0
24 *
25 * @par Description:
26 * Provides the once-per-frame functions of ordinary events.
27 *
28 */
29
30
31 #include "../jj1bullet.h"
32 #include "../jj1level.h"
33 #include "../jj1levelplayer.h"
34 #include "jj1event.h"
35
36 #include "io/gfx/sprite.h"
37 #include "io/gfx/video.h"
38 #include "io/sound.h"
39 #include "util.h"
40 #include "io/log.h"
41
42 #include <stdlib.h>
43
44
45 /**
46 * Create standard event.
47 *
48 * @param event The event type
49 * @param gX The grid X-coordinate of the origin of the event
50 * @param gY The grid Y-coordinate of the origin of the event
51 * @param startX The initial X-coordinate of the event
52 * @param startY The initial Y-coordinate of the event
53 */
54 JJ1StandardEvent::JJ1StandardEvent (JJ1EventType* event, unsigned char gX, unsigned char gY, fixed startX, fixed startY) : JJ1Event(gX, gY) {
55
56 set = event;
57 x = startX;
58 y = startY;
59
60 node = 0;
61 onlyLAnimOffset = false;
62 onlyRAnimOffset = false;
63
64 switch (set->movement) {
65
66 case 2: // Walk from side to side
67 case 4: // Walk from side to side and down hills
68
69 setAnimType(E_LEFTANIM);
70 onlyLAnimOffset = true;
71
72 break;
73
74 case 6: // Use the path from the level file
75 case 7: // Flying snake behavior
76
77 setAnimType(E_LEFTANIM);
78 noAnimOffset = true;
79
80 break;
81
82 case 21: // Destructible block
83 case 25: // Float up / Belt
84 case 37: // Sucker tubes
85 case 38: // Sucker tubes
86 case 40: // Monochrome
87 case 42: // Reflection
88 case 45: // Semitransparency
89 case 57: // Bubbles
90
91 animType = E_LEFTANIM;
92 setAnimType(E_NOANIM);
93
94 break;
95
96 case 26: // Flip animation
97
98 setAnimType(E_RIGHTANIM);
99 onlyRAnimOffset = true;
100
101 break;
102
103 default:
104
105 setAnimType(E_LEFTANIM);
106
107 break;
108
109 }
110
111 }
112
113
114 /**
115 * Move standard event.
116 *
117 * @param ticks Time
118 */
119 void JJ1StandardEvent::move (unsigned int ticks) {
120
121 JJ1LevelPlayer* levelPlayer;
122 int length;
123 fixed angle;
124
125
126 if ((animType & ~1) == E_LSHOOTANIM) {
127
128 dx = 0;
129 dy = 0;
130
131 return;
132
133 }
134
135
136 levelPlayer = localPlayer->getJJ1LevelPlayer();
137
138
139 // Handle movement
140
141 switch (set->movement) {
142
143 case 1:
144
145 // Sink down
146 dy = ES_FAST;
147
148 break;
149
150 case 2:
151
152 // Walk from side to side
153 if (animType == E_LEFTANIM) dx = -ES_FAST;
154 else if (animType == E_RIGHTANIM) dx = ES_FAST;
155 else dx = 0;
156
157 break;
158
159 case 3:
160
161 // Seek jazz
162 if (levelPlayer->getX() + PXO_R < x) dx = -ES_FAST;
163 else if (levelPlayer->getX() + PXO_L > x + width) dx = ES_FAST;
164 else dx = 0;
165
166 break;
167
168 case 4:
169
170 // Walk from side to side and down hills
171
172 if (!level->checkMaskDown(x + (width >> 1), y)) {
173
174 // Fall downwards
175 dx = 0;
176 dy = ES_FAST;
177
178 } else {
179
180 // Walk from side to side
181 if (animType == E_LEFTANIM) dx = -ES_FAST;
182 else if (animType == E_RIGHTANIM) dx = ES_FAST;
183
184 dy = 0;
185
186 }
187
188 break;
189
190 case 5:
191
192 /// @todo Find out what behaviour 5 is
193
194 break;
195
196 case 6:
197 case 7:
198
199 node = (node + FH) % ITOF(level->path[set->multiA].length);
200
201 // Use the path from the level file
202 dx = TTOF(gridX) + ITOF(level->path[set->multiA].x[FTOI(node)]) - x;
203 dy = TTOF(gridY) + ITOF(level->path[set->multiA].y[FTOI(node)]) - y;
204
205 x += dx;
206 y += dy;
207 dx = dx << 6;
208 dy = dy << 6;
209
210 return;
211
212 case 8:
213
214 /// @todo Bird-esque following
215
216 break;
217
218 case 9:
219
220 /// @todo Find out what behaviour 9 is
221
222 break;
223
224 case 10:
225
226 /// @todo Find out what behaviour 10 is
227
228 break;
229
230 case 11:
231
232 // Sink to ground
233 if (!level->checkMaskDown(x + (width >> 1), y)) dy = ES_FAST;
234 else dy = 0;
235
236 break;
237
238 case 12:
239
240 // Move back and forth horizontally
241 if (animType == E_LEFTANIM) dx = -ES_SLOW;
242 else if (animType == E_RIGHTANIM) dx = ES_SLOW;
243 else dx = 0;
244
245 break;
246
247 case 13:
248
249 // Move up and down
250 if (animType == E_LEFTANIM) dy = -ES_SLOW;
251 else if (animType == E_RIGHTANIM) dy = ES_SLOW;
252 else dy = 0;
253
254 break;
255
256 case 14:
257
258 /// @todo Move back and forth rapidly
259
260 break;
261
262 case 15:
263
264 /// @todo Rise or lower to meet jazz
265
266 break;
267
268 case 16:
269
270 // Move across level to the left or right
271 if (set->magnitude == 0) dx = -ES_SLOW;
272 else dx = set->magnitude * ES_SLOW;
273
274 break;
275
276 case 17:
277
278 /// @todo Find out what behaviour 17 is
279
280 break;
281
282 case 18:
283
284 /// @todo Find out what behaviour 18 is
285
286 break;
287
288 case 19:
289
290 /// @todo Find out what behaviour 19 is
291
292 break;
293
294 case 20:
295
296 /// @todo Find out what behaviour 20 is
297
298 break;
299
300 case 21:
301
302 // Destructible block
303 if (level->getEventHits(gridX, gridY) >= set->strength)
304 level->setTile(gridX, gridY, set->multiA);
305
306 break;
307
308 case 22:
309
310 /// @todo Fall down in random spot and repeat
311
312 break;
313
314 case 23:
315
316 /// @todo Find out what behaviour 23 is
317
318 break;
319
320 case 24:
321
322 /// @todo Crawl along ground and go downstairs
323
324 break;
325
326 case 27:
327
328 /// @todo Face jazz
329
330 break;
331
332 case 29:
333
334 // Rotate
335
336 length = set->pieceSize * set->pieces;
337 angle = (set->angle << 2) + (set->magnitude * ticks / 13);
338
339 dx = TTOF(gridX) + (fSin(angle) * length) - x;
340 dy = TTOF(gridY) + ((fCos(angle) + F1) * length) - y;
341
342 x += dx;
343 y += dy;
344 dx = dx << 6;
345 dy = dy << 6;
346
347 return;
348
349 case 30:
350
351 // Swing
352
353 length = set->pieceSize * set->pieces;
354 angle = (set->angle << 2) + (set->magnitude * ticks / 13);
355
356 dx = TTOF(gridX) + (fSin(angle) * length) - x;
357 dy = TTOF(gridY) + ((abs(fCos(angle)) + F1) * length) - y;
358
359 x += dx;
360 y += dy;
361 dx = dx << 6;
362 dy = dy << 6;
363
364 return;
365
366 case 31:
367 case 32:
368
369 // Move horizontally
370 if (animType == E_LEFTANIM) dx = -ES_FAST;
371 else dx = ES_FAST;
372
373 break;
374
375 case 33:
376
377 // Sparks-esque following
378
379 if (levelPlayer->getFacing() && (x + width < levelPlayer->getX())) {
380
381 dx = ES_FAST;
382
383 if (y + height < levelPlayer->getY() + PYO_TOP) dy = ES_SLOW;
384 else if (y > levelPlayer->getY()) dy = -ES_SLOW;
385 else dy = 0;
386
387 } else if (!levelPlayer->getFacing() && (x > levelPlayer->getX() + F32)) {
388
389 dx = -ES_FAST;
390
391 if (y + height < levelPlayer->getY() + PYO_TOP) dy = ES_SLOW;
392 else if (y > levelPlayer->getY()) dy = -ES_SLOW;
393 else dy = 0;
394
395 } else {
396
397 dx = 0;
398 dy = 0;
399
400 }
401
402 break;
403
404 case 34:
405
406 // Launching event
407
408 if (ticks > level->getEventTime(gridX, gridY)) {
409
410 if (animType == E_LEFTANIM)
411 dy = -(F16 + y - (TTOF(gridY) - (set->multiA * F12))) * 10;
412 else
413 dy = (F16 + y - (TTOF(gridY) - (set->multiA * F12))) * 10;
414
415 } else {
416
417 dy = TTOF(gridY) + F16 - y;
418
419 y += dy;
420 dy = dy << 6;
421
422 return;
423
424 }
425
426 break;
427
428 case 35:
429
430 // Non-floating Sparks-esque following
431
432 if (levelPlayer->getFacing() && (x + width < levelPlayer->getX() + PXO_L - F4)) {
433
434 if (level->checkMaskDown(x + width, y + F4) &&
435 !level->checkMaskDown(x + width + F4, y - (height >> 1)))
436 dx = ES_FAST;
437 else
438 dx = 0;
439
440 } else if (!levelPlayer->getFacing() && (x > levelPlayer->getX() + PXO_R + F4)) {
441
442 if (level->checkMaskDown(x, y + F4) &&
443 !level->checkMaskDown(x - F4, y - (height >> 1)))
444 dx = -ES_FAST;
445 else
446 dx = 0;
447
448 } else dx = 0;
449
450 break;
451
452 case 36:
453
454 // Walk from side to side and down hills, staying on-screen
455
456 if (!level->checkMaskDown(x + (width >> 1), y)) {
457
458 // Fall downwards
459 dx = 0;
460 dy = ES_FAST;
461
462 } else {
463
464 // Walk from side to side, staying on-screen
465 if (animType == E_LEFTANIM) dx = -ES_FAST;
466 else if (animType == E_RIGHTANIM) dx = ES_FAST;
467 else dx = 0;
468
469 dy = 0;
470
471 }
472
473 break;
474
475 case 39:
476
477 /// @todo Collapsing floor
478
479 break;
480
481 case 40:
482
483 /// @todo Find out what behaviour 40 is
484
485 break;
486
487 case 41:
488
489 /// @todo Switch left & right anim periodically
490
491 break;
492
493 case 42:
494
495 /// @todo Find out what behaviour 42 is
496
497 break;
498
499 case 43:
500
501 /// @todo Find out what behaviour 43 is
502
503 break;
504
505 case 44:
506
507 /// @todo Leap to greet Jazz very quickly
508
509 break;
510
511 case 45:
512
513 /// @todo Find out what behaviour 45 is
514
515 break;
516
517 case 46:
518
519 /// @todo "Final" boss
520
521 break;
522
523 case 53:
524
525 // Dreempipes turtles
526
527 if (y > level->getWaterLevel()) {
528
529 if (animType == E_LEFTANIM) dx = -ES_SLOW;
530 else if (animType == E_RIGHTANIM) dx = ES_SLOW;
531 else dx = 0;
532
533 } else dx = 0;
534
535 break;
536
537 default:
538
539 // Do nothing for the following:
540 // 0: Static
541 // 25: Float up / Belt
542 // 26: Flip Animation
543 // 37/38: Repel
544
545 /// @todo Remaining event behaviours
546
547 break;
548
549 }
550
551
552 dx /= set->speed;
553 dy /= set->speed;
554 x += dx >> 6;
555 y += dy >> 6;
556
557 }
558
559
560 /**
561 * Event iteration.
562 *
563 * @param ticks Time
564 *
565 * @return Remaining event
566 */
567 JJ1Event* JJ1StandardEvent::step (unsigned int ticks) {
568
569 JJ1LevelPlayer* levelPlayer;
570 int count;
571 unsigned int eventTime;
572 int hits;
573
574
575 set = prepareStep(ticks);
576 hits = level->getEventHits(gridX, gridY);
577
578 // If the event is off-screen, remove it (permanently if it's been deflected by a shield)
579 if (!set) return remove(hits == 255);
580
581
582 // If the event has been deflected by a shield, move it
583 if (hits == 255) {
584
585 dy = 200 * F1;
586
587 x += dx >> 6;
588 y += dy >> 6;
589
590 return this;
591
592 }
593
594
595 // Get the time of the event's next action
596 eventTime = level->getEventTime(gridX, gridY);
597
598
599 // If the event's finish animation has expired, remove it
600 if (eventTime && ((animType & ~1) == E_LFINISHANIM)) {
601
602 if (anim == NULL) return remove(true);
603
604 if (((int)(ticks - eventTime) / (int)(set->animSpeed << 3)) > anim->getLength())
605 return remove(true);
606
607 }
608
609
610 // Get the player
611 levelPlayer = localPlayer->getJJ1LevelPlayer();
612
613
614 // Move
615 move(ticks);
616
617
618 // Choose animation and direction
619
620 if ((animType & ~1) == E_LEFTANIM) {
621
622 switch (set->movement) {
623
624 case 2:
625
626 // Walk from side to side
627 if (animType == E_LEFTANIM) {
628
629 if (!level->checkMaskDown(x, y + F4) ||
630 level->checkMaskDown(x - F4, y - (height >> 1)))
631 setAnimType(E_RIGHTANIM);
632
633 } else if (animType == E_RIGHTANIM) {
634
635 if (!level->checkMaskDown(x + width, y + F4) ||
636 level->checkMaskDown(x + width + F4, y - (height >> 1)))
637 setAnimType(E_LEFTANIM);
638
639 }
640
641 break;
642
643 case 3:
644
645 // Seek jazz
646 if (levelPlayer->getX() + PXO_R < x)
647 setAnimType(E_LEFTANIM);
648 else if (levelPlayer->getX() + PXO_L > x + width)
649 setAnimType(E_RIGHTANIM);
650
651 break;
652
653 case 4:
654
655 // Walk from side to side and down hills
656
657 if (level->checkMaskDown(x + (width >> 1), y)) {
658
659 // Walk from side to side
660 if (animType == E_LEFTANIM) {
661
662 if (level->checkMaskDown(x - F4, y - (height >> 1) - F12))
663 setAnimType(E_RIGHTANIM);
664
665 } else if (animType == E_RIGHTANIM) {
666
667 if (level->checkMaskDown(x + width + F4, y - (height >> 1) - F12))
668 setAnimType(E_LEFTANIM);
669
670 }
671
672 }
673
674 break;
675
676 case 6:
677
678 // Use the path from the level file
679 // Check movement direction
680 if ((FTOI(node) < 3) ||
681 (level->path[set->multiA].x[FTOI(node)] <= level->path[set->multiA].x[FTOI(node) - 3]))
682 setAnimType(E_LEFTANIM);
683 else
684 setAnimType(E_RIGHTANIM);
685
686 break;
687
688 case 7:
689
690 // Move back and forth horizontally with tail
691
692 if (animType == E_LEFTANIM) {
693
694 if (x < TTOF(gridX)) setAnimType(E_RIGHTANIM);
695
696 } else if (animType == E_RIGHTANIM) {
697
698 if (x > TTOF(gridX) + F100) setAnimType(E_LEFTANIM);
699
700 }
701
702 break;
703
704 case 12:
705
706 // Move back and forth horizontally
707
708 if (animType == E_LEFTANIM) {
709
710 if (level->checkMaskDown(x - F4, y - (height >> 1)))
711 setAnimType(E_RIGHTANIM);
712
713 } else if (animType == E_RIGHTANIM) {
714
715 if (level->checkMaskDown(x + width + F4, y - (height >> 1)))
716 setAnimType(E_LEFTANIM);
717
718 }
719
720 break;
721
722 case 13:
723
724 // Move up and down
725
726 if (animType == E_LEFTANIM) {
727
728 if (level->checkMaskDown(x + (width >> 1), y - height - F4))
729 setAnimType(E_RIGHTANIM);
730
731 } else if (animType == E_RIGHTANIM) {
732
733 if (level->checkMaskDown(x + (width >> 1), y + F4))
734 setAnimType(E_LEFTANIM);
735
736 }
737
738 break;
739
740 case 26:
741
742 // Flip animation
743
744 if (levelPlayer->overlap(x, y - height, width, height))
745 setAnimType(E_LEFTANIM);
746 else
747 setAnimType(E_RIGHTANIM);
748
749 break;
750
751 case 31:
752
753 // Moving platform
754
755 if (animType == E_LEFTANIM) {
756
757 if (level->checkMaskDown(x, y - (height >> 1)))
758 setAnimType(E_RIGHTANIM);
759
760 } else if (animType == E_RIGHTANIM) {
761
762 if (level->checkMaskDown(x + width, y - (height >> 1)))
763 setAnimType(E_LEFTANIM);
764
765 }
766
767 break;
768
769 case 32:
770
771 // Moving platform
772
773 if (x < TTOF(gridX) - (set->pieceSize << 14))
774 setAnimType(E_RIGHTANIM);
775 else if (x > TTOF(gridX + set->pieceSize))
776 setAnimType(E_LEFTANIM);
777
778 break;
779
780 case 33:
781
782 // Sparks-esque following
783
784 if (levelPlayer->getFacing() &&
785 (x + width < levelPlayer->getX())) {
786
787 setAnimType(E_RIGHTANIM);
788
789 } else if (!levelPlayer->getFacing() &&
790 (x > levelPlayer->getX() + F32)) {
791
792 setAnimType(E_LEFTANIM);
793
794 }
795
796 break;
797
798 case 34:
799
800 // Launching event
801
802 if (ticks > eventTime) {
803
804 if (y <= F16 + TTOF(gridY) - (set->multiA * F12))
805 setAnimType(E_RIGHTANIM);
806 else if (y >= F16 + TTOF(gridY)) {
807
808 setAnimType(E_LEFTANIM);
809 level->setEventTime(gridX, gridY, ticks + (set->multiB * 50));
810
811 }
812
813 } else setAnimType(E_LEFTANIM);
814
815 break;
816
817 case 36:
818
819 // Walk from side to side and down hills, staying on-screen
820
821 if (level->checkMaskDown(x + (width >> 1), y)) {
822
823 // Walk from side to side, staying on-screen
824 if (animType == E_LEFTANIM) {
825
826 if (level->checkMaskDown(x - F4, y - (height >> 1)) ||
827 (x - F4 < viewX))
828 setAnimType(E_RIGHTANIM);
829
830 } else if (animType == E_RIGHTANIM) {
831
832 if (level->checkMaskDown(x + width + F4, y - (height >> 1)) ||
833 (x + width + F4 > viewX + ITOF(canvasW)))
834 setAnimType(E_LEFTANIM);
835
836 }
837
838 }
839
840 break;
841
842 case 53:
843
844 // Dreempipes turtles
845
846 if (y > level->getWaterLevel()) {
847
848 if (animType == E_LEFTANIM) {
849
850 if (level->checkMaskDown(x - F4, y - (height >> 1)))
851 setAnimType(E_RIGHTANIM);
852
853 } else if (animType == E_RIGHTANIM) {
854
855 if (level->checkMaskDown(x + width + F4, y - (height >> 1)))
856 setAnimType(E_LEFTANIM);
857
858 } else setAnimType(E_LEFTANIM);
859
860 }
861
862 break;
863
864 default:
865
866 if (levelPlayer->getX() + PXO_MID < x + (width >> 1))
867 setAnimType(E_LEFTANIM);
868 else
869 setAnimType(E_RIGHTANIM);
870
871 break;
872
873 }
874
875 }
876
877
878 // If the event is in its finish stage, nothing else needs to be done
879 if ((animType & ~1) == E_LFINISHANIM) return this;
880
881
882 // Check for kill
883 int strength = set->strength;
884 if (strength) {
885 // In turbo difficulty, enemy events generally take one more hit
886 if (level->getDifficulty() == difficultyType::Turbo && set->modifier == 0)
887 strength++;
888
889 // If the event has been destroyed, play its finishing animation and
890 // set its reaction time
891 if(hits >= strength)
892 destroy(ticks);
893 }
894
895
896 if (set->bulletPeriod) {
897
898 count = level->getAnim(set->anims[E_LSHOOTANIM | (animType & 1)])->getLength() * set->animSpeed << 5;
899
900 if ((ticks % (set->bulletPeriod * 32) > (unsigned int)(set->bulletPeriod * 32) - count) &&
901 ((animType & ~1) == E_LEFTANIM)) {
902
903 // Enter firing mode
904 if (animType == E_LEFTANIM) setAnimType(E_LSHOOTANIM);
905 else setAnimType(E_RSHOOTANIM);
906
907 level->setEventTime(gridX, gridY, ticks + count);
908
909 }
910
911 }
912
913
914 // If the reaction time has expired
915 if (eventTime && (ticks > eventTime)) {
916
917 if ((animType & ~1) == E_LSHOOTANIM) {
918
919 if (set->bullet < 32)
920 level->createBullet(
921 NULL,
922 gridX,
923 gridY,
924 drawnX + anim->getShootX(),
925 drawnY + anim->getShootY(),
926 set->bullet,
927 (animType & 1)? true: false,
928 ticks);
929
930 setAnimType(E_LEFTANIM | (animType & 1));
931
932 } else {
933
934 level->setEventTime(gridX, gridY, 0);
935
936 }
937
938 }
939
940
941 if (level->getStage() == LS_END) return this;
942
943
944 // Handle contact with player
945
946 for (count = 0; count < nPlayers; count++) {
947
948 levelPlayer = players[count].getJJ1LevelPlayer();
949
950 // Check if the player is touching the event
951
952 if (set->modifier == 6) {
953
954 if (width && height &&
955 levelPlayer->overlap(drawnX, drawnY - F4, width - F8, F8) &&
956 (levelPlayer->getY() <= F4 + (PYS_FALL >> 6) + drawnY) &&
957 !level->checkMaskDown(levelPlayer->getX() + PXO_MID, PYO_TOP + drawnY)) {
958
959 // Player is on a platform
960
961 levelPlayer->setPlatform(gridX, gridY, (dx >> 6), drawnY);
962
963 } else levelPlayer->clearEvent(gridX, gridY);
964
965 } else {
966
967 // Check if the player is touching the event
968 if (width && height &&
969 levelPlayer->overlap(drawnX + F2, drawnY + F2, width - F4, height - F4)) {
970
971 // If the player picks up the event, destroy it
972 if (levelPlayer->touchEvent(set, gridX, gridY, ticks)) {
973
974 if (level->getEventHits(gridX, gridY) == 255) {
975
976 if (levelPlayer->getX() + PXO_MID > x + (width >> 1))
977 dx = -400 * F1;
978 else
979 dx = 400 * F1;
980
981 dy = 200 * F1;
982
983 } else {
984
985 destroy(ticks);
986
987 }
988
989 }
990
991 }
992
993 }
994
995 }
996
997
998 return this;
999
1000 }
1001
1002
1003 /**
1004 * Draw standard event.
1005 *
1006 * @param ticks Time
1007 * @param change Time since last iteration
1008 */
1009 void JJ1StandardEvent::draw (unsigned int ticks, int change) {
1010
1011 if (next) next->draw(ticks, change);
1012
1013 // Uncomment the following to see the raw location
1014 /*drawRect(FTOI(getDrawX(change)),
1015 FTOI(getDrawY(change) - height), FTOI(width),
1016 FTOI(height), 88);*/
1017
1018 // If the event has been removed from the grid, do not show it
1019 if (!set) return;
1020
1021 // Check if the event has anything to draw
1022 if (animType == E_NOANIM) {
1023
1024 drawnX = x;
1025 drawnY = y - F32;
1026 width = F32;
1027 height = F32;
1028
1029 return;
1030
1031 }
1032
1033 if ((animType & ~1) == E_LFINISHANIM) {
1034
1035 setAnimFrame((ticks - level->getEventTime(gridX, gridY)) / (set->animSpeed << 3), false);
1036
1037 } else if ((animType & ~1) == E_LSHOOTANIM) {
1038
1039 setAnimFrame((ticks + (anim->getLength() * set->animSpeed << 5) - level->getEventTime(gridX, gridY)) / (set->animSpeed << 5), false);
1040
1041 } else {
1042
1043 setAnimFrame((ticks / (set->animSpeed << 5)) + gridX + gridY, true);
1044
1045 }
1046
1047 // Calculate new positions
1048 fixed changeX = getDrawX(change);
1049 fixed changeY = getDrawY(change);
1050
1051
1052 // Draw the event
1053
1054 // Check if an explosive effect should be drawn
1055 if (((animType & ~1) == E_LFINISHANIM) && (set->anims[animType] & 0x80)) {
1056
1057 // In case of an explosion
1058
1059 // Determine position in a half circle path
1060 fixed xOffset = fCos((ticks - level->getEventTime(gridX, gridY)) >> 1) * 48 - ITOF(16);
1061 fixed yOffset = fSin((ticks - level->getEventTime(gridX, gridY)) >> 1) * 48;
1062
1063 int val = gridX + gridY;
1064
1065 // Draw the animation in six different positions
1066 anim->draw(changeX - yOffset, changeY - xOffset);
1067 anim->draw(changeX + yOffset, changeY - xOffset);
1068 anim->draw(changeX + ITOF(val % 32) - yOffset, changeY - ITOF(val % 8) - xOffset);
1069 anim->draw(changeX - ITOF(val % 16) + yOffset, changeY - ITOF(val % 16) - xOffset);
1070 anim->draw(changeX + ITOF(val % 24) - yOffset, changeY + ITOF(val % 12) - xOffset);
1071 anim->draw(changeX - ITOF(val % 48) + yOffset, changeY + ITOF(val % 24) - xOffset);
1072
1073 } else {
1074
1075 // In case an event can be drawn normally
1076
1077 fixed offset;
1078
1079 if ((ticks < flashTime) && ((ticks >> 4) & 3)) anim->flashPalette(0);
1080
1081 // Determine the corect vertical offset
1082 // Most animations need a default offset of 1 tile (32 pixels)
1083
1084 if ((anim->getWidth() == 1) && (anim->getHeight() == 1)) {
1085
1086 offset = -F32;
1087
1088 } else if (noAnimOffset) {
1089
1090 offset = 0;
1091
1092 } else {
1093
1094 if (onlyLAnimOffset && (animType == E_RIGHTANIM)) {
1095
1096 offset = level->getAnim(set->anims[E_LEFTANIM] & 0x7F)->getOffset();
1097
1098 } else if (onlyRAnimOffset && (animType == E_LEFTANIM)) {
1099
1100 offset = level->getAnim(set->anims[E_RIGHTANIM] & 0x7F)->getOffset();
1101
1102 } else {
1103
1104 offset = anim->getOffset();
1105
1106 }
1107
1108 if (offset == 0) offset = -ITOF(TTOI(1) - 1);
1109
1110 }
1111
1112 drawnX = x + anim->getXOffset() + F1;
1113 drawnY = y + anim->getYOffset() + offset + F1;
1114
1115 // Uncomment the following line to see the draw area
1116 //drawRect(FTOI(changeX - x + drawnX), FTOI(changeY - y + drawnY), FTOI(width), FTOI(height), 88);
1117
1118 anim->draw(changeX + F1, changeY + offset + F1 - anim->getOffset());
1119
1120 if ((ticks < flashTime) && ((ticks >> 4) & 3)) anim->restorePalette();
1121
1122 }
1123
1124 // If the event has been destroyed, draw an explosion
1125 if (set->strength && ((animType & ~1) == E_LFINISHANIM)) {
1126
1127 Anim* miscAnim = level->getMiscAnim(MA_EXPLOSION1);
1128 miscAnim->setFrame((ticks - level->getEventTime(gridX, gridY)) >> 3, false);
1129 miscAnim->draw(changeX, changeY);
1130
1131 }
1132
1133 }