123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- local WireWorld = {}
- function WireWorld.new()
- local self = setmetatable({}, {__index = WireWorld})
- self.world = {}
-
- return self
- end
- function WireWorld.getCollisions(world1, world2)
- local collisions = {}
-
- for xPos, yTable in pairs(world1.world) do
- for yPos, world1Steps in pairs(yTable) do
- local pos = Vector2.new(xPos,yPos)
- local world2Steps = world2:getTraversed(pos)
- local isColliding = world1Steps and world2Steps
-
-
- if isColliding then
- local contactInfo = {
- pos = pos,
- combinedSteps = world1Steps + world2Steps
- }
- table.insert(collisions, contactInfo)
- end
- end
- end
-
- return collisions
- end
- function WireWorld:getTraversed(p)
- local x, y = p.X, p.Y
- if not self.world[x] then return nil end
- return self.world[x][y]
- end
- function WireWorld:setTraversed(p, value)
- local x, y = p.X, p.Y
- if not self.world[x] then self.world[x] = {} end
- self.world[x][y] = value
- end
- return WireWorld
|