-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnira.lua
More file actions
73 lines (60 loc) · 1.29 KB
/
nira.lua
File metadata and controls
73 lines (60 loc) · 1.29 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
Object = require "classic"
local Player = Object:extend()
function Player:new()
self.x = 400
self.y = 500
self.velocity = 1000
self.direction = {}
self.direction.x = 0
self.direction.y = 0
self.tpAmmount = 100
self.didTped = false
end
function Player:input()
if love.keyboard.isDown("right") then
self.direction.x = 1
elseif love.keyboard.isDown("left") then
self.direction.x = -1
else
self.direction.x = 0
end
if love.keyboard.isDown("up") then
self.direction.y = -1
elseif love.keyboard.isDown("down") then
self.direction.y = 1
else
self.direction.y = 0
end
end
function Player:tp(pressed)
if pressed and not didTped then
self.x = self.x + self.tpAmmount * self.direction.x
self.y = self.y + self.tpAmmount * self.direction.y
self.didTped = true
elseif not pressed then
self.didTped = false
end
end
function Player:move(dt)
self.x = self.x + 100 * dt * self.direction.x
self.y = self.y + 100 * dt * self.direction.y
end
function Player:keyreleased(key)
if key == "space" then
self.tp(self, false)
end
end
function Player:keypressed(key)
if key == "space" then
self.tp(self, true)
end
end
function Player:update(dt)
self:input()
self:move(dt)
self:tp()
end
function Player:draw()
love.graphics.rectangle("line", self.x, self.y, 10, 10)
end
return Player