@ @PPP````p $ $"""""""""""""""""""""""""""""""""""""""""""!! !! ! ! !!! ! ! !! !! ! !! ! ! 666666666666666666666666666666S? ^-- title: Night Raid -- author: Exotux -- desc: Destroy the city -- site: https://exotux.itch.io/ -- license: MIT License (change this to your license of choice) -- version: 0.1 -- script: lua lastTimeUpd = 0 timer=0 toggle = true level = 1 oldlevel = 1 init = false score = 0 spr_width = 8 spr_height = 8 scr_width = 240 scr_height = 135 -- Ovni ovni = {} -- liste des tirs tirList = {} gamemode = "menu" function create_ovni(level) o = { x = 10, y = 20, velocity = 0.5, type = "ovni", spr = { 256,257 }, anim_speed = 0.3, anim_time = 0, anim_nfrm = 2, anim_cfrm = 1, exploded = false, explode_t = 0, explode_t_toggle = 0, explode_anim_time = 60*3, toggle = true, shooted = false, update = function(dt) if (ovni.exploded) then ovni.explode_t = ovni.explode_t + 1 if ovni.explode_t > ovni.explode_anim_time then gamemode="gameover" end if ovni.explode_t_toggle > 15 then ovni.toggle = not ovni.toggle ovni.explode_t_toggle = 0 else ovni.explode_t_toggle = ovni.explode_t_toggle + 1 end else o.anim_time = o.anim_time + dt if (o.anim_time > o.anim_speed) then o.anim_cfrm = o.anim_cfrm + 1 o.anim_time = 0 if o.anim_cfrm > o.anim_nfrm then o.anim_cfrm = 1 end end -- Déplacement auto vers la droite o.x = o.x + o.velocity if o.x + 8 > 240 then o.x = 0 o.y = o.y + 8 end if key(48) and not o.shooted then -- tir o.shooted = true sfx(1, "A-3", 10) create_tir() end end end, collide = function() return collide(o) end, draw = function() if ovni.toggle then spr(o.spr[o.anim_cfrm], o.x, o.y, 0) end end } local diff = level - oldlevel if (diff > 0) then for i=1, diff do -- augmentation de la vitesse de 5% à chaque niveau o.velocity = o.velocity * 1.05 end end return o end function create_tir() local t = { x = ovni.x, y = ovni.y+8, velocity = 0.75, type="tir", power = math.floor(math.random(1,3)) } function t:update(self) self.y = self.y + self.velocity if self.y + 8 > 136 then table.remove(tirList) ovni.shooted = false end end function t:draw(self) spr(272, self.x, self.y, 0) end function t:collide(self) if collide(self) then local multi = 1 if (self.power > 0) then multi = self.power end score = score + (1*multi) sfx(0, "C-4", 20) return true else return false end end table.insert(tirList, t) end function collide(entity) -- on parcours le tableau de la ville for col, buiding in pairs(city.map) do for hauteur = #buiding, 1, -1 do posX = 50+((col-1)*spr_width) posY = scr_height - (spr_height*hauteur) if (entity.x+3) < (posX + spr_width) and (entity.x + spr_width-4) > posX and entity.y < (posY + spr_height) and (entity.y + spr_height) > posY then -- bombs if (entity.type == "tir") then entity.power = entity.power - 1 table.remove(city.map[col], hauteur) -- Supprime l'étage end return true end end end return false end -- Génération de la ville function create_city(mxBuilding, mxHeight) local city = {} local nbBuilding = math.random(3+level, mxBuilding+level) city.map = {} -- Generation des buildings for i=1, nbBuilding do building = {} -- Génération de la hauteur des buildings (max 10 étages) local max = mxHeight+level if max > 10 then max = 10 end local height = math.floor(math.random(0 , max)) building = {} for j=1, height do table.insert(building, math.random(1,2)) end table.insert(city.map, building) end function city:update() end function city:draw() for i, b in pairs(city.map) do h = spr_height for j, tile in pairs(b) do -- on doit commencer par le bas et remonter spr(287+tile, 50+((i-1)*spr_width), scr_height-h) h = h + spr_height end end line(0,scr_height,scr_width,scr_height,13) end return city end function updateGame(dt) ovni.update(dt) if not ovni.exploded then if ovni.collide() then ovni.exploded = true ovni.explode_t = 0 sfx(0, "C-4", 60) elseif #tirList > 0 then touched = false for i, tir in ipairs(tirList) do tir:update(tir) if tir:collide(tir) and tir.power == 0 then touched = true end end if touched then table.remove(tirList) ovni.shooted = false end end end end function drawGame() print("Score : " .. score, 8, 8, 13) print("Level : " .. level, 180, 8, 13) city:draw() ovni.draw() if #tirList >= 1 then for i, tir in ipairs(tirList) do tir:draw(tir) end end end function checkEndLevel() local nbStayFloor = 0 -- on parcours le tableau de la ville for idx, buiding in ipairs(city.map) do for _, _ in pairs(buiding) do nbStayFloor = nbStayFloor + 1 end end return (nbStayFloor == 0) end -- Draw text "Press space" function drawInstruction(text, x, y, color) local color = color or 12 if timer >=45 then timer=0 toggle = not toggle else timer=timer+1 end if (toggle) then print(text, x, y, color) end end function drawTransitionLevelStart(level) print("Level : " .. level, 95, 65, 13) end function initGame(lvl) city = create_city(5,3) ovni = create_ovni(lvl) tirList = {} toggle = true timer = 0 level = lvl if level == 1 then score = 0 oldlevel = 1 end end function TIC() cls(0) if gamemode == "menu" then map(0,0,240,135,0,0,-1) drawInstruction("Press space to start", 60, 65, 13) if key(48) then -- space initGame(1) timer = 0 gamemode="game" end elseif gamemode == "game" then if (timer <= 120) then drawTransitionLevelStart(level) timer = timer+1 else updateGame(computeDt()) drawGame() end if checkEndLevel() then -- Change de niveau level = level + 1 initGame(level) timer = 0 end elseif gamemode == "gameover" then print("Game Over", 85, 5, 13, 2) print("Score : " .. score , 85, 30, 13, 2) drawInstruction("Press space to return to menu", 40, 65, 13) if keyp(48) then -- space gamemode="menu" timer = 0 toggle = true end end end -- Return Deltatime function computeDt() local ct = time() local dt = (ct - lastTimeUpd) / 1000 lastTimeUpd = ct return dt end