-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.lua
68 lines (44 loc) 路 1.32 KB
/
Player.lua
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
Player = Class{}
function Player:init(params)
-- x is placed in the middle
self.x = VIRTUAL_WIDTH / 2 - 16
self.y = VIRTUAL_HEIGHT - 30
self.dx = 0
self.width = 16
self.height = 24
self.stateMachine = params.stateMachine
end
function Player:changeState(state, params)
self.stateMachine:change(state, params)
end
function Player:update(dt)
self.stateMachine:update(dt)
if love.keyboard.isDown('left') then
self.dx = -100
elseif love.keyboard.isDown('right') then
self.dx = 100
else
self.dx = 0
end
if love.keyboard.isDown('up') then
self.dy = -100
elseif love.keyboard.isDown('down') then
self.dy = 100
else
self.dy = 0
end
if self.dx < 0 then
self.x = math.max(0, self.x + self.dx * dt)
else
self.x = math.min(VIRTUAL_WIDTH - self.width, self.x + self.dx * dt)
end
if self.dy < 0 then
self.y = math.max(0, self.y + self.dy * dt)
else
self.y = math.min(VIRTUAL_HEIGHT - self.height, self.y + self.dy * dt)
end
end
function Player:render()
--love.graphics.rectangle('fill', self.x, self.y, self.width, self.height)
love.graphics.draw(gTextures['mage'], gFrames['mage'][self.currentAnimation:getCurrentFrame()], self.x, self.y)
end