1 2 3-- ----------------------------------------------------------------- 4-- Init 5-- ----------------------------------------------------------------- 6local function prog_init() 7 initModels() 8 sound_playMusic("music/rybky07.ogg") 9 local pokus = getRestartCount() 10 local main = {} 11 local roompole = createArray(2) 12 13 14 -- ------------------------------------------------------------- 15 local function prog_init_room() 16 local pom1, pom2, pomb1, pomb2 = 0, 0, false, false 17 18 room.aktivni = main 19 room.poc = random(50 + pokus) + 100 20 room.halo = 0 21 room.mikros = 0 22 room.nemam = 200 23 room.odsud = 0 24 room.pronej = 10 + random(50) 25 room.uhnu = 500 + random(500) 26 room.teduz = 0 27 28 return function() 29 switch(room.aktivni){ 30 [main] = function() 31 if room.poc > 0 then 32 room.poc = room.poc - 1 33 else 34 pomb1 = zluty.X == ztel.X and zluty.Y + 3 == ztel.Y 35 pomb2 = modry.X == mtel.X and modry.Y + 3 == mtel.Y 36 room.poc = random(80) + 50 37 room.zvon = 0 38 if pomb1 then 39 if pomb2 then 40 if odd(random(10)) then 41 room.aktivni = zluty 42 else 43 room.aktivni = modry 44 end 45 else 46 room.aktivni = zluty 47 end 48 elseif pomb2 then 49 room.aktivni = modry 50 else 51 room.aktivni = ibudik 52 end 53 end 54 end, 55 [zluty] = function() 56 if room.poc == 0 then 57 zluty:killSound() 58 room.poc = random(30) + 30 59 room.aktivni = main 60 zluty.afaze = 0 61 else 62 room.poc = room.poc - 1 63 if room.pronej > 0 then 64 room.pronej = room.pronej - 1 65 end 66 if zluty.X == ztel.X and zluty.Y + 3 == ztel.Y then 67 if zluty:isTalking() then 68 room.zvon = room.zvon + 1 69 if odd(room.zvon) then 70 zluty.afaze = 1 71 else 72 zluty.afaze = 2 73 end 74 elseif room.zvon > 0 then 75 room.zvon = room.zvon - 1 76 zluty.afaze = 0 77 else 78 zluty:talk("bat-t-phone0", VOLUME_FULL) 79 end 80 else 81 zluty:killSound() 82 zluty.afaze = 0 83 room.aktivni = ztel 84 room.halo = 1 85 end 86 end 87 zluty:updateAnim() 88 end, 89 [modry] = function() 90 if room.poc == 0 then 91 modry:killSound() 92 room.poc = random(30) + 30 93 room.aktivni = main 94 modry.afaze = 0 95 else 96 room.poc = room.poc - 1 97 if room.pronej > 0 then 98 room.pronej = room.pronej - 1 99 end 100 if modry.X == mtel.X and modry.Y + 3 == mtel.Y then 101 if modry:isTalking() then 102 room.zvon = room.zvon + 1 103 if odd(room.zvon) then 104 modry.afaze = 1 105 else 106 modry.afaze = 2 107 end 108 elseif room.zvon > 0 then 109 room.zvon = room.zvon - 1 110 modry.afaze = 0 111 else 112 modry:talk("bat-t-phone1", VOLUME_FULL) 113 end 114 else 115 modry:killSound() 116 modry.afaze = 0 117 room.aktivni = mtel 118 room.halo = 1 119 end 120 end 121 modry:updateAnim() 122 end, 123 [ztel] = function() 124 if room.halo ~= 2 then 125 room.aktivni = main 126 room.poc = random(100) + 30 127 end 128 end, 129 [mtel] = function() 130 if room.halo ~= 2 then 131 room.aktivni = main 132 room.poc = random(100) + 30 133 end 134 end, 135 [ibudik] = function() 136 if room.poc > 0 then 137 room.poc = room.poc - 1 138 elseif not ibudik:isTalking() then 139 ibudik:talk("bat-t-budik", VOLUME_FULL, -1) 140 elseif ibudik.dir ~= dir_no then 141 ibudik:killSound() 142 room.aktivni = -1 143 end 144 end, 145 } 146 if room.halo == 1 then 147 room.halo = 2 148 if pokus > 5 then 149 pom1 = random(11) 150 else 151 pom1 = random(8) 152 end 153 local bin_table = {} 154 switch(pom1){ 155 [0] = function() 156 bin_table[0] = true 157 bin_table[1] = true 158 end, 159 [1] = function() 160 bin_table[0] = true 161 bin_table[2] = true 162 bin_table[4] = true 163 end, 164 [2] = function() 165 bin_table[0] = true 166 bin_table[3] = true 167 end, 168 [3] = function() 169 bin_table[5] = true 170 end, 171 [4] = function() 172 bin_table[4] = true 173 bin_table[5] = true 174 end, 175 [5] = function() 176 bin_table[1] = true 177 bin_table[2] = true 178 end, 179 [6] = function() 180 bin_table[0] = true 181 bin_table[3] = true 182 bin_table[4] = true 183 end, 184 [7] = function() 185 bin_table[1] = true 186 end, 187 default = function() 188 bin_table = {} 189 end, 190 } 191 if bin_table[0] then 192 room:planDialog(5, "bat-p-0") 193 end 194 if bin_table[1] then 195 room:planDialog(5, "bat-p-1") 196 end 197 if bin_table[2] then 198 room:planDialog(5, "bat-p-2") 199 end 200 if bin_table[3] then 201 room:planDialog(5, "bat-p-3") 202 end 203 if bin_table[5] then 204 room:planDialog(5, "bat-p-5") 205 end 206 if bin_table[4] then 207 room:planDialog(5, "bat-p-4") 208 end 209 if countPairs(bin_table) == 0 then 210 room:planDialog(5, "bat-p-zhov"..random(2)) 211 end 212 planSet(room, "halo", 0) 213 end 214 if no_dialog() and isReady(small) and isReady(big) then 215 if game_getCycles() == 20 and random(pokus) < 3 then 216 addm(5, "bat-m-tohle") 217 elseif room.mikros == 0 and dist(small, mikroskop) < 3 and mikroskop.dir ~= dir_no and random(10) == 1 then 218 room.mikros = 1 219 addm(6, "bat-m-mikro") 220 elseif room.odsud == 0 and zluty.X > 32 and dist(small, zluty) < 4 and random(30) == 1 then 221 room.odsud = 1 222 addm(7, "bat-m-sluch") 223 elseif room.teduz == 0 and room.aktivni == -1 and random(70) == 1 then 224 room.teduz = 1 225 addv(8, "bat-v-klid") 226 elseif room.nemam > 0 then 227 room.nemam = room.nemam - 1 228 else 229 switch(room.aktivni){ 230 [ibudik] = function() 231 if random(100) == 1 then 232 room.nemam = 200 + random(200) 233 addv(1, "bat-v-vyp") 234 end 235 end, 236 default = function() 237 if room.aktivni == zluty or room.aktivni == modry then 238 if random(100) == 1 then 239 room.nemam = 200 + random(200) 240 if dist(small, room.aktivni) < dist(big, room.aktivni) then 241 addv(1, "bat-v-zved1") 242 else 243 addv(1, "bat-v-zved0") 244 end 245 end 246 end 247 end, 248 } 249 end 250 end 251 if no_dialog() then 252 if room.pronej == 0 and (room.aktivni == zluty or room.aktivni == modry) and random(30) == 1 then 253 room.pronej = random(100) 254 planDialogSet(3, "bat-s-prome"..random(3), 111, snek, "mluvi") 255 elseif room.uhnu == 0 and (room.aktivni == -1 or room.poc > 30 and room.aktivni == main) then 256 room.uhnu = 300 + random(300) 257 pom2 = random(4) 258 if pom2 ~= 1 or roompole[1] > 0 then 259 planDialogSet(12, "bat-s-snek"..pom2, 111, snek, "mluvi") 260 end 261 roompole[1] = roompole[1] + 1 262 end 263 end 264 if room.uhnu > 0 then 265 room.uhnu = room.uhnu - 1 266 end 267 end 268 end 269 270 -- ------------------------------------------------------------- 271 local function prog_init_dhled() 272 local pom1, pom2, pomb1, pomb2 = 0, 0, false, false 273 274 dhled.padal = 0 275 276 return function() 277 if dhled.padal == 4 then 278 dhled.afaze = 0 279 dhled.padal = 0 280 elseif dhled.padal == 3 then 281 dhled.padal = 4 282 elseif dhled.padal == 2 then 283 dhled.padal = 3 284 elseif dhled.dir == dir_down then 285 dhled.padal = 1 286 elseif dhled.padal == 1 then 287 dhled.afaze = 1 288 dhled.padal = 2 289 end 290 dhled:updateAnim() 291 end 292 end 293 294 -- ------------------------------------------------------------- 295 local function prog_init_snek() 296 local pom1, pom2, pomb1, pomb2 = 0, 0, false, false 297 298 snek.mluvi = 0 299 300 return function() 301 if odd(game_getCycles()) and snek.mluvi ~= 0 then 302 snek.afaze = random(2) 303 else 304 snek.afaze = 0 305 end 306 snek:updateAnim() 307 end 308 end 309 310 -- ------------------------------------------------------------- 311 local function prog_init_ibudik() 312 return function() 313 if odd(game_getCycles()) and ibudik:isTalking() then 314 ibudik.afaze = 1 315 else 316 ibudik.afaze = 0 317 end 318 ibudik:updateAnim() 319 end 320 end 321 322 -- ------------------------------------------------------------- 323 local function prog_init_mikroskop() 324 local pom1, pom2, pomb1, pomb2 = 0, 0, false, false 325 326 mikroskop.poc = 0 327 328 return function() 329 if mikroskop.poc > 0 then 330 mikroskop.poc = mikroskop.poc - 1 331 else 332 mikroskop.afaze = random(3) 333 mikroskop.poc = random(6) 334 end 335 if mikroskop.dir ~= dir_no then 336 mikroskop.poc = 0 337 end 338 mikroskop:updateAnim() 339 end 340 end 341 342 -- -------------------- 343 local update_table = {} 344 local subinit 345 subinit = prog_init_room() 346 if subinit then 347 table.insert(update_table, subinit) 348 end 349 subinit = prog_init_dhled() 350 if subinit then 351 table.insert(update_table, subinit) 352 end 353 subinit = prog_init_snek() 354 if subinit then 355 table.insert(update_table, subinit) 356 end 357 subinit = prog_init_ibudik() 358 if subinit then 359 table.insert(update_table, subinit) 360 end 361 subinit = prog_init_mikroskop() 362 if subinit then 363 table.insert(update_table, subinit) 364 end 365 return update_table 366end 367local update_table = prog_init() 368 369 370-- ----------------------------------------------------------------- 371-- Update 372-- ----------------------------------------------------------------- 373function prog_update() 374 for key, subupdate in pairs(update_table) do 375 subupdate() 376 end 377end 378 379