Viewport es mou a l'abad
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
require "fps"
|
||||
require "mapa"
|
||||
require "abad"
|
||||
|
||||
local viewport= require("viewport")
|
||||
|
||||
local arcade_config = require("arcade_config")
|
||||
@@ -8,9 +10,20 @@ local tile_h = arcade_config.tiles_height
|
||||
local res_w = arcade_config.resolucion.width
|
||||
local res_h = arcade_config.resolucion.height
|
||||
|
||||
local viewp = viewport.new()
|
||||
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
|
||||
|
||||
@@ -59,19 +72,71 @@ function update_game()
|
||||
---
|
||||
--- 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
|
||||
--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
|
||||
|
||||
if key.press(key.N1) then
|
||||
local hab = math.random(0, 79)
|
||||
local abad_x, abad_y = arc_mapa_get_coords ( hab, 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)
|
||||
end
|
||||
if key.press(key.N0) then
|
||||
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)
|
||||
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
|
||||
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)
|
||||
msg_print(0,21,"VIEW= "..vp_x..", "..vp_y)
|
||||
end
|
||||
|
||||
function msg_print(x, y, msg )
|
||||
draw.rectf(x,y,45,14,16)
|
||||
draw.text(msg,x+1,y+1,2)
|
||||
end
|
||||
Reference in New Issue
Block a user