Fix broken redraw code, implement player sprites (some) and get ready for interactable objects.

This commit is contained in:
2019-12-09 18:50:20 -05:00
parent 3a9fac53f0
commit cdced463ed
5 changed files with 101 additions and 52 deletions

View File

@ -90,15 +90,42 @@ function draw_player()
-- todo: animate the character on move
-- draw the player's HUD
if fget(mget(player_pos_x, player_pos_y), 1) then
-- flag 1 represents an interactable (read: destructible) sprite.
-- need a map of destructible map objects, appropriate sfx, replacement
-- sprites.
local interact_x, interact_y = can_interact()
if interact_x and interact_y then
spr(119, 0, 120)
end
-- todo: introduce the concept of an inventory here
end
-- uses global variables instead of arguments
-- returns x,y for the map-local coordinates of the interactable object
-- nil,nil if nothing to interact with
function can_interact()
-- flag 1 represents an interactable (read: destructible) sprite.
-- need a map of destructible map objects, appropriate sfx, replacement
-- sprites.
local player_rel_x, player_rel_y = player_pos_x+8, player_pos_y+8
-- check the tile the player is standing on
if fget(mget(player_rel_x, player_rel_y), 1) then
return player_rel_x, player_rel_y
end
-- check the tile the player is facing
faced_tile_x, faced_tile_y = get_position_facing()
if fget(mget(faced_tile_x, faced_tile_y), 1) then
return faced_tile_x, faced_tile_y
end
return nil, nil
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
end
-- pos is camera position, meaning the map-relative player
-- position is pos + {8, 8}.
function legal_move(pos_x, pos_y)