1
2
Player = Tile:extend{
2
3
image = 'data/player.png',
4
maxVelocity = {x=velLimit,y=velLimit},
5
minVelocity = {x=-velLimit, y=-velLimit},
3
6
onNew = function(self)
4
self.collider = PlayerCollider:new{x=self.x, y=self.y}
7
self.collider = PlayerCollider:new()
5
8
the.view:add(self.collider)
7
-- onUpdate = function(self, dt)
8
-- self.collider.x = self.x + self.width / 2 * (1 - self.scale)
9
-- self.collider.y = self.y + self.height / 2 * (1 - self.scale)
10
onStartFrame = function(self)
11
if the.keys:pressed('left') then
12
self.velocity.x = -200 * the.activeMaze.moveMod
13
elseif the.keys:pressed('right') then
14
self.velocity.x = 200 * the.activeMaze.moveMod
19
if the.keys:pressed('up') then
20
self.velocity.y = -200 * the.activeMaze.moveMod
21
elseif the.keys:pressed('down') then
22
self.velocity.y = 200 * the.activeMaze.moveMod
27
onUpdate = function(self, dt)
28
self.collider.x = self.x + self.width / 2 * (1 - self.scale)
29
self.collider.y = self.y + self.height / 2 * (1 - self.scale)
13
33
PlayerCollider = Fill:extend{
16
onStartFrame = function(self)
17
local mouseup, mousedn, mousert, mouselt
18
if the.mouse:pressed() then
19
local x, y = love.mouse.getPosition()
20
local w, h = love.window.getMode()
22
local theta = math.atan2(y - h/2, x - w/2)
23
--local theta = math.atan2(y - self.y * the.app.scale,
24
-- x - self.x * the.app.scale)
26
-- 1/8 = .125, 7/8 = .875
27
if theta > math.pi * .125 and theta < math.pi * .875 then
29
elseif theta < -math.pi * .125 and theta > -math.pi * .875 then
33
-- 3/8 = .375, 5/8 = .625
34
if math.abs(theta) < math.pi * .375 then
36
elseif math.abs(theta) > math.pi * .625 then
40
--print('mouse pressed: ' .. theta)
43
if the.keys:pressed('left') or mouselt then
44
self.velocity.x = -200 * the.activeMaze.moveMod
45
elseif the.keys:pressed('right') or mousert then
46
self.velocity.x = 200 * the.activeMaze.moveMod
51
if the.keys:pressed('up') or mouseup then
52
self.velocity.y = -200 * the.activeMaze.moveMod
53
elseif the.keys:pressed('down') or mousedn then
54
self.velocity.y = 200 * the.activeMaze.moveMod
59
update = function(self, elapsed)
60
self.visible = DEBUG and the.console.visible
62
self:doPhysics('x', elapsed)
63
if not (DEBUG and the.console.visible) then
64
self:collide(the.activeMaze)
67
-- handle X collisions
68
for _, col in ipairs(self.collisions) do
69
col.other:displaceDir(self, 'x')
72
self:doPhysics('y', elapsed)
73
if not (DEBUG and the.console.visible) then
74
self:collide(the.activeMaze)
77
-- handle Y collisions
78
for _, col in ipairs(self.collisions) do
79
col.other:displaceDir(self, 'y')
83
p.x = self.x - p.width / 2 * (1 - p.scale)
84
p.y = self.y - p.height / 2 * (1 - p.scale)
86
collide = function (self, ...)
88
Fill.collide(self, ...)
90
onCollide = function (self, other, xOverlap, yOverlap)
91
if other == the.activeMaze then return end
94
--print(inspect(other))
96
table.insert(self.collisions, {other = other,
98
yOverlap = yOverlap })
35
onUpdate = function(self, dt)
36
self.visible = DEBUG and the.console.visible
38
onCollide = function(self, other)
42
p.x = self.x - p.width / 2 * (1 - p.scale)
43
p.y = self.y - p.height / 2 * (1 - p.scale)
b'\\ No newline at end of file'