Files
cacaus-arcade/data/game.lua
2026-03-18 21:04:50 +01:00

126 lines
3.6 KiB
Lua

require "fps"
require "mapa"
local viewport= require("viewport")
local arcade_config = require("arcade_config")
o2aX = arcade_config.org2arc_escala
local txr = arcade_config.tiles_per_row-1
local txr2 = arcade_config.tiles_per_row_base2
local toff= arcade_config.tiles_offset
local tw = arcade_config.tiles_width
local th = arcade_config.tiles_height
local viewp = viewport.new()
function game_init(menu)
game_update=update_game
end
function render_view ( hab, x ,y )
local curr_ssurf = surf.source()
local curr_tsurf = surf.target()
local room_x = hab % mapa_rooms_per_piso
local room_y = math.floor(hab / mapa_rooms_per_piso)
local first_x = -1
local first_y = -1
local first_x = 0
local first_y = 0
if room_x == 0 then first_x = 0 end
if room_y == 0 then first_y = 0 end
surf.target(map_buffer)
surf.cls(16)
surf.source(tiles)
for ry=0,2 do
for rx=0,2 do
local buffer_x = rx*mapa_room_cols*tw
local buffer_y = ry*mapa_room_rows*th
local room = (room_y+ry+first_y)*mapa_rooms_per_piso+(room_x+rx+first_x)
draw_hab(room, buffer_x, buffer_y)
end
end
surf.source(map_buffer)
surf.target(0)
print(hab)
viewp.roomXY(hab)
draw.surf(viewp.x,viewp.y,viewp.width,viewp.height,0,0,viewp.width,viewp.height)
surf.source(curr_ssurf)
surf.source(curr_tsurf)
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)
-- render_view(10)
--- 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
vp_x = vp_x+1
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
vp_y = vp_y+1
end
viewp:position(vp_x, vp_y)
local room = viewp:room()
render_view(room)
fps_print()
viewp:print()
end
function draw_hab(hab,x,y,editing)
-- print(hab.." "..x.." "..y)
view.origin(x,y)
mapa_draw(hab)
-- if not editing then
-- for key,actor in pairs(actors) do
-- if actor.hab==hab then
-- actor:draw()
-- end
-- end
-- if imp.hab==hab then imp.draw() end
-- if bambolla.hab==hab then bambolla.draw() end
-- if cacau.hab==hab then cacau:draw() end
-- if fireball.hab==hab then fireball:draw() end
-- end
view.origin(0,0)
end