Permalink
Browse files

Fixing issues with the collisions

  • Loading branch information...
1 parent 32e9b29 commit a7dc2c72209b36a164c29d9a7eabda3cca40cc22 @ChrisJan00 committed Feb 8, 2012
Showing with 27 additions and 3 deletions.
  1. +12 −2 char.lua
  2. +15 −1 platforms.lua
View
@@ -42,10 +42,20 @@ function Character:update(dt)
local colRes = self.game:checkCharStatus( self.pos, {10, 10} )
-- jump?
- if not colRes[1] and self.standing then
+ self.lastStandingPlatform = self.standingPlatform
+ self.standingPlatform = colRes[4]
+ if not colRes[1] and self.standing and self.lastStandingPlatform then
+ if self.lastStandingPlatform:moved() then
+ self.lastStandingPlatform:resetMoved()
+ else
self.dir[2] = self.jump
+ end
end
-
+
+ if self.standingPlatform and self.standingPlatform ~= self.lastStandingPlatform and self.standingPlatform:moved() then
+ self.standingPlatform:resetMoved()
+ end
+
-- correct position on collision
if colRes[1] then
self.pos = colRes[2]
View
@@ -26,6 +26,7 @@ MovablePlatform = class(function(self)
self.dragging = false
self.mouseDown = false
self.transparent = false
+ self.wasMoved = false
end)
function MovablePlatform:set(ps)
@@ -77,6 +78,7 @@ end
function MovablePlatform:stopDrag()
self.dragging = false
+ self.wasMoved = true
end
--- collision: assume all platforms are rectangles by now
@@ -140,6 +142,14 @@ function MovablePlatform:correctedPos( pos, size )
end
end
+function MovablePlatform:moved()
+ return self.wasMoved
+end
+
+function MovablePlatform:resetMoved()
+ self.wasMoved = false
+end
+
--------------------------------------------------------------------------
@@ -174,15 +184,19 @@ function MovablePlatformList:checkCharStatus( pos, size )
local result = {}
local newnormal = Vector(0,0)
local endres = false
+ local lastStandingPlatform = nil
while elem do
result = elem:correctedPos( newpos, size )
if result[1] then
newpos = result[2]
+ if result[3][1]==0 and result[3][2]==-1 then
+ lastStandingPlatform = elem
+ end
newnormal = newnormal:add( result[3] )
endres = true
--~ return elem:correctedPos( pos )
end
elem = self.list:getNext()
end
- return {endres,newpos,newnormal}
+ return {endres,newpos,newnormal, lastStandingPlatform}
end

0 comments on commit a7dc2c7

Please sign in to comment.