123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- Dinoland = extend(Map)
- Dinoland.groundHeight = 100
- function Dinoland:init(index)
- self.zones = {}
- self.name = 'dinoland'
- self.defaultPersonType = Caveman
- 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 = 6600
- self.height = 900
- local obstacle = {}
- obstacle.width, obstacle.height = 500, 200
- obstacle.body = love.physics.newBody(ctx.world, 2100, self.height - self.groundHeight - obstacle.height / 2)
- 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)
- obstacle = {}
- obstacle.width, obstacle.height = 1000, 100
- obstacle.body = love.physics.newBody(ctx.world, 1850, self.height - self.groundHeight - obstacle.height / 2)
- 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)
- obstacle = {}
- obstacle.width, obstacle.height = 1000, 100
- obstacle.body = love.physics.newBody(ctx.world, 4000, self.height - self.groundHeight - obstacle.height / 2)
- 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)
- obstacle = {}
- obstacle.width, obstacle.height = 200, 150
- obstacle.body = love.physics.newBody(ctx.world, 4000, self.height - self.groundHeight - obstacle.height / 2 - 100)
- 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)
- obstacle = {}
- obstacle.width, obstacle.height = 200, 300
- obstacle.body = love.physics.newBody(ctx.world, 5100, self.height - self.groundHeight - obstacle.height / 2)
- 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)
- obstacle = {}
- obstacle.width, obstacle.height = 200, 200
- obstacle.body = love.physics.newBody(ctx.world, 4950, self.height - self.groundHeight - obstacle.height / 2)
- 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)
- obstacle = {}
- obstacle.width, obstacle.height = 200, 100
- obstacle.body = love.physics.newBody(ctx.world, 4800, self.height - self.groundHeight - obstacle.height / 2)
- 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)
- elseif self.index == 2 then
- self.width = 5800
- self.height = 900
- makeObstacle(1200, 0, 500, 100)
- makeObstacle(2000, 0, 100, 300)
- makeObstacle(2000, 0, 300, 100)
- makeObstacle(3450, 0, 600, 100)
- makeObstacle(4400, 0, 600, 200)
- makeObstacle(4800, 0, 200, 100)
- makeObstacle(4000, 0, 200, 100)
- elseif self.index == 3 then
- self.width = 6000
- self.height = 900
- makeObstacle(2900, 0, 200, 300)
- makeObstacle(3000, 0, 800, 200)
- makeObstacle(2800, 0, 800, 100)
- makeObstacle(4200, 0, 100, 400)
- makeObstacle(4200, 0, 300, 200)
- makeObstacle(4200, 0, 600, 100)
- end
- Map.init(self)
- self.decorations = {}
- for i = 1, 20 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.dinoland['shrub' .. love.math.random(1, 4)],
- x = obstacle.body:getX() - obstacle.width / 2 + love.math.random() * obstacle.width,
- y = obstacle.body:getY() - obstacle.height / 2,
- height = 30 + love.math.random() * 50,
- direction = love.math.random() > .5 and -1 or 1
- })
- if love.math.random() < .01 then
- self.decorations[#self.decorations].image = data.media.graphics.dinoland.ufo
- end
- end
- self.dactyls = {}
- for i = 1, 3 do
- table.insert(self.dactyls, {
- x = love.math.random(100, self.width),
- y = love.math.random(0, 450),
- height = love.math.random(40, 55),
- speed = love.math.random(30, 50),
- rate = love.math.random(2, 4)
- })
- end
- self.dactylTimer = 30
- end
- function Dinoland:update()
- Map.update(self)
- self.dactylTimer = timer.rot(self.dactylTimer, function()
- table.insert(self.dactyls, {
- x = self.width + 100,
- y = love.math.random(0, 450),
- height = love.math.random(40, 55),
- speed = love.math.random(30, 50),
- rate = love.math.random(2, 4)
- })
- return love.math.random(20, 40)
- end)
- local i = #self.dactyls
- while i >= 1 do
- local dactyl = self.dactyls[i]
- if not dactyl then break end
- dactyl.x = dactyl.x - dactyl.speed * ls.tickrate
- if dactyl.x < -100 then
- table.remove(self.dactyls, i)
- else
- i = i - 1
- end
- end
- end
- function Dinoland:draw()
- Map.draw(self)
- local g = love.graphics
- g.setColor(255, 255, 255)
- table.each(self.dactyls, function(dactyl)
- local image = data.media.graphics.dinoland['pterodactyl' .. (((math.floor(ls.tick * ls.tickrate * dactyl.rate) % 2) == 0) and 1 or 2)]
- local w, h = image:getDimensions()
- local scale = dactyl.height / h
- g.draw(image, dactyl.x, dactyl.y, 0, scale, scale, w / 2, h / 2)
- end)
- end
- function Dinoland: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
- ctx.buildings:add(Building, {x = 950, y = self.height - self.ground.height})
- ctx.buildings:add(Building, {x = 2000, y = self.height - self.ground.height - 200})
- ctx.buildings:add(Building, {x = 2200, y = self.height - self.ground.height - 200})
- ctx.buildings:add(Building, {x = 2100, y = self.height - self.ground.height})
- ctx.buildings:add(Building, {x = 2800, y = self.height - self.ground.height})
- ctx.buildings:add(Building, {x = 3000, y = self.height - self.ground.height})
- ctx.buildings:add(Building, {x = 3200, y = self.height - self.ground.height})
- ctx.buildings:add(Building, {x = 3800, y = self.height - self.ground.height - 100})
- ctx.buildings:add(Building, {x = 4200, y = self.height - self.ground.height - 100})
- ctx.buildings:add(Building, {x = 4000, y = self.height - self.ground.height - 250})
- ctx.buildings:add(Building, {x = 5300, y = self.height - self.ground.height})
- ctx.buildings:add(Building, {x = 5400, y = self.height - self.ground.height})
- ctx.buildings:add(Building, {x = 5500, y = self.height - self.ground.height})
- ctx.buildings:add(Building, {x = 5600, y = self.height - self.ground.height})
- for i = 1, 20 do
- ctx.enemies:add(Caveman, {x = 2700 + love.math.random() * 600, y = self.height - self.ground.height})
- end
- for i = 1, 20 do
- ctx.enemies:add(Caveman, {x = 1600 - 150 + love.math.random() * 300, y = self.height - self.ground.height - 200})
- end
- for i = 1, 20 do
- ctx.enemies:add(Caveman, {x = 3500 + love.math.random() * 900, y = self.height - self.ground.height - 150})
- end
- for i = 1, 25 do
- ctx.enemies:add(Caveman, {x = 5100 + love.math.random() * 400, y = self.height - self.ground.height})
- end
- elseif self.index == 2 then
- makeBuilding(1050, 100)
- makeBuilding(1350, 0)
- makeBuilding(1200, 100)
- makeBuilding(2000, 300)
- makeBuilding(2650, 0)
- makeBuilding(3250, 100)
- makeBuilding(3350, 0)
- makeBuilding(3450, 100)
- makeBuilding(3550, 0)
- makeBuilding(3650, 100)
- makeBuilding(4000, 100)
- makeBuilding(4400, 200)
- makeBuilding(4800, 100)
- for i = 1, 20 do
- ctx.enemies:add(Caveman, {x = 1500 + love.math.random() * 300, y = self.height - self.ground.height})
- end
- for i = 1, 10 do
- ctx.enemies:add(Caveman, {x = 1900 + love.math.random() * 200, y = self.height - self.ground.height - 100})
- end
- for i = 1, 20 do
- ctx.enemies:add(Caveman, {x = 2650 + love.math.random() * 400, y = self.height - self.ground.height})
- end
- for i = 1, 20 do
- ctx.enemies:add(Caveman, {x = 4100 + love.math.random() * 600, y = self.height - self.ground.height})
- end
- for i = 1, 20 do
- ctx.enemies:add(Caveman, {x = 4100 + love.math.random() * 600, y = self.height - self.ground.height - 200})
- end
- elseif self.index == 3 then
- makeBuilding(900, 0)
- makeBuilding(1500, 0)
- makeBuilding(2100, 0)
- for i = 1, 15 do
- ctx.enemies:add(Caveman, {x = 1000 + love.math.random() * 400, y = self.height - self.ground.height})
- end
- for i = 1, 15 do
- ctx.enemies:add(Caveman, {x = 1600 + love.math.random() * 400, y = self.height - self.ground.height})
- end
- makeBuilding(2500, 100)
- makeBuilding(2900, 300)
- makeBuilding(3000, 0)
- makeBuilding(3150, 100)
- makeBuilding(3300, 200)
- for i = 1, 20 do
- ctx.enemies:add(Caveman, {x = 2600 + love.math.random() * 800, y = self.height - self.ground.height - 200})
- end
- for i = 1, 8 do
- ctx.enemies:add(Caveman, {x = 3000 + love.math.random() * 300, y = self.height - self.ground.height})
- end
- makeBuilding(3950, 100)
- makeBuilding(4450, 100)
- for i = 1, 10 do
- ctx.enemies:add(Caveman, {x = 4175 + love.math.random() * 50, y = self.height - self.ground.height - 400})
- end
- makeBuilding(5000, 200)
- for i = 1, 35 do
- ctx.enemies:add(Caveman, {x = 4500 + love.math.random() * 600, y = self.height - self.ground.height})
- end
- end
- end
|