dinoland.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. Dinoland = extend(Map)
  2. Dinoland.groundHeight = 100
  3. function Dinoland:init(index)
  4. self.zones = {}
  5. self.name = 'dinoland'
  6. self.defaultPersonType = Caveman
  7. self.index = index
  8. self.obstacles = {}
  9. local function makeObstacle(x, y, w, h)
  10. local obstacle = {}
  11. obstacle.width, obstacle.height = w, h
  12. obstacle.body = love.physics.newBody(ctx.world, x, self.height - self.groundHeight - obstacle.height / 2 - y)
  13. obstacle.shape = love.physics.newRectangleShape(obstacle.width, obstacle.height)
  14. obstacle.fixture = love.physics.newFixture(obstacle.body, obstacle.shape)
  15. obstacle.fixture:setCategory(ctx.categories.oneWayPlatform)
  16. obstacle.body:setUserData(obstacle)
  17. obstacle.tag = 'platform'
  18. table.insert(self.obstacles, obstacle)
  19. end
  20. if self.index == 1 then
  21. self.width = 6600
  22. self.height = 900
  23. local obstacle = {}
  24. obstacle.width, obstacle.height = 500, 200
  25. obstacle.body = love.physics.newBody(ctx.world, 2100, self.height - self.groundHeight - obstacle.height / 2)
  26. obstacle.shape = love.physics.newRectangleShape(obstacle.width, obstacle.height)
  27. obstacle.fixture = love.physics.newFixture(obstacle.body, obstacle.shape)
  28. obstacle.fixture:setCategory(ctx.categories.oneWayPlatform)
  29. obstacle.body:setUserData(obstacle)
  30. obstacle.tag = 'platform'
  31. table.insert(self.obstacles, obstacle)
  32. obstacle = {}
  33. obstacle.width, obstacle.height = 1000, 100
  34. obstacle.body = love.physics.newBody(ctx.world, 1850, self.height - self.groundHeight - obstacle.height / 2)
  35. obstacle.shape = love.physics.newRectangleShape(obstacle.width, obstacle.height)
  36. obstacle.fixture = love.physics.newFixture(obstacle.body, obstacle.shape)
  37. obstacle.fixture:setCategory(ctx.categories.oneWayPlatform)
  38. obstacle.body:setUserData(obstacle)
  39. obstacle.tag = 'platform'
  40. table.insert(self.obstacles, obstacle)
  41. obstacle = {}
  42. obstacle.width, obstacle.height = 1000, 100
  43. obstacle.body = love.physics.newBody(ctx.world, 4000, self.height - self.groundHeight - obstacle.height / 2)
  44. obstacle.shape = love.physics.newRectangleShape(obstacle.width, obstacle.height)
  45. obstacle.fixture = love.physics.newFixture(obstacle.body, obstacle.shape)
  46. obstacle.fixture:setCategory(ctx.categories.oneWayPlatform)
  47. obstacle.body:setUserData(obstacle)
  48. obstacle.tag = 'platform'
  49. table.insert(self.obstacles, obstacle)
  50. obstacle = {}
  51. obstacle.width, obstacle.height = 200, 150
  52. obstacle.body = love.physics.newBody(ctx.world, 4000, self.height - self.groundHeight - obstacle.height / 2 - 100)
  53. obstacle.shape = love.physics.newRectangleShape(obstacle.width, obstacle.height)
  54. obstacle.fixture = love.physics.newFixture(obstacle.body, obstacle.shape)
  55. obstacle.fixture:setCategory(ctx.categories.oneWayPlatform)
  56. obstacle.body:setUserData(obstacle)
  57. obstacle.tag = 'platform'
  58. table.insert(self.obstacles, obstacle)
  59. obstacle = {}
  60. obstacle.width, obstacle.height = 200, 300
  61. obstacle.body = love.physics.newBody(ctx.world, 5100, self.height - self.groundHeight - obstacle.height / 2)
  62. obstacle.shape = love.physics.newRectangleShape(obstacle.width, obstacle.height)
  63. obstacle.fixture = love.physics.newFixture(obstacle.body, obstacle.shape)
  64. obstacle.fixture:setCategory(ctx.categories.oneWayPlatform)
  65. obstacle.body:setUserData(obstacle)
  66. obstacle.tag = 'platform'
  67. table.insert(self.obstacles, obstacle)
  68. obstacle = {}
  69. obstacle.width, obstacle.height = 200, 200
  70. obstacle.body = love.physics.newBody(ctx.world, 4950, self.height - self.groundHeight - obstacle.height / 2)
  71. obstacle.shape = love.physics.newRectangleShape(obstacle.width, obstacle.height)
  72. obstacle.fixture = love.physics.newFixture(obstacle.body, obstacle.shape)
  73. obstacle.fixture:setCategory(ctx.categories.oneWayPlatform)
  74. obstacle.body:setUserData(obstacle)
  75. obstacle.tag = 'platform'
  76. table.insert(self.obstacles, obstacle)
  77. obstacle = {}
  78. obstacle.width, obstacle.height = 200, 100
  79. obstacle.body = love.physics.newBody(ctx.world, 4800, self.height - self.groundHeight - obstacle.height / 2)
  80. obstacle.shape = love.physics.newRectangleShape(obstacle.width, obstacle.height)
  81. obstacle.fixture = love.physics.newFixture(obstacle.body, obstacle.shape)
  82. obstacle.fixture:setCategory(ctx.categories.oneWayPlatform)
  83. obstacle.body:setUserData(obstacle)
  84. obstacle.tag = 'platform'
  85. table.insert(self.obstacles, obstacle)
  86. elseif self.index == 2 then
  87. self.width = 5800
  88. self.height = 900
  89. makeObstacle(1200, 0, 500, 100)
  90. makeObstacle(2000, 0, 100, 300)
  91. makeObstacle(2000, 0, 300, 100)
  92. makeObstacle(3450, 0, 600, 100)
  93. makeObstacle(4400, 0, 600, 200)
  94. makeObstacle(4800, 0, 200, 100)
  95. makeObstacle(4000, 0, 200, 100)
  96. elseif self.index == 3 then
  97. self.width = 6000
  98. self.height = 900
  99. makeObstacle(2900, 0, 200, 300)
  100. makeObstacle(3000, 0, 800, 200)
  101. makeObstacle(2800, 0, 800, 100)
  102. makeObstacle(4200, 0, 100, 400)
  103. makeObstacle(4200, 0, 300, 200)
  104. makeObstacle(4200, 0, 600, 100)
  105. end
  106. Map.init(self)
  107. self.decorations = {}
  108. for i = 1, 20 do
  109. local obstacle
  110. if love.math.random() < .75 then
  111. obstacle = self.ground
  112. else
  113. obstacle = self.obstacles[love.math.random(1, #self.obstacles)]
  114. end
  115. table.insert(self.decorations, {
  116. image = data.media.graphics.dinoland['shrub' .. love.math.random(1, 4)],
  117. x = obstacle.body:getX() - obstacle.width / 2 + love.math.random() * obstacle.width,
  118. y = obstacle.body:getY() - obstacle.height / 2,
  119. height = 30 + love.math.random() * 50,
  120. direction = love.math.random() > .5 and -1 or 1
  121. })
  122. if love.math.random() < .01 then
  123. self.decorations[#self.decorations].image = data.media.graphics.dinoland.ufo
  124. end
  125. end
  126. self.dactyls = {}
  127. for i = 1, 3 do
  128. table.insert(self.dactyls, {
  129. x = love.math.random(100, self.width),
  130. y = love.math.random(0, 450),
  131. height = love.math.random(40, 55),
  132. speed = love.math.random(30, 50),
  133. rate = love.math.random(2, 4)
  134. })
  135. end
  136. self.dactylTimer = 30
  137. end
  138. function Dinoland:update()
  139. Map.update(self)
  140. self.dactylTimer = timer.rot(self.dactylTimer, function()
  141. table.insert(self.dactyls, {
  142. x = self.width + 100,
  143. y = love.math.random(0, 450),
  144. height = love.math.random(40, 55),
  145. speed = love.math.random(30, 50),
  146. rate = love.math.random(2, 4)
  147. })
  148. return love.math.random(20, 40)
  149. end)
  150. local i = #self.dactyls
  151. while i >= 1 do
  152. local dactyl = self.dactyls[i]
  153. if not dactyl then break end
  154. dactyl.x = dactyl.x - dactyl.speed * ls.tickrate
  155. if dactyl.x < -100 then
  156. table.remove(self.dactyls, i)
  157. else
  158. i = i - 1
  159. end
  160. end
  161. end
  162. function Dinoland:draw()
  163. Map.draw(self)
  164. local g = love.graphics
  165. g.setColor(255, 255, 255)
  166. table.each(self.dactyls, function(dactyl)
  167. local image = data.media.graphics.dinoland['pterodactyl' .. (((math.floor(ls.tick * ls.tickrate * dactyl.rate) % 2) == 0) and 1 or 2)]
  168. local w, h = image:getDimensions()
  169. local scale = dactyl.height / h
  170. g.draw(image, dactyl.x, dactyl.y, 0, scale, scale, w / 2, h / 2)
  171. end)
  172. end
  173. function Dinoland:spawnHuts()
  174. local function makeBuilding(x, y)
  175. ctx.buildings:add(Building, {x = x, y = self.height - self.ground.height - y})
  176. end
  177. if self.index == 1 then
  178. ctx.buildings:add(Building, {x = 950, y = self.height - self.ground.height})
  179. ctx.buildings:add(Building, {x = 2000, y = self.height - self.ground.height - 200})
  180. ctx.buildings:add(Building, {x = 2200, y = self.height - self.ground.height - 200})
  181. ctx.buildings:add(Building, {x = 2100, y = self.height - self.ground.height})
  182. ctx.buildings:add(Building, {x = 2800, y = self.height - self.ground.height})
  183. ctx.buildings:add(Building, {x = 3000, y = self.height - self.ground.height})
  184. ctx.buildings:add(Building, {x = 3200, y = self.height - self.ground.height})
  185. ctx.buildings:add(Building, {x = 3800, y = self.height - self.ground.height - 100})
  186. ctx.buildings:add(Building, {x = 4200, y = self.height - self.ground.height - 100})
  187. ctx.buildings:add(Building, {x = 4000, y = self.height - self.ground.height - 250})
  188. ctx.buildings:add(Building, {x = 5300, y = self.height - self.ground.height})
  189. ctx.buildings:add(Building, {x = 5400, y = self.height - self.ground.height})
  190. ctx.buildings:add(Building, {x = 5500, y = self.height - self.ground.height})
  191. ctx.buildings:add(Building, {x = 5600, y = self.height - self.ground.height})
  192. for i = 1, 20 do
  193. ctx.enemies:add(Caveman, {x = 2700 + love.math.random() * 600, y = self.height - self.ground.height})
  194. end
  195. for i = 1, 20 do
  196. ctx.enemies:add(Caveman, {x = 1600 - 150 + love.math.random() * 300, y = self.height - self.ground.height - 200})
  197. end
  198. for i = 1, 20 do
  199. ctx.enemies:add(Caveman, {x = 3500 + love.math.random() * 900, y = self.height - self.ground.height - 150})
  200. end
  201. for i = 1, 25 do
  202. ctx.enemies:add(Caveman, {x = 5100 + love.math.random() * 400, y = self.height - self.ground.height})
  203. end
  204. elseif self.index == 2 then
  205. makeBuilding(1050, 100)
  206. makeBuilding(1350, 0)
  207. makeBuilding(1200, 100)
  208. makeBuilding(2000, 300)
  209. makeBuilding(2650, 0)
  210. makeBuilding(3250, 100)
  211. makeBuilding(3350, 0)
  212. makeBuilding(3450, 100)
  213. makeBuilding(3550, 0)
  214. makeBuilding(3650, 100)
  215. makeBuilding(4000, 100)
  216. makeBuilding(4400, 200)
  217. makeBuilding(4800, 100)
  218. for i = 1, 20 do
  219. ctx.enemies:add(Caveman, {x = 1500 + love.math.random() * 300, y = self.height - self.ground.height})
  220. end
  221. for i = 1, 10 do
  222. ctx.enemies:add(Caveman, {x = 1900 + love.math.random() * 200, y = self.height - self.ground.height - 100})
  223. end
  224. for i = 1, 20 do
  225. ctx.enemies:add(Caveman, {x = 2650 + love.math.random() * 400, y = self.height - self.ground.height})
  226. end
  227. for i = 1, 20 do
  228. ctx.enemies:add(Caveman, {x = 4100 + love.math.random() * 600, y = self.height - self.ground.height})
  229. end
  230. for i = 1, 20 do
  231. ctx.enemies:add(Caveman, {x = 4100 + love.math.random() * 600, y = self.height - self.ground.height - 200})
  232. end
  233. elseif self.index == 3 then
  234. makeBuilding(900, 0)
  235. makeBuilding(1500, 0)
  236. makeBuilding(2100, 0)
  237. for i = 1, 15 do
  238. ctx.enemies:add(Caveman, {x = 1000 + love.math.random() * 400, y = self.height - self.ground.height})
  239. end
  240. for i = 1, 15 do
  241. ctx.enemies:add(Caveman, {x = 1600 + love.math.random() * 400, y = self.height - self.ground.height})
  242. end
  243. makeBuilding(2500, 100)
  244. makeBuilding(2900, 300)
  245. makeBuilding(3000, 0)
  246. makeBuilding(3150, 100)
  247. makeBuilding(3300, 200)
  248. for i = 1, 20 do
  249. ctx.enemies:add(Caveman, {x = 2600 + love.math.random() * 800, y = self.height - self.ground.height - 200})
  250. end
  251. for i = 1, 8 do
  252. ctx.enemies:add(Caveman, {x = 3000 + love.math.random() * 300, y = self.height - self.ground.height})
  253. end
  254. makeBuilding(3950, 100)
  255. makeBuilding(4450, 100)
  256. for i = 1, 10 do
  257. ctx.enemies:add(Caveman, {x = 4175 + love.math.random() * 50, y = self.height - self.ground.height - 400})
  258. end
  259. makeBuilding(5000, 200)
  260. for i = 1, 35 do
  261. ctx.enemies:add(Caveman, {x = 4500 + love.math.random() * 600, y = self.height - self.ground.height})
  262. end
  263. end
  264. end