summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-05-12 18:44:19 +0200
committerAki <nthirtyone@gmail.com>2016-05-12 18:44:19 +0200
commit8947c17408c129be8fec3523e2acb8615e85d39a (patch)
tree3576d5a5fdc8ac498c5370e092b620a62cbcd368
parentc06e67a268708dab348a72b9b3d85a53959e6945 (diff)
downloadroflnauts-8947c17408c129be8fec3523e2acb8615e85d39a.zip
roflnauts-8947c17408c129be8fec3523e2acb8615e85d39a.tar.gz
roflnauts-8947c17408c129be8fec3523e2acb8615e85d39a.tar.bz2
Horizontal movement
-rw-r--r--ground.lua2
-rw-r--r--player.lua59
2 files changed, 31 insertions, 30 deletions
diff --git a/ground.lua b/ground.lua
index 47c4ec7..e0c490a 100644
--- a/ground.lua
+++ b/ground.lua
@@ -19,6 +19,6 @@ function Ground:new (world, x, y, shape, sprite)
o.fixture = love.physics.newFixture(o.body, o.shape)
o.sprite = love.graphics.newImage(sprite)
o.fixture:setCategory(1)
- o.fixture:setFriction(0.7)
+ o.fixture:setFriction(0.75)
return o
end \ No newline at end of file
diff --git a/player.lua b/player.lua
index b0604c3..f01fcba 100644
--- a/player.lua
+++ b/player.lua
@@ -50,6 +50,7 @@ function Player:new(world, x, y, spritesheet)
o.fixture:setMask(2)
o.body:setFixedRotation(true)
o.body:setLinearDamping(0.1)
+ print(o.body.mass)
-- Animation
o.initial = o.delay
o.current = o.animations.idle
@@ -58,6 +59,7 @@ end
-- Update callback of `Player`
function Player:update(dt)
+ -- VERTICAL MOVEMENT
-- Jumping
if self.jumpactive and self.jumptimer > 0 then
local x,y = self.body:getLinearVelocity()
@@ -65,26 +67,44 @@ function Player:update(dt)
self.jumptimer = self.jumptimer - dt
end
+ -- Salto
+ if not self.jumpdouble and self.inAir then
+ self.rotate = (self.rotate + 17 * dt * self.facing) % 360
+ else
+ self.rotate = 0
+ end
+
+ -- HORIZONTAL MOVEMENT
-- Walking
+ local x,y = self.body:getLinearVelocity()
if love.keyboard.isDown(self.key_left) then
self.facing = -1
- local x,y = self.body:getLinearVelocity()
- if math.abs(x) > self.max_velocity then
- self.body:applyForce(-200, 0)
- else
- self.body:setLinearVelocity(-self.max_velocity/2, y)
+ self.body:applyForce(-200, 0)
+ if x < -self.max_velocity then
+ self.body:applyForce(200, 0)
end
end
if love.keyboard.isDown(self.key_right) then
self.facing = 1
- local x,y = self.body:getLinearVelocity()
- if math.abs(x) > self.max_velocity then
- self.body:applyForce(200, 0)
- else
- self.body:setLinearVelocity(self.max_velocity/2, y)
+ self.body:applyForce(200, 0)
+ if x > self.max_velocity then
+ self.body:applyForce(-200, 0)
end
end
+
+ -- Limit `Player` horizontal speed
+ -- Maximum speed may be actually a little bit higher or lower
+ --[[
+ local x,y = self.body:getLinearVelocity()
+ if x > self.max_velocity then
+ self.body:setLinearVelocity(self.max_velocity, y)
+ end
+ if x < -self.max_velocity then
+ self.body:setLinearVelocity(-self.max_velocity, y)
+ end
+ --]]
+ -- ANIMATIONS
-- Animation
self.delay = self.delay - dt
if self.delay < 0 then
@@ -101,25 +121,6 @@ function Player:update(dt)
self:changeAnimation("idle")
end
end
-
- -- Salto mothafocka
- if not self.jumpdouble and self.inAir then
- self.rotate = (self.rotate + 17 * dt * self.facing) % 360
- else
- self.rotate = 0
- end
-
- --[[
- -- Limit `Player` horizontal speed
- -- Maximum speed may be actually a little bit higher or lower
- local x,y = self.body:getLinearVelocity()
- if x > self.max_velocity then
- self.body:setLinearVelocity(self.max_velocity, y)
- end
- if x < -self.max_velocity then
- self.body:setLinearVelocity(-self.max_velocity, y)
- end
- --]]
end
-- Keypressed callback of `Player`