Add some rudimentary code for facing and collision detection.
This commit is contained in:
parent
bbd3c089d9
commit
546de63412
59
infimap.p8
59
infimap.p8
|
@ -13,3 +13,62 @@ __gfx__
|
|||
00700700000000003333333355545555333553333338a8333e333e33333388830000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000033333333355555533335533333338333e9e3e9e3333337330000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000333333333355553333555533333333333e333e33333333330000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000007700000000000000700000000700007777000000777700000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000070070000000000007000000000070070000000000000070000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000000700007000000000070000000000007070000000000000070000000000000000
|
||||
00000000000000000000000000000000000000000000000000000000000000007000000700000000700000000000000770000000000000077000000000000007
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000070000007700000000000000770000000000000077000000000000007
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000007000070070000000000007000000000000000007000000000000007
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000700700007000000000070000000000000000007000000000000007
|
||||
00000000000000000000000000000000000000000000000000000000000000000000000000077000000700000000700000000000000000000777700000077770
|
||||
__gff__
|
||||
0000000303000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
|
|
54
movement.lua
54
movement.lua
|
@ -1,14 +1,53 @@
|
|||
function init_movement()
|
||||
camera_pos = {0, 0}
|
||||
|
||||
-- [1] is vertical facing, [2] is horizontal, -1 is up/left, 0 is neutral,
|
||||
-- and 1 is down/right
|
||||
facing = {1, 0}
|
||||
|
||||
-- this is a constant for looking up player sprites by facing
|
||||
player_lookup = {
|
||||
[{0, 0}] = -1, -- this state is an error
|
||||
[{-1, 0}] = 120, -- up
|
||||
[{1, 0}] = 121, -- down
|
||||
[{0, -1}] = 122, -- left
|
||||
[{0, 1}] = 123, -- right
|
||||
[{-1, -1}] = 124, -- up-left
|
||||
[{-1, 1}] = 125, -- up-right
|
||||
[{1, -1}] = 126, -- down-left
|
||||
[{1, 1}] = 127 -- down-right
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
function handle_input()
|
||||
new_pos = camera_pos
|
||||
if (btnp(0)) new_pos[1] -= 1 -- move left
|
||||
if (btnp(1)) new_pos[1] += 1 -- move right
|
||||
if (btnp(2)) new_pos[2] -= 1 -- move up
|
||||
if (btnp(3)) new_pos[2] += 1 -- move down
|
||||
|
||||
if btnp(0) or btnp(1) or btnp(2) or btnp(3) then
|
||||
if btnp(0) then
|
||||
new_pos[1] -= 1 -- move left
|
||||
facing[2] = -1
|
||||
end
|
||||
if btnp(1) then
|
||||
new_pos[1] += 1 -- move right
|
||||
facing[2] = 1
|
||||
end
|
||||
if not (btnp(0) or btnp(1)) then
|
||||
facing[2] = 0
|
||||
end
|
||||
|
||||
if btnp(2) then
|
||||
new_pos[2] -= 1 -- move up
|
||||
facing[1] = -1
|
||||
end
|
||||
if btnp(3) then
|
||||
new_pos[2] += 1 -- move down
|
||||
facing[1] = 1
|
||||
end
|
||||
if not (btnp(2) or btnp(3)) then
|
||||
facing[1] = 0
|
||||
end
|
||||
end
|
||||
|
||||
if legal_move(new_pos) then
|
||||
camera_pos = new_pos
|
||||
|
@ -18,9 +57,12 @@ function handle_input()
|
|||
end
|
||||
|
||||
function draw_player()
|
||||
|
||||
spr(player_lookup[facing], 64, 64)
|
||||
-- todo: animate the character on move
|
||||
end
|
||||
|
||||
-- pos is a camera position, meaning the player position is
|
||||
-- pos + {8, 8}
|
||||
function legal_move(pos)
|
||||
return true
|
||||
return fget(mget(pos[1]+8, pos[2]+8), 0)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user