1 2-- ----------------------------------------------------------------- 3-- Init 4-- ----------------------------------------------------------------- 5local function prog_init() 6 initModels() 7 sound_playMusic("music/rybky09.ogg") 8 local pokus = getRestartCount() 9 10 11 -- ------------------------------------------------------------- 12 local function prog_init_room() 13 local pom1, pom2, pomb1, pomb2 = 0, 0, false, false 14 local boring = 0 15 16 room.uvod = 0 17 room.zivy = 0 18 room.poklad = 0 19 room.chobotnicka = 0 20 room.chobotnicka1 = 0 21 room.kostricky = randint(200, 1000) 22 room.mysleni = randint(1000, 5000) 23 room.posvitime = 0 24 room.hrbet = randint(25, 100) 25 room.operenej = 0 26 27 return function() 28 if small:getAction() == "rest" and big:getAction() == "rest" then 29 boring = boring + 1 30 else 31 boring = 0 32 end 33 34 if isReady(small) and isReady(big) and no_dialog() then 35 if room.zivy > 0 then 36 room.zivy = room.zivy + 1 37 end 38 if room.zivy > 50 then 39 room.zivy = 0 40 end 41 if room.kostricky > 0 then 42 room.kostricky = room.kostricky - 1 43 end 44 if room.mysleni > 0 then 45 room.mysleni = room.mysleni - 1 46 end 47 if room.hrbet > 0 and big.Y == poklop.Y + 1 and poklop.Y < poklop.YStart then 48 room.hrbet = room.hrbet - 1 49 end 50 if room.uvod == 0 then 51 if pokus == 1 or random(100) < 50 then 52 addv(randint(20, 30), "ka2-v-nekde") 53 if random(100) < 40 then 54 addm(random(5), "ka2-m-kdepak") 55 end 56 end 57 room.uvod = 1 58 elseif (0 <= papzivy.afaze and papzivy.afaze <= 8) and room.operenej == 0 then 59 addv(0, "ka2-v-papousek") 60 room.operenej = 1 61 room.zivy = 1 62 elseif look_at(small, papzivy) and room.zivy > 0 and room.zivy < 50 and room.operenej == 1 then 63 addm(0, "ka2-m-kostra") 64 room.zivy = 0 65 room.operenej = 0 66 elseif dist(small, truhla) <= 3 and room.poklad == 0 and look_at(small, truhla) and random(100) < 10 then 67 room.poklad = 1 68 addm(random(5), "ka2-m-posledni") 69 local rand7 = random(7) 70 if rand7 == 0 or rand7 == 1 then 71 addv(random(5), "ka2-v-mapa0") 72 elseif rand7 == 2 or rand7 == 3 then 73 addv(random(5), "ka2-v-mapa1") 74 elseif rand7 == 4 or rand7 == 5 then 75 addv(random(5), "ka2-v-mapa2") 76 end 77 elseif small.X >= chobot.X and small.X <= chobot.X + 4 and small.Y == chobot.Y - 1 and room.chobotnicka == 0 and random(100) < 2 then 78 room.chobotnicka = 1 79 addm(1, "ka2-m-chapadlo") 80 switch(random(3)){ 81 [0] = function() 82 addv(random(5) + 10, "ka2-v-fik") 83 end, 84 [1] = function() 85 addv(random(5) + 10, "ka2-v-fik") 86 chobot:planDialog(5, "k1-chob-p") 87 addv(random(5), "ka2-v-napad") 88 end, 89 } 90 elseif dist(small, chobot) <= 2 and look_at(small, chobot) and room.chobotnicka1 == 0 and room.chobotnicka == 1 and random(100) < 3 then 91 room.chobotnicka1 = -1 92 addm(1, "ka2-m-hej") 93 if random(3) <= 1 then 94 addm(randint(30, 50), "ka2-m-diky") 95 end 96 elseif room.kostricky == 0 and small.X > 8 and big.X > 8 then 97 room.kostricky = -1 98 addv(random(5), "ka2-v-kostry") 99 if random(100) < 70 then 100 addm(random(5), "ka2-m-patrne") 101 end 102 elseif room.mysleni == 0 and boring > 40 then 103 room.mysleni = -1 104 addv(random(10), "ka2-v-myslet") 105 addm(random(5), "ka2-m-tezko") 106 elseif lampa.dir ~= dir_no and room.posvitime == 0 and random(100) < 40 then 107 addm(10, "ka2-m-svitit") 108 room.posvitime = 1 109 elseif room.hrbet == 0 and big.Y == poklop.Y + 1 and poklop.Y < poklop.YStart then 110 room.hrbet = -1 111 addv(0, "ka2-v-hrbet") 112 end 113 end 114 end 115 end 116 117 -- ------------------------------------------------------------- 118 local function prog_init_truhla() 119 return function() 120 if truhla.dir ~= dir_no and level_isNewRound() then 121 truhla:talk("k1-x-vrz", VOLUME_FULL) 122 end 123 end 124 end 125 126 -- ------------------------------------------------------------- 127 local function prog_init_papouch() 128 local pom1, pom2, pomb1, pomb2 = 0, 0, false, false 129 130 papouch.stav = 0 131 132 return function() 133 if papouch.stav == 0 and random(250) == 0 and no_dialog() then 134 switch(random(7)){ 135 [0] = function() 136 planDialogSet(0, "k1-pap-sucharek", 101, papouch, "stav") 137 end, 138 [1] = function() 139 planDialogSet(0, "k1-pap-kruty", 101, papouch, "stav") 140 end, 141 [2] = function() 142 planDialogSet(0, "k1-pap-3xkruty", 101, papouch, "stav") 143 end, 144 [3] = function() 145 planDialogSet(0, "k1-pap-kruci", 101, papouch, "stav") 146 end, 147 [4] = function() 148 planDialogSet(0, "k1-pap-sakris", 101, papouch, "stav") 149 end, 150 [5] = function() 151 planDialogSet(0, "k1-pap-trhnisi", 101, papouch, "stav") 152 end, 153 [6] = function() 154 planDialogSet(0, "k1-pap-problem", 101, papouch, "stav") 155 end, 156 } 157 elseif papouch.stav == 101 then 158 papouch.afaze = random(2) 159 end 160 papouch:updateAnim() 161 end 162 end 163 164 -- ------------------------------------------------------------- 165 local function prog_init_chobot() 166 local pom1, pom2, pomb1, pomb2 = 0, 0, false, false 167 168 chobot.lastdir = dir_no 169 chobot.oci = 0 170 chobot.chapadla = 0 171 chobot.akcnost = 2 172 173 return function() 174 if chobot.dir ~= dir_no then 175 chobot.akcnost = 7 176 elseif chobot.akcnost > 2 and math.mod(game_getCycles(), 5) == 0 then 177 chobot.akcnost = chobot.akcnost - 1 178 end 179 if chobot.dir ~= chobot.lastdir then 180 if not chobot:isTalking() then 181 if chobot.dir == dir_down then 182 chobot:talk("k1-chob-p", VOLUME_FULL) 183 elseif chobot.dir ~= dir_no then 184 switch(random(3)){ 185 [0] = function() 186 chobot:talk("k1-chob-1", VOLUME_FULL) 187 end, 188 [1] = function() 189 chobot:talk("k1-chob-2", VOLUME_FULL) 190 end, 191 [2] = function() 192 chobot:talk("k1-chob-3", VOLUME_FULL) 193 end, 194 } 195 end 196 end 197 chobot.lastdir = chobot.dir 198 end 199 if chobot.dir == dir_no and math.mod(game_getCycles(), chobot.akcnost) == 0 then 200 if random(2) == 0 then 201 if chobot.chapadla < 2 then 202 chobot.chapadla = chobot.chapadla + 1 203 else 204 chobot.chapadla = 0 205 end 206 else 207 if chobot.chapadla > 0 then 208 chobot.chapadla = chobot.chapadla - 1 209 else 210 chobot.chapadla = 2 211 end 212 end 213 end 214 pomb1 = xdist(small, chobot) == 0 and ydist(small, chobot) <= 0 or xdist(big, chobot) == 0 and ydist(big, chobot) <= 0 215 pomb1 = pomb1 or chobot.dir ~= dir_no 216 if pomb1 then 217 chobot.oci = 1 218 end 219 switch(chobot.oci){ 220 [0] = function() 221 if random(100) < 10 then 222 chobot.oci = 2 223 end 224 end, 225 [2] = function() 226 if random(100) < 10 then 227 chobot.oci = 0 228 end 229 end, 230 [1] = function() 231 if not pomb1 and random(100) < 20 then 232 chobot.oci = 0 233 end 234 end, 235 } 236 chobot.afaze = chobot.oci + 3 * chobot.chapadla 237 chobot:updateAnim() 238 end 239 end 240 241 -- ------------------------------------------------------------- 242 local function prog_init_small() 243 local pom1, pom2, pomb1, pomb2 = 0, 0, false, false 244 245 small.lebku = 0 246 247 return function() 248 end 249 end 250 251 -- ------------------------------------------------------------- 252 local function prog_init_papzivy() 253 local pom1, pom2, pomb1, pomb2 = 0, 0, false, false 254 255 papzivy.cinnost = 0 256 papzivy.pocet = 0 257 papzivy.afaze = 9 258 259 return function() 260 if papzivy.cinnost > 0 and papzivy.cinnost < 20 and small:getAction() == "turn" then 261 if papzivy.cinnost < 5 then 262 papzivy.cinnost = 24 - papzivy.cinnost 263 else 264 papzivy.cinnost = 20 265 end 266 end 267 switch(papzivy.cinnost){ 268 [0] = function() 269 if random(1000) < 4 then 270 if xdist(small, papzivy) > 1 and not small:isLeft() or xdist(small, papzivy) < -1 and small:isLeft() then 271 papzivy.cinnost = 1 272 end 273 end 274 end, 275 [5] = function() 276 papzivy.delay = random(5) + 2 277 papzivy.cinnost = papzivy.cinnost + 1 278 end, 279 [6] = function() 280 if papzivy.delay > 0 then 281 papzivy.delay = papzivy.delay - 1 282 else 283 papzivy.cinnost = papzivy.cinnost + 1 284 end 285 end, 286 [7] = function() 287 papzivy.afaze = 0 288 papzivy.cinnost = papzivy.cinnost + 1 289 papzivy.delay = random(100) + 10 290 end, 291 [8] = function() 292 if papzivy.delay > 0 then 293 papzivy.delay = papzivy.delay - 1 294 else 295 papzivy.cinnost = papzivy.cinnost + 1 296 papzivy.delay = random(60) + 20 297 end 298 end, 299 [9] = function() 300 if odd(game_getCycles()) then 301 papzivy.afaze = random(4) + 1 302 end 303 if papzivy.delay > 0 then 304 papzivy.delay = papzivy.delay - 1 305 else 306 papzivy.cinnost = 7 307 end 308 end, 309 [24] = function() 310 papzivy.cinnost = 0 311 end, 312 default = function() 313 if 1 <= papzivy.cinnost and papzivy.cinnost <= 4 then 314 papzivy.afaze = 9 - papzivy.cinnost 315 papzivy.cinnost = papzivy.cinnost + 1 316 elseif 20 <= papzivy.cinnost and papzivy.cinnost <= 23 then 317 papzivy.afaze = papzivy.cinnost - 14 318 papzivy.cinnost = papzivy.cinnost + 1 319 end 320 end, 321 } 322 papzivy:updateAnim() 323 end 324 end 325 326 -- -------------------- 327 local update_table = {} 328 local subinit 329 subinit = prog_init_room() 330 if subinit then 331 table.insert(update_table, subinit) 332 end 333 subinit = prog_init_truhla() 334 if subinit then 335 table.insert(update_table, subinit) 336 end 337 subinit = prog_init_papouch() 338 if subinit then 339 table.insert(update_table, subinit) 340 end 341 subinit = prog_init_chobot() 342 if subinit then 343 table.insert(update_table, subinit) 344 end 345 subinit = prog_init_small() 346 if subinit then 347 table.insert(update_table, subinit) 348 end 349 subinit = prog_init_papzivy() 350 if subinit then 351 table.insert(update_table, subinit) 352 end 353 return update_table 354end 355local update_table = prog_init() 356 357 358-- ----------------------------------------------------------------- 359-- Update 360-- ----------------------------------------------------------------- 361function prog_update() 362 for key, subupdate in pairs(update_table) do 363 subupdate() 364 end 365end 366 367