aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Cholewiński <harry666t@gmail.com>2016-02-21 14:58:37 +0100
committerKamil Cholewiński <harry666t@gmail.com>2016-02-21 14:58:37 +0100
commit1e5e9d1e03c247e08ed488be9c077d2ecd91c590 (patch)
treed10920e083e21815dd2697ffa862b425f274cd6b
parentd3edaacb7dafe57782c5619f5c34e98857ca40e5 (diff)
downloadkittenlanding-1e5e9d1e03c247e08ed488be9c077d2ecd91c590.zip
kittenlanding-1e5e9d1e03c247e08ed488be9c077d2ecd91c590.tar.gz
kittenlanding-1e5e9d1e03c247e08ed488be9c077d2ecd91c590.tar.bz2
Kitten L/R controls
-rw-r--r--data/shapes.json6
-rw-r--r--game/Game.lua4
-rw-r--r--game/Kitten.lua52
3 files changed, 46 insertions, 16 deletions
diff --git a/data/shapes.json b/data/shapes.json
index 52408ee..4ae62d4 100644
--- a/data/shapes.json
+++ b/data/shapes.json
@@ -74,11 +74,7 @@
{"type": "ref", "ref": "parachute-det1", "translate": [-30, 0]},
{"type": "ref", "ref": "parachute-det1", "translate": [ 30, 0]},
{"type": "ref", "ref": "parachute-det2l", "translate": [-60, 0]},
- {"type": "ref", "ref": "parachute-det2r", "translate": [ 60, 0]},
- {"type": "edge", "points": [-30, -15, 0, -80]},
- {"type": "edge", "points": [ 30, -15, 0, -80]},
- {"type": "edge", "points": [-80, -15, 0, -80]},
- {"type": "edge", "points": [ 80, -15, 0, -80]}
+ {"type": "ref", "ref": "parachute-det2r", "translate": [ 60, 0]}
]
}
}
diff --git a/game/Game.lua b/game/Game.lua
index 8fd879c..12de058 100644
--- a/game/Game.lua
+++ b/game/Game.lua
@@ -59,7 +59,7 @@ function Game:init(args)
end
self.camera:follow()
- self.camera:fit(800, 600)
+ self:resize()
for i = 1, 1 do
local ctl = control.KeyboardController.new {
@@ -103,7 +103,7 @@ function Game:draw()
end
function Game:resize(w, h)
- self.camera:fit(800, 600)
+ self.camera:fit(1200, 900)
end
function Game:attach_player(player)
diff --git a/game/Kitten.lua b/game/Kitten.lua
index 8e1f5cc..bed22af 100644
--- a/game/Kitten.lua
+++ b/game/Kitten.lua
@@ -30,28 +30,31 @@ function Kitten:init(args)
self.body:setLinearDamping(1)
self.body:setAngularDamping(1)
- local j1, j2 = nil, nil
+ local pj = {nil, nil}
+ self.parachute_joints = pj
self.spawnParachute = function()
if self.parachute then return end
local x, y = self.body:getWorldCenter()
self.parachute = args.game:spawn(Parachute, {x=x, y=y-80, angle=0})
local px, py = self.parachute.body:getWorldCenter()
- j1 = love.physics.newRopeJoint(
+ pj[1] = love.physics.newRopeJoint(
self.body, self.parachute.body,
- x, y, px-10, py, 100, false
+ x-20, y, px-75, py+25, 100, false
)
- j2 = love.physics.newRopeJoint(
+ pj[2] = love.physics.newRopeJoint(
self.body, self.parachute.body,
- x, y, px+10, py, 100, false
+ x+20, y, px+75, py+25, 100, false
)
end
self.killParachute = function()
if not self.parachute then return end
args.game:kill(self.parachute)
self.parachute = nil
- j1:destroy()
- j2:destroy()
+ pj[1]:destroy()
+ pj[2]:destroy()
+ pj[1] = nil
+ pj[2] = nil
end
end
@@ -61,15 +64,46 @@ function Kitten:update(dt)
elseif not self.controls.brake and self.parachute then
self.killParachute()
end
+
+ if self.parachute then
+ self.parachute.body:applyForce(0, -250)
+ self.body:applyForce(0, 100)
+ self.rightingReflex(self.parachute, 10000)
+ end
+
+ self.body:applyForce(self.controls.dx * 1000, 0)
+ self.body:applyTorque(self.controls.dx * 5000)
+
self:rightingReflex()
+
+ local x = self.body:getX()
+ if x > 500 then self.body:applyForce(-1000 - (x*10), 0) end
+ if x < -500 then self.body:applyForce( 1000 - (x*10), 0) end
+
+ local y = self.body:getY()
+ if y < 50 then
+ self.body:applyForce(0, 100-y)
+ end
end
-function Kitten:rightingReflex()
+function Kitten:rightingReflex(factor)
-- https://en.wikipedia.org/wiki/Cat_righting_reflex
+ factor = factor or 1000
local angle = math.rad(math.deg(self.body:getAngle()) % 360)
if angle > math.tau * 0.95 or angle < math.tau * 0.05 then return end
local torque = -(math.tau * 0.5) + angle
- self.body:applyTorque(torque * 1000)
+ self.body:applyTorque(torque * factor)
+end
+
+function Kitten:draw()
+ if self.parachute then
+ love.graphics.setColor(self.parachute.color)
+ for _, j in ipairs(self.parachute_joints) do
+ local x1, y1, x2, y2 = j:getAnchors()
+ love.graphics.line(x1, y1, x2, y2)
+ end
+ end
+ Entity.draw(self)
end
return Kitten