1
2
Player = Tile:extend{
2
3
image = 'data/player.png',
4
self.collider = PlayerCollider:new{x=self.x, y=self.y}
5
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)
13
PlayerCollider = Fill:extend{
4
maxVelocity = {x=velLimit,y=velLimit},
5
minVelocity = {x=-velLimit, y=-velLimit},
16
6
onStartFrame = function(self)
17
7
if the.keys:pressed('left') then
18
self.velocity.x = -200 * the.activeMaze.moveMod
19
9
elseif the.keys:pressed('right') then
20
self.velocity.x = 200 * the.activeMaze.moveMod
22
12
self.velocity.x = 0
25
15
if the.keys:pressed('up') then
26
self.velocity.y = -200 * the.activeMaze.moveMod
16
self.velocity.y = -200
27
17
elseif the.keys:pressed('down') then
28
self.velocity.y = 200 * the.activeMaze.moveMod
30
20
self.velocity.y = 0
33
update = function(self, elapsed)
34
self.visible = DEBUG and the.console.visible
36
self:doPhysics('x', elapsed)
37
if not (DEBUG and the.console.visible) then
38
self:collide(the.activeMaze)
41
-- handle X collisions
42
for _, col in ipairs(self.collisions) do
43
col.other:displaceDir(self, 'x')
46
self:doPhysics('y', elapsed)
47
if not (DEBUG and the.console.visible) then
48
self:collide(the.activeMaze)
51
-- handle Y collisions
52
for _, col in ipairs(self.collisions) do
53
col.other:displaceDir(self, 'y')
57
p.x = self.x - p.width / 2 * (1 - p.scale)
58
p.y = self.y - p.height / 2 * (1 - p.scale)
60
collide = function (self, ...)
62
Fill.collide(self, ...)
64
onCollide = function (self, other, xOverlap, yOverlap)
65
if other == the.activeMaze then return end
68
--print(inspect(other))
70
table.insert(self.collisions, {other = other,
72
yOverlap = yOverlap })
23
onCollide = function(self, other)
b'\\ No newline at end of file'