Intentant fer scroll
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
title=Cacaus Arcade
|
title=Cacaus Arcade
|
||||||
config=cacaus_arcade
|
config=cacaus_arcade
|
||||||
width=256
|
width=576
|
||||||
height=192
|
height=288
|
||||||
zoom=3
|
zoom=3
|
||||||
|
|||||||
131
data/game.lua
131
data/game.lua
@@ -1,92 +1,56 @@
|
|||||||
require "fps"
|
require "fps"
|
||||||
require "mapa"
|
require "mapa"
|
||||||
|
local viewport= require("viewport")
|
||||||
|
|
||||||
local arcade_config = require("arcade_config")
|
local arcade_config = require("arcade_config")
|
||||||
o2aX = arcade_config.org2arc_escala
|
o2aX = arcade_config.org2arc_escala
|
||||||
local txr = arcade_config.tiles_per_row-1
|
local txr = arcade_config.tiles_per_row-1
|
||||||
local txr2 = arcade_config.tiles_per_row_base2
|
local txr2 = arcade_config.tiles_per_row_base2
|
||||||
local toff= arcade_config.tiles_offset
|
local toff= arcade_config.tiles_offset
|
||||||
local tw = arcade_config.tiles_width
|
local tw = arcade_config.tiles_width
|
||||||
local th = arcade_config.tiles_height
|
local th = arcade_config.tiles_height
|
||||||
|
|
||||||
|
local viewp = viewport.new()
|
||||||
|
|
||||||
function game_init(menu)
|
function game_init(menu)
|
||||||
game_update=update_game
|
game_update=update_game
|
||||||
end
|
end
|
||||||
|
|
||||||
function render_view ( hab )
|
function render_view ( hab, x ,y )
|
||||||
-- el mapa te 10 habitacions d'ample
|
local curr_ssurf = surf.source()
|
||||||
room_width = tw*12
|
local curr_tsurf = surf.target()
|
||||||
room_height = th*6
|
|
||||||
room_x_offset = 0
|
|
||||||
draw_1st_col = 0
|
|
||||||
draw_2nd_col = 0
|
|
||||||
|
|
||||||
x_offset_col1 = 0
|
local room_x = hab % mapa_rooms_per_piso
|
||||||
x_offset_col2 = room_width
|
local room_y = math.floor(hab / mapa_rooms_per_piso)
|
||||||
x_offset_col3 = 2*room_width
|
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
|
surf.target(map_buffer)
|
||||||
y_offset_row2 = (arcade_config.resolucion.height-room_height)/2
|
surf.cls(16)
|
||||||
y_offset_row3 = (arcade_config.resolucion.height+room_height)/2
|
|
||||||
|
|
||||||
-- 1ª columna d'habitacions
|
surf.source(tiles)
|
||||||
curr_hab = hab-10-1
|
|
||||||
if curr_hab>=0 then
|
for ry=0,2 do
|
||||||
draw_hab(curr_hab,x_offset_col1,y_offset_row1)
|
for rx=0,2 do
|
||||||
draw_1st_col = 1
|
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
|
end
|
||||||
|
|
||||||
curr_hab = hab-1
|
surf.source(map_buffer)
|
||||||
if curr_hab>=10 then
|
surf.target(0)
|
||||||
draw_hab(curr_hab,x_offset_col1,y_offset_row2)
|
print(hab)
|
||||||
draw_1st_col = 1
|
viewp.roomXY(hab)
|
||||||
end
|
draw.surf(viewp.x,viewp.y,viewp.width,viewp.height,0,0,viewp.width,viewp.height)
|
||||||
|
|
||||||
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(curr_ssurf)
|
||||||
|
surf.source(curr_tsurf)
|
||||||
end
|
end
|
||||||
|
|
||||||
function update_game()
|
function update_game()
|
||||||
@@ -98,10 +62,8 @@ function update_game()
|
|||||||
-- draw.text("UPDATE_GAME",0,0,15)
|
-- draw.text("UPDATE_GAME",0,0,15)
|
||||||
-- surf.source(logo)
|
-- surf.source(logo)
|
||||||
-- draw.surf(0,0,36,5,56,70,arcade_config.logo_sf.width,arcade_config.logo_sf.height)
|
-- 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
|
--- if abad.hurting == 0 then
|
||||||
--- draw_hab(abad.hab,0,0)
|
--- draw_hab(abad.hab,0,0)
|
||||||
@@ -127,10 +89,25 @@ function update_game()
|
|||||||
--- end
|
--- end
|
||||||
---
|
---
|
||||||
--- mapa_update(abad.hab,cameras[current_camera].hab)
|
--- 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
|
end
|
||||||
|
|
||||||
function draw_hab(hab,x,y,editing)
|
function draw_hab(hab,x,y,editing)
|
||||||
|
-- print(hab.." "..x.." "..y)
|
||||||
view.origin(x,y)
|
view.origin(x,y)
|
||||||
mapa_draw(hab)
|
mapa_draw(hab)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
require "fade"
|
require "fade"
|
||||||
require "audio"
|
require "audio"
|
||||||
require "intro"
|
require "intro"
|
||||||
|
require "map"
|
||||||
|
|
||||||
local arcade_config = require("arcade_config")
|
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)
|
logo=surf.new(arcade_config.logo_sf.width,arcade_config.logo_sf.height)
|
||||||
back=surf.new(arcade_config.surface.width,arcade_config.surface.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()
|
fade.init()
|
||||||
|
|
||||||
textsf=surf.new(arcade_config.org_resolucion.width,arcade_config.org_resolucion.height)
|
textsf=surf.new(arcade_config.org_resolucion.width,arcade_config.org_resolucion.height)
|
||||||
|
|||||||
12
data/map.lua
12
data/map.lua
@@ -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={
|
mapa={
|
||||||
-- 1
|
-- 1
|
||||||
{
|
{
|
||||||
|
|||||||
64
data/viewport.lua
Normal file
64
data/viewport.lua
Normal 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
|
||||||
Reference in New Issue
Block a user