diff --git a/.gitignore b/.gitignore index 5fb6fb8..8a9b54f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *~ *.sublime-* .DS_Store +.ackrc + diff --git a/colliderwrapper.lua b/colliderwrapper.lua index 04d8089..afbe3cf 100755 --- a/colliderwrapper.lua +++ b/colliderwrapper.lua @@ -1,8 +1,16 @@ local class = require 'middleclass.middleclass' local HC = require 'HardonCollider' +require 'events.eraseevent' + ColliderWrapper = class('ColliderWrapper') +-- number of ticks of slack/buffer to allow when erasing an event +-- theoretically, this should not be necessary, but using it guarantees +-- that we will not encounter hard-to-reproduce bugs due to off-by-one +-- errors on the order of milliseconds +ColliderWrapper.static.erasureSlack = 10 + function ColliderWrapper:initialize(eventLog) self.collider = HC(100, function(...) self:onCollide(...) end) self.hitboxes = {} @@ -25,10 +33,12 @@ function ColliderWrapper:onCollide(dt, hitbox1, hitbox2, dx, dy) if entity1:hit(entity2, dx, dy) then self.eventLog:insert(DestroyEvent(id1), self.time) + self.eventLog:insert(EraseEvent(id1), self.time + constants.jumpTime + self.class.erasureSlack) end if entity2:hit(entity1, -dx, -dy) then self.eventLog:insert(DestroyEvent(id2), self.time) + self.eventLog:insert(EraseEvent(id2), self.time + constants.jumpTime + self.class.erasureSlack) end end diff --git a/events/eraseevent.lua b/events/eraseevent.lua new file mode 100644 index 0000000..535abda --- /dev/null +++ b/events/eraseevent.lua @@ -0,0 +1,12 @@ +local class = require 'middleclass.middleclass' + +require 'events.event' +require 'utils' + +EraseEvent = class('events.EraseEvent', EntityEvent) + + +function EraseEvent:safeApply(state, collider) + collider:remove(state[self.entityId].hitbox) + state[self.entityId] = nil +end