Repository navigation
Expand file tree
/
Copy pathnesgame.c
More file actions
1600 lines (1469 loc) · 42.1 KB
/
Copy pathnesgame.c
File metadata and controls
1600 lines (1469 loc) · 42.1 KB
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
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Another game for the nes
*/
// Neslib
#include "neslib.h"
// 0 = horizontal mirroring
// 1 = vertical mirroring
#define NES_MIRRORING 1
// link the pattern table into CHR ROM
//#link "chr_generic.s"
// VRAMBuf
#include "vrambuf.h"
//#link "vrambuf.c"
// FamiTone2
//#link "famitone2.s"
//#link "music.s"
#include "music_songlist.inc"
extern byte music_data_nes_game_music[];
// String
#include <string.h>
// Offscreen Tiles
#include "offscreen.h"
//#link "offscreen.c"
// Area Loader
#include "area.h"
//#link "area.c"
// Metasprite Display
#include "sprite.h"
//#link "sprite.c"
// Flags
#include "flags.h"
//#link "flags.c"
// BCD
#include "bcd.h"
//#link "bcd.c"
#define INITIAL_AREA 0
#define INITIAL_WEAPON 0
#define INITIAL_COMPASS false
#define INITIAL_HORSE false
const byte weapon_damage[] = {3, 4, 6, 1};
#define DEFAULT_MAX_HEALTH 12
#define FOUNTAIN_HEALTH 4
// Global Variables
#define INITIAL_COINS 0
#define INITIAL_KEYS 0
word deaths = 0;
void death() {
char counter[4] = "\x26 ";
deaths = bcd_add(deaths, 1);
counter[1] = 0x30+((deaths>>8)&0xf);
counter[deaths > 0x99 ? 2 : 1] = 0x30+((deaths>>4)&0xf);
counter[deaths > 9 ? (deaths > 0x99 ? 3 : 2) : 1] = 0x30+(deaths&0xf);
vrambuf_put(NTADR_A(16, 2), counter, 4);
}
char* death_messages[10] = {
"Just a mild inconvenience",
"Pretend that didn't happen",
"Time travel saves the day",
"Maybe swing earlier?",
"This counter goes to 999",
"Running is strategic",
"It could have been worse",
"Timing is critical.",
"It saves while loading.",
"There are 10 of these",
};
byte coins;
bool doorinhibitor = false;
bool compass = false;
void update_coins(byte new) {
char disp[2] = "\x10 ";
coins = new;
if (coins == 0) {
vrambuf_put(NTADR_A(22, 2), " ", 2);
return;
}
disp[1] = 0x30+coins;
vrambuf_put(NTADR_A(22,2), disp, 2);
}
byte keys = 0;
void update_keys(byte num) {
char disp[2] = "\x19 ";
keys = num;
disp[1] = 0x30 + keys;
if (keys == 0) {
vrambuf_put(NTADR_A(28,2), " ", 2);
return;
}
vrambuf_put(NTADR_A(28,2), disp, 2);
}
byte weapon = 0;
bool bow = false;
byte anim;
word t_scroll = 0;
bool offroad = false;
#define t_scroll_speed 16
word x_scroll = 0;
word newx_scroll;
byte dir = RIGHT;
#define PLAYER_WALK 2
#define PLAYER_RUN 4
#define PLAYER_WALK_ANIM_SPEED 1
#define PLAYER_RUN_ANIM_SPEED 2
#define PLAYER_RUN_MIN_HEALTH 4
#define HORSE 6
#define HORSE_STEAL_DISTANCE 12
#define SPIDER_DAMAGE 3
#define GREEN_SPIDER_DAMAGE 4
byte playerspeed = 0;
bool shield = false;
#define ATTACK_TIME 8
#define HIT_TIME (ATTACK_TIME-4)
#define HIT_RADIUS 10
byte attacktimer = 0;
bool attacking = false;
word playerx = 50;
byte playery = 0;
bool collision(word x1, byte y1, word x2, byte y2) {
return (x1 < x2+8 && x1+8 >= x2 && y1 < y2+8 && y1+8 >= y2);
}
bool player_collision(word x, byte y) {
return collision(x,y, playerx, playery);
}
bool attack_hit(word x, byte y) {
return (playerx < x+HIT_RADIUS && playerx+HIT_RADIUS >= x && playery < y+HIT_RADIUS && playery+HIT_RADIUS >= y);
}
bool horse = false;
bool moving = false;
word oldplayerx = 0;
byte oldplayery = 0;
byte MAX_PLAYER_HEALTH = 12;
#define INITIAL_HEALTH 12
byte playerhealth;
#define DAMAGE_COOLDOWN 12
#define PLAYER_KNOCKBACK 6
#define WEAK_PLAYER_KNOCKBACK 3
#define WEAK_HIT_HP 1
byte damage_cooldown = 0;
bool knockback_flip = false;
void damage(byte dmg) {
byte i, j;
if (knockback_flip) dir = dir==RIGHT? LEFT:RIGHT;
if (dmg > WEAK_HIT_HP)
j = PLAYER_KNOCKBACK;
else
j = WEAK_PLAYER_KNOCKBACK;
playerx = oldplayerx+(dir == RIGHT? -j : j);
playery = oldplayery;
if ( dir == RIGHT && oldplayerx < playerx || dir == LEFT && oldplayerx > playerx)
playerx = oldplayerx;
dir = dir==RIGHT? LEFT:RIGHT;
knockback_flip = true;
if (damage_cooldown != 0)
return;
damage_cooldown = DAMAGE_COOLDOWN;
playerhealth -= dmg;
if (dmg != 255 && playerhealth > i) {
playerhealth = 0;
}
i = playerhealth;
if (playerhealth <= 1 && !(flags[BOBBERT]&PLAYER_SAVED))
playerhealth = 1;
// Player health
for (i = 0; i < MAX_PLAYER_HEALTH; i+=4) {
if (i > playerhealth)
j = 0x14;
else if (playerhealth - i > 4)
j = 0x18;
else
j = 0x14+(playerhealth-i)%5;
vrambuf_put(NTADR_A(2+(i>>2),2), &j, 1);
}
}
#define CENTER 119
#define HORSE_INDEX MAX_ENTITIES
EntityState current_entities[MAX_ENTITIES+1];
byte horse_area = 0;
// Pre def
void dialogue(char* name, char* text);
#define YES 1
#define NO 2
#define MAYBE 3
byte decision(char* title);
void load_area(byte newarea, word x, byte y);
void wait_frame();
// Entity Callbacks
void pushable(EntityState* entity) {
entity->x += playerx-oldplayerx;
entity->y += playery-oldplayery;
doorinhibitor = true;
}
void horse_mount(EntityState* entity) {
if (!horse) {
horse = true;
entity->entity = 0;
playery = entity->y;
playerx = entity->x;
}
}
void bobbert_walk(EntityState* entity) {
// Anim
entity->chr_offset = (anim&4) ? 4 : 0;
if (entity->x > playerx+6*TILE_SIZE) {
if (!(flags[BOBBERT]&PLAYER_SLOW)) {
dialogue("?", "Are you coming or not?");
flags[BOBBERT] |= PLAYER_SLOW;
}
entity->chr_offset = 4;
}
else if (entity->x < 27*TILE_SIZE) {
entity->x+=(playerx<entity->x-TILE_SIZE*2? 1: 2);
if (entity->y > 6*TILE_SIZE-8)
entity->y--;
else if (entity->y < 6*TILE_SIZE-8)
entity->y++;
}
else if (entity->y > 1*TILE_SIZE)
entity->y-=2;
else {
entity->entity = 2; // Standstill
entity->chr_offset = 0;
dialogue("?", "My soup can heal you");
dialogue("Bobbert", "By the way, I'm Bobbert");
if (player_collision(entity->x, entity->y)) {
entity->x-=TILE_SIZE;
}
}
}
void player_pushback() {
playerx = oldplayerx;
playery = oldplayery;
}
void bobbert_init(EntityState* entity) {
if (flags[BOBBERT]&PLAYER_SAVED) {
entity->x = 27*TILE_SIZE;
entity->y = 1*TILE_SIZE;
entity->entity = 2;
}
}
void bobbert_save(EntityState* entity) {
byte y;
word x;
byte t;
if (current_entities[2].entity != 7) {
// Anim
entity->chr_offset = (anim&4) ? 4 : 0;
sprite(entity->x-4, entity->y+(anim&8 ? 8 : 4), 0x84, 2 | OAM_FLIP_H | (anim&8 ? OAM_FLIP_V : 0));
t = 0;
for (t = 2; t < 5 && current_entities[t].entity == 0; t++);
if (current_entities[t].entity != 0) {
y = current_entities[t].y;
x = current_entities[t].x;
if (collision(entity->x,entity->y,x,y)) {
current_entities[t].entity = 0;
}
}
else {
entity->entity = 3;
flags[BOBBERT] |= PLAYER_SAVED;
dialogue("?", "Follow me, I can heal you");
return;
}
if (entity->x > x)
entity->x-=4;
else if (entity->x < x)
entity->x+=6;
if (entity->y > y)
entity->y-=2;
else if (entity->y < y)
entity->y+=2;
}
}
void bobbert_soup(EntityState*) {
if (flags[BOBBERT]&HORSE_STOLEN) {
dialogue("Bobbert", "Horse thief, you want soup?");
if (coins >= 2) {
dialogue("Bobbert", "It seems you can pay.");
switch (decision("Give Bobbert the coins?")) {
case YES:
update_coins(coins-2);
while(playerhealth < MAX_PLAYER_HEALTH) {
playerhealth++;
damage_cooldown = 0;
damage(0);
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
}
wait_frame();
if (!(flags[BOBBERT]&RESTAURANT_MENTIONED)) {
dialogue("Bobbert", "This gives me an idea ...");
dialogue("Bobbert", "I could make a restaurant!");
flags[BOBBERT] |= RESTAURANT_MENTIONED;
}
break;
case NO:
dialogue("Bobbert", "Oh well...");
break;
case MAYBE:
dialogue("Bobbert", "So you're considering it?");
break;
}
}
else dialogue("Bobbert", "Give me two coins.");
}
else {
if (playerhealth != MAX_PLAYER_HEALTH) dialogue("Bobbert", "Go on, try the soup!");
else if (!(flags[BOBBERT]&RESTAURANT_MENTIONED)) {
dialogue("Bobbert", "What did you think?");
switch (decision("Was the soup good?")) {
case YES:
dialogue("Bobbert", "Thank you!");
break;
case NO:
dialogue("Bobbert", "I'll try to make it better.");
break;
case MAYBE:
dialogue("Bobbert", "I'll improve it for you!");
break;
}
dialogue("Bobbert", "Anyways, I was thinking ...");
dialogue("Bobbert", "I could make a restaurant!");
flags[BOBBERT] |= RESTAURANT_MENTIONED;
}
}
player_pushback();
}
void soup_pot(EntityState* e) {
if (e != NULL && flags[BOBBERT]&HORSE_STOLEN)
dialogue("Bobbert", "No soup for you!");
else {
while(playerhealth < MAX_PLAYER_HEALTH) {
playerhealth++;
damage_cooldown = 0;
damage(0);
wait_frame();
wait_frame();
wait_frame();
wait_frame();
}
if (e != NULL && !(flags[BOBBERT]&HORSE_LENT)) {
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
dialogue("Bobbert", "Could you do a favor for me?");
dialogue("Bobbert", "I need this letter delivered");
dialogue("Bobbert", "Go quickly on my horse!");
dialogue("Bobbert", "You can dismount with \x12");
vrambuf_put(NTADR_A(26,2), "\x1e", 1);
flags[BOBBERT] |= HAS_MESSAGE;
flags[BOBBERT] |= HORSE_LENT;
}
}
player_pushback();
}
void bobbert_house(EntityState*) {
if (flags[BOBBERT]&HORSE_STOLEN)
dialogue("Bobbert", "You stole my horse, thief.");
else if (playerhealth == MAX_PLAYER_HEALTH)
dialogue("Bobbert", "Come back any time!");
else
dialogue("Bobbert", "Go inside and try my soup!");
player_pushback();
}
void spider_wait(EntityState* entity) {
if (playerx+4*TILE_SIZE > entity->x && playerx < entity->x+4*TILE_SIZE)
entity->entity = (entity->entity == 7) ? 8 : 21;
}
#define SPIDER_SPEED 4
void spider_attack(EntityState* entity) {
if (playerx > entity->x)
entity->x+=SPIDER_SPEED;
else if (playerx < entity->x)
entity->x-=SPIDER_SPEED;
if (playery > entity->y)
entity->y+=SPIDER_SPEED;
else if (playery < entity->y)
entity->y-=SPIDER_SPEED;
}
void spider_hit(EntityState* entity) {
entity->entity = 9;
damage(SPIDER_DAMAGE);
}
void spider_retreat(EntityState* entity) {
entity->y += rand8()&7;
entity->y -= rand8()&7;
if (entity->x < playerx+TILE_SIZE*4)
entity->x += rand8()&7;
else
entity->entity = 8;
}
void sign_read(EntityState*) {
byte i;
switch (area) {
case 2:
dialogue("Sign", "<-- Forest ------ Turlin -->");
break;
case 3:
if (flags[TURLIN]&SIGN_UPDATE && !(flags[TURLIN]&HOUSE_KEYS)) {
dialogue("Welcome to Turlin!", "Population: 1 :(");
flags[TURLIN] |= UPDATE_CHECK;
}
else dialogue("Welcome to Turlin!", "Population: 2");
break;
case 5:
dialogue("End of the road.", "Continue if you dare");
break;
case 9:
dialogue("Deep within the forest", "The great sword lies");
break;
case 11:
dialogue("Look behind you", "Monsters.");
for (i = 1; i <= 3; i++) {
current_entities[i].entity = 7;
current_entities[i].x = TILE_SIZE*32;
current_entities[i].y = (TILE_SIZE*3)+(TILE_SIZE*3-8)*(i-1);
current_entities[i].health = SPIDER_HP;
}
for (i = 4; i <= 5; i++) {
current_entities[i].entity = 17;
current_entities[i].x = TILE_SIZE*i*5;
current_entities[i].y = TILE_SIZE*6-8;
}
break;
case 20:
dialogue("Position the turtles.", "The paths show the way.");
break;
// Temp win
case 23:
dialogue("You win!", "That's all for now");
break;
default:
dialogue("Faded Sign", "The text is unreadable");
};
player_pushback();
}
void basic_sword_collect(EntityState* entity) {
weapon=2;
entity->entity = 0;
load_area(14, TILE_SIZE*38, TILE_SIZE*5);
}
void fountain_of_health(EntityState*) {
switch(decision("Toss coin into fountain?")) {
case YES:
if (coins) {
dialogue("Plop.", "The coin lands in the water");
update_coins(coins-1);
MAX_PLAYER_HEALTH+=FOUNTAIN_HEALTH;
dialogue("Max health increased", "You feel stronger somehow");
}
else
dialogue("...", "You just tossed in some air");
break;
case NO:
break;
case MAYBE:
dialogue("You stare at the fountain", "A few coins are inside.");
break;
}
player_pushback();
}
void basic_die(EntityState* entity) {
entity->entity = 0;
}
void basic_knockback(EntityState* entity) {
if (dir == LEFT) entity->x-=TILE_SIZE*2+8;
else entity->x+=TILE_SIZE*2+8;
}
void mayor_turt(EntityState*) {
if (!(flags[TURLIN]&LE_INTRODUCTION)) {
flags[TURLIN] |= LE_INTRODUCTION;
dialogue("Turt Le", "Hello, I am Turt Le, ...");
dialogue("Mayor Le", "... Mayor of Turlin!");
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
}
if (weapon == 0) {
dialogue("Mayor Le", "You don't have a sword!");
dialogue("Mayor Le", "It's dangerous to go alone.");
dialogue("Mayor Le", "Take this.");
dialogue("Mayor Le", "Attack with \x13");
weapon = 4;
}
else if (!(flags[TURLIN]&LE_MONSTERS)) {
dialogue("Mayor Le", "Have you seen them?");
dialogue("Mayor Le", "The monsters.");
flags[TURLIN]|=LE_MONSTERS;
}
else if (flags[TURLIN]&OSCAR_DISCOVERY && !(flags[TURLIN]&SIGN_UPDATE)) {
dialogue("Mayor Le", "Wait...");
dialogue("Mayor Le", "So no one lives there?");
wait_frame();
wait_frame();
wait_frame();
wait_frame();
dialogue("Mayor Le", "Oscar used to live there.");
dialogue("Mayor Le", "I haven't seen him,");
dialogue("Mayor Le", "Not recently anyway.");
dialogue("Mayor Le", "Not since the monsters.");
wait_frame();
wait_frame();
wait_frame();
wait_frame();
dialogue("Mayor Le", "I hope he's ok...");
wait_frame();
wait_frame();
wait_frame();
wait_frame();
dialogue("Mayor Le", "I should update that sign");
flags[TURLIN] |= SIGN_UPDATE;
}
else if (flags[TURLIN]&SIGN_UPDATE && !(flags[TURLIN]&HOUSE_KEYS)) {
if (flags[TURLIN]&UPDATE_CHECK) {
dialogue("Mayor Le", "You saw it?");
dialogue("Mayor Le", "Kind of sad honestly.");
wait_frame();
wait_frame();
wait_frame();
wait_frame();
wait_frame();
dialogue("Mayor Le", "Hey, I have an idea!");
dialogue("Mayor Le", "Do you want to live here?");
switch(decision("Live in Turlin?")) {
case YES:
dialogue("Mayor Le", "Yay!");
dialogue("Mayor Le", "Here are some keys.");
dialogue("Mayor Le", "The ones to that house.");
dialogue("Mayor Le", "I always keep spares");
flags[TURLIN] |= HOUSE_KEYS;
wait_frame();
wait_frame();
wait_frame();
wait_frame();
dialogue("Mayor Le", "I'll update that sign again");
break;
case NO:
dialogue("Mayor Le", "Oh well...");
break;
case MAYBE:
dialogue("Mayor Le", "I hope you decide to!");
break;
}
}
else dialogue("Mayor Le", "Go check out the sign!");
}
else if (flags[TURLIN]&HOUSE_KEYS) {
dialogue("Mayor Le", "How is living in Turlin?");
switch (decision("Do you like Turlin?")) {
case YES:
dialogue("Mayor Le", "I knew you would!");
break;
case NO:
dialogue("Mayor Le", "That's too bad.");
break;
case MAYBE:
dialogue("Mayor Le", "I think you will!");
break;
}
}
else {
dialogue("Mayor Le", "Let me tell you a story.");
dialogue("Mayor Le", "A few months ago,");
dialogue("Mayor Le", "A monster came to Turlin.");
dialogue("Mayor Le", "It tried to take a coin,");
dialogue("Mayor Le", "One from the fountain.");
dialogue("Mayor Le", "It just died on the spot.");
dialogue("Mayor Le", "How strange ...");
flags[TURLIN]|=LE_STORY;
}
player_pushback();
}
void chest_collect(EntityState* entity) {
switch(area) {
case 8:
compass = true;
break;
case 12:
update_coins(coins+1);
flags[FOREST] |= COINS_1;
break;
case 10:
update_keys(keys+1);
flags[FOREST] |= KEYS_1;
break;
case 14:
update_coins(coins+1);
flags[FOREST] |= COINS_2;
break;
case 19:
update_keys(keys+1);
flags[FOREST] |= KEYS_2;
break;
case 16:
update_coins(coins+2);
flags[FOREST] |= COINS_3;
break;
}
entity->entity = 0;
}
void chest_init(EntityState* entity) {
bool empty = false;
switch (area) {
case 8:
if (compass)
empty = true;
break;
case 12:
if (flags[FOREST]&COINS_1) empty = true;
break;
case 10:
if (flags[FOREST]&KEYS_1) empty = true;
break;
case 14:
if (flags[FOREST]&COINS_2) empty = true;
break;
case 19:
if (flags[FOREST]&KEYS_2) empty = true;
break;
case 16:
if (flags[FOREST]&COINS_3) empty = true;
break;
}
if (empty)
entity->entity = 0;
}
void solid_entity(EntityState*) {
player_pushback();
}
void bat_fly(EntityState* entity) {
entity->chr_offset = (anim&4) ? 4 : 0;
if (entity->y+TILE_SIZE*2 > playery)
entity->y--;
else if (entity->x+TILE_SIZE*2 > playerx && entity->x < playerx+TILE_SIZE*2)
entity->entity = 18;
else
entity->y += rand8()&1 ? -1 : 1;
if (playerx > entity->x)
entity->x++;
else if (playerx < entity->x)
entity->x--;
else
entity->x+= rand8()&1 ? -2 : 2;
}
void bat_attack(EntityState* entity) {
if (playerx > entity->x)
entity->x+=3;
else if (playerx < entity->x)
entity->x-=3;
if (playery > entity->y)
entity->y+=3;
else if (playery < entity->y)
entity->y-=3;
}
void bat_hit(EntityState* entity) {
damage(1);
entity->entity = 17;
}
void tunnel_door_inhibitor(EntityState* entity) {
doorinhibitor = true;
if (entity->x > TILE_SIZE*11 || entity->x < TILE_SIZE*9
|| entity->y < TILE_SIZE*5 || entity->y > TILE_SIZE*7)
doorinhibitor = false;
}
void strong_spider_hit(EntityState* entity) {
damage(GREEN_SPIDER_DAMAGE);
entity->entity = 22;
}
void strong_spider_attack(EntityState* entity) {
byte sign = 0;
if (entity->memory < 10) entity->memory++;
if (playerx > entity->x)
sign += 1;
else
sign -= 1;
if (entity->x > playerx) {
entity->x -= entity->memory/2;
}
else if (entity->x < playerx) {
entity->x += entity->memory/2;
}
if (playerx > entity->x)
sign += 1;
else
sign -= 1;
if (sign == 0)
entity->x = playerx;
if (entity->y > playery) {
entity->y -= entity->memory;
}
else if (entity->y < playery) {
entity->y += entity->memory;
}
}
void strong_spider_retreat(EntityState* entity) {
entity->memory = 0;
entity->x += 12;
entity->y += rand8()&7;
entity->y -= rand8()&7;
if (entity->y > playery)
entity->y += 1;
if (entity->y < playery)
entity->y -= 1;
if (entity->x > playerx+TILE_SIZE*4)
entity->entity = 21;
}
void maze_puzzle_solved(EntityState* entity) {
bool solved = true;
doorinhibitor = true;
if (current_entities[0].y != TILE_SIZE*8)
solved = false;
if (current_entities[1].y != TILE_SIZE*8)
solved = false;
if (current_entities[2].y != TILE_SIZE*3)
solved = false;
if (solved) {
doorinhibitor = false;
entity->entity = 0;
}
}
void puzzle_pushable(EntityState* entity) {
entity->y += playery-oldplayery;
playerx = oldplayerx;
if (entity->y < TILE_SIZE*3) {
entity->y = TILE_SIZE*3;
playery = oldplayery;
}
if (entity->y > TILE_SIZE*8) {
entity->y = TILE_SIZE*8;
playery = oldplayery;
}
}
void ball_hit(EntityState* entity) {
entity->entity = 0;
damage(1);
}
void ball_tick(EntityState* entity) {
entity->x-=(entity->memory&0b10000000) ? -2 : 2;
if (entity->memory&0b01000000)
entity->y -= entity->memory&0xf;
else
entity->y += entity->memory&0xf;
if (entity->x < TILE_SIZE*1-8 || entity->x > TILE_SIZE*15-8) {
entity->memory^=0b10000000;
}
if (entity->y < TILE_SIZE*2-8 || entity->y > TILE_SIZE*10-8) {
entity->memory^=0b01000000;
}
}
void ball_whack(EntityState* entity) {
entity->entity = 26;
}
void ball_flyback(EntityState* entity) {
entity->x += 8;
// Course Correction
if (entity->y > TILE_SIZE*6-8)
entity->y-=2;
if (entity->y < TILE_SIZE*6-8)
entity->y+=2;
if (collision(entity->x, entity->y, current_entities[MAX_ENTITIES-1].x, current_entities[MAX_ENTITIES-1].y)) {
entity->entity = 0;
current_entities[MAX_ENTITIES-2].memory--;
}
if (entity->x > TILE_SIZE*16) {
entity->entity = 0;
}
}
void boss_tick(EntityState* entity) {
bool summon = true;
byte i = 0;
for (i = 0; i < 4; i++) {
if (current_entities[i].entity != 0)
summon = false;
}
if (summon && entity->memory == 0)
current_entities[MAX_ENTITIES-1].memory++;
entity->chr_offset = 4;
if (summon) switch (current_entities[MAX_ENTITIES-1].memory) {
case 1:
current_entities[0].entity = 25;
current_entities[0].x = TILE_SIZE*14;
current_entities[0].y = TILE_SIZE*6-8;
current_entities[0].memory = 0;
current_entities[0].chr_offset = 0;
entity->memory = 1;
break;
case 2:
current_entities[0].entity = 25;
current_entities[0].x = TILE_SIZE*14;
current_entities[0].y = TILE_SIZE*6-8;
current_entities[0].memory = 1;
current_entities[0].chr_offset = 0;
current_entities[1].entity = 25;
current_entities[1].x = TILE_SIZE*14;
current_entities[1].y = TILE_SIZE*6-8;
current_entities[1].memory = 0b01000010;
current_entities[1].chr_offset = 0;
entity->memory = 2;
break;
case 3:
current_entities[0].entity = 25;
current_entities[0].x = TILE_SIZE*14;
current_entities[0].y = TILE_SIZE*6-8;
current_entities[0].memory = 5;
current_entities[0].chr_offset = 0;
current_entities[1].entity = 25;
current_entities[1].x = TILE_SIZE*14;
current_entities[1].y = TILE_SIZE*6-8;
current_entities[1].memory = 0b01000100;
current_entities[1].chr_offset = 0;
entity->memory = 2;
break;
case 13:
current_entities[0].entity = 25;
current_entities[0].x = TILE_SIZE*14;
current_entities[0].y = TILE_SIZE*6-8;
current_entities[0].memory = 1;
current_entities[0].chr_offset = 0;
entity->memory = 1;
current_entities[1].entity = 17;
current_entities[1].x = TILE_SIZE*14;
current_entities[1].y = TILE_SIZE*3;
break;
case 34:
current_entities[0].entity = 25;
current_entities[0].x = TILE_SIZE*14;
current_entities[0].y = TILE_SIZE*6-8;
current_entities[0].memory = 4;
current_entities[0].chr_offset = 0;
current_entities[1].entity = 25;
current_entities[1].x = TILE_SIZE*14;
current_entities[1].y = TILE_SIZE*6-8;
current_entities[1].memory = 0b01000100;
current_entities[1].chr_offset = 0;
entity->memory = 3;
current_entities[2].entity = 25;
current_entities[2].x = TILE_SIZE*14;
current_entities[2].y = TILE_SIZE*6-8;
current_entities[2].memory = 0;
current_entities[2].chr_offset = 0;
break;
case 100:
current_entities[0].entity = 8;
current_entities[0].health = SPIDER_HP;
current_entities[0].x = TILE_SIZE*14;
current_entities[0].y = TILE_SIZE*8;
current_entities[0].chr_offset = 0;
current_entities[1].entity = 8;
current_entities[1].health = SPIDER_HP;
current_entities[1].x = TILE_SIZE*14;
current_entities[1].y = TILE_SIZE*3;
current_entities[1].chr_offset = 0;
current_entities[2].entity = 25;
current_entities[2].x = TILE_SIZE*14;
current_entities[2].y = TILE_SIZE*6-8;
current_entities[2].memory = 0;
current_entities[2].chr_offset = 0;
entity->memory = 1;
break;
case 255:
// Melee
entity->entity = 30;
current_entities[MAX_ENTITIES-1].entity = 0;
break;
}
else entity->chr_offset = 0;
}
void sword_lowering(EntityState* entity) {
entity->y+=2;
if (entity->y == TILE_SIZE*6-8) {
entity->y = TILE_SIZE*6-8;
entity->entity = 11;
}
}
void boss_melee_fly(EntityState* entity) {
entity->chr_offset = (anim&4) ? 4 : 0;
if (entity->y+TILE_SIZE*2 > playery)
entity->y--;
else if (entity->x+TILE_SIZE*2 > playerx && entity->x < playerx+TILE_SIZE*2)
entity->entity = 31;
else
entity->y += rand8()&1 ? -1 : 1;
if (playerx > entity->x)
entity->x+=4;
else if (playerx < entity->x)
entity->x-=4;
else
entity->x+= rand8()&1 ? -2 : 2;
}
void boss_melee_attack(EntityState* entity) {
if (playerx > entity->x) {
entity->x+=6;
}
else if (playerx < entity->x) {
entity->x-=6;
}
if (playery > entity->y) {
entity->y+=4;