Files
cacaus-arcade/data/game.lua
2026-03-20 20:59:00 +01:00

142 lines
4.2 KiB
Lua

require "fps"
require "mapa"
require "abad"
local viewport= require("viewport")
local arcade_config = require("arcade_config")
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
viewp = viewport.new()
viewp:position(0,0)
actors={}
function game_init(menu)
abad_init()
table.insert(actors,abad)
local abad_x, abad_y = arc_mapa_get_coords ( 10, 4, 3 )
print(abad_x..", "..abad_y)
abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
game_update=update_game
end
function render_map( sf_map, sf_tiles, x, y )
map.surf(sf_map)
map.cell(16, 16)
surf.source(sf_tiles)
surf.target(0)
view.origin(-x,-y)
map.draw()
view.origin(0,0)
end
function update_game()
surf.target(0)
surf.cls(16)
-- surf.target(logo)
-- surf.cls(16)
-- draw.text("UPDATE_GAME",0,0,15)
-- surf.source(logo)
-- draw.surf(0,0,36,5,56,70,arcade_config.logo_sf.width,arcade_config.logo_sf.height)
--- if abad.hurting == 0 then
--- draw_hab(abad.hab,0,0)
--- --text(abad.hab,1,1,2)
--- draw_hab(cameras[current_camera].hab,0,48)
--- -- text(camera_names[current_camera],2*o2aX,49*o2aX,8)
--- arc_textB(camera_names[current_camera],2*o2aX,49*o2aX,8)
---
--- score.draw()
--- surf.source(tiles)
--- -- draw.text("x"..abad.vides,114*o2aX,13*o2aX,2)
--- arc_text("x"..abad.vides,114*o2aX,13*o2aX,2)
--- draw.rectf((102+(abad.energia>>1))*o2aX,30*o2aX,(21-(abad.energia>>1))*o2aX,8*o2aX,16)
--- else
--- draw.surf(0,0,16*o2aX,9*o2aX,50*o2aX,40*o2aX,16*o2aX,9*o2aX,true)
--- if abad.hurting > 40 then
--- -- draw.text("x"..abad.vides+1,63*o2aX,43*o2aX,3)
--- arc_text("x"..abad.vides+1,63*o2aX,43*o2aX,3)
--- elseif abad.hurting < 20 then
--- -- draw.text("x"..abad.vides,63*o2aX,43*o2aX,2)
--- arc_text("x"..abad.vides,63*o2aX,43*o2aX,2)
--- end
--- end
---
--- mapa_update(abad.hab,cameras[current_camera].hab)
--local vp_x, vp_y = viewp:position()
--if key.down(keyRight) then
-- if vp_x+1<=(tile_w*mapa_room_cols*(mapa_rooms_per_piso))-(res_w) then vp_x = vp_x+1 end
--elseif key.down(keyLeft) then
-- if vp_x>0 then vp_x = vp_x-1 end
--elseif key.down(keyUp) then
-- if vp_y>0 then vp_y = vp_y -1 end
--elseif key.down(keyDown) then
-- if vp_y+1<=(tile_h*mapa_room_rows*mapa_pisos)-(res_h) then vp_y = vp_y+1 end
--end
if key.press(key.N1) then
local hab = math.random(0, 79)
local abad_x, abad_y = arc_mapa_get_coords ( hab, 4, 3 )
print(abad_x..", "..abad_y)
abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end
if key.press(key.N0) then
local abad_x, abad_y = arc_mapa_get_coords ( 10, 4, 3 )
print(abad_x..", "..abad_y)
abad:move(abad_x, abad_y)
local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y)
end
for key,actor in pairs(actors) do
actor:update()
--if actor.hab==cacau.hab and actor~=abad then
-- if aabb(actor,cacau) then
-- if actor.hit~=nil then
-- actor:hit()
-- cacau.hab=-1
-- end
-- end
--end
end
local vp_x = viewp.x
local vp_y = viewp.y
--viewp:position(vp_x, vp_y)
local vp_center_offset_x = (viewp.width >> 1)
local vp_center_offset_y = (viewp.height >> 1)
vp_x = abad.x - 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)
render_map(sf_mapa, tiles, vp_x, vp_y)
for key,actor in pairs(actors) do
-- if actor.hab==hab then
if true then
actor:draw()
end
end
fps_print()
viewp:print()
msg_print(0,14,"ABAD= "..abad.x..", "..abad.y)
msg_print(0,21,"VIEW= "..vp_x..", "..vp_y)
end
function msg_print(x, y, msg )
draw.rectf(x,y,45,14,16)
draw.text(msg,x+1,y+1,2)
end