-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmotion.lua
More file actions
58 lines (49 loc) · 1.45 KB
/
Copy pathmotion.lua
File metadata and controls
58 lines (49 loc) · 1.45 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
pico-8 cartridge // http://www.pico-8.com
version 18
__lua__
-- motion
function getmotion()
local motion = {}
local cmp_type = "motion"
motion.__index = motion
setmetatable(motion, {
__index = component, -- this is what makes the inheritance work
__call = function (klass, ...)
local self = setmetatable({}, klass)
self:_init(...)
return self
end,
})
function motion:_init(velocity_x, velocity_y, acceleration_x, acceleration_y)
component._init(self, cmp_type) -- call the base class constructor
self.velocity_x = velocity_x
self.acceleration_x = acceleration_x
self.velocity_y = velocity_y
self.acceleration_y = acceleration_y
end
-- return vector
function motion:get_velocity()
local vel = {
x = self.velocity_x,
y = self.velocity_y
}
return vel
end
-- return vector
function motion:get_acceleration()
local acc = {
x = self.acceleration_x,
y = self.acceleration_y
}
return acc
end
function motion:set_velocity(velocity_x, velocity_y)
self.velocity_x = velocity_x
self.velocity_y = velocity_y
end
function motion:set_acceleration(acceleration_x, acceleration_y)
self.acceleration_x = acceleration_x
self.acceleration_y = acceleration_y
end
return motion
end