aboutsummaryrefslogtreecommitdiff
path: root/players.lua
blob: 92c3646b222faa00d54da5a6aaeca1cf469c6e9c (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
playercount = -1
players = {}

function addplayer()
    playercount += 1
    local player = {}
    player.x = 18
    player.y = 60
    player.ymov = 0
    player.id = playercount
    player.shootcooldown = 0.0
    player.type = "player"

    function player.draw(player)
        if (player.ymov == 0) then
            spr(2, player.x, player.y)
        elseif (player.ymov == 1) then
            spr(3, player.x, player.y)
        elseif (player.ymov == -1) then
            spr(3, player.x, player.y, 1, 1, false, true)
        end
    end

    function player.update(player)
        --movement
        if btn(0, player.id) then
            player.x -= 2
        elseif btn(1, player.id) then
            player.x += 2
        end
        if btn(2, player.id) then
            player.y -= 2
            player.ymov = 1
        elseif btn(3, player.id) then
            player.y += 2
            player.ymov = -1
        else
            player.ymov = 0
        end
        player.x = mid(0, player.x, 120)
        player.y = mid(0, player.y, 120)

        --shooting
        player.shootcooldown -= 1/30
        if btn(4, player.id) and player.shootcooldown < 0 then
            addbullet(player.x+3, player.y, 4, 0, false)
            player.shootcooldown = 0.1
        end
    end

    add(obj, player)
    add(players, #obj)
end

addplayer()