1
Player = Animation:extend {
2
image = 'data/player.png',
6
stand = { frames = { 1 }, fps = 1 },
7
walk = { frames = { 2, 3 }, fps = 5 },
8
jump = { frames = { 4 }, fps = 1 },
9
climbLeft = { frames = { 5, 6 }, fps = 5 },
10
climbRight = { frames = { 7, 8 }, fps = 5 }
15
onNew = function (self)
17
self.maxVelocity.y = 400
19
onStartFrame = function (self)
20
-- this is all in startframe so it happens before
21
-- physics calc at beginning of update
23
-- jumping/falling updates could go in EndFrame...
24
self.falling = self.velocity.y > 0
25
if self.falling then self.jumping = false end
26
--print(self.jumping, self.falling)
28
if (not self.onGround) and (not self.onWall) then
32
self.acceleration.y = 800
35
self.acceleration.y = 0
37
if self.onWall == 'right' then
38
self:play('climbRight')
39
elseif self.onWall == 'left' then
40
self:play('climbLeft')
43
if the.keys:pressed('up') then
44
self.velocity.y = -200
45
elseif the.keys:pressed('down') then
49
self:freeze(self.sequences[self.currentName].frames[1])
53
if the.keys:pressed('left') then
54
self.velocity.x = -200
55
if self.onGround then self:play('walk') end
56
if self.onWall == 'right' then
58
self.leftWallAt = love.timer.getTime()
60
elseif the.keys:pressed('right') then
62
if self.onGround then self:play('walk') end
63
if self.onWall == 'left' then
65
self.leftWallAt = love.timer.getTime()
68
if not self.onWall then
69
if self.onGround then self:play('stand') end
74
if the.keys:justPressed('up') and
76
(DEBUG and the.console.visible) or
77
(love.timer.getTime() - self.leftWallAt < .1) ) then
78
self.velocity.y = -400
82
update = function (self, elapsed)
83
-- NOTE: this is an override, not a callback
85
self:doPhysics('x', elapsed)
86
self:collide(the.view.map)
88
-- handle X collisions
90
for _, col in ipairs(self.collisions) do
91
col.other:displaceDir(self, 'x')
92
if self.velocity.x > 0 then
94
elseif self.velocity.x < 0 then
101
self.onGround = false -- right before Y collision callbacks
102
self:doPhysics('y', elapsed)
103
self:collide(the.view.map)
105
-- handle Y collisions
106
for _, col in ipairs(self.collisions) do
107
if self.velocity.y > 0 then
111
col.other:displaceDir(self, 'y')
117
if not self.text then
118
self.text = Text:new{wordWrap = true, width = 50, tint = {0,0,0}}
119
self.textfill = Fill:new{width = 54, border = {0,0,255}}
120
--the.view:add(self.textfill)
121
--the.view:add(self.text)
123
self.text.text = "Blah blah big text etc etc wrapping"
124
self.text:centerAround(self.x+16, self.y+16, 'horizontal')
125
_, texth = self.text:getSize()
126
self.text.y = self.y - texth - 4
127
self.textfill.x = self.text.x - 2
128
self.textfill.y = self.text.y - 2
129
self.textfill.height = texth + 4
131
Animation.update(self, elapsed)
133
collide = function (self, ...)
135
Animation.collide(self, ...)
136
-- I could return a true/false value here if I wanted to...
138
onCollide = function (self, other, xOverlap, yOverlap)
139
if other == the.view.map then return end
141
table.insert(self.collisions, {other = other,
143
yOverlap = yOverlap })