|
@@ -1,87 +1,27 @@
|
|
|
Building = class()
|
|
|
|
|
|
-Building.wallWidth = 16
|
|
|
+Building.size = 60
|
|
|
|
|
|
function Building:activate()
|
|
|
self.y = ctx.map.height - ctx.map.ground.height
|
|
|
+ self.image = data.media.graphics.dinoland['hut' .. love.math.random(1, 2)]
|
|
|
|
|
|
- self.pieces = {}
|
|
|
-
|
|
|
- -- Roof
|
|
|
- local piece = {}
|
|
|
- piece.body = love.physics.newBody(ctx.world, self.x, self.y - self.height - self.wallWidth / 2, 'dynamic')
|
|
|
- piece.body:setUserData(self)
|
|
|
- piece.shape = love.physics.newRectangleShape(self.width, self.wallWidth)
|
|
|
- piece.fixture = love.physics.newFixture(piece.body, piece.shape)
|
|
|
- piece.fixture:setCategory(ctx.categories.building)
|
|
|
- piece.fixture:setMask(ctx.categories.debris)
|
|
|
- piece.phlerp = PhysicsInterpolator(piece.body)
|
|
|
- table.insert(self.pieces, piece)
|
|
|
-
|
|
|
- -- Left wall
|
|
|
- piece = {}
|
|
|
- piece.body = love.physics.newBody(ctx.world, self.x - self.width / 2 + self.wallWidth / 2, self.y - self.height / 2, 'dynamic')
|
|
|
- piece.body:setUserData(self)
|
|
|
- piece.shape = love.physics.newRectangleShape(self.wallWidth, self.height)
|
|
|
- piece.fixture = love.physics.newFixture(piece.body, piece.shape)
|
|
|
- piece.fixture:setCategory(ctx.categories.building)
|
|
|
- piece.fixture:setMask(ctx.categories.debris)
|
|
|
- piece.phlerp = PhysicsInterpolator(piece.body)
|
|
|
- table.insert(self.pieces, piece)
|
|
|
-
|
|
|
- -- Right wall
|
|
|
- piece = {}
|
|
|
- piece.body = love.physics.newBody(ctx.world, self.x + self.width / 2 - self.wallWidth / 2, self.y - self.height / 2, 'dynamic')
|
|
|
- piece.body:setUserData(self)
|
|
|
- piece.shape = love.physics.newRectangleShape(self.wallWidth, self.height)
|
|
|
- piece.fixture = love.physics.newFixture(piece.body, piece.shape)
|
|
|
- piece.fixture:setCategory(ctx.categories.building)
|
|
|
- piece.fixture:setMask(ctx.categories.debris)
|
|
|
- piece.phlerp = PhysicsInterpolator(piece.body)
|
|
|
- table.insert(self.pieces, piece)
|
|
|
-
|
|
|
- self.destroyed = false
|
|
|
+ self.personTimer = 6 + love.math.random() * 3
|
|
|
|
|
|
ctx.event:emit('view.register', {object = self})
|
|
|
end
|
|
|
|
|
|
function Building:update()
|
|
|
- table.each(self.pieces, function(piece)
|
|
|
- piece.phlerp:update()
|
|
|
+ self.personTimer = timer.rot(self.personTimer, function()
|
|
|
+ ctx.enemies:add(Caveman, {x = self.x, y = self.y - 20})
|
|
|
+ return 6 + love.math.random() * 3
|
|
|
end)
|
|
|
-
|
|
|
- if ctx.pigeon.body:getY() + ctx.pigeon.shapeSize / 2 > self.pieces[1].body:getY() - self.wallWidth / 2 then
|
|
|
- --self.pieces[1].fixture:setCategory(ctx.categories.oneWayPlatform)
|
|
|
- else
|
|
|
- --self.pieces[1].fixture:setCategory(ctx.categories.building)
|
|
|
- end
|
|
|
end
|
|
|
|
|
|
function Building:draw()
|
|
|
local g = love.graphics
|
|
|
-
|
|
|
- table.each(self.pieces, function(piece)
|
|
|
- piece.phlerp:lerp()
|
|
|
- local points = {piece.body:getWorldPoints(piece.shape:getPoints())}
|
|
|
- g.setColor(255, 255, 255)
|
|
|
- g.polygon('line', points)
|
|
|
- piece.phlerp:delerp()
|
|
|
- end)
|
|
|
+ local scale = self.size / self.image:getWidth()
|
|
|
+ g.setColor(255, 255, 255)
|
|
|
+ g.draw(self.image, self.x, self.y, 0, scale, scale, self.image:getWidth() / 2, self.image:getHeight())
|
|
|
end
|
|
|
|
|
|
-function Building:collideWith(other)
|
|
|
- if isa(other, Building) then return true
|
|
|
- elseif isa(other, Pigeon) then self:destroy() end
|
|
|
-end
|
|
|
-
|
|
|
-function Building:destroy()
|
|
|
- if self.destroyed then return end
|
|
|
-
|
|
|
- self.destroyed = true
|
|
|
-
|
|
|
- table.each(self.pieces, function(piece)
|
|
|
- --piece.body:setType('dynamic')
|
|
|
- piece.body:applyAngularImpulse(lume.random(1000, 2000) * (love.math.random() > .5 and 1 or -1))
|
|
|
- piece.fixture:setCategory(ctx.categories.debris)
|
|
|
- end)
|
|
|
-end
|