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

229 lines
6.9 KiB
Lua

arcade_config = require("arcade_config")
require "fps"
require "mapa"
require "abad"
require "cacau"
local viewport= require("viewport")
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()
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
load_tilemap( sf_mapa )
if key.press(key.N1) then
local hab = math.random(0, 79)
local hab_x = math.random(0, mapa_room_cols-1)
local hab_y = math.random(0, mapa_room_rows-1)
local abad_x, abad_y = arc_mapa_get_coords ( hab, hab_x, hab_y)
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 ( 24, 1, 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
switches.update()
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, true)
msg_print(0,21,"VIEW= "..vp_x..", "..vp_y, true)
local hab, xx, yy = arc_mapa_get_map_coords(abad.x, abad.y)
msg_print(0,28,hab.." ( "..xx..", "..yy.." )", true)
-- msg_print(0,35,hab.." ( "..xx..", "..yy.." )", true)
msg_print(0,42," JH= "..abad.jump_height,true)
-- view_coord(abad.x+8, abad.y+0, 16, 32, 6)
-- view_coord(abad.x+abad.bb.x, abad.y+abad.bb.h, 2, 2, 4)
-- view_coord(abad.x+abad.bb.x+abad.bb.w, abad.y+abad.bb.h, 2, 2, 2)
-- view_coord(abad.x, abad.y, 2, 2, 3)
if key.press(key.T) then
view_tile_id = not view_tile_id
view_checking_tile = false
end
if key.press(key.C) then
view_checking_tile = not view_checking_tile
view_tile_id = false
end
if view_tile_id then
write_tile(abad.x, abad.y, 0, true, "R")
write_tile(abad.x, abad.y+16, 0, true, "R")
write_tile(abad.x, abad.y+32, 0, true, "R")
write_tile(abad.x+16, abad.y+32, 0, true, "C")
write_tile(abad.x+32, abad.y, 0, true, "L")
write_tile(abad.x+32, abad.y+16, 0, true, "L")
write_tile(abad.x+32, abad.y+32, 0, true, "L")
end
if view_checking_tile then
local msg = "FLIP= true"
if not abad.flip then
msg ="FLIP= false"
view_coord(abad.x+abad.bb.w+abad.bb.x-1, abad.y+abad.bb.h-4, 2, 2, 2)
else
view_coord(abad.x+abad.bb.x-1, abad.y+abad.bb.h-4, 2, 2, 2)
end
msg_print(abad.x, abad.y-8,msg)
end
end
function msg_print(x, y, msg, direct_print )
local scr_x, scr_y
direct_print = direct_print or false
if direct_print then
scr_x = x
scr_y = y
else
scr_x, scr_y = viewp:screen_coords(x, y)
end
draw.rectf(scr_x,scr_y,45,7,16)
draw.text(msg,scr_x+1,scr_y+1,2)
end
function view_coord(x, y, w, h, color)
local scr_x, scr_y = viewp:screen_coords(x, y)
draw.rect(scr_x, scr_y, w, h, color)
end
function write_tile(x, y, yplus, print_type, align )
local scr_x, scr_y = viewp:screen_coords(x, y)
local hab, xx, yy = arc_mapa_get_map_coords(x, y)
yplus = yplus or 0
print_type = print_type or false
align = align or "R"
local txt_offset = -7
if align=="R" then txt_offset = -14
elseif align=="L" then txt_offset = 0
end
draw.rectf(scr_x+txt_offset,scr_y+yplus,14,7,16)
local msg = mapa_get_tile(hab,xx,yy)
if print_type then
msg = msg.." "..arc_check_tile(x, y)
end
draw.text(msg,scr_x+txt_offset+1,scr_y+1+yplus,2)
end