File: code.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 (230 lines) | stat: -rw-r--r-- 7,706 bytes parent folder | download | duplicates (8)
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

-- -----------------------------------------------------------------
-- Init
-- -----------------------------------------------------------------
local function prog_init()
    initModels()
    sound_playMusic("music/rybky03.ogg")
    local pokus = getRestartCount()


    -- -------------------------------------------------------------
    local function prog_init_room()
        local pom1, pom2, pomb1, pomb2 = 0, 0, false, false

        switch(pokus){
            [1] = function()
                room.uvod = 0
            end,
            [2] = function()
                room.uvod = 1
            end,
            default = function()
                room.uvod = random(4)
            end,
        }
        room.setk = 0
        if pokus == 1 then
            room.prehnala = 22
        else
            room.prehnala = 21
        end

        return function()
            if isReady(small) and isReady(big) and no_dialog() then
                if room.uvod < 3 then
                    switch(room.uvod){
                        [0] = function()
                            addm(random(30), "sch-m-spadlo")
                        end,
                        [1] = function()
                            addm(random(30), "sch-m-spadlo")
                            addv(random(30), "sch-v-lastura")
                        end,
                        [2] = function()
                            addv(random(30), "sch-v-lastura")
                        end,
                    }
                    room.uvod = 3
                elseif plzik.X >= room.prehnala then
                    addm(random(40), "sch-m-moc"..random(3))
                    room.prehnala = 100
                elseif room.setk == 0 and plzik.X == 10 and plzik.Y == 14 then
                    addv(random(40), "sch-v-setkani")
                    room.setk = 1
                end
            end
        end
    end

    -- -------------------------------------------------------------
    local function prog_init_plzik()
        local pom1, pom2, pomb1, pomb2 = 0, 0, false, false

        plzik.stav = 0

        return function()
            if plzik.dir ~= dir_no then
                plzik.stav = 15
            end
            if isWater(plzik.X + 1, plzik.Y + 2) then
                plzik.stav = 10
            end
            switch(plzik.stav){
                [0] = function()
                    plzik.afaze = 0
                    if random(100) < 2 then
                        plzik.stav = plzik.stav + 1
                    end
                end,
                [1] = function()
                    plzik.afaze = 5
                    plzik.stav = plzik.stav + 1
                end,
                [2] = function()
                    plzik.afaze = random(3) + 1
                    plzik.stav = plzik.stav + 1
                end,
                [3] = function()
                    if odd(game_getCycles()) then
                        if random(100) < 20 then
                            plzik.afaze = random(3) + 1
                        end
                    end
                    if random(1000) < 5 then
                        plzik.stav = plzik.stav + 1
                    end
                end,
                [4] = function()
                    plzik.afaze = 5
                    plzik.stav = 0
                end,
                [10] = function()
                    plzik.afaze = 4
                    if isWater(plzik.X + 1, plzik.Y + 2) then
                        plzik.stav = 21 + random(20)
                    end
                end,
                [15] = function()
                    plzik.afaze = 5
                    if plzik.dir == dir_no then
                        plzik.stav = 21 + random(20)
                    end
                end,
                [20] = function()
                    plzik.stav = 3
                end,
                default = function()
                    if plzik.stav >= 21 or plzik.stav <= 100 then 
                        plzik.stav = plzik.stav - 1
                    end
                end,
            }
            plzik:updateAnim()
        end
    end

    -- -------------------------------------------------------------
    local function prog_init_snecek()
        local pom1, pom2, pomb1, pomb2 = 0, 0, false, false

        snecek.cinnost = 0
        snecek.sour = random(6) * 3
        snecek.smer = random(2) * 2 - 1

        return function()
            switch(snecek.cinnost){
                [0] = function()
                    if random(100) < 1 then
                        snecek.cinnost = 1
                    elseif random(100) < 2 then
                        snecek.cinnost = 2
                    end
                end,
                [1] = function()
                    if random(100) < 3 then
                        snecek.cinnost = 0
                    end
                end,
                [2] = function()
                    if math.mod(snecek.sour, 3) == 0 and random(100) < 30 then
                        snecek.cinnost = 0
                    elseif math.mod(snecek.sour, 3) == 0 and random(100) < 10 then
                        snecek.cinnost = 3
                    elseif random(100) < 2 or snecek.smer == -1 and snecek.sour == 0 or snecek.smer == 1 and snecek.sour == 15 then
                        snecek.smer = -snecek.smer
                    elseif snecek.smer < 0 then
                        snecek.sour = snecek.sour - 1
                    elseif snecek.smer > 0 then
                        snecek.sour = snecek.sour + 1
                    end
                end,
                [3] = function()
                    if random(100) < 3 then
                        snecek.cinnost = 2
                    end
                end,
            }
            switch(snecek.cinnost){
                [0] = function()
                    if snecek.smer < 0 then
                        snecek.afaze = 15 - snecek.sour
                    else
                        snecek.afaze = 22 + snecek.sour
                    end
                end,
                [2] = function()
                    if snecek.smer < 0 then
                        snecek.afaze = 15 - snecek.sour
                    else
                        snecek.afaze = 22 + snecek.sour
                    end
                end,
                [1] = function()
                    if snecek.smer < 0 then
                        snecek.afaze = 21 - math.floor(snecek.sour / 3)
                    else
                        snecek.afaze = 38 + math.floor(snecek.sour / 3)
                    end
                end,
                [3] = function()
                    if snecek.smer < 0 then
                        snecek.afaze = 21 - math.floor(snecek.sour / 3)
                    else
                        snecek.afaze = 38 + math.floor(snecek.sour / 3)
                    end
                end,
            }
            snecek:updateAnim()
        end
    end

    -- --------------------
    local update_table = {}
    local subinit
    subinit = prog_init_room()
    if subinit then
        table.insert(update_table, subinit)
    end
    subinit = prog_init_plzik()
    if subinit then
        table.insert(update_table, subinit)
    end
    subinit = prog_init_snecek()
    if subinit then
        table.insert(update_table, subinit)
    end
    return update_table
end
local update_table = prog_init()


-- -----------------------------------------------------------------
-- Update
-- -----------------------------------------------------------------
function prog_update()
    for key, subupdate in pairs(update_table) do
        subupdate()
    end
end