-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
6323 lines (5596 loc) · 259 KB
/
main.lua
File metadata and controls
6323 lines (5596 loc) · 259 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
-- Enhanced RPG with Tilemap, Collision, and Interactions
-- Controls: WASD/Arrows to move, E to interact, F3 for debug
-- Require modules
local GameState = require("src.core.gamestate")
local World = require("world")
local Spell = require("src.entities.spell")
local SpellSystem = require("src.entities.spellsystem")
local LightingSystem = require("src.systems.lighting")
local SaveManager = require("src.core.savemanager")
local DevMode = require("src.systems.devmode")
local TransitionSystem = require("src.systems.transition")
local AudioSystem = require("src.systems.audio")
local Cutscenes = require("src.systems.cutscenes")
local Projectile = require("src.entities.projectile")
-- Systems
local transition -- initialized in love.load
-- Debug mode
DEBUG_MODE = false
-- UI Images
local deathScreenImage = nil
local titleScreenImage = nil
local classImages = {}
SideDoorImage = nil
-- Class Information Database
local classInfo = {
["Fire Mage"] = {
element = "fire",
description = "Masters of flame and destruction, Fire Mages wield the raw power of fire to incinerate their enemies.",
strengths = {
"High burst damage",
"Area damage potential",
"Fast spell casting",
"Excellent against groups"
},
weaknesses = {
"Lower sustained damage",
"High mana consumption",
"Vulnerable in melee",
"Fire-resistant enemies"
},
abilities = {
"Fireball - Launches a burning projectile",
"Flame Ward - Protective fire shield (future)",
"Meteor Storm - Devastating area attack (future)"
},
lore = "Born from the eternal flames of the Crimson Peaks, Fire Mages channel the destructive force of fire itself. Their magic is chaotic and powerful, consuming everything in its path. They are feared across the realm for their ability to reduce entire armies to ash."
},
["Ice Mage"] = {
element = "ice",
description = "Ice mages who freeze their foes and control the battlefield with chilling precision.",
strengths = {
"Crowd control effects",
"Defensive capabilities",
"Slowing enemies",
"Consistent damage"
},
weaknesses = {
"Lower single-target damage",
"Slower cast times",
"Ice-immune enemies",
"Requires positioning"
},
abilities = {
"Ice Shard - Piercing frozen projectile",
"Frost Armor - Protective ice barrier (future)",
"Blizzard - Freezing area storm (future)"
},
lore = "From the frozen wastes of the Glacial Expanse come the Ice Mages, wielders of eternal winter. Their magic flows like glacial rivers, methodical and unstoppable. They are patient strategists who can freeze time itself."
},
["Storm Mage"] = {
element = "lightning",
description = "Wielders of lightning and thunder, Storm Mages strike with the fury of the tempest.",
strengths = {
"Fastest spells",
"Chain lightning effects",
"High mobility",
"Ignores armor"
},
weaknesses = {
"Mana intensive",
"Less area coverage",
"Grounded enemies resist",
"Requires accuracy"
},
abilities = {
"Lightning Bolt - Instant electric strike",
"Storm Shield - Crackling defense (future)",
"Thunder Cascade - Multi-target lightning (future)"
},
lore = "The Storm Mages draw their power from the Sky Temples, where eternal storms rage. Their magic is swift and precise, striking like judgment from the heavens. They are known for their unpredictable nature and devastating speed."
},
["Earth Mage"] = {
element = "earth",
description = "Earth mages who command stone and earth, standing firm as mountains against any threat.",
strengths = {
"High defense",
"Sustained damage",
"Tanky playstyle",
"Resource efficient"
},
weaknesses = {
"Slow mobility",
"Lower burst damage",
"Weak to magic",
"Limited range"
},
abilities = {
"Stone Spike - Erupting earthen projectile",
"Rock Shield - Stone barrier defense (future)",
"Earthquake - Ground-shaking area attack (future)"
},
lore = "Earth Mages are bound to the Deep Roots, ancient places where the earth's power flows strongest. Their magic is steady and enduring, like the mountains themselves. They are the immovable pillars that protect the innocent and crush the wicked."
}
}
local strategyInfo = {
["Tank"] = {
strategy = "armor",
description = "Become an unstoppable fortress, reducing all incoming damage through superior defense and endurance.",
strengths = {
"Consistent damage reduction",
"Reliable survivability",
"Great for beginners",
"Works against all damage types"
},
weaknesses = {
"Passive only (no active healing)",
"Lower damage potential",
"Slow resource recovery",
"Requires good positioning"
},
mechanics = {
"10% base damage reduction",
"+5% reduction per spell level",
"Always active (passive spell)",
"Stacks with resistance spells"
},
lore = "The path of the Tank is ancient and noble. Warriors who choose this path become living bulwarks, their skin as tough as iron. Through meditation and endurance training, they learn to shrug off wounds that would fell lesser mortals. They are the first into battle and the last to fall."
},
["Lifesteal"] = {
strategy = "drain",
description = "Siphon the life force from nearby enemies, draining their vitality to sustain yourself in battle.",
strengths = {
"Active healing in combat",
"Scales with enemy count",
"Effective in prolonged fights",
"Range increases with level"
},
weaknesses = {
"Requires nearby enemies",
"Ineffective against single targets",
"No healing outside combat",
"Lower total healing per second"
},
mechanics = {
"Drains 2 HP/sec from enemies",
"+1 HP/sec per spell level",
"Affects all enemies in range",
"120 base range (+15/level)"
},
lore = "The Lifesteal path walks the edge between life and death. Practitioners learn the forbidden art of soul extraction, drawing the essence of living beings to fuel their own existence. They are feared as vampiric sorcerers, but their power keeps them alive when all else fails."
},
["Soul Reaper"] = {
strategy = "necromancer",
description = "Harvest the souls of the fallen, gaining a surge of vitality with each enemy you defeat.",
strengths = {
"Large healing bursts",
"Rewards aggressive play",
"Scales with spell level",
"No range limitations"
},
weaknesses = {
"Only heals on kills",
"No passive healing",
"Requires killing blows",
"Risky against bosses"
},
mechanics = {
"Gain 20 HP per enemy kill",
"+10 HP per spell level",
"Instant healing on kill",
"Works from any distance"
},
lore = "Soul Reapers are necromancers who have mastered the art of death itself. Each fallen enemy empowers them, their souls absorbed and converted to pure life force. They grow stronger with each kill, becoming increasingly unstoppable. They are both feared and respected for their dark mastery."
}
}
-- Game state
local player = {
x = 400,
y = 300,
speed = 150,
direction = "south",
isMoving = false,
-- Combat stats
health = 100,
maxHealth = 100,
armor = 0,
maxArmor = 0,
armorRegenRate = 0,
isDead = false,
wasMoving = false,
scale = 2,
-- Collision box offsets (relative to player center)
collisionLeft = -13, -- Left edge of hitbox (negative = left of center)
collisionRight = 13, -- Right edge of hitbox (positive = right of center)
collisionTop = -4, -- Top edge of hitbox (negative = above center, small value = near feet)
collisionBottom = 28, -- Bottom edge of hitbox (positive = below center, at feet)
-- Knockback state
knockbackVelocityX = 0,
knockbackVelocityY = 0,
knockbackDecay = 0.88, -- How quickly knockback fades (lower = faster fade)
-- Immunity frames (invincibility after being hit)
immunityTimer = 0,
immunityDuration = 1.2 -- Seconds of immunity after being hit
}
local animations = {
walk = {},
idle = {}
}
-- Animation state (grouped to reduce upvalue count)
local animState = {
currentFrame = 1,
frameTimer = 0,
walkFrameDelay = 0.1,
idleFrameDelay = 0.15,
gameTime = 0 -- For water animation
}
local camera = {
x = 0,
y = 0
}
-- Game systems
local gameState
local world
local spellSystem
local projectiles = {} -- Active projectiles
local lighting
local saveManager
-- Audio (grouped to reduce upvalue count)
---@class AudioManager
---@field footstepSound any
---@field footstepTargetVolume number
---@field footstepCurrentVolume number
---@field footstepFadeSpeed number
---@field riverSound any
---@field riverTargetVolume number
---@field riverCurrentVolume number
---@field riverFadeSpeed number
---@field riverPreviousTargetVolume number
---@field fountainSound any
---@field fountainTargetVolume number
---@field fountainCurrentVolume number
---@field fountainFadeSpeed number
---@field fountainPreviousTargetVolume number
---@field caveSound any
---@field caveTargetVolume number
---@field caveCurrentVolume number
---@field caveFadeSpeed number
---@field overworldSound any
---@field overworldTargetVolume number
---@field overworldCurrentVolume number
---@field overworldFadeSpeed number
---@field chestCreakSound any
---@field doorCreakSound any
---@field unlockingDoorSound any
---@field pauseMenuOpenSound any
---@field panelSwipeSound any
---@field skeletonChaseSound any
---@field npcTalkingSound any
---@field earthCastSound any
---@field fireCastSound any
---@field stormCastSound any
---@field iceCastSound any
---@field illuminationCastSound any
---@field magicalVoyageMusic any
---@field trialsSpawnSound any
---@field fightSongMusic any
---@field goldCoinsSound any
---@field villageSound any
local audio = {
footstepSound = nil,
footstepTargetVolume = 0,
footstepCurrentVolume = 0,
footstepFadeSpeed = 2.0,
riverSound = nil,
riverTargetVolume = 0,
riverCurrentVolume = 0,
riverFadeSpeed = 0.5,
riverPreviousTargetVolume = 0,
fountainSound = nil,
fountainTargetVolume = 0,
fountainCurrentVolume = 0,
fountainFadeSpeed = 0.5,
fountainPreviousTargetVolume = 0,
caveSound = nil,
caveTargetVolume = 0,
caveCurrentVolume = 0,
caveFadeSpeed = 0.5,
overworldSound = nil,
overworldTargetVolume = 0,
overworldCurrentVolume = 0,
overworldFadeSpeed = 0.5,
villageSound = nil,
villageTargetVolume = 0,
villageCurrentVolume = 0,
villageFadeSpeed = 0.5,
chestCreakSound = nil,
doorCreakSound = nil,
unlockingDoorSound = nil,
pauseMenuOpenSound = nil,
panelSwipeSound = nil,
goldCoinsSound = nil,
skeletonChaseSound = nil,
npcTalkingSound = nil,
npcTalkingTargetVolume = 0,
npcTalkingCurrentVolume = 0,
npcTalkingFadeSpeed = 2.0,
earthCastSound = nil,
fireCastSound = nil,
stormCastSound = nil,
iceCastSound = nil,
illuminationCastSound = nil,
magicalVoyageMusic = nil,
magicalVoyageTargetVolume = 0,
magicalVoyageCurrentVolume = 0,
magicalVoyageFadeSpeed = 0.5,
trialsSpawnSound = nil,
fightSongMusic = nil,
fightSongTargetVolume = 0,
fightSongCurrentVolume = 0,
fightSongFadeSpeed = 0.5
}
local devMode
-- Message state (grouped to reduce upvalue count)
local messageState = {
currentMessage = nil,
currentMessageItem = nil, -- Store item for message icon
messageTimer = 0,
messageDuration = 5 -- Increased from 3 to give more time to read
}
-- UI state (grouped to reduce upvalue count)
local uiState = {
showFullInventory = false,
inventoryWidth = 0, -- Current animated width
inventoryTargetWidth = 0, -- Target width to lerp to
inventoryScrollOffset = 0,
selectedInventoryItem = nil, -- Currently selected item for equipping
showHelp = false,
showDebugPanel = false,
isPaused = false,
pauseMenuState = "main", -- "main", "controls", "settings", or "save_confirm"
pauseMenuHeight = 280, -- Current animated height
pauseMenuTargetHeight = 280, -- Target height to lerp to
-- Settings slider state
draggingMusicSlider = false,
draggingSFXSlider = false
}
-- Cutscene state (grouped to reduce upvalue count)
local cutsceneState = {
inCutscene = false,
cutsceneWalkTarget = nil,
cutsceneOnComplete = nil,
cutsceneDelayTimer = 0,
cutsceneDelayCallback = nil
}
-- Start screen state (grouped to reduce upvalue count)
local startScreen = {
gameStarted = false,
playerNameInput = "",
showProfileMenu = false,
state = "menu", -- "menu", "new_game", "loading"
menuSelection = 1, -- 1 = New Game, 2 = Load Game, 3 = Quit
cursorBlinkTimer = 0,
cursorVisible = true
}
-- Class selection UI state (grouped to reduce upvalue count)
local classSelection = {
show = false,
selectedIcon = nil,
scrollOffset = 0,
confirmation = false
}
-- Strategy selection UI state (grouped to reduce upvalue count)
local strategySelection = {
show = false,
selectedIcon = nil,
scrollOffset = 0,
confirmation = false
}
-- Skeleton spawn animation state (grouped to reduce upvalue count)
local skeletonSpawn = {
state = "none", -- none, spawning, combat
timer = 0,
skeletons = {}
}
-- Fade transition state (grouped to reduce upvalue count)
local fade = {
state = "none", -- "none", "fade_out", "fade_in"
alpha = 0,
speed = 2, -- How fast to fade (alpha per second)
targetMap = nil,
spawnX = nil,
spawnY = nil,
sourceMap = nil -- Track where we came from for non-portal transitions
}
-- Portal animation state (grouped to reduce upvalue count)
local portal = {
animState = "none", -- "none", "shrinking", "growing", "walking_out"
animTimer = 0,
animDuration = 0.8, -- Duration for shrink/grow
walkDuration = 0.5, -- Duration for walking out
playerScale = 1,
temp = nil, -- Temporary portal object for arrival animation
despawnTimer = 0,
sourceMap = nil -- Track where portal came from
}
-- Camera pan cutscene state (grouped to reduce upvalue count)
local cameraPan = {
state = "none", -- "none", "pan_to_target", "pause", "pan_back"
target = {x = 0, y = 0},
speed = 300, -- Pixels per second
pauseTimer = 0,
pauseDuration = 2, -- Seconds to pause at target
original = {x = 0, y = 0},
caveCutsceneShown = false, -- Track if we've shown the cave cutscene
northPathCutsceneShown = false -- Track if we've shown the northern path cutscene
}
-- Town greeting cutscene state (grouped to reduce upvalue count)
local townGreeting = {
state = "none", -- "none", "player_walk", "pan_up", "pause", "npc_walk", "pan_back", "dialogue"
timer = 0,
duration = 0,
npcStartX = 0,
npcStartY = 0,
npcTargetX = 0,
npcTargetY = 0,
npc = nil -- Reference to the greeter NPC
}
-- Shop UI state (grouped to reduce upvalue count)
local shopState = {
isOpen = false,
shopType = nil, -- "potions", "general", "weapons"
merchantNPC = nil, -- Reference to merchant NPC
selectedItem = nil, -- Currently hovered/selected item
scrollOffset = 0
}
-- Shop inventory definitions
local shopInventories = {
potions = {
{name = "Health Potion", price = 25, description = "Restores 50 HP"},
{name = "Mana Potion", price = 30, description = "Restores 50 Mana"},
{name = "Class Changer Potion", price = 100, description = "Change class while preserving spells & progress"},
{name = "Speed Potion", price = 50, description = "Low Stock - Shipment Coming Soon!", disabled = true},
{name = "Strength Potion", price = 50, description = "Low Stock - Shipment Coming Soon!", disabled = true},
{name = "Defense Potion", price = 50, description = "Low Stock - Shipment Coming Soon!", disabled = true}
}
}
-- Direction mappings
local directions = {
"north", "north-east", "east", "south-east",
"south", "south-west", "west", "north-west"
}
-- Forward declarations
local loadAnimations, getDirection, drawPlayer, drawUI, drawMessage, drawPauseMenu, drawClassSelection, drawStrategySelection
local checkInteraction, getNearestInteractable, getNearestNPC, useItem
function love.load()
-- Set up window
love.window.setTitle("RPG Adventure")
love.window.setMode(800, 600, {resizable=false})
love.graphics.setDefaultFilter("nearest", "nearest")
-- Enable text input for name entry
love.keyboard.setTextInput(true)
-- Load UI images
local success, image = pcall(love.graphics.newImage, "assets/ui/you-died.png")
if success then
deathScreenImage = image
else
print("Warning: Could not load death screen image")
end
success, image = pcall(love.graphics.newImage, "assets/ui/rpg.png")
if success then
titleScreenImage = image
else
print("Warning: Could not load title screen image")
end
-- Load class images
local classImageFiles = {
["Fire Mage"] = "fire-mage.png",
["Ice Mage"] = "ice-mage.png",
["Storm Mage"] = "storm-mage.png",
["Earth Mage"] = "earth-mage.png"
}
for className, filename in pairs(classImageFiles) do
success, image = pcall(love.graphics.newImage, "assets/ui/" .. filename)
if success then
classImages[className] = image
else
print("Warning: Could not load " .. filename)
end
end
-- Load door image
success, image = pcall(love.graphics.newImage, "assets/buildings/side-door.png")
if success then
SideDoorImage = image
else
print("Warning: Could not load side-door.png")
SideDoorImage = nil
end
-- Initialize game systems
gameState = GameState:new()
world = World:new()
world:setGameState(gameState)
-- Initialize spell system
spellSystem = SpellSystem:new(gameState)
-- Initialize lighting system
lighting = LightingSystem.new()
-- Initialize save manager
saveManager = SaveManager
-- Initialize dev mode
devMode = DevMode:new()
-- Initialize centralized audio system and load sources
audio = AudioSystem.new()
audio:loadAll(gameState)
-- Initialize transitions system with references to fade/portal state
transition = TransitionSystem.new(fade, portal)
-- Load audio
local audioSuccess, audioError = pcall(function()
---@type any
local footsteps = love.audio.newSource("assets/sounds/footsteps.mp3", "stream")
audio.footstepSound = footsteps
footsteps:setLooping(true)
footsteps:setVolume(0) -- Start at 0, will fade in when moving
footsteps:setPitch(2.0) -- Play twice as fast
end)
if not audioSuccess then
print("Warning: Could not load footsteps.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded footsteps.mp3 successfully. Max Volume: 0.5, Pitch: 2.0x, Looping: true")
if audio.footstepSound then
---@type any
local fs = audio.footstepSound
print("[AUDIO] Audio duration: " .. string.format("%.2f", fs:getDuration()) .. "s")
fs:play() -- Start playing but at 0 volume
print("[AUDIO] Footsteps playback started (will fade in when moving)")
end
end
-- Load river sound
audioSuccess, audioError = pcall(function()
---@type any
local river = love.audio.newSource("assets/sounds/river.mp3", "stream")
audio.riverSound = river
river:setLooping(true)
river:setVolume(0) -- Start at 0, will fade in when visible
end)
if not audioSuccess then
print("Warning: Could not load river.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded river.mp3 successfully. Looping: true, Max Volume: 0.85")
if audio.riverSound then
---@type any
local rs = audio.riverSound
print("[AUDIO] River duration: " .. string.format("%.2f", rs:getDuration()) .. "s")
rs:play() -- Start playing but at 0 volume
print("[AUDIO] River playback started (will fade in when water visible)")
end
end
-- Load fountain sound
audioSuccess, audioError = pcall(function()
---@type any
local fountain = love.audio.newSource("assets/sounds/fountain.mp3", "stream")
audio.fountainSound = fountain
fountain:setLooping(true)
fountain:setVolume(0) -- Start at 0, will fade in when visible
end)
if not audioSuccess then
print("Warning: Could not load fountain.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded fountain.mp3 successfully. Looping: true, Max Volume: 0.7")
if audio.fountainSound then
---@type any
local fs = audio.fountainSound
print("[AUDIO] Fountain duration: " .. string.format("%.2f", fs:getDuration()) .. "s")
fs:play() -- Start playing but at 0 volume
print("[AUDIO] Fountain playback started (will fade in when fountain visible)")
end
end
-- Load cave ambient sound
audioSuccess, audioError = pcall(function()
---@type any
local cave = love.audio.newSource("assets/sounds/cave-sounds.mp3", "stream")
audio.caveSound = cave
cave:setLooping(true)
cave:setVolume(0) -- Start at 0, will fade in when in cave
end)
if not audioSuccess then
print("Warning: Could not load cave-sounds.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded cave-sounds.mp3 successfully. Looping: true, Max Volume: 0.6")
if audio.caveSound then
---@type any
local cs = audio.caveSound
print("[AUDIO] Cave duration: " .. string.format("%.2f", cs:getDuration()) .. "s")
cs:play() -- Start playing but at 0 volume
print("[AUDIO] Cave playback started (will fade in when in cave)")
end
end
-- Load overworld ambient sound
audioSuccess, audioError = pcall(function()
---@type any
local overworld = love.audio.newSource("assets/sounds/overworld-sounds.mp3", "stream")
audio.overworldSound = overworld
overworld:setLooping(true)
overworld:setVolume(0) -- Start at 0, will fade in when in overworld
end)
if not audioSuccess then
print("Warning: Could not load overworld-sounds.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded overworld-sounds.mp3 successfully. Looping: true, Max Volume: 0.5")
if audio.overworldSound then
---@type any
local ow = audio.overworldSound
print("[AUDIO] Overworld duration: " .. string.format("%.2f", ow:getDuration()) .. "s")
ow:play() -- Start playing but at 0 volume
print("[AUDIO] Overworld playback started (will fade in when in overworld)")
end
end
-- Load chest creak sound effect
audioSuccess, audioError = pcall(function()
---@type any
local chest = love.audio.newSource("assets/sounds/chest-creak.mp3", "static")
audio.chestCreakSound = chest
chest:setVolume(0.6 * gameState.sfxVolume)
end)
if not audioSuccess then
print("Warning: Could not load chest-creak.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded chest-creak.mp3 successfully (skips 0.2s initial delay)")
end
-- Load door creak sound effect
audioSuccess, audioError = pcall(function()
---@type any
local door = love.audio.newSource("assets/sounds/door-creak.mp3", "static")
audio.doorCreakSound = door
door:setVolume(0.45 * gameState.sfxVolume) -- 25% quieter than 0.6
end)
if not audioSuccess then
print("Warning: Could not load door-creak.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded door-creak.mp3 successfully (volume: 0.45)")
end
-- Load unlocking door sound effect
audioSuccess, audioError = pcall(function()
---@type any
local unlocking = love.audio.newSource("assets/sounds/unlocking-door.mp3", "static")
audio.unlockingDoorSound = unlocking
unlocking:setVolume(0.6 * gameState.sfxVolume)
end)
if not audioSuccess then
print("Warning: Could not load unlocking-door.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded unlocking-door.mp3 successfully. Volume: 0.6 (skips 1.0s initial silence)")
end
-- Load pause menu open sound effect
audioSuccess, audioError = pcall(function()
---@type any
local pauseOpen = love.audio.newSource("assets/sounds/pause-menu-open.mp3", "static")
audio.pauseMenuOpenSound = pauseOpen
pauseOpen:setVolume(0.5 * gameState.sfxVolume)
end)
if not audioSuccess then
print("Warning: Could not load pause-menu-open.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded pause-menu-open.mp3 successfully. Volume: 0.5")
end
-- Load panel swipe sound effect
audioSuccess, audioError = pcall(function()
---@type any
local panelSwipe = love.audio.newSource("assets/sounds/panel-swipe.mp3", "static")
audio.panelSwipeSound = panelSwipe
panelSwipe:setVolume(0.5 * gameState.sfxVolume)
end)
if not audioSuccess then
print("Warning: Could not load panel-swipe.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded panel-swipe.mp3 successfully. Volume: 0.5")
end
-- Load gold coins sound effect
audioSuccess, audioError = pcall(function()
---@type any
local goldCoins = love.audio.newSource("assets/sounds/gold-coins.mp3", "static")
audio.goldCoinsSound = goldCoins
goldCoins:setVolume(0.6 * gameState.sfxVolume)
end)
if not audioSuccess then
print("Warning: Could not load gold-coins.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded gold-coins.mp3 successfully. Volume: 0.6")
end
-- Load village ambient sound
audioSuccess, audioError = pcall(function()
---@type any
local village = love.audio.newSource("assets/sounds/village-sounds.mp3", "stream")
audio.villageSound = village
village:setLooping(true)
village:setVolume(0) -- Start at 0, will fade in when in town
end)
if not audioSuccess then
print("Warning: Could not load village-sounds.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded village-sounds.mp3 successfully. Looping: true, Volume: 0-0.3")
if audio.villageSound then
---@type any
local village = audio.villageSound
print("[AUDIO] Village duration: " .. string.format("%.2f", village:getDuration()) .. "s")
village:play() -- Start playing but at 0 volume
print("[AUDIO] Village playback started (will fade in when in town)")
end
end
-- Load skeleton chase sound effect
audioSuccess, audioError = pcall(function()
---@type any
local skeletonChase = love.audio.newSource("assets/sounds/skeleton-chase.mp3", "static")
audio.skeletonChaseSound = skeletonChase
skeletonChase:setVolume(0.6 * gameState.sfxVolume)
end)
if not audioSuccess then
print("Warning: Could not load skeleton-chase.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded skeleton-chase.mp3 successfully. Volume: 0.6")
end
-- Load NPC talking sound effect
audioSuccess, audioError = pcall(function()
---@type any
local npcTalk = love.audio.newSource("assets/sounds/npc-talking.mp3", "static")
audio.npcTalkingSound = npcTalk
npcTalk:setVolume(0) -- Start at 0, will fade in/out
npcTalk:setLooping(true) -- Loop so it can play for duration of message
end)
if not audioSuccess then
print("Warning: Could not load npc-talking.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded npc-talking.mp3 successfully. Looping: true, Volume: 0-1.0")
end
-- Load spell casting sounds
audioSuccess, audioError = pcall(function()
audio.earthCastSound = love.audio.newSource("assets/sounds/earth-cast-1.mp3", "static")
audio.earthCastSound:setVolume(0.6 * gameState.sfxVolume)
end)
if not audioSuccess then
print("Warning: Could not load earth-cast-1.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded earth-cast-1.mp3 successfully")
end
audioSuccess, audioError = pcall(function()
audio.fireCastSound = love.audio.newSource("assets/sounds/fire-cast-1.mp3", "static")
audio.fireCastSound:setVolume(0.6 * gameState.sfxVolume)
end)
if not audioSuccess then
print("Warning: Could not load fire-cast-1.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded fire-cast-1.mp3 successfully")
end
audioSuccess, audioError = pcall(function()
audio.stormCastSound = love.audio.newSource("assets/sounds/storm-cast-1.mp3", "static")
audio.stormCastSound:setVolume(0.6 * gameState.sfxVolume)
end)
if not audioSuccess then
print("Warning: Could not load storm-cast-1.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded storm-cast-1.mp3 successfully")
end
audioSuccess, audioError = pcall(function()
audio.iceCastSound = love.audio.newSource("assets/sounds/ice-cast-1.mp3", "static")
audio.iceCastSound:setVolume(0.6 * gameState.sfxVolume)
end)
if not audioSuccess then
print("Warning: Could not load ice-cast-1.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded ice-cast-1.mp3 successfully")
end
audioSuccess, audioError = pcall(function()
audio.illuminationCastSound = love.audio.newSource("assets/sounds/illumination-cast.mp3", "static")
audio.illuminationCastSound:setVolume(0.6 * gameState.sfxVolume)
end)
if not audioSuccess then
print("Warning: Could not load illumination-cast.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded illumination-cast.mp3 successfully")
end
-- Load background music
audioSuccess, audioError = pcall(function()
---@type any
local voyage = love.audio.newSource("assets/sounds/magical-voyage.mp3", "stream")
audio.magicalVoyageMusic = voyage
voyage:setLooping(true)
voyage:setVolume(0)
end)
if not audioSuccess then
print("Warning: Could not load magical-voyage.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded magical-voyage.mp3 successfully. Looping: true, Volume: 0-0.4")
end
audioSuccess, audioError = pcall(function()
audio.trialsSpawnSound = love.audio.newSource("assets/sounds/trials-spawn.mp3", "static")
audio.trialsSpawnSound:setVolume(0.5 * gameState.sfxVolume)
end)
if not audioSuccess then
print("Warning: Could not load trials-spawn.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded trials-spawn.mp3 successfully")
end
audioSuccess, audioError = pcall(function()
---@type any
local fight = love.audio.newSource("assets/sounds/fight-song.mp3", "stream")
audio.fightSongMusic = fight
fight:setLooping(true)
fight:setVolume(0)
end)
if not audioSuccess then
print("Warning: Could not load fight-song.mp3: " .. tostring(audioError))
else
print("[AUDIO] Loaded fight-song.mp3 successfully. Looping: true, Volume: 0-0.4")
end
-- Create example maps
world:createExampleOverworld()
world:createHouseInterior()
world:createCaveLevel1()
world:createClassSelection()
world:createDefenseTrials()
world:createTown()
world:createInnInterior()
world:createPotionShopInterior()
world:loadMap("overworld")
-- Sync all interactables with game state
local interactables = world:getCurrentInteractables()
for _, obj in ipairs(interactables) do
obj:syncWithGameState(gameState)
end
-- Load animations
loadAnimations()
-- Set initial position (center of map)
player.x = 40 * 32 -- Center of 80-tile wide map
player.y = 30 * 32 -- Center of 60-tile tall map
animState.currentFrame = 1
end
function loadAnimations()
-- Load walking animations (6 frames per direction)
for _, direction in ipairs(directions) do
animations.walk[direction] = {}
for i = 0, 5 do
local path = string.format("assets/player/animations/walk/%s/frame_%03d.png", direction, i)
local success, image = pcall(love.graphics.newImage, path)
if success then
table.insert(animations.walk[direction], image)
else
print("Failed to load walk animation: " .. path)
end
end
end
-- Try to load breathing idle animations (4 frames per direction)
for _, direction in ipairs(directions) do
animations.idle[direction] = {}
local foundIdleAnimation = false
for i = 0, 3 do
local path = string.format("assets/player/animations/breathing-idle/%s/frame_%03d.png", direction, i)
local success, image = pcall(love.graphics.newImage, path)
if success then
table.insert(animations.idle[direction], image)
foundIdleAnimation = true
end
end
-- If no idle animation found, use first frame of walk animation
if not foundIdleAnimation and #animations.walk[direction] > 0 then
print("No idle animation found for " .. direction .. ", using walk frame 0")
table.insert(animations.idle[direction], animations.walk[direction][1])
end
end
end
function love.update(dt)
-- Update centralized audio system volumes
---@diagnostic disable-next-line: undefined-field
if audio then audio:update(dt, gameState, startScreen, uiState, world, player, skeletonSpawn, camera) end
-- Don't update game if not started (but update cursor blink)
if not startScreen.gameStarted then
-- Update cursor blink timer for name input
if startScreen.state == "new_game" then
startScreen.cursorBlinkTimer = startScreen.cursorBlinkTimer + dt
if startScreen.cursorBlinkTimer >= 0.5 then
startScreen.cursorVisible = not startScreen.cursorVisible
startScreen.cursorBlinkTimer = 0
end
end
return
end
-- Always update UI animations even when paused
if uiState.isPaused then
-- Lerp pause menu height
local lerpSpeed = 12
uiState.pauseMenuHeight = uiState.pauseMenuHeight + (uiState.pauseMenuTargetHeight - uiState.pauseMenuHeight) * lerpSpeed * dt
return
end
-- Lerp inventory width animation
local lerpSpeed = 12
uiState.inventoryWidth = uiState.inventoryWidth + (uiState.inventoryTargetWidth - uiState.inventoryWidth) * lerpSpeed * dt
-- Apply dev mode speed multiplier
if devMode and devMode.enabled and devMode.speedMultiplier > 1 then
dt = dt * devMode.speedMultiplier
end
animState.gameTime = animState.gameTime + dt
-- Update play time
gameState.playTime = gameState.playTime + dt
-- Update footstep sound volume with smooth fading
if audio.footstepSound and startScreen.gameStarted and not uiState.isPaused then
-- Smoothly lerp current volume towards target
if audio.footstepCurrentVolume < audio.footstepTargetVolume then
audio.footstepCurrentVolume = math.min(audio.footstepTargetVolume, audio.footstepCurrentVolume + audio.footstepFadeSpeed * dt)
elseif audio.footstepCurrentVolume > audio.footstepTargetVolume then
audio.footstepCurrentVolume = math.max(audio.footstepTargetVolume, audio.footstepCurrentVolume - audio.footstepFadeSpeed * dt)
end
-- Apply the current volume
---@type any