-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.lua
59 lines (48 loc) · 1.55 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
require "entity"
Player = Entity:new()
function Player:setWeapon(weapon)
self.weapon = weapon
end
-- update the players position
function Player:update(deltaTime)
-- TODO diagonal movement is faster .. that shouldn't be
local x = 0
local y = 0
if love.keyboard.isDown("down") or love.keyboard.isDown("s") then
y = self.speed * deltaTime * 32 * world:getSpeed()
elseif love.keyboard.isDown("up") or love.keyboard.isDown("w") then
y = -1 * self.speed * deltaTime * 32 * world:getSpeed()
end
if love.keyboard.isDown("left") or love.keyboard.isDown("a") then
x = -1 * self.speed * deltaTime * 32 * world:getSpeed()
elseif love.keyboard.isDown("right") or love.keyboard.isDown("d") then
x = self.speed * deltaTime * 32 * world:getSpeed()
end
if not world:outOfBoundaries(self.x + x, self.y + y) then
self.x = self.x + x
self.y = self.y + y
elseif not world:outOfBoundaries(self.x + x, self.y) then
self.x = self.x + x
elseif not world:outOfBoundaries(self.x, self.y + y) then
self.y = self.y + y
end
if self.weapon then
self.weapon:update(deltaTime)
end
end
-- The player starts shooting
function Player:startShooting()
self.shooting = true
end
-- The player stopped shooting
function Player:stopShooting()
self.shooting = false
end
-- Is the player currently shooting?
function Player:isShooting()
return self.shooting
end
-- Get the type of this object
function Player:getType()
return "player"
end