123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- Kingdumb = extend(Map)
- Kingdumb.groundHeight = 100
- function Kingdumb:init(index)
- self.zones = {}
- self.name = 'kingdumb'
- self.defaultPersonType = Peasant
- self.index = index
- self.obstacles = {}
- local function makeObstacle(x, y, w, h)
- local obstacle = {}
- obstacle.width, obstacle.height = w, h
- obstacle.body = love.physics.newBody(ctx.world, x, self.height - self.groundHeight - obstacle.height / 2 - y)
- obstacle.shape = love.physics.newRectangleShape(obstacle.width, obstacle.height)
- obstacle.fixture = love.physics.newFixture(obstacle.body, obstacle.shape)
- obstacle.fixture:setCategory(ctx.categories.oneWayPlatform)
- obstacle.body:setUserData(obstacle)
- obstacle.tag = 'platform'
- table.insert(self.obstacles, obstacle)
- end
- if self.index == 1 then
- self.width = 6000
- self.height = 900
- makeObstacle(1700, 0, 200, 200)
- makeObstacle(1400, 0, 800, 100)
- makeObstacle(2450, 0, 200, 200)
- makeObstacle(3000, 0, 200, 350)
- makeObstacle(2900, 0, 400, 250)
- makeObstacle(2750, 0, 600, 100)
- makeObstacle(3800, 0, 400, 100)
- makeObstacle(4500, 0, 200, 200)
- makeObstacle(4300, 0, 200, 100)
- makeObstacle(4100, 0, 200, 200)
- elseif self.index == 2 then
- self.width = 5600
- self.height = 900
- makeObstacle(1700, 0, 400, 300)
- makeObstacle(1500, 0, 100, 200)
- makeObstacle(1500, 0, 600, 100)
- makeObstacle(3200, 0, 300, 200)
- makeObstacle(3200, 0, 600, 100)
- makeObstacle(4000, 0, 100, 300)
- makeObstacle(4000, 0, 300, 100)
- elseif self.index == 3 then
- self.width = 6400
- self.height = 900
- makeObstacle(1400, 200, 400, 100)
- makeObstacle(1400, 100, 400, 100)
- makeObstacle(1400, 0, 400, 100)
- makeObstacle(3300, 0, 200, 200)
- makeObstacle(3000, 0, 800, 100)
- makeObstacle(4200, 0, 200, 350)
- makeObstacle(4500, 0, 600, 100)
- end
- Map.init(self)
- self.decorations = {}
- for i = 1, 30 do
- local obstacle
- if love.math.random() < .75 then
- obstacle = self.ground
- else
- obstacle = self.obstacles[love.math.random(1, #self.obstacles)]
- end
- table.insert(self.decorations, {
- image = data.media.graphics.kingdumb['shrub' .. love.math.random(1, 2)],
- x = obstacle.body:getX() - obstacle.width / 2 + love.math.random() * obstacle.width,
- y = obstacle.body:getY() - obstacle.height / 2,
- height = 20 + love.math.random() * 20,
- direction = love.math.random() > .5 and -1 or 1
- })
- if love.math.random() < .5 then
- self.decorations[#self.decorations].image = data.media.graphics.kingdumb['fence' .. love.math.random(1, 2)]
- self.decorations[#self.decorations].height = 25
- end
- end
- end
- function Kingdumb:spawnHuts()
- local function makeBuilding(x, y)
- ctx.buildings:add(Building, {x = x, y = self.height - self.ground.height - y})
- end
- if self.index == 1 then
- for i = 1, 30 do
- ctx.enemies:add(Peasant, {x = 800 + love.math.random() * 500, y = self.height - self.ground.height})
- end
- makeBuilding(1200, 100)
- makeBuilding(1950, 0)
- makeBuilding(2175, 0)
- for i = 1, 20 do
- ctx.enemies:add(Peasant, {x = 1300 + love.math.random() * 300, y = self.height - self.ground.height})
- end
- makeBuilding(1700, 200)
- makeBuilding(2450, 200)
- makeBuilding(3000, 350)
- for i = 1, 20 do
- ctx.enemies:add(Peasant, {x = 2800 + love.math.random() * 500, y = self.height - self.ground.height})
- end
- makeBuilding(3700, 0)
- makeBuilding(3900, 100)
- makeBuilding(4500, 200)
- makeBuilding(4700, 100)
- makeBuilding(4800, 100)
- makeBuilding(4900, 100)
- makeBuilding(5000, 100)
- makeBuilding(5100, 100)
- for i = 1, 20 do
- ctx.enemies:add(Peasant, {x = 3900 + love.math.random() * 600, y = self.height - self.ground.height})
- end
- elseif self.index == 2 then
- makeBuilding(900, 0)
- makeBuilding(1100, 0)
- makeBuilding(1300, 100)
- makeBuilding(1400, 100)
- makeBuilding(1500, 0)
- makeBuilding(1800, 200)
- makeBuilding(1950, 0)
- makeBuilding(2100, 0)
- makeBuilding(2250, 0)
- makeBuilding(3200, 0)
- makeBuilding(3200, 200)
- makeBuilding(4000, 300)
- makeBuilding(4400, 300)
- makeBuilding(4600, 300)
- for i = 1, 5 do
- ctx.enemies:add(Peasant, {x = 3150 + love.math.random() * 100, y = self.height - self.ground.height - 100})
- end
- for i = 1, 15 do
- ctx.enemies:add(Peasant, {x = 1600 + love.math.random() * 300, y = self.height - self.ground.height - 200})
- end
- for i = 1, 35 do
- ctx.enemies:add(Peasant, {x = 2300 + love.math.random() * 600, y = self.height - self.ground.height - 200})
- end
- for i = 1, 35 do
- ctx.enemies:add(Peasant, {x = 4000 + love.math.random() * 800, y = self.height - self.ground.height})
- end
- elseif self.index == 3 then
- for i = 1, 25 do
- ctx.enemies:add(Peasant, {x = 700 + love.math.random() * 400, y = self.height - self.ground.height})
- end
- makeBuilding(1300, 0)
- makeBuilding(1400, 0)
- makeBuilding(1500, 0)
- makeBuilding(1400, 100)
- makeBuilding(1350, 200)
- makeBuilding(1450, 200)
- makeBuilding(1400, 300)
- makeBuilding(1700, 0)
- makeBuilding(1850, 0)
- for i = 1, 25 do
- ctx.enemies:add(Peasant, {x = 2000 + love.math.random() * 500, y = self.height - self.ground.height})
- end
- for i = 1, 25 do
- ctx.enemies:add(Peasant, {x = 2700 + love.math.random() * 400, y = self.height - self.ground.height - 100})
- end
- makeBuilding(2900, 0)
- makeBuilding(3300, 200)
- for i = 1, 20 do
- ctx.enemies:add(Peasant, {x = 3700 + love.math.random() * 400, y = self.height - self.ground.height - 350})
- end
- makeBuilding(3600, 0)
- makeBuilding(3800, 0)
- for i = 1, 5 do
- ctx.enemies:add(Peasant, {x = 4100 + love.math.random() * 100, y = self.height - self.ground.height - 350})
- end
- makeBuilding(4400, 100)
- makeBuilding(4600, 100)
- for i = 1, 35 do
- ctx.enemies:add(Peasant, {x = 4900 + love.math.random() * 600, y = self.height - self.ground.height - 350})
- end
- makeBuilding(5100, 0)
- makeBuilding(5300, 0)
- makeBuilding(5500, 0)
- end
- end
|