-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.lua
More file actions
107 lines (90 loc) · 1.89 KB
/
player.lua
File metadata and controls
107 lines (90 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--player code
function make_player()
actor = create_actor(1, 38, 56, 7, 7, cant_move_player)
p={}
p.actor = actor
p.keys=0
p.hp = 15
p.mp = 0
p.gp = 0
p.xp = 0
p.level = 1
p.strength = 0
p.agility = 4
p.speed = 0.125
p.level = 1
end
local function interact(x,y)
if (is_tile(key,x,y)) then
get_key(x,y)
elseif (is_tile(door,x,y) and p.keys>0) then
open_door(x,y)
end
end
local function get_key(x,y)
p.keys+=1
swap_tile(x,y)
sfx(1)
end
local function open_door(x,y)
p.keys-=1
swap_tile(x,y)
sfx(2)
end
local function smooth_move_player()
-- smooth movement, 4-way (I don't want to normalize diagonals)
-- if dir button goes down that frame (i.e. wasn't already down) set deltax/y
-- prioritize new dir buttons that go down that frame
-- if two dir buttons go down in the same frame... arbitrary which wins
local dx,dy = 0,0
if btn(left) then
dx = -1*p.speed dy = 0
end
if btn(right) then
dx = p.speed dy = 0
end
if btn(up) then
dx = 0 dy = -1*p.speed
end
if btn(down) then
dx = 0 dy = p.speed
end
p.actor.dx = dx
p.actor.dy = dy
end
local function old_move_player()
local newx=p.actor.x
local newy=p.actor.y
if (btnp(⬅️)) newx-=1
if (btnp(➡️)) newx+=1
if (btnp(⬆️)) newy-=1
if (btnp(⬇️)) newy+=1
interact(newx,newy)
if (can_move(newx,newy)) then
p.actor.x=mid(0,newx,127)
p.actor.y=mid(0,newy,63)
else
sfx(0)
end
end
function handle_player_input()
smooth_move_player()
end
function transport_player(x, y)
p.actor.x = x
p.actor.y = y
end
function get_player_pos()
return p.actor.x, p.actor.y
end
function take_sword(attack)
p.strength += attack
end
function cant_move_player(actor)
sfx(0)
end
function respawn_player()
-- todo change to respect player's max level hp
p.hp = 15
goto_respawn_cave()
end