-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplayer.lua
executable file
·54 lines (46 loc) · 1.52 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
--player
local _lg = love.graphics
local player = {
speed = 1,
x = 3.1,
y = 3.1,
height = 0.1,
width = 0.1,
radius = 5
}
player.update = function(self, dt, level)
self:movement(dt, level)
end
player.draw = function(self)
_lg.setColor(255,0,0)
_lg.circle('fill', player.x*tileSize,player.y*tileSize, player.radius, 100)
end
player.movement = function(self, dt, level)
local moved = false
--Character Movement (needs collision detection with walls, edge of screen)
if love.keyboard.isDown("left") or love.keyboard.isDown("a") then
if CheckTileCollisions(level, self.x- self.speed*dt - self.width/2, self.y -self.height/2 , self.width, self.height, 1) then
self.x = self.x - self.speed*dt
moved = true
end
end
if love.keyboard.isDown("right") or love.keyboard.isDown("d") then
if CheckTileCollisions(level, self.x+ self.speed*dt- self.width/2, self.y -self.height/2, self.width, self.height, 1) then
self.x = self.x + self.speed*dt
moved = true
end
end
if love.keyboard.isDown("up") or love.keyboard.isDown("w")then
if CheckTileCollisions(level, self.x- self.width/2, self.y - self.speed*dt -self.height/2, self.width, self.height, 1) then
self.y = self.y - self.speed*dt
moved = true
end
end
if love.keyboard.isDown("down") or love.keyboard.isDown("s") then
if CheckTileCollisions(level, self.x- self.width/2, self.y + self.speed*dt -self.height/2, self.width, self.height, 1) then
self.y = self.y + self.speed*dt
moved = true
end
end
end
return player