-
Notifications
You must be signed in to change notification settings - Fork 0
/
jj2levelplayerframe.cpp
981 lines (588 loc) · 17.6 KB
/
jj2levelplayerframe.cpp
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
/**
*
* @file jj2levelplayerframe.cpp
*
* Part of the OpenJazz project
*
* @par History:
* - 23rd August 2005: Created level.c
* - 1st January 2006: Created events.c from parts of level.c
* - 3rd February 2009: Renamed events.c to events.cpp and level.c to level.cpp,
* created player.cpp
* - 5th February 2009: Added parts of events.cpp and level.cpp to player.cpp
* - 18th July 2009: Created playerframe.cpp from parts of player.cpp
* - 24th June 2010: Renamed playerframe.cpp to levelplayerframe.cpp
* - 29th June 2010: Created jj2levelplayerframe.cpp from parts of
* levelplayerframe.cpp
*
* @par Licence:
* Copyright (c) 2005-2013 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
*
* @par Description:
* Provides the once-per-frame functions of players in levels.
*
*/
#include "../jj2event/jj2event.h"
#include "../jj2level.h"
#include "jj2levelplayer.h"
#include "io/controls.h"
#include "io/gfx/font.h"
#include "io/gfx/video.h"
#include "io/sound.h"
#include "util.h"
/**
* Determine whether or not the area below the player is solid when travelling
* downwards.
*
* @param yOffset Vertical offset of the mask values to check
*
* @return Solidity
*/
bool JJ2LevelPlayer::checkMaskDown (fixed yOffset, bool drop) {
return jj2Level->checkMaskDown(x + JJ2PXO_ML, y + yOffset, drop) ||
jj2Level->checkMaskDown(x + JJ2PXO_MID, y + yOffset, drop) ||
jj2Level->checkMaskDown(x + JJ2PXO_MR, y + yOffset, drop);
}
/**
* Determine whether or not the area above the player is solid when travelling
* upwards.
*
* @param yOffset Vertical offset of the mask values to check
*
* @return Solidity
*/
bool JJ2LevelPlayer::checkMaskUp (fixed yOffset) {
return jj2Level->checkMaskUp(x + JJ2PXO_ML, y + yOffset) ||
jj2Level->checkMaskUp(x + JJ2PXO_MID, y + yOffset) ||
jj2Level->checkMaskUp(x + JJ2PXO_MR, y + yOffset);
}
/**
* Move the player to the ground's surface.
*/
void JJ2LevelPlayer::ground () {
// If on an uphill slope, push the player upwards
if (checkMaskUp(0) && !checkMaskUp(-F1)) y -= F1;
// If on a downhill slope, push the player downwards
if (!checkMaskUp(F1) && checkMaskUp(F2)) y += F1;
return;
}
/**
* Respond to tile modifier events.
*
* @param nextMod The modifier event
* @param ticks Time
*/
void JJ2LevelPlayer::modify (JJ2Modifier* nextMod, unsigned int ticks) {
switch (nextMod->type) {
case 2: // Spikes
if (jj2Level->checkMaskDown(x + JJ2PXO_MID, y + F1, false))
hit(NULL, ticks);
break;
case 4: // Hook
dx = 0;
break;
case 6: // H-pole
if (!stopTime) {
// Catch player
if (nextMod != mod) {
centreX();
centreY();
stopTime = ticks + 1000;
}
} else if (ticks > stopTime) {
dx = (dx > 0) ? JJ2PXS_POLE: -JJ2PXS_POLE;
stopTime = 0;
}
break;
case 7: // V-pole
if (!stopTime) {
// Catch player
if (nextMod != mod) {
centreX();
centreY();
stopTime = ticks + 1000;
}
} else if (ticks > stopTime) {
if (dy < 0) {
throwY = y - TTOF(16);
dy = -JJ2PYS_POLE;
} else {
dy = JJ2PYS_POLE;
}
stopTime = 0;
}
break;
case 8: // Fly off
floating = false;
break;
case 17: // End of level
case 18: // End of level
if (!energy) return;
if (!player->endOfLevel(FTOT(x + JJ2PXO_MID), FTOT(y + JJ2PYO_MID))) return;
jj2Level->setStage(LS_END);
break;
case 206: // Sucker tube
dx = (nextMod->properties & 0x40) ? -((nextMod->properties << 15) & 0x1F8000): ((nextMod->properties << 15) & 0x1F8000);
dy = (nextMod->properties & 0x2000) ? -((nextMod->properties << 8) & 0x1F8000): ((nextMod->properties << 8) & 0x1F8000);
if (dx) centreY();
if (dy) centreX();
break;
case 207: // Text
break;
case 208: // Water level
jj2Level->setWaterLevel(nextMod->properties & 0xFF, nextMod->properties & 0x100);
break;
case 230: // Warp
if (!stopTime) {
// Catch player
if (coins >= ((nextMod->properties >> 8) & 255)) stopTime = ticks + 1000;
} else if (ticks > stopTime) {
coins -= (nextMod->properties >> 8) & 255;
jj2Level->warp(this, nextMod->properties & 255);
stopTime = 0;
}
break;
default:
stopTime = 0;
break;
}
mod = nextMod;
return;
}
/**
* Respond to controls, unless the player has been killed
*
* @param ticks Time
* @param msps Ticks per step
*/
void JJ2LevelPlayer::control (unsigned int ticks, int msps) {
JJ2Modifier* nextMod;
bool drop, platform;
// If the player has been killed, do not move
if (!energy) {
dx = 0;
dy = 0;
animType = JJ2PA_DIE;
return;
}
// Get overlapping modifier
nextMod = jj2Level->getModifier(FTOT(x + JJ2PXO_MID), FTOT(y + JJ2PYO_MID));
if (stopTime) {
// Can't control player, so just apply modifier
modify(nextMod, ticks);
return;
}
if (player->pcontrols[C_RIGHT]) {
// Walk/run right
if (dx < 0) dx += JJ2PXA_REVERSE * msps;
else if (dx < JJ2PXS_WALK) dx += JJ2PXA_WALK * msps;
else if (dx < JJ2PXS_RUN) dx += JJ2PXA_RUN * msps;
facing = true;
} else if (player->pcontrols[C_LEFT]) {
// Walk/run left
if (dx > 0) dx -= JJ2PXA_REVERSE * msps;
else if (dx > -JJ2PXS_WALK) dx -= JJ2PXA_WALK * msps;
else if (dx > -JJ2PXS_RUN) dx -= JJ2PXA_RUN * msps;
facing = false;
} else if ((nextMod->type >> 1) != 3) {
// Slow down
if (dx > 0) {
if (dx < JJ2PXA_STOP * msps) dx = 0;
else dx -= JJ2PXA_STOP * msps;
}
if (dx < 0) {
if (dx > -JJ2PXA_STOP * msps) dx = 0;
else dx += JJ2PXA_STOP * msps;
}
}
drop = player->pcontrols[C_DOWN];
// Check for platform event, bridge or level mask below player
platform = (event == JJ2PE_PLATFORM) ||
checkMaskDown(1, drop) ||
((dx > 0) && jj2Level->checkMaskDown(x + JJ2PXO_ML, y + F8, drop)) ||
((dx < 0) && jj2Level->checkMaskDown(x + JJ2PXO_MR, y + F8, drop));
if (floating) {
if (player->pcontrols[C_UP]) {
// Fly upwards
if (dy > 0) dy -= JJ2PXA_REVERSE * msps;
else if (dy > -JJ2PXS_WALK) dy -= JJ2PXA_WALK * msps;
else if (dy > -JJ2PXS_RUN) dy -= JJ2PXA_RUN * msps;
} else if (player->pcontrols[C_DOWN]) {
// Fly downwards
if (dy < 0) dy += JJ2PXA_REVERSE * msps;
else if (dy < JJ2PXS_WALK) dy += JJ2PXA_WALK * msps;
else if (dy < JJ2PXS_RUN) dy += JJ2PXA_RUN * msps;
} else if ((nextMod->type >> 1) != 3) {
// Slow down
if (dy > 0) {
if (dy < JJ2PXA_STOP * msps) dy = 0;
else dy -= JJ2PXA_STOP * msps;
}
if (dy < 0) {
if (dy > -JJ2PXA_STOP * msps) dy = 0;
else dy += JJ2PXA_STOP * msps;
}
}
if (event == JJ2PE_SPRING) dy = JJ2PYS_SPRING;
else if (event == JJ2PE_FLOAT) dy = JJ2PYS_JUMP;
} else if (y + JJ2PYO_MID > jj2Level->getWaterLevel()) {
if (player->pcontrols[C_SWIM]) {
// Swim upwards
if (dy > 0) dy -= JJ2PXA_REVERSE * msps;
else if (dy > -JJ2PXS_WALK) dy -= JJ2PXA_WALK * msps;
else if (dy > -JJ2PXS_RUN) dy -= JJ2PXA_RUN * msps;
// Prepare to jump upon leaving the water
if (!jj2Level->checkMaskUp(x + JJ2PXO_MID, y - F36)) {
throwY = y - jumpHeight;
if (dx < 0) throwY += dx >> 4;
else if (dx > 0) throwY -= dx >> 4;
event = JJ2PE_NONE;
}
} else if (player->pcontrols[C_DOWN]) {
// Swim downwards
if (dy < 0) dy += JJ2PXA_REVERSE * msps;
else if (dy < JJ2PXS_WALK) dy += JJ2PXA_WALK * msps;
else if (dy < JJ2PXS_RUN) dy += JJ2PXA_RUN * msps;
} else {
// Sink
dy += JJ2PYA_SINK * msps;
if (dy > JJ2PYS_SINK) dy = JJ2PYS_SINK;
}
} else {
if (platform && player->pcontrols[C_JUMP] &&
!jj2Level->checkMaskUp(x + JJ2PXO_MID, y - F36)) {
// Jump
throwY = y - jumpHeight;
// Increase jump height if walking/running
if (dx < 0) throwY += dx >> 3;
else if (dx > 0) throwY -= dx >> 3;
event = JJ2PE_NONE;
playSound(S_JUMPA);
}
// Stop jumping
if (!player->pcontrols[C_JUMP] && (event != JJ2PE_SPRING) && (event != JJ2PE_FLOAT))
throwY = TTOF(256);
if (y >= throwY) {
// If jumping, rise
dy = (throwY - y - F64) * 4;
// Avoid jumping too fast, unless caused by an event
if ((event == JJ2PE_NONE) && (dy < JJ2PYS_JUMP)) dy = JJ2PYS_JUMP;
} else if (!platform) {
// Fall under gravity
dy += JJ2PYA_GRAVITY * msps;
if (dy > JJ2PYS_FALL) dy = JJ2PYS_FALL;
}
// Don't descend through platforms
if ((dy > 0) && (event == JJ2PE_PLATFORM)) dy = 0;
if (platform && !lookTime) {
// If requested, look up or down
if (player->pcontrols[C_UP]) lookTime = -ticks;
else if (player->pcontrols[C_DOWN]) lookTime = ticks;
}
// Stop looking if there is no platform or the control has been released
if (!platform ||
(!player->pcontrols[C_UP] && (lookTime < 0)) ||
(!player->pcontrols[C_DOWN] && (lookTime > 0))) lookTime = 0;
}
// If there is an obstacle above and the player is not floating up, stop
// rising
if (jj2Level->checkMaskUp(x + JJ2PXO_MID, y + JJ2PYO_TOP - F1) && (throwY < y) && (event != JJ2PE_FLOAT)) {
throwY = TTOF(256);
if (dy < 0) dy = 0;
if (event != JJ2PE_PLATFORM) event = JJ2PE_NONE;
}
// If jump completed, stop rising
if (y <= throwY) {
throwY = TTOF(256);
if (event != JJ2PE_PLATFORM) event = JJ2PE_NONE;
}
// Apply modifier
modify(nextMod, ticks);
// Limit speed
if (dx < -JJ2PXS_LIMIT) dx = -JJ2PXS_LIMIT;
else if (dx > JJ2PXS_LIMIT) dx = JJ2PXS_LIMIT;
if (dy < -JJ2PYS_LIMIT) dy = -JJ2PYS_LIMIT;
else if (dy > JJ2PYS_LIMIT) dy = JJ2PYS_LIMIT;
// Handle firing
if (player->pcontrols[C_FIRE]) {
if (ticks > fireTime) {
// Make sure bullet position is taken from correct animation
if (platform) animType = JJ2PA_STANDSHOOT;
/// @todo Create new bullet when firing
// Set when the next bullet can be fired
if (player->fireSpeed) fireTime = ticks + (1000 / player->fireSpeed);
else fireTime = 0x7FFFFFFF;
// Remove the bullet from the arsenal
if (player->ammoType != -1) player->ammo[player->ammoType]--;
/* If the current ammo type has been exhausted, use the previous
non-exhausted ammo type */
while ((player->ammoType > -1) && !player->ammo[player->ammoType]) player->ammoType--;
}
} else fireTime = 0;
// Check for a change in ammo
if (player->pcontrols[C_CHANGE]) {
if (player == localPlayer) controls.release(C_CHANGE);
player->ammoType = ((player->ammoType + 2) % 5) - 1;
// If there is no ammo of this type, go to the next type that has ammo
while ((player->ammoType > -1) && !player->ammo[player->ammoType])
player->ammoType = ((player->ammoType + 2) % 5) - 1;
}
// Deal with the bird
//if (birds) birds = birds->step(ticks, msps);
// Choose animation
if ((reaction == JJ2PR_HURT) && (reactionTime - ticks > JJ2PRT_HURT - JJ2PRT_HURTANIM))
animType = JJ2PA_HURT;
else if (y + JJ2PYO_MID > jj2Level->getWaterLevel())
animType = JJ2PA_SWIM;
else if (floating) animType = JJ2PA_BOARD;
else if (dy < 0) {
if (event == JJ2PE_SPRING) animType = JJ2PA_FLOAT1;
else animType = JJ2PA_JUMP;
} else if (platform) {
if (dx) {
if (dx <= -JJ2PXS_RUN) animType = JJ2PA_RUN;
else if (dx >= JJ2PXS_RUN) animType = JJ2PA_RUN;
else if ((dx < 0) && facing) animType = JJ2PA_STOP1;
else if ((dx > 0) && !facing) animType = JJ2PA_STOP1;
else animType = JJ2PA_WALKSHOOT;
} else if (!jj2Level->checkMaskDown(x + JJ2PXO_ML, y + F12, drop) &&
!jj2Level->checkMaskDown(x + JJ2PXO_L, y + F2, drop) &&
(event != JJ2PE_PLATFORM))
animType = JJ2PA_EDGE;
else if (!jj2Level->checkMaskDown(x + JJ2PXO_MR, y + F12, drop) &&
!jj2Level->checkMaskDown(x + JJ2PXO_R, y + F2, drop) &&
(event != JJ2PE_PLATFORM))
animType = JJ2PA_EDGE;
else if ((lookTime < 0) && ((int)ticks > 1000 - lookTime))
animType = JJ2PA_LOOKUP;
else if (lookTime > 0) {
if ((int)ticks < 1000 + lookTime) animType = JJ2PA_CROUCHED;
else animType = JJ2PA_CROUCH1;
}
else if (player->pcontrols[C_FIRE]) animType = JJ2PA_STANDSHOOT;
else animType = JJ2PA_STAND;
} else animType = JJ2PA_FALL;
return;
}
/**
* Move the player.
*
* @param ticks Time
* @param msps Ticks per step
*/
void JJ2LevelPlayer::move (unsigned int ticks, int msps) {
fixed pdx, pdy;
bool grounded = false;
int count;
bool drop;
if (stopTime) return;
// Apply as much of the trajectory as possible, without going into the
// scenery
if (fastFeetTime > ticks) {
pdx = (dx * msps * 3) >> 11;
pdy = (dy * msps * 3) >> 11;
} else {
pdx = (dx * msps) >> 10;
pdy = (dy * msps) >> 10;
}
// First for the vertical component of the trajectory
drop = player->pcontrols[C_DOWN];
if (pdy < 0) {
// Moving up
count = (-pdy) >> 10;
while (count > 0) {
if (jj2Level->checkMaskUp(x + JJ2PXO_MID, y + JJ2PYO_TOP - F1)) {
y &= ~1023;
dy = 0;
break;
}
y -= F1;
count--;
}
pdy = (-pdy) & 1023;
if (jj2Level->checkMaskUp(x + JJ2PXO_MID, y + JJ2PYO_TOP - pdy)) {
y &= ~1023;
dy = 0;
} else y -= pdy;
} else {
if (pdy > 0) {
// Moving down
count = pdy >> 10;
while (count > 0) {
if (checkMaskDown(F1, drop)) {
y |= 1023;
dy = 0;
break;
}
y += F1;
count--;
}
pdy &= 1023;
if (checkMaskDown(pdy, drop)) y |= 1023;
else y += pdy;
}
if (checkMaskDown(0, drop)) {
// In the ground, so move up
if (y >= 1024) y = (y - 1024) | 1023;
dy = 0;
grounded = true;
} else if (checkMaskDown(1, drop)) {
// On the ground
dy = 0;
grounded = true;
}
}
// Then for the horizontal component of the trajectory
if (pdx < 0) {
// Moving left
count = (-pdx) >> 10;
while (count > 0) {
// If there is an obstacle, stop
if (jj2Level->checkMaskUp(x + JJ2PXO_L - F1, y + JJ2PYO_MID)) {
x &= ~1023;
dx = 0;
break;
}
x -= F1;
count--;
if (grounded) ground();
}
pdx = (-pdx) & 1023;
if (jj2Level->checkMaskUp(x + JJ2PXO_L - pdx, y + JJ2PYO_MID)) {
x &= ~1023;
dx = 0;
} else x -= pdx;
if (grounded) ground();
} else if (pdx > 0) {
// Moving right
count = pdx >> 10;
while (count > 0) {
// If there is an obstacle, stop
if (jj2Level->checkMaskUp(x + JJ2PXO_R + F1, y + JJ2PYO_MID)) {
x |= 1023;
dx = 0;
break;
}
x += F1;
count--;
if (grounded) ground();
}
pdx &= 1023;
if (jj2Level->checkMaskUp(x + JJ2PXO_R + pdx, y + JJ2PYO_MID)) {
x |= 1023;
dx = 0;
} else x += pdx;
if (grounded) ground();
}
// If using a float up event and have hit a ceiling, ignore event
if ((event == JJ2PE_FLOAT) && jj2Level->checkMaskUp(x + JJ2PXO_MID, y + JJ2PYO_TOP - F1)) {
throwY = TTOF(256);
event = JJ2PE_NONE;
}
if (jj2Level->getStage() == LS_END) return;
return;
}
/**
* Calculate viewport.
*
* @param ticks Time
* @param mspf Ticks per frame
* @param change Time since last step
*/
void JJ2LevelPlayer::view (unsigned int ticks, int mspf, int change) {
int oldViewX, oldViewY, speed;
// Record old viewport position for applying lag
oldViewX = viewX;
oldViewY = viewY;
// Find new position
viewX = x + ((dx * change) >> 10) + F8 - (canvasW << 9);
viewY = y + ((dy * change) >> 10) - F24 - (canvasH << 9);
if ((lookTime > 0) && ((int)ticks > 1000 + lookTime)) {
// Look down
if ((int)ticks < 2000 + lookTime) viewY += 64 * (ticks - (1000 + lookTime));
else viewY += F64;
} else if ((lookTime < 0) && ((int)ticks > 1000 - lookTime)) {
// Look up
if ((int)ticks < 2000 - lookTime) viewY -= 64 * (ticks - (1000 - lookTime));
else viewY -= F64;
}
// Apply lag proportional to player "speed"
speed = ((dx >= 0? dx: -dx) + (dy >= 0? dy: -dy)) >> 14;
if (speed && (mspf < speed)) {
viewX = ((oldViewX * (speed - mspf)) + (viewX * mspf)) / speed;
viewY = ((oldViewY * (speed - mspf)) + (viewY * mspf)) / speed;
}
return;
}
/**
* Draw the player.
*
* @param ticks Time
* @param change Time since last step
*/
void JJ2LevelPlayer::draw (unsigned int ticks, int change) {
Anim *an;
int frame;
fixed drawX, drawY;
// The current frame for animations
if (reaction == JJ2PR_KILLED) frame = (ticks + JJ2PRT_KILLED - reactionTime) / 75;
else frame = ticks / 75;
// Get position
drawX = getDrawX(stopTime? 0: change);
drawY = getDrawY(stopTime? 0: change);
// Choose sprite
an = getAnim();
an->setFrame(frame, reaction != JJ2PR_KILLED);
// Show the player
// Use player colour
an->setPalette(palette, 16, 32);
// Flash on and off if hurt
if ((reaction != JJ2PR_HURT) || ((ticks / 30) & 2)) {
// Draw "motion blur"
if (fastFeetTime > ticks) an->draw(drawX + F16 - (dx >> 6), drawY + F16);
// Draw player
an->draw(drawX + F16, drawY + F16);
}
// Uncomment the following to see the area of the player
/*drawRect(FTOI(drawX + JJ2PXO_L - viewX),
FTOI(drawY + JJ2PYO_TOP - viewY),
FTOI(JJ2PXO_R - JJ2PXO_L),
FTOI(-JJ2PYO_TOP), 89);
drawRect(FTOI(drawX + JJ2PXO_ML - viewX),
FTOI(drawY + JJ2PYO_TOP - viewY),
FTOI(JJ2PXO_MR - JJ2PXO_ML),
FTOI(-JJ2PYO_TOP), 88);*/
if (reaction == JJ2PR_INVINCIBLE) {
/// @todo Show invincibility effect
}
switch (shield) {
case JJ2S_NONE:
// Do nothing
break;
case JJ2S_FLAME:
/// @todo Show shield effect
break;
case JJ2S_BUBBLE:
/// @todo Show shield effect
break;
case JJ2S_PLASMA:
/// @todo Show shield effect
break;
case JJ2S_LASER:
/// @todo Show shield effect
break;
}
// Show the bird
//if (birds) birds->draw(ticks, change);
// Show the player's name
if (nPlayers > 1)
panelBigFont->showString(player->name,
FTOI(drawX + JJ2PXO_MID) - (panelBigFont->getStringWidth(player->name) >> 1),
FTOI(drawY - F32 - F16));
panelBigFont->setPalette(palette);
//panelBigFont->showNumber(mod->properties, FTOI(drawX) + 24, FTOI(drawY) + 12);
return;
}