Intentant fer scroll

This commit is contained in:
2026-03-18 21:04:50 +01:00
parent 59fc474770
commit ef277ee9b2
5 changed files with 142 additions and 82 deletions

View File

@@ -1,5 +1,5 @@
title=Cacaus Arcade
config=cacaus_arcade
width=256
height=192
width=576
height=288
zoom=3

View File

@@ -1,92 +1,56 @@
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 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 )
-- el mapa te 10 habitacions d'ample
room_width = tw*12
room_height = th*6
room_x_offset = 0
draw_1st_col = 0
draw_2nd_col = 0
function render_view ( hab, x ,y )
local curr_ssurf = surf.source()
local curr_tsurf = surf.target()
x_offset_col1 = 0
x_offset_col2 = room_width
x_offset_col3 = 2*room_width
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
y_offset_row1 = (arcade_config.resolucion.height-3*room_height)/2
y_offset_row2 = (arcade_config.resolucion.height-room_height)/2
y_offset_row3 = (arcade_config.resolucion.height+room_height)/2
surf.target(map_buffer)
surf.cls(16)
-- 1ª columna d'habitacions
curr_hab = hab-10-1
if curr_hab>=0 then
draw_hab(curr_hab,x_offset_col1,y_offset_row1)
draw_1st_col = 1
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
curr_hab = hab-1
if curr_hab>=10 then
draw_hab(curr_hab,x_offset_col1,y_offset_row2)
draw_1st_col = 1
end
curr_hab = hab+10-1
if curr_hab>=20 then
draw_hab(curr_hab,x_offset_col1,y_offset_row3)
draw_1st_col = 1
end
-- 2ª columna d'habitacions
room_x_offset = x_offset_col1
if draw_1st_col == 1 then
room_x_offset = x_offset_col2
end
curr_hab = hab-10
if curr_hab>=0 then
draw_hab(curr_hab,room_x_offset,y_offset_row1)
end
curr_hab = hab
if curr_hab>=10 then
draw_hab(curr_hab,room_x_offset,y_offset_row2)
end
curr_hab = hab+10
if hab+10+1>=20 then
draw_hab(hab+10+1,0,y_offset_row3)
end
-- 3ª columna d'habitacions
room_x_offset = x_offset_col2
if draw_1st_col == 1 then
room_x_offset = x_offset_col3
end
curr_hab = hab-10+1
if curr_hab>=0 then
draw_hab(curr_hab,room_x_offset,y_offset_row1)
end
curr_hab = hab+1
if curr_hab>=10 then
draw_hab(curr_hab,room_x_offset,y_offset_row2)
end
curr_hab = hab+10+1
if curr_hab>=20 then
draw_hab(curr_hab,room_x_offset,y_offset_row3)
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()
@@ -98,10 +62,8 @@ function update_game()
-- 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)
surf.source(tiles)
render_view(10)
fps_print()
-- render_view(10)
--- if abad.hurting == 0 then
--- draw_hab(abad.hab,0,0)
@@ -127,10 +89,25 @@ function update_game()
--- 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)

View File

@@ -1,6 +1,7 @@
require "fade"
require "audio"
require "intro"
require "map"
local arcade_config = require("arcade_config")
@@ -12,6 +13,12 @@ function mini.init()
logo=surf.new(arcade_config.logo_sf.width,arcade_config.logo_sf.height)
back=surf.new(arcade_config.surface.width,arcade_config.surface.height)
-- buffer per a 3x3 habitacions
local map_buffer_width = 3*mapa_room_cols*arcade_config.tiles_width
local map_buffer_height = 3*mapa_room_rows*arcade_config.tiles_height
local map_buffer_width = 1024
local map_buffer_height = 1024
map_buffer=surf.new(map_buffer_width, map_buffer_height)
fade.init()
textsf=surf.new(arcade_config.org_resolucion.width,arcade_config.org_resolucion.height)

View File

@@ -1,3 +1,15 @@
mapa_room_cols = 12; -- en quantitat de tiles
mapa_room_rows = 6; -- en quantitat de tiles
mapa_rooms_per_piso = 10
mapa_pisos = 7
-- 0 1 2 3 4 5 6 7 8 9
-- 10 11 12 13 14 15 16 17 18 19
-- ...
-- 70 71 72 73 74 75 76 77 78 79
--
-- Hi ha una habitació 80 que no se que es
mapa={
-- 1
{

64
data/viewport.lua Normal file
View File

@@ -0,0 +1,64 @@
require "map"
local arcade_config = require("arcade_config")
local viewport={}
function viewport.new()
return { x=0, y=0,
width=arcade_config.resolucion.width,
height=arcade_config.resolucion.height,
position=viewport.position,
print=viewport.print,
room=viewport.coord2room,
roomXY=viewport.room2coord }
end
function viewport:coord2room ()
local tw = arcade_config.tiles_width
local th = arcade_config.tiles_height
local cols = mapa_room_cols
local rows = mapa_room_rows
local rooms_per_floor = mapa_rooms_per_piso
local calc_col = math.floor(self.x / (tw * cols))
local calc_row = math.floor(self.y / (th * rows))
local calc_room = calc_row*rooms_per_floor+calc_col
return calc_room
end
function viewport:room2coord ( room )
local tw = arcade_config.tiles_width
local th = arcade_config.tiles_height
local cols = mapa_room_cols
local rows = mapa_room_rows
local rooms_per_floor = mapa_rooms_per_piso
local x = (room % rooms_per_floor) * cols * tw
local y = math.floor(room/rooms_per_floor) * rows * th
local room_center_x_offset = (cols * tw) >> 1
local room_center_y_offset = (rows * th) >> 1
return x+room_center_x_offset, y+room_center_y_offset
end
function viewport:position(x, y)
local nx = (x ~= nil) and x or self.x
local ny = (y ~= nil) and y or self.y
self.x = nx
self.y = ny
return self.x, self.y
end
function viewport:print()
local room = self:room()
draw.rectf(0,7,45,14,16)
draw.text("X="..self.x.." , Y= "..self.y..", R"..room,1,8,2)
end
return viewport