-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity.lua
62 lines (50 loc) · 1.25 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
Entity = class("Entity")
---
-- Entity:initialize
-- The base class for every entity.
--
-- @param x X position
-- @param y Y position
-- @param bodyType "statis", "dynamic" or "kinematic"
-- @param shape Shape, using love.physics.new*Shape()
--
function Entity:initialize(x, y, bodyType, shape)
self.x = x
self.y = y
self.objectid = game.addObject(self)
self.body = love.physics.newBody(game.world, self.x, self.y, bodyType)
self.shape = shape
self.fixture = love.physics.newFixture(self.body, self.shape)
self.fixture:setRestitution(0.1)
self.fixture:setUserData(self.objectid)
end
---
-- Entity:update
-- Does nothing by default, override this in a subclass.
--
function Entity:update()
end
---
-- Entity:draw
-- Does nothing by default, override this in a subclass.
--
function Entity:draw()
end
---
-- Entity:impact
-- Gets called whenever there's a collision with another entity.
--
-- @param ent The entity collided with
-- @param contact The contact object of the collision
--
function Entity:impact(ent, contact)
end
---
-- Entity:destroy
-- Destroys the entity.
--
function Entity:destroy()
self.body:destroy()
game.objects[self.objectid] = nil
self = nil
end