-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot.lua
More file actions
85 lines (85 loc) · 2.34 KB
/
robot.lua
File metadata and controls
85 lines (85 loc) · 2.34 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
73
74
75
76
77
78
79
80
81
82
83
84
85
local graphics, physics
do
local _obj_0 = love
graphics, physics = _obj_0.graphics, _obj_0.physics
end
local cos, pi, sin
do
local _obj_0 = math
cos, pi, sin = _obj_0.cos, _obj_0.pi, _obj_0.sin
end
local Robot
do
local _class_0
local _base_0 = {
getPosition = function(self)
return self.body:getPosition()
end,
getX = function(self)
return self.body:getX()
end,
getY = function(self)
return self.body:getY()
end,
left = function(self, force)
return self:thrust(force, self.angle - pi)
end,
right = function(self, force)
return self:thrust(force, self.angle)
end,
up = function(self, force)
return self:thrust(force, self.angle - pi / 2)
end,
down = function(self, force)
return self:thrust(force, self.angle + pi / 2)
end,
thrust = function(self, force, angle)
return self.body:applyForce(cos(angle) * force, sin(angle) * force)
end,
reset = function(self)
self.body:setPosition(self.initialX, self.initialY)
self.body:setLinearVelocity(0, 0)
return self.body:setInertia(0)
end,
update = function(self, dt, moon)
local dx = self:getX() - moon:getX()
local dy = self:getY() - moon:getY()
self.angle = math.atan2(dy, dx) + pi / 2
end,
draw = function(self)
return graphics.draw(self.tex, self.body:getX(), self.body:getY(), self.angle, 1, 1, self.width / 2, self.height / 2)
end
}
_base_0.__index = _base_0
_class_0 = setmetatable({
__init = function(self, assets, world, x, y)
self.tex = assets.tex.robot
self.height, self.width = self.tex:getDimensions()
self.initialX = x
self.initialY = y
self.body = physics.newBody(world, x, y, "dynamic")
self.body:setLinearDamping(1.0)
self.shape = physics.newCircleShape(self.width / 2 + 2)
self.fixture = physics.newFixture(self.body, self.shape)
self.fixture:setFriction(1.0)
self.fixture:setGroupIndex(self.__class.PH_GROUP)
self.angle = 0.0
end,
__base = _base_0,
__name = "Robot"
}, {
__index = _base_0,
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
local self = _class_0
self.PH_GROUP = 2
Robot = _class_0
end
return {
Robot = Robot
}