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

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

View File

@ -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,

View File

@ -16,13 +16,27 @@
14 - tree stump
15 - cactus stump
16 - mushroom stump
17 - long grass
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
---
@ -32,7 +46,8 @@
9 - desert wind
10 - desert music 2
11 - chopping wood
12 - chopping vegetation
12 - chopping thick vegetation
13 - collecting small vegetation
### patterns
---

View File

@ -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

View File

@ -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

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)