-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity.lua
77 lines (59 loc) · 1.41 KB
/
entity.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
69
70
71
72
73
74
75
76
77
require 'middleclass'
require 'point'
Entity = class("Entity")
function Entity:initialize(point)
self._point = point
self._alive = true
end
function Entity:update()
error('Entity.update not implemented.')
end
function Entity:draw()
error('Entity.draw not implemented.')
end
function Entity:getX()
return self._point:getX()
end
function Entity:getY()
return self._point:getY()
end
function Entity:getLocation()
return self._point
end
function Entity:setLocation(x, y)
self._point = tonumber(x) ~= nil and Point(x, y) or x -- crude overloading
end
function Entity:moveX(distance)
self._point = Point(self:getX() + distance, self:getY())
end
function Entity:moveY(distance)
self._point = Point(self:getX(), self:getY() + distance)
end
function Entity:getWidth()
error('Entity.getWidth not implemented.')
end
function Entity:getHeight()
error('Entity.getHeight not implemented.')
end
function Entity:setAlive(alive)
self._alive = alive
end
function Entity:isAlive()
return self._alive
end
function Entity:updateEntities(list)
local iterator = list:iterator()
while(iterator:hasNext()) do
local item = iterator:next()
if (item:isAlive()) then
item:update()
else
iterator:remove()
end
end
end
function Entity:drawEntities(list)
for index, item in ipairs(list:getTable()) do
item:draw()
end
end