bzr branch
http://9ix.org/bzr/ld27
3
by Josh C
map loading, super basic movement |
1 |
Player = Tile:extend{ |
2 |
image = 'data/player.png', |
|
19
by Josh C
separate collision box for player so it can scale |
3 |
onNew = function(self) |
25
by Josh C
overhaul collision and physics to fix an annoying collision resolution |
4 |
self.collider = PlayerCollider:new{x=self.x, y=self.y} |
19
by Josh C
separate collision box for player so it can scale |
5 |
the.view:add(self.collider) |
6 |
end, |
|
25
by Josh C
overhaul collision and physics to fix an annoying collision resolution |
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 |
-- end, |
|
11 |
} |
|
12 |
||
13 |
PlayerCollider = Fill:extend{ |
|
14 |
fill = {0,0,255}, |
|
15 |
collisions = {}, |
|
3
by Josh C
map loading, super basic movement |
16 |
onStartFrame = function(self) |
17 |
if the.keys:pressed('left') then |
|
9
by Josh C
3rd maze... reverse |
18 |
self.velocity.x = -200 * the.activeMaze.moveMod |
3
by Josh C
map loading, super basic movement |
19 |
elseif the.keys:pressed('right') then |
9
by Josh C
3rd maze... reverse |
20 |
self.velocity.x = 200 * the.activeMaze.moveMod |
3
by Josh C
map loading, super basic movement |
21 |
else |
22 |
self.velocity.x = 0 |
|
23 |
end |
|
24 |
||
25 |
if the.keys:pressed('up') then |
|
9
by Josh C
3rd maze... reverse |
26 |
self.velocity.y = -200 * the.activeMaze.moveMod |
3
by Josh C
map loading, super basic movement |
27 |
elseif the.keys:pressed('down') then |
9
by Josh C
3rd maze... reverse |
28 |
self.velocity.y = 200 * the.activeMaze.moveMod |
3
by Josh C
map loading, super basic movement |
29 |
else |
30 |
self.velocity.y = 0 |
|
31 |
end |
|
32 |
end, |
|
25
by Josh C
overhaul collision and physics to fix an annoying collision resolution |
33 |
update = function(self, elapsed) |
34 |
self.visible = DEBUG and the.console.visible |
|
35 |
||
36 |
self:doPhysics('x', elapsed) |
|
37 |
if not (DEBUG and the.console.visible) then |
|
38 |
self:collide(the.activeMaze) |
|
39 |
end |
|
40 |
||
41 |
-- handle X collisions |
|
42 |
for _, col in ipairs(self.collisions) do |
|
43 |
col.other:displaceDir(self, 'x') |
|
44 |
end |
|
45 |
||
46 |
self:doPhysics('y', elapsed) |
|
47 |
if not (DEBUG and the.console.visible) then |
|
48 |
self:collide(the.activeMaze) |
|
49 |
end |
|
50 |
||
51 |
-- handle Y collisions |
|
52 |
for _, col in ipairs(self.collisions) do |
|
53 |
col.other:displaceDir(self, 'y') |
|
54 |
end |
|
55 |
||
56 |
local p = the.player |
|
57 |
p.x = self.x - p.width / 2 * (1 - p.scale) |
|
58 |
p.y = self.y - p.height / 2 * (1 - p.scale) |
|
59 |
end, |
|
60 |
collide = function (self, ...) |
|
61 |
self.collisions = {} |
|
62 |
Fill.collide(self, ...) |
|
63 |
end, |
|
64 |
onCollide = function (self, other, xOverlap, yOverlap) |
|
65 |
if other == the.activeMaze then return end |
|
66 |
||
67 |
--print('collision') |
|
68 |
--print(inspect(other)) |
|
69 |
||
70 |
table.insert(self.collisions, {other = other, |
|
71 |
xOverlap = xOverlap, |
|
72 |
yOverlap = yOverlap }) |
|
73 |
end |
|
74 |
||
3
by Josh C
map loading, super basic movement |
75 |
} |