From cdced463ed5046db9b2f5a9ff921f0caaac72eaf Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Mon, 9 Dec 2019 18:50:20 -0500 Subject: [PATCH] Fix broken redraw code, implement player sprites (some) and get ready for interactable objects. --- constants.lua | 7 ++++ index_map.md | 93 ++++++++++++++++++++++++++++++--------------------- infimap.p8 | 16 ++++----- main.lua | 2 +- player.lua | 35 ++++++++++++++++--- 5 files changed, 101 insertions(+), 52 deletions(-) diff --git a/constants.lua b/constants.lua index 5e399c3..3a3335d 100644 --- a/constants.lua +++ b/constants.lua @@ -13,6 +13,13 @@ function init_constants() -- the indices here are sprite numbers. object_interaction_map = { + -- bush + [3] = { + replacement = 17, + sfx = 13, + drop = 69 + }, + -- tree [4] = { replacement = 14, diff --git a/index_map.md b/index_map.md index 22a8fda..82c3199 100644 --- a/index_map.md +++ b/index_map.md @@ -1,39 +1,54 @@ -### sprites ---- -### map tiles -2 - grass -3 - bush -4 - tree -5 - red flowers -6 - pink flowers -7 - mushrooms -8 - big mushroom -9 - sand -10 - cactus with flower -11 - pebbles -12 - rock -13 - cactus -14 - tree stump -15 - cactus stump -16 - mushroom stump -17 - long grass - -### inventory icons -65 - wood -66 - mushroom -67 - cactus meat -68 - cactus flower - -### sfx ---- -0 - noise effect for wind track (sfx 9) -1 - little bell -8 - desert music 1 -9 - desert wind -10 - desert music 2 -11 - chopping wood -12 - chopping vegetation - -### patterns ---- -0-1 - desert bgm (loops on 1) +### sprites +--- +### map tiles +2 - grass +3 - bush +4 - tree +5 - red flowers +6 - pink flowers +7 - mushrooms +8 - big mushroom +9 - sand +10 - cactus with flower +11 - pebbles +12 - rock +13 - cactus +14 - tree stump +15 - cactus stump +16 - mushroom stump +17 - empty bush +18 - long grass + + +### inventory icons +65 - wood +66 - mushroom +67 - cactus meat +68 - cactus flower +69 - berries + +### HUD and player +119 - interaction exclamation +120 - player back +121 - player front +122 - player left +123 - player right +124 - player up-left +125 - player up-right +126 - player down-left +127 - player down-right + +### sfx +--- +0 - noise effect for wind track (sfx 9) +1 - little bell +8 - desert music 1 +9 - desert wind +10 - desert music 2 +11 - chopping wood +12 - chopping thick vegetation +13 - collecting small vegetation + +### patterns +--- +0-1 - desert bgm (loops on 1) diff --git a/infimap.p8 b/infimap.p8 index 7a2fcc0..808b76a 100644 --- a/infimap.p8 +++ b/infimap.p8 @@ -63,14 +63,14 @@ __gfx__ 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -00000000000000000000000000000000000000000000000000000000000000000007700000000000000700000000700007777000000777700000000000000000 -00000000000000000000000000000000000000000000000000000000000000000070070000000000007000000000070070000000000000070000000000000000 -00000000000000000000000000000000000000000000000000000000000000000700007000000000070000000000007070000000000000070000000000000000 -00000000000000000000000000000000000000000000000000000000000000007000000700000000700000000000000770000000000000077000000000000007 -00000000000000000000000000000000000000000000000000000000000000000000000070000007700000000000000770000000000000077000000000000007 -00000000000000000000000000000000000000000000000000000000000000000000000007000070070000000000007000000000000000007000000000000007 -00000000000000000000000000000000000000000000000000000000000000000000000000700700007000000000070000000000000000007000000000000007 -00000000000000000000000000000000000000000000000000000000000000000000000000077000000700000000700000000000000000000777700000077770 +00000000000000000000000000000000000000000000000000000000000880000002200000022000000220000002200007777000000777700000000000000000 +00000000000000000000000000000000000000000000000000000000000880000022220000244200000420000002400070000000000000070000000000000000 +00000000000000000000000000000000000000000000000000000000000880000022220000244200000422000022400070000000000000070000000000000000 +00000000000000000000000000000000000000000000000000000000000880000288882002888820000880000008800070000000000000077000000000000007 +00000000000000000000000000000000000000000000000000000000000880000048840000488400000480000008400070000000000000077000000000000007 +00000000000000000000000000000000000000000000000000000000000000000048840000488400000480000008400000000000000000007000000000000007 +00000000000000000000000000000000000000000000000000000000000880000008800000088000000880000008800000000000000000007000000000000007 +00000000000000000000000000000000000000000000000000000000000880000001100000011000001100000000110000000000000000000777700000077770 __gff__ 0000000303000000020003000103000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 diff --git a/main.lua b/main.lua index bf80e43..40f2f63 100644 --- a/main.lua +++ b/main.lua @@ -32,7 +32,7 @@ function handle_map_update() -- we need to regenerate the map, so we generate a map chunk that -- places the player in the middle of it. generate_map(player_pos_x-32, player_pos_y-32) - camera_pos_x, camera_pos_y = 24 + camera_pos_x, camera_pos_y = 24, 24 end end diff --git a/player.lua b/player.lua index e3fba7e..68e96df 100644 --- a/player.lua +++ b/player.lua @@ -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)