-
Notifications
You must be signed in to change notification settings - Fork 0
/
circwal.lua
62 lines (53 loc) · 2.17 KB
/
circwal.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
-- circwal.lua
-- © Zach Nielsen 2021
--
require("math")
local CircWal = {}
function CircWal.moveUp(cw, amount, limit)
local wall_limit = limit -- + self.radius
cw:setY(math.max(wall_limit, cw:getY() - amount))
end
function CircWal.moveDown(cw, amount, limit)
local wall_limit = limit -- - self.radius
cw:setY(math.min(wall_limit, cw:getY() + amount))
end
function CircWal.moveLeft(cw, amount, limit)
local wall_limit = limit -- + self.radius
cw:setX(math.max(wall_limit, cw:getX() - amount))
end
function CircWal.moveRight(cw, amount, limit)
local wall_limit = limit -- radius
cw:setX(math.min(wall_limit, cw:getX() + amount))
end
function CircWal.rotateLeft(cw, amount)
cw:setAngle(cw:getAngle() - amount)
end
function CircWal.rotateRight(cw, amount)
cw:setAngle(cw:getAngle() + amount)
end
function CircWal.moveForward(cw, amount)
local xComp = amount * math.cos(cw:getAngle())
local yComp = amount * math.sin(cw:getAngle())
cw:setLinearVelocity(xComp, yComp)
end
function CircWal.moveBackward(cw, amount)
local xComp = amount * math.cos(cw:getAngle() + math.pi)
local yComp = amount * math.sin(cw:getAngle() + math.pi)
cw:setLinearVelocity(xComp, yComp)
end
function CircWal.setBorders(window_width, window_height)
box_body = love.physics.newBody(world, 0,0, "static")
box_left = love.physics.newRectangleShape (-5, window_height/2, 5, window_height)
box_right = love.physics.newRectangleShape(window_width+5, window_height/2, 5, window_height)
box_top = love.physics.newRectangleShape (window_width/2, -5, window_width, 5)
box_bottom = love.physics.newRectangleShape(window_width/2, window_height+5, window_width, 5)
box_fixture_left = love.physics.newFixture(box_body, box_left)
box_fixture_right = love.physics.newFixture(box_body, box_right)
box_fixture_top = love.physics.newFixture(box_body, box_top)
box_fixture_bottom = love.physics.newFixture(box_body, box_bottom)
box_fixture_left:setUserData("window_border")
box_fixture_right:setUserData("window_border")
box_fixture_top:setUserData("window_border")
box_fixture_bottom:setUserData("window_border")
end
return CircWal