Add interactability with some map objects, and store changed map tiles in a buffer for persistence.
This commit is contained in:
20
player.lua
20
player.lua
@ -49,6 +49,10 @@ function handle_input()
|
||||
local new_pos_x, new_pos_y = camera_pos_x, camera_pos_y
|
||||
local new_ppos_x, new_ppos_y = player_pos_x, player_pos_y
|
||||
|
||||
if btnp"4" then
|
||||
interact()
|
||||
end
|
||||
|
||||
if btnp"0" or btnp"1" or btnp"2" or btnp"3" then
|
||||
if btnp"0" then
|
||||
new_pos_x -= 1 -- move left
|
||||
@ -121,6 +125,22 @@ function can_interact()
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
function interact()
|
||||
-- get the position to interact with
|
||||
local x, y = can_interact()
|
||||
if (x == nil or y == nil) return
|
||||
|
||||
local sprite = mget(x, y)
|
||||
local data = object_interaction_map[sprite]
|
||||
-- todo: figure out playing sound effects, animation?
|
||||
|
||||
-- modify the rendered tile
|
||||
mset(x, y, data.replacement)
|
||||
|
||||
-- and write the change to the buffer
|
||||
write_map_change(data.replacement, x, y)
|
||||
end
|
||||
|
||||
-- returns x,y representing the map-local position the player is facing.
|
||||
function get_position_facing()
|
||||
return camera_pos_x+8+facing_h, camera_pos_y+8+facing_v
|
||||
|
Reference in New Issue
Block a user