-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
960 lines (815 loc) · 36.5 KB
/
main.lua
File metadata and controls
960 lines (815 loc) · 36.5 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
--[[
This is the main function where the game logic runs.
Alot of this may be moved in the future as alot of the love.load code
is what should happen when you press "play" on a main menu
]]
local base_width = 1920
local base_height = 1080
canvas = love.graphics.newCanvas(base_width, base_height)
handspace = { x = canvas:getWidth() / 2, y = 0, w = canvas:getWidth() / 2, h = canvas:getHeight() }
eventspace = { x = 0, y = 0, w = canvas:getWidth() / 2, h = canvas:getHeight() }
-- setting up fonts
eventFont = love.graphics.newFont(30)
menuFont = love.graphics.newFont(30)
gameLoaded = false
ForesightWithDiscard = false
local CARD = require("card")
local HAND = require("hand")
local DECKS = require("decks")
local EVENTS = require("events")
local EVENTCARD = require("eventCard")
local PLAYAREA = require("playarea")
local USEFUL = require("useful")
local MENUELEMENTS = require("menuElements")
--options are mainmenu, game, foresight, win, lose
local SCENE = ""
local MOD_ENABLED = false
-- Mouse position variables for hover effects
mouseX = 0
mouseY = 0
local foresightPadding = 50
local totalWidth = EVENTCARD.width * 3 + foresightPadding * 2
local startX = (canvas:getWidth() - totalWidth) / 2
local centerY = canvas:getHeight() / 2 - EVENTCARD.height / 2
ForesightCards = {
{ x = startX, y = centerY, selected = false },
{ x = startX + EVENTCARD.width + foresightPadding, y = centerY, selected = false },
{ x = startX + (EVENTCARD.width + foresightPadding) * 2, y = centerY, selected = false },
width = EVENTCARD.width,
height = EVENTCARD.height
}
-- Define god buttons and their corresponding blessing data
godButtons = {
{ button = MENUELEMENTS.beginningsButton, blessings = { EVENTS.blessings.beginnings.beginnersLuck, EVENTS.blessings.beginnings.inheritance }, refname = 'beginnings', selected = false },
{ button = MENUELEMENTS.rhybaaxButton, blessings = { EVENTS.blessings.rhybaax.performHaruspicy, EVENTS.blessings.rhybaax.necromancy }, refname = 'rhybaax', selected = false },
{ button = MENUELEMENTS.wiindigoButton, blessings = { EVENTS.blessings.wiindigoo.organHarvest, EVENTS.blessings.wiindigoo.tastingTheFuture }, refname = 'wiindigoo', selected = false },
{ button = MENUELEMENTS.jhaitiButton, blessings = { EVENTS.blessings.jhaiti.assassination, EVENTS.blessings.jhaiti.importingTea }, refname = 'jhaiti', selected = false },
{ button = MENUELEMENTS.kekujiraButton, blessings = { EVENTS.blessings.kekujira.aeromancy, EVENTS.blessings.kekujira.holiday }, refname = 'kekujira', selected = false },
{ button = MENUELEMENTS.yacareButton, blessings = { EVENTS.blessings.yacare.startAFarm, EVENTS.blessings.yacare.oomancy }, refname = 'yacare', selected = false },
{ button = MENUELEMENTS.uhluhtcButton, blessings = { EVENTS.blessings.uhluhtc.soothsayerInTown, EVENTS.blessings.uhluhtc.sacrificialPact }, refname = 'uhluhtc', selected = false },
} -- this needs to be more dynamic now that the modded gods are in place
function love.load()
math.randomseed(os.time())
-- shaders
--glowShader = MOONSHINE(MOONSHINE.effects.glow)
--love.graphics.setBlendMode("screen", "premultiplied")
--love.window.setMode(base_width, base_height, {resizable=true})
--love.window.setMode(base_width, base_height)
--SCENE = "game" -- hardcoding to load as game until main menu created
SCENE = "mainmenu" -- menu
love.graphics.setFont(menuFont)
--love.graphics.setFont(eventFont)
love.graphics.setLineWidth(6)
-- scale pixel art properly
love.graphics.setDefaultFilter("nearest")
--music
background_music = love.audio.newSource("assets/music/dd.mp3", "stream")
background_music:setLooping(true)
background_music:play()
--love.audio.play(background_music)
--sound effects
shuffle_sound = love.audio.newSource("assets/sounds/card-shuffle.ogg", "static")
card_pickup_sound = love.audio.newSource("assets/sounds/card-place-1.ogg", "static")
card_place_sound = love.audio.newSource("assets/sounds/card-place-2.ogg", "static")
expand_sound = love.audio.newSource("assets/sounds/card-slide-5.ogg", "static")
option_select_sound = love.audio.newSource("assets/sounds/card-slide-6.ogg", "static")
--background image
bg_image = love.graphics.newImage("assets/images/bg/BG_IMAGE.png")
end
function loadGame(isTutorial)
local loadTutorial = isTutorial or false
tutorialMode = loadTutorial
--hand initiation
hand = HAND
if MOD_ENABLED == true then
EVENTS:loadMods()
end
--decks initiation
decks = DECKS
local selectedGods = {}
for i = 1, #godButtons do
if godButtons[i].selected then
table.insert(selectedGods, godButtons[i].refname)
end
end
if loadTutorial then
hand.cards = {}
decks:initiateTutoralDecks() --not working
else
hand:createStartingHand()
-- for use in testing
-- hand:addCards({ suspicion = 2, relic = 15 })
--
hand:sort()
for i, card in pairs(hand.cards) do
CARD.setHandPosition(card, #hand.cards, i)
end
decks:initiateDecks(selectedGods)
end
--visible event card
--this is used to track which card is currently in play and modify it on the fly
currentEvent = EVENTCARD
currentEvent:updateEvent(decks.deck[1])
currentEvent.expanded = false
--setup area where the resources are placed
playarea = PLAYAREA
gameLoaded = true
end
function love.update(dt)
-- get mouse pos on canvas
local mx, my = getVirtualMousePosition()
if gameLoaded then
-- detect if the player is dragging any card
local holdingCard = false
for _, card in ipairs(hand.cards) do
if card.dragging then
holdingCard = true
end
end
-- Clear previous hover states
local foundHover = false
for _, card in ipairs(hand.cards) do
card.hovered = false
end
-- detect if cutsor is over a card
for i = #hand.cards, 1, -1 do
-- search backwards so the top card is always hovered
local card = hand.cards[i]
if not holdingCard and not foundHover then
-- if a card isnt already being dragged and it hasnt already found an overlapped hovered card
if pointinrect(mx, my, card.x, card.y, card.width, card.height) then
card.hovered = true
foundHover = true -- used so only one card is hovered at a time
end
end
end
-- Pre-calculate stack positions for selected cards
local stackCounts = {}
for _, card in ipairs(hand.cards) do
if card.selected then
local resourceType = card.resource.value
stackCounts[resourceType] = (stackCounts[resourceType] or 0) + 1
card.stackIndex = stackCounts[resourceType] - 1
end
end
-- locking cards to their positions in the playarea and hand when not being actively dragged
for _, card in ipairs(hand.cards) do
if not card.dragging then
if card.selected then
-- if card being played move it to its designated position in the playarea with stacking offset
local stackOffset = 25 -- pixels to offset each stacked card
local targetX = card.playX + (card.stackIndex * stackOffset)
local targetY = card.playY +
(card.stackIndex * stackOffset * 0.5) -- slight downward offset for bottom-right stacking
card.x = lerp(card.x, targetX, dt * hand.returnSpeed)
card.y = lerp(card.y, targetY, dt * hand.returnSpeed)
else
-- if card has been taken out of the play area, move it to its position in the hand
card.x = lerp(card.x, card.originalX, dt * hand.returnSpeed)
card.y = lerp(card.y, card.originalY, dt * hand.returnSpeed)
end
end
end
local unselectedCards = {}
for _, card in ipairs(hand.cards) do
if not card.dragging and not card.selected then
table.insert(unselectedCards, card)
end
end
-- sets the position to the designated hand position
for i, card in pairs(unselectedCards) do
CARD.setHandPosition(card, #unselectedCards, i - 1)
end
-- shuffling timer
if currentEvent.shuffling and SCENE == "game" then
shuffle_sound:play()
--end
-- tracking time shuffling using delta time
currentEvent.timeSpentShuffling = currentEvent.timeSpentShuffling + dt
if currentEvent.timeSpentShuffling >= currentEvent.timeToShuffle then
currentEvent.shuffling = false
currentEvent.timeSpentShuffling = 0
shuffle_sound:stop()
end
end
-- sort the hand
if not hand:isSorted() and not hand.isChanging then
hand:sort()
end
end
end
function love.draw()
--love.graphics.draw(bg_image, 0, 0, 0, bg_image:getWidth(), bg_image:getHeight())
--love.graphics.draw(bg_image, 0, 0, 90, 0.1, 0.1)
-- ugly brown bg
---local bg_col = USEFUL.RGB255ToRGB1({ r = 85, g = 57, b = 39 })
-- matte grey
local bg_col = USEFUL.RGB255ToRGB1({ r = 25, g = 25, b = 25 })
love.graphics.setColor(bg_col.r, bg_col.g, bg_col.b)
-- base width and height will need to change to window witdth and height as background is being drawn under canvas
love.graphics.rectangle("fill", 0, 0, base_width, base_height) -- temporary solid colour background
--love.graphics.draw(bg_image, 0, 0, 0, canvas:getWidth(), canvas:getHeight())
love.graphics.setCanvas(canvas)
love.graphics.clear()
drawToCanvas()
love.graphics.setCanvas()
local scaleX, scaleY, offsetX, offsetY = getCanvasScale()
love.graphics.draw(canvas, offsetX, offsetY, 0, scaleX, scaleY)
end
function drawToCanvas()
--[[
function where all draw code is placed minus that that shouldnt scale with window size
]]
if SCENE == "game" then
DrawGameScene()
elseif SCENE == "foresight" then
DrawForesightScene()
elseif SCENE == 'mainmenu' then
DrawMainMenu()
elseif SCENE == 'godSelect' then
DrawGodSelection()
elseif SCENE == 'credits' then
DrawCreditsScene()
elseif SCENE == 'win' then
DrawWinScene()
elseif SCENE == 'lose' then
DrawLossScene()
end
end
function DrawGameScene()
local plx, ply, plw, plh = playarea:get()
-- black
playareaCol = USEFUL.RGB255ToRGB1({ r = 255, g = 255, b = 255 })
love.graphics.setColor(playareaCol.r, playareaCol.g, playareaCol.b)
love.graphics.rectangle("line", plx, ply, plw, plh)
love.graphics.setColor(1, 1, 1, 1)
local unselectedCards = {}
for _, card in ipairs(hand.cards) do
if not card.dragging and not card.selected then
table.insert(unselectedCards, card)
end
end
-- display the number of cards owned not in the play area
love.graphics.print(#unselectedCards, ((handspace.w - eventFont:getWidth(#unselectedCards)) / 2) + eventspace.w,
(handspace.h - eventFont:getHeight(#unselectedCards)) / 4)
-- display the number of cards left in the deck
-- this is used to make foresight feel more fair
love.graphics.print(#decks.deck)
if currentEvent.event then
if not currentEvent.expanded then
-- drawing the single face of the event
if not currentEvent.shuffling then
-- when images start being used this backup colour will be used as a fall back
-- for now its being used for all
love.graphics.setColor(currentEvent.backupColour.r, currentEvent.backupColour.g,
currentEvent.backupColour.b)
love.graphics.rectangle("fill", currentEvent.x, currentEvent.y, currentEvent.width, currentEvent.height)
love.graphics.setColor(0, 0, 0)
love.graphics.rectangle("line", currentEvent.x, currentEvent.y, currentEvent.width, currentEvent.height)
love.graphics.printf(currentEvent.event.title, currentEvent.x, currentEvent.y, currentEvent.width,
"center")
elseif currentEvent.shuffling then
-- if the shuffling timer has not finished, nothing but a shuffling dialogue should be drawn yet
love.graphics.setColor(1, 1, 1)
love.graphics.printf("Shuffling", currentEvent.x, currentEvent.y, currentEvent.width, "center")
love.graphics.setColor(0, 0, 0)
end
else
-- drawing the options
-- draw card backs
love.graphics.setColor(currentEvent.backupColour.r, currentEvent.backupColour.g, currentEvent.backupColour.b)
-- Draw filled rectangles for all options
for i = 1, 3 do
local optionX = currentEvent["option" .. i .. "x"]
local optionY = currentEvent["option" .. i .. "y"]
love.graphics.rectangle("fill", optionX, optionY, currentEvent.width, currentEvent.height)
end
love.graphics.setColor(0, 0, 0)
-- Draw outlines for all options
for i = 1, 3 do
local optionX = currentEvent["option" .. i .. "x"]
local optionY = currentEvent["option" .. i .. "y"]
love.graphics.rectangle("line", optionX, optionY, currentEvent.width, currentEvent.height)
end
-- Write option text and output text for all options
for i = 1, 3 do
local option = currentEvent.event["option" .. i]
local optionX = currentEvent["option" .. i .. "x"]
local optionY = currentEvent["option" .. i .. "y"]
-- Writing option text
love.graphics.printf(option.optiontext, optionX, optionY, currentEvent.width, "center")
-- Writing output text
local outputtext = option.outputtext or ""
local _, wrapped = eventFont:getWrap(outputtext, currentEvent.width)
local wrappedHeight = eventFont:getHeight() * #wrapped
love.graphics.printf(outputtext, optionX, optionY + currentEvent.height - wrappedHeight,
currentEvent.width, "center")
end
-- writing resource costs
-- potentially make this dynamic based on order in card.lua
local ordered_keys = { "relic", "money", "cultist", "food", "prisoner", "suspicion" }
for i = 1, 3 do
local option = currentEvent.event["option" .. i]
local optionX = currentEvent["option" .. i .. "x"]
local optionY = currentEvent["option" .. i .. "y"]
local resString = ""
for resource, amount in pairs(option.requirements) do
if amount ~= 0 then
resString = resString .. resource:sub(1, 1):upper() .. ": " .. amount .. " "
end
end
if USEFUL.IntToBool(currentEvent.event["option" .. i].cultistequalsprisoner) then
resString = resString .. "\n(cultist/Prisoner)"
end
love.graphics.printf(resString, optionX, optionY + (currentEvent.height / 3), currentEvent.width,
"center")
love.graphics.printf("---------------", optionX, optionY + (currentEvent.height / 2), currentEvent.width,
"center")
end
for i = 1, 3 do
local option = currentEvent.event["option" .. i]
local optionX = currentEvent["option" .. i .. "x"]
local optionY = currentEvent["option" .. i .. "y"]
local resString = ""
for resource, amount in pairs(option.rewards) do
if amount ~= 0 then
resString = resString .. resource:sub(1, 1):upper() .. ": " .. amount .. " "
end
end
love.graphics.printf(resString, optionX, optionY + (currentEvent.height / 1.75), currentEvent.width,
"center")
end
end
end
love.graphics.setColor(1, 1, 1, 1)
-- draw resource cards in hand (moved to end to ensure they're always on top)
for _, card in ipairs(hand.cards) do
if not card.dragging or not card.hovered then
cardImage = card.resource.img
cardScaleX = card.width / cardImage:getWidth()
cardScaleY = card.height / cardImage:getHeight()
love.graphics.draw(cardImage, card.x, card.y, 0, cardScaleX, cardScaleY)
end
end
--draw card being dragged or hovered last so its on top
for _, card in ipairs(hand.cards) do
if card.hovered or card.dragging then
local cardImage = card.resource.img
local cardScaleX = card.width / cardImage:getWidth()
local cardScaleY = card.height / cardImage:getHeight()
love.graphics.draw(cardImage, card.x, card.y, 0, cardScaleX, cardScaleY)
end
end
end
function DrawForesightScene()
love.graphics.setColor(1, 1, 1, 1)
xImage = love.graphics.newImage("assets/images/ui/X.png")
love.graphics.draw(xImage, 0, 0, 0, 100 / xImage:getWidth(), 100 / xImage:getHeight())
love.graphics.setColor(EVENTCARD.backupColour.r, EVENTCARD.backupColour.g, EVENTCARD.backupColour.b)
for i = 1, 3 do
love.graphics.rectangle("fill", ForesightCards[i].x, ForesightCards[i].y + 20, ForesightCards.width,
ForesightCards
.height)
-- Print card title on each rectangle
if decks.deck[i] then
love.graphics.setColor(0, 0, 0)
love.graphics.printf(decks.deck[i].title, ForesightCards[i].x, ForesightCards[i].y + 20, ForesightCards
.width,
"center")
love.graphics.printf(ForesightCards[i].selected and 'Discard' or 'Keep', ForesightCards[i].x,
ForesightCards[i].y + ForesightCards.height - 10,
ForesightCards
.width,
"center")
love.graphics.setColor(EVENTCARD.backupColour.r, EVENTCARD.backupColour.g, EVENTCARD.backupColour.b)
end
end
end
-- Helper function to draw a menu button with hover effect
function drawMenuButton(button, virtualMouseX, virtualMouseY)
if pointinrect(virtualMouseX, virtualMouseY, button.x, button.y, button.w, button.h) then
love.graphics.setColor(1, 1, 0) -- Yellow when hovered
else
love.graphics.setColor(1, 1, 1) -- White normally
end
love.graphics.print(button.text, button.x, button.y, button.width, button.height)
end
-- Helper function to handle main menu button clicks
function handleMainMenuClick(x, y)
local buttonActions = {
{
button = MENUELEMENTS.playButton,
action = function()
SCENE = "godSelect"
end
},
{
button = MENUELEMENTS.exitButton,
action = function()
love.event.quit()
end
},
{
button = MENUELEMENTS.tutorialButton,
action = function()
loadGame(true)
SCENE = "game"
end
},
{
button = MENUELEMENTS.creditsButton,
action = function()
SCENE = "credits"
end
},
{
button = MENUELEMENTS.modToggleButton,
action = function()
MOD_ENABLED = not MOD_ENABLED
end
},
}
for _, buttonAction in ipairs(buttonActions) do
local button = buttonAction.button
if pointinrect(x, y, button.x, button.y, button.w, button.h) then
buttonAction.action()
return
end
end
end
function DrawMainMenu()
--print('in main menu draw func')
-- Get virtual mouse position for hover detection
local virtualMouseX, virtualMouseY = getVirtualMousePosition()
-- Define which buttons to show in main menu
local mainMenuButtons = {
MENUELEMENTS.playButton,
MENUELEMENTS.tutorialButton,
MENUELEMENTS.settingsButton,
MENUELEMENTS.creditsButton,
MENUELEMENTS.exitButton,
MENUELEMENTS.modToggleButton
}
-- Draw all buttons dynamically
for _, button in ipairs(mainMenuButtons) do
if button == MENUELEMENTS.modToggleButton and MOD_ENABLED then
love.graphics.setColor(0, 1, 0)
love.graphics.print(button.text, button.x, button.y)
else
drawMenuButton(button, virtualMouseX, virtualMouseY)
end
end
-- Draw title
love.graphics.setColor(1, 1, 1)
love.graphics.print('UNDERCLONE', 600, 100)
end
function DrawGodSelection()
local virtualMouseX, virtualMouseY = getVirtualMousePosition()
love.graphics.setColor(1, 1, 1)
love.graphics.print('Select your gods', 100, 0)
-- Helper function to draw a blessing card
local function drawBlessing(blessing, xOffset)
-- Create temporary blessing display object
local tempBlessing = {
x = EVENTCARD.x + 600 + (xOffset or 0),
y = EVENTCARD.y,
width = EVENTCARD.width,
height = EVENTCARD.height,
backupColour = EVENTCARD.backupColour,
event = blessing
}
love.graphics.setColor(tempBlessing.backupColour.r, tempBlessing.backupColour.g, tempBlessing.backupColour.b)
love.graphics.rectangle("fill", tempBlessing.x, tempBlessing.y, tempBlessing.width, tempBlessing.height)
love.graphics.setColor(0, 0, 0)
love.graphics.rectangle("line", tempBlessing.x, tempBlessing.y, tempBlessing.width, tempBlessing.height)
love.graphics.printf(tempBlessing.event.title, tempBlessing.x, tempBlessing.y, tempBlessing.width, "center")
end
-- Loop through all god buttons
for _, godData in ipairs(godButtons) do
local button = godData.button
local blessings = godData.blessings
local selected = godData.selected
-- Check if hovering over this god button
local isHovered = pointinrect(virtualMouseX, virtualMouseY, button.x, button.y, button.w, button.h)
-- Show blessings if hovering and they exist
if isHovered and #blessings > 0 then
for i, blessing in ipairs(blessings) do
local padding = 20
local xOffset = (i - 1) * (EVENTCARD.width + padding)
drawBlessing(blessing, xOffset)
end
end
-- Set button color and draw
if selected then
love.graphics.setColor(0, 1, 0) -- Red when selected
elseif isHovered then
love.graphics.setColor(1, 1, 0) -- Yellow when hovered
else
love.graphics.setColor(1, 1, 1) -- White normally
end
love.graphics.print(button.text, button.x, button.y)
end
local isHovered = pointinrect(virtualMouseX, virtualMouseY, MENUELEMENTS.startButton.x, MENUELEMENTS.startButton.y,
MENUELEMENTS.startButton.w, MENUELEMENTS.startButton.h)
if isHovered then
love.graphics.setColor(1, 1, 0) -- Yellow when hovered
else
love.graphics.setColor(1, 1, 1) -- White normally
end
love.graphics.print(MENUELEMENTS.startButton.text, MENUELEMENTS.startButton.x, MENUELEMENTS.startButton.y)
love.graphics.setColor(1, 1, 1)
end
function DrawCreditsScene()
love.graphics.setColor(1, 1, 1)
love.graphics.print("Credits", 100, 100)
love.graphics.setColor(1, 1, 1)
love.graphics.print("Programming: \nJDN", 100, 200)
love.graphics.setColor(1, 1, 1)
love.graphics.print("Art: \nSentientCrumb (twt: @SentientCrumb)", 100, 300)
love.graphics.setColor(1, 1, 1)
love.graphics.print("-----------------", 100, 400)
love.graphics.setColor(1, 1, 1)
love.graphics.print("Music: \nDances and Dames - Kevin Macleod", 100, 500)
love.graphics.setColor(1, 1, 1)
love.graphics.print("Sounds: \nKenney (www.kenney.nl)", 100, 600)
love.graphics.setColor(1, 1, 1)
love.graphics.print("Original Concept: Underhand - SpoopySquad", 100, 700)
love.graphics.setColor(1, 1, 1)
love.graphics.print("Special Thanks: \nUnderhand and Underhand RAVAMPED discord communities \nunderhand.clanweb.eu",
100, 800)
end
function DrawWinScene()
local virtualMouseX, virtualMouseY = getVirtualMousePosition()
drawMenuButton(MENUELEMENTS.mainMenuButton, virtualMouseX, virtualMouseY)
love.graphics.setColor(1, 1, 1)
love.graphics.print("You Win!", 100, 200)
end
function DrawLossScene()
local virtualMouseX, virtualMouseY = getVirtualMousePosition()
drawMenuButton(MENUELEMENTS.mainMenuButton, virtualMouseX, virtualMouseY)
love.graphics.setColor(1, 1, 1)
love.graphics.print("You Lose!", 100, 200)
end
function love.mousepressed(x, y, button)
x, y = getVirtualMousePosition()
if SCENE == "game" then
for i = #hand.cards, 1, -1 do
-- search cards backwards so cards on the top of the pile get dragged first
local card = hand.cards[i]
if pointinrect(x, y, card.x, card.y, card.width, card.height) then
local cps = card_pickup_sound:clone()
cps:play()
-- if cursor is over the card while clicking then its being dragged
card.dragging = true
if not card.selected then
card.originalX = card.x
card.originalY = card.y
end
card.offsetX = x - card.x
card.offsetY = y - card.y
break
end
end
-- alot of this should probably be in seperate checking functions and have this only check for clicks and direct functions
-- however its like this for now
if currentEvent.expanded then
local optionClicked = ""
-- detecting which option was clicked
if pointinrect(x, y, currentEvent.option1x, currentEvent.option1y, currentEvent.width, currentEvent.height) and currentEvent.event.option1.optiontext ~= "" then
-- option 1
optionClicked = "option1"
elseif pointinrect(x, y, currentEvent.option2x, currentEvent.option2y, currentEvent.width, currentEvent.height) and currentEvent.event.option2.optiontext ~= "" then
-- option2
optionClicked = "option2"
elseif pointinrect(x, y, currentEvent.option3x, currentEvent.option3y, currentEvent.width, currentEvent.height) and currentEvent.event.option3.optiontext ~= "" then
-- option3
optionClicked = "option3"
end
if optionClicked ~= "" then
if currentEvent.event[optionClicked].iswin ~= "" then
SCENE = "win"
return
elseif USEFUL.IntToBool(currentEvent.event[optionClicked].islose) then
SCENE = "lose"
return
end
local CasP = USEFUL.IntToBool(currentEvent.event[optionClicked].cultistequalsprisoner)
if hand:checkIfCanRemove(currentEvent.event[optionClicked].requirements, CasP) then
local oss = option_select_sound:clone()
oss:play()
hand:removeCards(currentEvent.event[optionClicked].requirements, CasP)
hand:addCards(currentEvent.event[optionClicked].rewards)
hand:returnCards()
currentEvent.expanded = false
else
return
end
currentEvent.loadNext = true -- this flag is used to prevent "there is no event" errors from tasks running concurrently
if currentEvent.event[optionClicked].shuffle.specificids ~= {} then
-- gods demand sacrifice only sometimes causes a crash here and ive got not a clue why
-- add events if the played event adds new cards
local addCardKeys = currentEvent.event[optionClicked].shuffle.specificids
USEFUL.fisherYates(addCardKeys)
local numToAdd = currentEvent.event[optionClicked].shuffle.numcards
local availableCards = #addCardKeys
for i = 1, numToAdd do
if i <= availableCards then
decks:insert(EVENTS.chained[addCardKeys[i]])
else
local randomIndex = math.random(1, availableCards)
decks:insert(EVENTS.chained[addCardKeys[randomIndex]])
end
end
end
local recurring = currentEvent.event[optionClicked].insertsSelf or
currentEvent.event.isrecurring
-- discard, move to permaDiscrd if not recurring
decks:discard(1, recurring)
-- check to see if a punsihment should be added to the top of the deck first
hand:checkPunishments()
if currentEvent.event[optionClicked].foresight.hasforesight == 1 then
ForesightWithDiscard = USEFUL.IntToBool(currentEvent.event[optionClicked].foresight.candiscard)
SCENE = "foresight"
end
-- top event of the deck is now the current event if there is one
if decks.deck[1] then
currentEvent:updateEvent(decks.deck[1])
else
currentEvent.event = nil
end
end
-- shuffle deck if empty
if #decks.deck == 0 then
currentEvent.shuffling = true
decks:shuffle()
currentEvent:updateEvent(decks.deck[1])
end
currentEvent.loadNext = false
else
if pointinrect(x, y, currentEvent.x, currentEvent.y, currentEvent.width, currentEvent.height) and not currentEvent.shuffling and not currentEvent.loadNext then
if not currentEvent.expanded then
local es = expand_sound:clone()
es:play()
currentEvent.expanded = true
end
end
end
elseif SCENE == "foresight" then
if ForesightWithDiscard then
for i = 1, #ForesightCards do
if pointinrect(x, y, ForesightCards[i].x, ForesightCards[i].y, ForesightCards.width, ForesightCards.height) then
ForesightCards[i].selected = not ForesightCards[i].selected
end
end
end
if pointinrect(x, y, 0, 0, 100, 100) then
-- Collect indices of selected cards in reverse order to avoid index shifting issues
if ForesightWithDiscard then
local selectedIndices = {}
for i = 1, #ForesightCards do
if ForesightCards[i].selected then
table.insert(selectedIndices, i)
end
end
-- Discard cards in reverse order to maintain correct indices
for i = #selectedIndices, 1, -1 do
decks:discard(selectedIndices[i], 1)
end
-- Update currentEvent only once after all discards are complete
if decks.deck[1] then
currentEvent:updateEvent(decks.deck[1])
else
currentEvent.event = nil
end
end
-- reset them all to be not selected
for i = 1, #ForesightCards do
ForesightCards[i].selected = false
end
SCENE = "game"
end
elseif SCENE == "mainmenu" then
handleMainMenuClick(x, y)
elseif SCENE == "godSelect" then
local selectedCount = 0
for i = 1, #godButtons do
if godButtons[i].selected == true then
selectedCount = selectedCount + 1
end
end
for i = 1, #godButtons do
if pointinrect(x, y, godButtons[i].button.x, godButtons[i].button.y, godButtons[i].button.w, godButtons[i].button.h) then
if selectedCount < 3 or godButtons[i].selected then
godButtons[i].selected = not godButtons[i].selected
end
end
end
if pointinrect(x, y, MENUELEMENTS.startButton.x, MENUELEMENTS.startButton.y, MENUELEMENTS.startButton.w, MENUELEMENTS.startButton.h) then
loadGame()
SCENE = "game"
end
elseif SCENE == "credits" then
if pointinrect(x, y, MENUELEMENTS.mainMenuButton.x, MENUELEMENTS.mainMenuButton.y, MENUELEMENTS.mainMenuButton.w, MENUELEMENTS.mainMenuButton.h) then
SCENE = "mainMenu"
end
elseif SCENE == "win" or SCENE == "lose" then
if pointinrect(x, y, MENUELEMENTS.mainMenuButton.x, MENUELEMENTS.mainMenuButton.y, MENUELEMENTS.mainMenuButton.w, MENUELEMENTS.mainMenuButton.h) then
SCENE = "mainmenu"
end
end
end
function love.mousereleased(x, y, button)
if SCENE == "game" then
for _, card in ipairs(hand.cards) do
local playareaX, playareaY, playareaWidth, playareaHeight = playarea:get()
local cps = card_place_sound:clone()
if card.dragging and pointinrect(card.x + (card.width / 2), card.y + (card.height / 2), playareaX, playareaY, playareaWidth, playareaHeight) then
card.selected = true
card.dragging = false
cps:play()
elseif card.dragging then
card.selected = false
card.dragging = false
cps:play()
end
end
end
end
function love.mousemoved(x, y, dx, dy)
-- Always update raw mouse position for hover effects
mouseX = x
mouseY = y
-- Handle card dragging in game scene
if gameLoaded then
local virtualX, virtualY = getVirtualMousePosition()
for _, card in ipairs(hand.cards) do
if card.dragging then
card.x = virtualX - card.offsetX
card.y = virtualY - card.offsetY
end
end
end
end
function getVirtualMousePosition()
local mousex, mousey = love.mouse.getPosition()
local scaleX, scaleY, offsetX, offsetY = getCanvasScale()
local virtX = (mousex - offsetX) / scaleX
local virty = (mousey - offsetY) / scaleY
return virtX, virty
end
function love.keypressed(key)
if SCENE == "game" then
if key == "space" then
-- return all cards
local cps = card_place_sound:clone()
cps:play()
hand:returnCards()
end
if key == "s" then
-- select hovered card
for _, card in ipairs(hand.cards) do
if card.hovered then
local cps = card_pickup_sound:clone()
cps:play()
card.selected = true
end
end
end
if key == "d" then
-- deselect hovered card
for _, card in ipairs(hand.cards) do
if card.hovered then
local cps = card_place_sound:clone()
cps:play()
card.selected = false
end
end
end
end
if key == "f11" then
fullscreen = not fullscreen
love.window.setFullscreen(fullscreen, "exclusive")
end
end
function love.keyreleased(key)
end
function getCanvasScale()
local window_width, window_height = love.graphics.getDimensions()
local scaleX = window_width / canvas:getWidth()
local scaleY = window_height / canvas:getHeight()
local scale = math.min(scaleX, scaleY) -- Preserve aspect ratio
local scaled_width = base_width * scale
local scaled_height = base_height * scale
local offsetX = (window_width - scaled_width) / 2
local offsetY = (window_height - scaled_height) / 2
return scale, scale, offsetX, offsetY
end
function pointinrect(px, py, rx, ry, rw, rh)
-- check if a point is within a rectangle
-- mostly used to check if cursor is over a card
return px >= rx and px <= rx + rw and py >= ry and py <= ry + rh
end
function lerp(a, b, t)
-- move from a to b smoothly
return a + (b - a) * math.min(t, 1)
end