aboutsummaryrefslogtreecommitdiff
path: root/assets/scripts/mainMenu.lua
blob: ca290c6148f50f227d4dce55f59a94ee62a349c0 (plain)
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
---@diagnostic disable: undefined-global
movementSpeed = 3;
bannerTextureWidth = 509;
buttonHeight = 50;
buttonWidth = 110;
bigButtonWidth = 150;
bigButtonHeight = buttonHeight;
characterSelectType = ""

Input = {
    prevKeys = {},
    isKeyPressedOnce = function(key)
        local code = getKeycodeByName(key)
        local wasDown = Input.prevKeys[code]
        local isDown = keys[code]
        Input.prevKeys[code] = isDown
        return isDown and not wasDown
    end,
    isKeyDown = function(key)
        local code = getKeycodeByName(key)
        return keys[code]
    end
}

Timer = {
    timers = {}
}

function Timer.after(delay, callback)
    table.insert(Timer.timers, {
        time = delay,
        action = callback
    })
end

function Timer.delay(seconds)
    local start = os.clock()
    while (os.clock() - start) < seconds do
        -- Busy wait, blocking here
    end
end

function Timer.clearAllTimers()
    Timer.timers = {}
end

function Timer.update(dt)
    for i = #Timer.timers, 1, -1 do
        local t = Timer.timers[i]
        t.time = t.time - dt
        if t.time <= 0 then
            t.action()
            table.remove(Timer.timers, i)
        end
    end
end

function Setup()
    setBgImage("assets/backgrounds/city-background-1.png")
    playSoundLoop("assets/sounds/Main Menu - Background Music (Knockout).wav")
end

function Local2PButton()
    characterSelectType = "Local 2P"
    dofile("assets/scripts/character-select.lua")
    Setup()
end

function MultiplayerButton()
    characterSelectType = "Multiplayer"
    dofile("assets/scripts/character-select.lua")
    Setup()
end

function SettingsButton()
    dofile("assets/scripts/settings.lua")
    Setup()
end

function Update()
    queueTextureForRender("assets/gui/mainMenu_banner.png", WIDTH // 2 - bannerTextureWidth // 2, 0)
    queueButtonForRender("Local 2P", WIDTH // 2 - buttonWidth // 2, HEIGHT // 2 - buttonHeight // 2, buttonWidth, buttonHeight, "Local2PButton");
    queueButtonForRender("Multiplayer", WIDTH // 2 - bigButtonWidth // 2, HEIGHT // 2 - bigButtonHeight // 2 + 55, bigButtonWidth, bigButtonHeight, "MultiplayerButton");
    queueButtonForRender("Settings", WIDTH // 2 - buttonWidth // 2, HEIGHT // 2 - buttonHeight // 2 + 55 + 55, buttonWidth, buttonHeight, "SettingsButton");
    queueButtonForRender("Quit Game", WIDTH - bigButtonWidth - 20, 20, bigButtonWidth, bigButtonHeight, "quitGame")
end