-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity.lua
More file actions
65 lines (55 loc) · 1.31 KB
/
Copy pathentity.lua
File metadata and controls
65 lines (55 loc) · 1.31 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
Class = require "lib.hump.class"
vector = require "lib.hump.vector"
Entity = Class {
init = function(self, x, y, state)
self.position = vector(x, y)
self.state = state
end,
isDestroyed = false
}
function Entity:update(dt)
end
function Entity:draw()
--[[
if self.hitbox then
love.graphics.setColor(255, 0, 0)
love.graphics.rectangle("line", self.hitbox.x1, self.hitbox.y1, self.hitbox.x2 - self.hitbox.x1, self.hitbox.y2 - self.hitbox.y1)
end
]]--
end
function Entity:move(v)
self.position = self.position + v
if self.hitbox then
self.hitbox.x1 = self.hitbox.x1 + v.x
self.hitbox.x2 = self.hitbox.x2 + v.x
self.hitbox.y1 = self.hitbox.y1 + v.y
self.hitbox.y2 = self.hitbox.y2 + v.y
end
end
function Entity:isOnScreen()
if self.position.x > 480 then
return false
elseif self.position.x < 0 then
return false
elseif self.position.y > 640 then
return false
elseif self.position.y < 0 then
return false
end
return true
end
function Entity:destroy()
self.isDestroyed = true
end
function Entity:collide(otherEntity)
if self.hitbox and otherEntity.hitbox then
return not (
otherEntity.hitbox.x1 > self.hitbox.x2 or
otherEntity.hitbox.x2 < self.hitbox.x1 or
otherEntity.hitbox.y1 > self.hitbox.y2 or
otherEntity.hitbox.y2 < self.hitbox.y1)
else
return false
end
end
return Entity