Intentant fer scroll
This commit is contained in:
137
data/game.lua
137
data/game.lua
@@ -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()
|
||||
|
||||
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)
|
||||
|
||||
x_offset_col1 = 0
|
||||
x_offset_col2 = room_width
|
||||
x_offset_col3 = 2*room_width
|
||||
surf.source(tiles)
|
||||
|
||||
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
|
||||
|
||||
-- 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
|
||||
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
|
||||
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-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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user