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
jump = love.audio.newSource('data/jump.ogg', 'static'),
16
onNew = function (self)
18
self.maxVelocity.y = 400
20
onStartFrame = function (self)
21
-- this is all in startframe so it happens before
22
-- physics calc at beginning of update
24
-- jumping/falling updates could go in EndFrame...
25
self.falling = self.velocity.y > 0
26
if self.falling then self.jumping = false end
27
--print(self.jumping, self.falling)
29
if (not self.onGround) and (not self.onWall) then
33
self.acceleration.y = 800
36
self.acceleration.y = 0
38
if self.onWall == 'right' then
39
self:play('climbRight')
40
elseif self.onWall == 'left' then
41
self:play('climbLeft')
44
if the.keys:pressed('up') then
45
self.velocity.y = -200
46
elseif the.keys:pressed('down') then
50
self:freeze(self.sequences[self.currentName].frames[1])
54
if the.keys:pressed('left') then
55
self.velocity.x = -200
56
if self.onGround then self:play('walk') end
57
if self.onWall == 'right' then
59
self.leftWallAt = love.timer.getTime()
61
elseif the.keys:pressed('right') then
63
if self.onGround then self:play('walk') end
64
if self.onWall == 'left' then
66
self.leftWallAt = love.timer.getTime()
69
if not self.onWall then
70
if self.onGround then self:play('stand') end
75
if the.keys:justPressed('up') and
77
(DEBUG and the.console.visible) or
78
(love.timer.getTime() - self.leftWallAt < .1) ) then
79
self.velocity.y = -400
81
--love.audio.play(self.jump)
84
update = function (self, elapsed)
85
-- NOTE: this is an override, not a callback
87
self:doPhysics('x', elapsed)
88
self:collide(the.view.map)
90
-- handle X collisions
92
for _, col in ipairs(self.collisions) do
93
col.other:displaceDir(self, 'x')
94
if self.velocity.x > 0 then
96
elseif self.velocity.x < 0 then
103
self.onGround = false -- right before Y collision callbacks
104
self:doPhysics('y', elapsed)
105
self:collide(the.view.map)
107
-- handle Y collisions
108
for _, col in ipairs(self.collisions) do
109
if self.velocity.y > 0 then
113
col.other:displaceDir(self, 'y')
119
if not self.text then
120
self.text = Text:new{wordWrap = true, width = 50, tint = {0,0,0}}
121
self.textfill = Fill:new{width = 54, border = {0,0,255}}
122
--the.view:add(self.textfill)
123
--the.view:add(self.text)
125
self.text.text = "Blah blah big text etc etc wrapping"
126
self.text:centerAround(self.x+16, self.y+16, 'horizontal')
127
_, texth = self.text:getSize()
128
self.text.y = self.y - texth - 4
129
self.textfill.x = self.text.x - 2
130
self.textfill.y = self.text.y - 2
131
self.textfill.height = texth + 4
133
Animation.update(self, elapsed)
135
collide = function (self, ...)
137
Animation.collide(self, ...)
138
-- I could return a true/false value here if I wanted to...
140
onCollide = function (self, other, xOverlap, yOverlap)
141
if other == the.view.map then return end
143
table.insert(self.collisions, {other = other,
145
yOverlap = yOverlap })