-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMETROIDVANIA_CODE_EXAMPLE.js
More file actions
1082 lines (908 loc) · 35.4 KB
/
METROIDVANIA_CODE_EXAMPLE.js
File metadata and controls
1082 lines (908 loc) · 35.4 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
/**
* WoWmon Metroidvania - Code Implementation Examples
* Agent 7: Exploration Strategy
*
* This file contains example code snippets for implementing the Metroidvania redesign.
* These can be integrated into the existing wowMon.html file.
*/
// ===================================================================
// 1. ENHANCED MAP SYSTEM WITH INTERCONNECTIONS
// ===================================================================
class MetroidvaniaMapSystem {
constructor() {
this.zones = new Map();
this.currentZone = 'goldshire';
this.discoveredZones = new Set(['goldshire']);
this.unlockedConnections = new Set();
this.playerAbilities = new Set();
this.initializeWorldData();
}
initializeWorldData() {
// Goldshire - Central Hub
this.addZone('goldshire', {
name: 'Goldshire',
size: { width: 40, height: 40 },
tileData: [], // 40x40 tile array
connections: [
{ to: 'dark_forest', x: 20, y: 0, requirement: null, direction: 'north' },
{ to: 'sunken_ruins', x: 0, y: 20, requirement: null, direction: 'west' },
{ to: 'burning_wastes', x: 39, y: 20, requirement: 'tree_cut', direction: 'east' },
{ to: 'underground_depths', x: 20, y: 39, requirement: 'rock_smash', direction: 'south' },
{ to: 'shadow_crypts', x: 15, y: 35, requirement: 'shadow_walk', hidden: true, direction: 'down' }
],
landmarks: [
{ id: 'inn', name: "Lion's Pride Inn", x: 20, y: 20, icon: '🏠', type: 'healing' },
{ id: 'oak', name: 'Great Oak', x: 25, y: 15, icon: '🌳', type: 'landmark' },
{ id: 'well', name: 'Well of Worlds', x: 18, y: 25, icon: '⚪', type: 'warp', hidden: true }
],
secrets: [
{
id: 'goldshire_exp_share',
x: 18, y: 26,
requirement: 'swimming',
type: 'hidden_item',
reward: { item: 'exp_share', quantity: 1 }
}
],
encounters: {
base: ['gnoll', 'kobold', 'wisp'],
scaled: {
2: ['wolf', 'spider'],
4: ['dire_wolf', 'nerubian'],
8: ['legendary_beast']
}
},
warpShrineLocation: { x: 20, y: 18 }
});
// Dark Forest - Nature Zone
this.addZone('dark_forest', {
name: 'Dark Forest',
size: { width: 60, height: 60 },
tileData: [],
connections: [
{ to: 'goldshire', x: 30, y: 59, requirement: null, direction: 'south' },
{ to: 'frozen_peaks', x: 30, y: 0, requirement: 'climbing', direction: 'north' },
{ to: 'underground_depths', x: 35, y: 45, requirement: 'rock_smash', direction: 'down' },
{ to: 'burning_wastes', x: 59, y: 30, requirement: 'tree_cut', hidden: true, direction: 'east' }
],
landmarks: [
{ id: 'twisted_grove', name: 'Twisted Grove', x: 30, y: 30, icon: '🌲', type: 'gym' },
{ id: 'moonwell', name: 'Moonwell Glade', x: 15, y: 20, icon: '✨', type: 'peaceful' }
],
secrets: [
{
id: 'secret_grove',
x: 5, y: 5,
requirement: 'tree_cut',
type: 'hidden_area',
reward: { creature: 'ancient_treant', level: 50 }
}
],
encounters: {
base: ['wisp', 'wolf', 'spider'],
scaled: {
3: ['ancient_wisp', 'dire_wolf'],
6: ['treant', 'nerubian']
}
},
warpShrineLocation: { x: 5, y: 5 }
});
// More zones would be added similarly...
}
addZone(id, zoneData) {
this.zones.set(id, zoneData);
}
canAccessConnection(connection) {
// Check if player has required ability
if (!connection.requirement) return true;
return this.playerAbilities.has(connection.requirement);
}
getAvailableConnections(zoneId) {
const zone = this.zones.get(zoneId);
return zone.connections.filter(conn => {
if (conn.hidden && !this.hasDiscoveredSecret(zoneId, conn)) return false;
return this.canAccessConnection(conn);
});
}
checkConnectionAtPosition(x, y) {
const zone = this.zones.get(this.currentZone);
const connection = zone.connections.find(conn =>
conn.x === x && conn.y === y
);
if (!connection) return null;
if (!this.canAccessConnection(connection)) {
return {
blocked: true,
requirement: connection.requirement,
message: this.getBlockedMessage(connection.requirement)
};
}
return { blocked: false, connection };
}
getBlockedMessage(requirement) {
const messages = {
'tree_cut': 'A thick tree blocks the path. Maybe a Nature creature could cut it?',
'rock_smash': 'A large boulder is in the way. A strong creature might be able to smash it.',
'swimming': 'Deep water ahead. You need a Water creature that can swim.',
'climbing': 'The cliff is too steep to climb without help.',
'lava_walking': 'The lava is too hot! You need protection from fire.',
'shadow_walk': 'A shadowy barrier blocks the way. Only shadow creatures can pass.',
'flight': 'The area is unreachable without flying.',
'ice_breaking': 'Ice blocks the path. Fire might melt it...'
};
return messages[requirement] || 'Something is blocking the way.';
}
unlockAbility(abilityName) {
this.playerAbilities.add(abilityName);
this.triggerAbilityUnlockEvent(abilityName);
return this.revealNewPaths(abilityName);
}
revealNewPaths(abilityName) {
const newPaths = [];
// Check all zones for newly accessible connections
for (const [zoneId, zone] of this.zones) {
for (const connection of zone.connections) {
if (connection.requirement === abilityName) {
newPaths.push({
zone: zone.name,
destination: this.zones.get(connection.to).name,
direction: connection.direction
});
}
}
}
return newPaths;
}
triggerAbilityUnlockEvent(abilityName) {
// Show cutscene/animation
console.log(`🎉 New ability unlocked: ${abilityName}!`);
console.log(`New areas are now accessible!`);
// Update map UI to show new connections
this.updateMapUI();
}
updateMapUI() {
// Refresh minimap display with newly available connections
// This would integrate with the game's rendering system
}
getScaledEncounters(zoneId, playerBadges) {
const zone = this.zones.get(zoneId);
let encounters = [...zone.encounters.base];
// Add scaled encounters based on badge count
for (const [badgeCount, creatures] of Object.entries(zone.encounters.scaled)) {
if (playerBadges >= parseInt(badgeCount)) {
encounters.push(...creatures);
}
}
return encounters;
}
}
// ===================================================================
// 2. ABILITY SYSTEM WITH WORLD INTERACTIONS
// ===================================================================
class AbilityManager {
constructor() {
this.abilities = this.initializeAbilities();
this.unlockedAbilities = new Set();
}
initializeAbilities() {
return {
tree_cut: {
name: 'Tree Cut',
displayName: 'Vine Whip',
obtainMethod: 'creature_type',
requiredType: ['nature'],
description: 'Cut through trees and vines blocking paths',
combatPower: 45,
combatType: 'nature',
worldInteractions: ['cut_tree', 'swing_vine', 'pull_lever'],
unlockMessage: 'Your Nature creature can now cut trees!',
visualEffect: 'leaf_particles'
},
rock_smash: {
name: 'Rock Smash',
displayName: 'Rock Smash',
obtainMethod: 'creature_type',
requiredType: ['beast', 'warrior', 'earth'],
description: 'Break cracked rocks and boulders',
combatPower: 40,
combatType: 'fighting',
worldInteractions: ['break_rock', 'break_wall', 'trigger_rockslide'],
unlockMessage: 'Your creature can now smash rocks!',
visualEffect: 'rock_debris'
},
swimming: {
name: 'Swimming',
displayName: 'Surf',
obtainMethod: 'creature_evolution',
requiredCreature: 'murloc_warrior',
description: 'Cross water and explore underwater areas',
combatPower: 90,
combatType: 'water',
worldInteractions: ['traverse_water', 'dive_underwater', 'water_current'],
unlockMessage: 'You can now surf on water!',
visualEffect: 'water_splash',
upgrades: ['dive_deep', 'water_speed']
},
lava_walking: {
name: 'Lava Walking',
displayName: 'Heat Resistance',
obtainMethod: 'gym_badge',
requiredBadge: 'fire_badge',
description: 'Walk safely on lava surfaces',
combatPower: 0,
worldInteractions: ['traverse_lava', 'resist_heat'],
unlockMessage: 'You can now walk on lava!',
visualEffect: 'fire_shield'
},
climbing: {
name: 'Climbing',
displayName: 'Scale',
obtainMethod: 'creature_type',
requiredType: ['dragon', 'flying', 'beast'],
description: 'Climb walls and cliffs',
combatPower: 0,
worldInteractions: ['climb_wall', 'climb_cliff', 'rope_climb'],
unlockMessage: 'Your creature can help you climb!',
visualEffect: 'climbing_creature',
stamina: 100
},
shadow_walk: {
name: 'Shadow Walk',
displayName: 'Shadow Phase',
obtainMethod: 'creature_type',
requiredType: ['shadow', 'undead', 'spirit'],
requiredLevel: 30,
description: 'Phase through shadow barriers',
combatPower: 80,
combatType: 'shadow',
worldInteractions: ['phase_barrier', 'enter_void', 'shadow_realm'],
unlockMessage: 'You can now walk through shadows!',
visualEffect: 'ghost_translucent'
},
ice_breaking: {
name: 'Ice Breaking',
displayName: 'Melt Ice',
obtainMethod: 'move_usage',
requiredMove: 'flame_strike',
description: 'Melt ice obstacles and frozen doors',
combatPower: 0,
worldInteractions: ['melt_ice', 'thaw_frozen', 'steam_puzzle'],
unlockMessage: 'Fire can melt ice barriers!',
visualEffect: 'steam_particles'
},
telekinesis: {
name: 'Telekinesis',
displayName: 'Psychic Move',
obtainMethod: 'creature_type',
requiredType: ['magic', 'psychic'],
requiredLevel: 35,
description: 'Move distant objects and activate remote switches',
combatPower: 80,
combatType: 'psychic',
worldInteractions: ['move_object', 'remote_switch', 'float_platform'],
unlockMessage: 'Your Psychic creature can move objects with its mind!',
visualEffect: 'psychic_glow'
},
flight: {
name: 'Flight',
displayName: 'Fly',
obtainMethod: 'creature_specific',
requiredCreature: ['dragon', 'phoenix', 'wyvern'],
requiredLevel: 40,
description: 'Fly to any discovered location',
combatPower: 90,
combatType: 'flying',
worldInteractions: ['fast_travel', 'sky_access', 'soar'],
unlockMessage: 'You can now fly anywhere!',
visualEffect: 'flying_creature',
enablesFastTravel: true
}
};
}
checkAbilityUnlock(player) {
// Check if player has unlocked any new abilities
for (const [abilityId, ability] of Object.entries(this.abilities)) {
if (this.unlockedAbilities.has(abilityId)) continue;
if (this.canUnlockAbility(ability, player)) {
this.unlockAbility(abilityId);
return abilityId;
}
}
return null;
}
canUnlockAbility(ability, player) {
switch (ability.obtainMethod) {
case 'creature_type':
return this.hasCreatureOfType(player.party, ability.requiredType);
case 'creature_evolution':
return this.hasCreature(player.party, ability.requiredCreature);
case 'gym_badge':
return player.badges.includes(ability.requiredBadge);
case 'move_usage':
return this.hasMove(player.party, ability.requiredMove);
case 'creature_specific':
return this.hasAnyCreature(player.party, ability.requiredCreature) &&
this.hasLevelRequirement(player.party, ability.requiredLevel);
default:
return false;
}
}
hasCreatureOfType(party, types) {
return party.some(creature =>
creature.types.some(t => types.includes(t))
);
}
hasCreature(party, creatureId) {
return party.some(c => c.id === creatureId);
}
hasAnyCreature(party, creatureIds) {
return party.some(c => creatureIds.includes(c.id));
}
hasLevelRequirement(party, minLevel) {
return party.some(c => c.level >= minLevel);
}
hasMove(party, moveName) {
return party.some(creature =>
creature.moves.some(move => move.id === moveName)
);
}
unlockAbility(abilityId) {
this.unlockedAbilities.add(abilityId);
const ability = this.abilities[abilityId];
// Show unlock cutscene
this.showUnlockCutscene(ability);
// Trigger world state changes
this.triggerWorldChanges(abilityId);
return ability;
}
showUnlockCutscene(ability) {
// Display ability unlock animation and message
console.log(`✨ ${ability.unlockMessage}`);
// This would integrate with the game's UI system
}
triggerWorldChanges(abilityId) {
// Update game world to reflect new ability
// e.g., show previously hidden paths, update NPC dialogue
console.log(`World updated with ${abilityId} ability!`);
}
useAbilityOnWorldTile(abilityId, tileX, tileY, map) {
const ability = this.abilities[abilityId];
const tile = map.getTile(tileX, tileY);
// Check if ability can interact with this tile
if (!tile.interactable) return false;
switch (tile.interactionType) {
case 'cut_tree':
if (ability.worldInteractions.includes('cut_tree')) {
this.cutTree(tileX, tileY, map);
return true;
}
break;
case 'break_rock':
if (ability.worldInteractions.includes('break_rock')) {
this.breakRock(tileX, tileY, map);
return true;
}
break;
case 'melt_ice':
if (ability.worldInteractions.includes('melt_ice')) {
this.meltIce(tileX, tileY, map);
return true;
}
break;
// More interaction types...
}
return false;
}
cutTree(x, y, map) {
map.removeTile(x, y);
map.addEffect(x, y, 'leaf_particles');
map.playSound('tree_cut');
}
breakRock(x, y, map) {
map.removeTile(x, y);
map.addEffect(x, y, 'rock_debris');
map.playSound('rock_smash');
// Check for hidden items under rock
map.checkHiddenItem(x, y);
}
meltIce(x, y, map) {
map.changeTile(x, y, 'water');
map.addEffect(x, y, 'steam_particles');
map.playSound('ice_melt');
}
}
// ===================================================================
// 3. BACKTRACKING INCENTIVE SYSTEM
// ===================================================================
class BacktrackingManager {
constructor(mapSystem) {
this.mapSystem = mapSystem;
this.revisitTriggers = new Map();
this.environmentalChanges = [];
this.npcDialogueUpdates = new Map();
this.secretsRevealed = new Set();
}
checkZoneRevisit(zoneId, playerState) {
const zone = this.mapSystem.zones.get(zoneId);
const rewards = {
newEncounters: [],
newDialogue: [],
newSecrets: [],
shortcuts: []
};
// 1. Scaled Encounters
rewards.newEncounters = this.getNewEncounters(zoneId, playerState.badges);
// 2. Updated NPC Dialogue
rewards.newDialogue = this.getUpdatedNPCDialogue(zoneId, playerState);
// 3. Newly Accessible Secrets
rewards.newSecrets = this.checkUnlockedSecrets(zoneId, playerState.abilities);
// 4. Shortcuts Revealed
rewards.shortcuts = this.checkNewShortcuts(zoneId, playerState.abilities);
return rewards;
}
getNewEncounters(zoneId, badgeCount) {
const zone = this.mapSystem.zones.get(zoneId);
const newEncounters = [];
for (const [requiredBadges, creatures] of Object.entries(zone.encounters.scaled)) {
if (badgeCount >= parseInt(requiredBadges)) {
creatures.forEach(creature => {
if (!this.hasEncountered(zoneId, creature)) {
newEncounters.push(creature);
this.markEncountered(zoneId, creature);
}
});
}
}
return newEncounters;
}
getUpdatedNPCDialogue(zoneId, playerState) {
const updates = [];
const npcs = this.mapSystem.zones.get(zoneId).npcs || [];
npcs.forEach(npc => {
const newDialogue = this.getNPCDialogueForState(npc, playerState);
if (newDialogue !== npc.lastDialogue) {
updates.push({ npc: npc.id, dialogue: newDialogue });
npc.lastDialogue = newDialogue;
}
});
return updates;
}
getNPCDialogueForState(npc, playerState) {
// NPCs give different hints based on player progression
const badgeCount = playerState.badges.length;
if (badgeCount === 0) {
return npc.dialogue.start || npc.dialogue.default;
} else if (badgeCount < 3) {
return npc.dialogue.early || npc.dialogue.default;
} else if (badgeCount < 6) {
return npc.dialogue.mid || npc.dialogue.default;
} else if (badgeCount < 8) {
return npc.dialogue.late || npc.dialogue.default;
} else {
return npc.dialogue.postgame || npc.dialogue.default;
}
}
checkUnlockedSecrets(zoneId, playerAbilities) {
const zone = this.mapSystem.zones.get(zoneId);
const newSecrets = [];
zone.secrets.forEach(secret => {
const secretKey = `${zoneId}_${secret.id}`;
if (!this.secretsRevealed.has(secretKey)) {
if (!secret.requirement || playerAbilities.has(secret.requirement)) {
newSecrets.push(secret);
this.secretsRevealed.add(secretKey);
}
}
});
return newSecrets;
}
checkNewShortcuts(zoneId, playerAbilities) {
// Check if any one-way shortcuts can now be activated
const shortcuts = [];
const zone = this.mapSystem.zones.get(zoneId);
zone.shortcuts?.forEach(shortcut => {
if (!shortcut.activated && playerAbilities.has(shortcut.requirement)) {
shortcuts.push(shortcut);
this.activateShortcut(zoneId, shortcut);
}
});
return shortcuts;
}
activateShortcut(zoneId, shortcut) {
shortcut.activated = true;
console.log(`🚀 New shortcut discovered: ${shortcut.name}`);
// Update map to show new connection
}
triggerEnvironmentalChange(eventId, affectedZones) {
// Major world events that change zones
const event = {
id: eventId,
timestamp: Date.now(),
zones: affectedZones
};
this.environmentalChanges.push(event);
// Apply changes to affected zones
affectedZones.forEach(zone => {
this.applyEnvironmentalChange(zone, eventId);
});
}
applyEnvironmentalChange(zoneId, eventId) {
// Examples:
// - Volcano erupts: Burning Wastes gets new lava flows
// - Forest grows: Dark Forest becomes denser, new areas
// - Ruins flood: Sunken Ruins water level rises
console.log(`🌍 Environmental change in ${zoneId}: ${eventId}`);
// Update zone tiles and encounters
}
hasEncountered(zoneId, creatureId) {
const key = `${zoneId}_${creatureId}`;
return this.revisitTriggers.has(key);
}
markEncountered(zoneId, creatureId) {
const key = `${zoneId}_${creatureId}`;
this.revisitTriggers.set(key, true);
}
}
// ===================================================================
// 4. PLATFORMING & TRAVERSAL MECHANICS
// ===================================================================
class PlatformingController {
constructor() {
this.isJumping = false;
this.jumpProgress = 0;
this.jumpHeight = 1; // tiles
this.isClimbing = false;
this.climbingStamina = 100;
this.maxClimbingStamina = 100;
this.isSwimming = false;
this.underwaterAir = 100;
this.maxUnderwaterAir = 100;
this.onMovingPlatform = null;
this.movingPlatformOffset = { x: 0, y: 0 };
}
update(deltaTime, player, map) {
// Update jumping
if (this.isJumping) {
this.updateJump(deltaTime, player);
}
// Update climbing
if (this.isClimbing) {
this.updateClimbing(deltaTime, player);
}
// Update swimming/diving
if (this.isSwimming) {
this.updateSwimming(deltaTime, player);
}
// Update moving platforms
if (this.onMovingPlatform) {
this.updateMovingPlatform(deltaTime, player);
}
// Check hazards
this.checkHazards(player, map);
}
jump(player, direction) {
if (this.isJumping || this.isClimbing) return false;
const targetX = player.x + (direction === 'right' ? 1 : direction === 'left' ? -1 : 0);
const targetY = player.y + (direction === 'down' ? 1 : direction === 'up' ? -1 : 0);
// Check if jump is valid
if (!this.canJumpTo(targetX, targetY, player.map)) {
return false;
}
this.isJumping = true;
this.jumpProgress = 0;
this.jumpStart = { x: player.x, y: player.y };
this.jumpTarget = { x: targetX, y: targetY };
this.jumpDirection = direction;
return true;
}
canJumpTo(x, y, map) {
const targetTile = map.getTile(x, y);
// Can jump to walkable tiles or certain special tiles
return targetTile.walkable ||
targetTile.type === 'ledge' ||
targetTile.type === 'platform';
}
updateJump(deltaTime, player) {
this.jumpProgress += deltaTime * 0.01; // Jump speed
if (this.jumpProgress >= 1) {
// Jump complete
player.x = this.jumpTarget.x;
player.y = this.jumpTarget.y;
this.isJumping = false;
this.jumpProgress = 0;
// Check for landing effects
this.handleLanding(player);
} else {
// Interpolate position
player.renderX = this.jumpStart.x + (this.jumpTarget.x - this.jumpStart.x) * this.jumpProgress;
player.renderY = this.jumpStart.y + (this.jumpTarget.y - this.jumpStart.y) * this.jumpProgress;
// Add jump arc (parabolic motion)
player.renderOffsetY = -Math.sin(this.jumpProgress * Math.PI) * this.jumpHeight * 8; // pixels
}
}
startClimbing(player, wall) {
if (!player.abilities.has('climbing')) {
return false;
}
this.isClimbing = true;
this.climbingWall = wall;
player.onClimbable = true;
return true;
}
updateClimbing(deltaTime, player) {
// Drain stamina while climbing
this.climbingStamina -= deltaTime * 0.1;
if (this.climbingStamina <= 0) {
// Fall if stamina depleted
this.stopClimbing(player);
this.handleFall(player);
}
}
stopClimbing(player) {
this.isClimbing = false;
this.climbingWall = null;
player.onClimbable = false;
}
startSwimming(player) {
if (!player.abilities.has('swimming')) {
return false;
}
this.isSwimming = true;
player.inWater = true;
return true;
}
dive(player) {
if (!this.isSwimming || !player.abilities.has('dive_deep')) {
return false;
}
player.isUnderwater = true;
return true;
}
updateSwimming(deltaTime, player) {
if (player.isUnderwater) {
// Drain air while underwater
this.underwaterAir -= deltaTime * 0.5;
if (this.underwaterAir <= 0) {
// Take damage from drowning
player.takeDamage(5);
this.surfaceFromDive(player);
}
}
}
surfaceFromDive(player) {
player.isUnderwater = false;
this.underwaterAir = this.maxUnderwaterAir;
}
checkHazards(player, map) {
const currentTile = map.getTile(player.x, player.y);
switch (currentTile.hazardType) {
case 'lava':
if (!player.abilities.has('lava_walking')) {
player.takeDamage(15);
this.playHazardEffect('lava_burn');
}
break;
case 'ice':
// Sliding on ice
if (!player.keys.moving) {
this.slideOnIce(player, map);
}
break;
case 'crumbling':
// Platform crumbles after 2 seconds
this.startCrumbleTimer(player, currentTile);
break;
case 'poison':
if (!this.hasProtection(player, 'poison')) {
player.takeDamage(5);
this.playHazardEffect('poison');
}
break;
}
}
slideOnIce(player, map) {
// Continue moving in last direction until hitting obstacle
const direction = player.lastMoveDirection;
const nextX = player.x + (direction === 'right' ? 1 : direction === 'left' ? -1 : 0);
const nextY = player.y + (direction === 'down' ? 1 : direction === 'up' ? -1 : 0);
const nextTile = map.getTile(nextX, nextY);
if (nextTile.walkable) {
// Continue sliding
player.x = nextX;
player.y = nextY;
setTimeout(() => this.slideOnIce(player, map), 200);
}
// Stop sliding when hit obstacle
}
handleLanding(player) {
const tile = player.map.getTile(player.x, player.y);
if (tile.type === 'crumbling') {
// Start crumble timer
this.startCrumbleTimer(player, tile);
}
}
startCrumbleTimer(player, tile) {
if (tile.crumbleTimer) return; // Already crumbling
tile.crumbleTimer = setTimeout(() => {
tile.crumbled = true;
player.handleFall();
}, 2000);
}
handleFall(player) {
// Player falls to tile below or takes damage
player.y += 1;
player.takeDamage(10);
}
updateMovingPlatform(deltaTime, player) {
// Move player with platform
const platform = this.onMovingPlatform;
const movement = platform.getMovement(deltaTime);
player.x += movement.x;
player.y += movement.y;
}
playHazardEffect(effectType) {
// Visual and audio feedback for hazards
console.log(`⚠️ Hazard: ${effectType}`);
}
hasProtection(player, hazardType) {
// Check if player has creature with immunity
return player.party.some(creature =>
creature.types.includes(hazardType + '_immunity')
);
}
}
// ===================================================================
// 5. SECRET DISCOVERY SYSTEM
// ===================================================================
class SecretManager {
constructor() {
this.discoveredSecrets = new Set();
this.secretHints = new Map();
this.secretRewards = new Map();
}
checkSecretAtPosition(x, y, zoneId, playerAbilities) {
const secretKey = `${zoneId}_${x}_${y}`;
// Check if already discovered
if (this.discoveredSecrets.has(secretKey)) {
return null;
}
// Check for secret at this location
const secret = this.getSecretAtPosition(x, y, zoneId);
if (!secret) return null;
// Check if player has required ability
if (secret.requirement && !playerAbilities.has(secret.requirement)) {
// Show hint about what's needed
return {
found: false,
hint: `You sense something here... ${this.getRequirementHint(secret.requirement)}`
};
}
// Secret discovered!
return this.discoverSecret(secret, secretKey);
}
getSecretAtPosition(x, y, zoneId) {
// Check zone data for secrets at this position
// This would integrate with the map system
return null; // Placeholder
}
discoverSecret(secret, secretKey) {
this.discoveredSecrets.add(secretKey);
const result = {
found: true,
type: secret.type,
reward: secret.reward,
message: this.getDiscoveryMessage(secret)
};
// Grant reward
this.grantReward(secret.reward);
// Trigger discovery effects
this.playDiscoveryEffect(secret);
return result;
}
getRequirementHint(requirement) {
const hints = {
'rock_smash': 'Maybe a strong creature could break through?',
'tree_cut': 'A Nature creature might be able to clear the way.',
'swimming': 'The path continues underwater...',
'shadow_walk': 'Only shadows can pass through here.',
'flight': 'If only you could fly...',
'illuminate': 'It\'s too dark to see...'
};
return hints[requirement] || 'You need something special...';
}
getDiscoveryMessage(secret) {
switch (secret.type) {
case 'hidden_item':
return `Found hidden item: ${secret.reward.item}!`;
case 'secret_passage':
return 'A secret passage has opened!';
case 'legendary_encounter':
return `A legendary ${secret.reward.creature} appeared!`;
case 'warp_shrine':
return 'Ancient shrine activated! Fast travel unlocked.';
default:
return 'You discovered a secret!';
}
}
grantReward(reward) {
// Grant rewards to player
// This would integrate with player inventory system
console.log('Reward granted:', reward);
}
playDiscoveryEffect(secret) {
// Visual and audio effects for secret discovery
console.log('✨ Secret discovered!');
}
checkForHiddenWalls(playerX, playerY, playerDirection, zoneId) {
// Check if player is facing a hidden wall
const facingX = playerX + (playerDirection === 'right' ? 1 : playerDirection === 'left' ? -1 : 0);
const facingY = playerY + (playerDirection === 'down' ? 1 : playerDirection === 'up' ? -1 : 0);
const secret = this.checkSecretAtPosition(facingX, facingY, zoneId, ['walk_through']);
if (secret && secret.type === 'hidden_wall') {
return true; // Player can walk through