viewport= require("viewport") require "stage_mgr" require "abad" require "cacau" require "llibre" require "gorro" require "peu" require "premiere" require "elalien" require "bol" require "gota" require "invisible" require "caco" require "zombie" require "score" -- require "switches" require "trigger" require "imp3" require "fireball" require "bar_meter" -- require "stage1" require "remote_view" require "dialeg" require "trigger_event" require "batman" require "health_potion" require "one_up" require "tiles_layer2" require "batvio" -- require "live_scene" require "copter" require "sign" local tile_w = arcade_config.tiles_width local tile_h = arcade_config.tiles_height local res_w = arcade_config.resolucion.width local res_h = arcade_config.resolucion.height local view_tile_id = false local view_checking_tile = false viewp = viewport.new(arcade_config.resolucion.width, arcade_config.resolucion.height) viewp:position(0,0) function foo() print("foo") end function actor_warp_draw(actor) local shrink_w = actor.w*actor.shrink local shrink_h = actor.h*actor.shrink local offset_x = math.floor((actor.w-shrink_w)/2) local offset_y = math.floor((actor.h-shrink_h)/2) local scr_x, scr_y = viewp:screen_coords( actor.x+offset_x, actor.y+offset_y ) shrink_w = math.floor(shrink_w) shrink_h = math.floor(shrink_h) if shrink_w>0 and shrink_h>0 then draw.surfrot((actor.frame&7)*cw, (actor.frame>>cxr2)*ch, cw, ch, scr_x, scr_y, actor.angle, shrink_w, shrink_h, actor.flip) end end function actor_warp_update(actor) -- warp, wait, respawn if actor.warping then if actor.step=360 then actor.angle = actor.angle % 360 end if actor.shrink<=0 then actor.shrink=1 actor.d_shrink=1 actor.angle=0 actor.d_angle=1 actor.warping = false actor.frame = -1 actor.step = 0 if actor.energy~=nil then actor.energy = actor.max_energy end end end elseif actor.step=actor.death_time then actor.frame=actor.anim[1] actor.step=0 actor.wait=0 if actor.name=="caco" then actor.update=caco.update_normal elseif actor.name=="zombie" then actor.update=zombie.update_normal end actor.dying = false end end actors={} function game_exit() -- mapa_restore_backup() actors={} -- cameras={} end function game_init(menu) -- print("GAME INIT") actors={} abad_init() table.insert(actors,abad) score.create() stages.load_stage(true) states:next() end function render_map( sf_map, sf_tiles, x, y, target ) target = target or 0 map.surf(sf_map) map.cell(16, 16) surf.source(sf_tiles) surf.target(target) view.origin(-x,-y) map.draw() view.origin(0,0) end function viewport_update() -- Moure el viewport local vp_x = viewp.x local vp_y = viewp.y local vp_center_offset_x = (viewp.width // 2) local vp_center_offset_y = (viewp.height // 2) vp_x = abad.x+(abad.w/2) - vp_center_offset_x if vp_x < 0 then vp_x = 0 end vp_y = abad.y - vp_center_offset_y if vp_y < 0 then vp_y = 0 end viewp:position(vp_x, vp_y) end function world_update() -- Actualitzar moviment del mapa (ex: tiles animats) arc_mapa_update() tiles_layer2.update() -- Moure a tots for key,actor in pairs(actors) do actor:update() -- Comprovar dispars contra "monstres" if viewp:inside(actor.x, actor.y, actor.w, actor.h) and actor~=abad then for _, cacau_shot in pairs(cacau.shots()) do -- if collision(actor,cacau_shot) then print("COLLISION") end -- if actor.enabled then print(actor.name) else print("NOT "..actor.name) end -- if cacau_shot.alive then print("CACAU") end if actor.enabled and cacau_shot.alive and collision(actor,cacau_shot) then if actor.hit ~= nil and not actor.dying then actor:hit() if actor.can_warp then warp.open(actor) end cacau:kill(cacau_shot) end end end end end if stages.stage_update then stages.stage_update() end -- Actualizar el que queda cacau.update() -- switches.update() warp.update_all() trigger_event.update() end function world_draw() -- Pintar la finestra del mon render_map(sf_mapa, tiles, viewp.x, viewp.y) tiles_layer2.draw() -- if stage_draw_back then stage_draw_back() end if stages.stage_draw_back then stages.stage_draw_back() end -- pintar warps for key,warp in pairs(warp.warp_list) do if viewp:inside(warp.x, warp.y, warp.w, warp.h) then warp:draw() end end --pintar actors for key,actor in pairs(actors) do if viewp:inside(actor.x, actor.y, actor.w, actor.h) and actor~=abad then actor:draw() end end abad:draw(); -- per a que estiga davant de tots dialeg.draw() -- if stage_draw_middle then stage_draw_middle() end if stages.stage_draw_middle then stages.stage_draw_middle() end cacau:draw() if stages.stage_draw_front then stages.stage_draw_front() end remote_view_draw() end function update_game() surf.target(0) surf.cls(16) world_update() viewport_update() world_draw() score.draw() if controller:check("ESC") then states:executar("pause", true) end if DEBUG then special_keys() debug_info() end end states:registrar("game", {game_init, update_game} ) require "game_debug"