File: level_update.lua

package info (click to toggle)
fillets-ng-data 0.6.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 73,664 kB
  • ctags: 2,328
  • sloc: makefile: 46
file content (71 lines) | stat: -rw-r--r-- 2,324 bytes parent folder | download | duplicates (3)
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

-- -----------------------------------------------------------------
-- View update
-- -----------------------------------------------------------------
local function animateFish(model)
    if model:isAlive() then
        local action = model:getAction()

        if "move_up" == action then
            model:runAnim("vertical_up")
        elseif "move_down" == action then
            model:runAnim("vertical_down")
        elseif "move_left" == action or "move_right" == action then
            model:runAnim("swam")
        elseif "turn" == action then
            model:runAnim("turn")
        elseif "activate" == action then
            model:setAnim("turn", 0)
        elseif "busy" == action then
            model:setAnim("turn", 0)
        else
            --NOTE: for talking see animateHead() bellow
            model:runAnim("rest")
        end
    else
        model:runAnim("skeleton")
    end
end

-- -----------------------------------------------------------------
local function animateHead(model)
    if model:isAlive() then
        local state = model:getState()
        if "talking" == state or model_isTalking(TALK_INDEX_BOTH) then
            if not model.talk_phase then
                model.talk_phase = random(3)
            elseif math.mod(game_getCycles(), 2) == 0 then
                model.talk_phase = math.mod(
                    model.talk_phase + randint(1, 2), 3)
            end
        else
            model.talk_phase = false
        end

        local action = model:getAction()
        if "busy" == action then
            if model.talk_phase then
                model:setAnim("talk", model.talk_phase)
            else
                model:setAnim("turn", 0)
            end
        else
            if "talking" == state or model_isTalking(TALK_INDEX_BOTH) then
                model:useSpecialAnim("head_talking", model.talk_phase)
            elseif "pushing" == state then
                model:useSpecialAnim("head_pushing", 0)
            elseif random(100) < 6 then
                model:useSpecialAnim("head_blink", 0)
            end
        end
    end
end

-- -----------------------------------------------------------------
function animateUnits()
    for index, unit in pairs(getUnitTable()) do
        animateFish(unit)
        animateHead(unit)
    end
end