kingdumb.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. Kingdumb = extend(Map)
  2. Kingdumb.groundHeight = 100
  3. function Kingdumb:init(index)
  4. self.zones = {}
  5. self.name = 'kingdumb'
  6. self.defaultPersonType = Peasant
  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 = 6000
  22. self.height = 900
  23. makeObstacle(1700, 0, 200, 200)
  24. makeObstacle(1400, 0, 800, 100)
  25. makeObstacle(2450, 0, 200, 200)
  26. makeObstacle(3000, 0, 200, 350)
  27. makeObstacle(2900, 0, 400, 250)
  28. makeObstacle(2750, 0, 600, 100)
  29. makeObstacle(3800, 0, 400, 100)
  30. makeObstacle(4500, 0, 200, 200)
  31. makeObstacle(4300, 0, 200, 100)
  32. makeObstacle(4100, 0, 200, 200)
  33. elseif self.index == 2 then
  34. self.width = 5600
  35. self.height = 900
  36. makeObstacle(1700, 0, 400, 300)
  37. makeObstacle(1500, 0, 100, 200)
  38. makeObstacle(1500, 0, 600, 100)
  39. makeObstacle(3200, 0, 300, 200)
  40. makeObstacle(3200, 0, 600, 100)
  41. makeObstacle(4000, 0, 100, 300)
  42. makeObstacle(4000, 0, 300, 100)
  43. elseif self.index == 3 then
  44. self.width = 6400
  45. self.height = 900
  46. makeObstacle(1400, 200, 400, 100)
  47. makeObstacle(1400, 100, 400, 100)
  48. makeObstacle(1400, 0, 400, 100)
  49. makeObstacle(3300, 0, 200, 200)
  50. makeObstacle(3000, 0, 800, 100)
  51. makeObstacle(4200, 0, 200, 350)
  52. makeObstacle(4500, 0, 600, 100)
  53. end
  54. Map.init(self)
  55. self.decorations = {}
  56. for i = 1, 30 do
  57. local obstacle
  58. if love.math.random() < .75 then
  59. obstacle = self.ground
  60. else
  61. obstacle = self.obstacles[love.math.random(1, #self.obstacles)]
  62. end
  63. table.insert(self.decorations, {
  64. image = data.media.graphics.kingdumb['shrub' .. love.math.random(1, 2)],
  65. x = obstacle.body:getX() - obstacle.width / 2 + love.math.random() * obstacle.width,
  66. y = obstacle.body:getY() - obstacle.height / 2,
  67. height = 20 + love.math.random() * 20,
  68. direction = love.math.random() > .5 and -1 or 1
  69. })
  70. if love.math.random() < .5 then
  71. self.decorations[#self.decorations].image = data.media.graphics.kingdumb['fence' .. love.math.random(1, 2)]
  72. self.decorations[#self.decorations].height = 25
  73. end
  74. end
  75. end
  76. function Kingdumb:spawnHuts()
  77. local function makeBuilding(x, y)
  78. ctx.buildings:add(Building, {x = x, y = self.height - self.ground.height - y})
  79. end
  80. if self.index == 1 then
  81. for i = 1, 30 do
  82. ctx.enemies:add(Peasant, {x = 800 + love.math.random() * 500, y = self.height - self.ground.height})
  83. end
  84. makeBuilding(1200, 100)
  85. makeBuilding(1950, 0)
  86. makeBuilding(2175, 0)
  87. for i = 1, 20 do
  88. ctx.enemies:add(Peasant, {x = 1300 + love.math.random() * 300, y = self.height - self.ground.height})
  89. end
  90. makeBuilding(1700, 200)
  91. makeBuilding(2450, 200)
  92. makeBuilding(3000, 350)
  93. for i = 1, 20 do
  94. ctx.enemies:add(Peasant, {x = 2800 + love.math.random() * 500, y = self.height - self.ground.height})
  95. end
  96. makeBuilding(3700, 0)
  97. makeBuilding(3900, 100)
  98. makeBuilding(4500, 200)
  99. makeBuilding(4700, 100)
  100. makeBuilding(4800, 100)
  101. makeBuilding(4900, 100)
  102. makeBuilding(5000, 100)
  103. makeBuilding(5100, 100)
  104. for i = 1, 20 do
  105. ctx.enemies:add(Peasant, {x = 3900 + love.math.random() * 600, y = self.height - self.ground.height})
  106. end
  107. elseif self.index == 2 then
  108. makeBuilding(900, 0)
  109. makeBuilding(1100, 0)
  110. makeBuilding(1300, 100)
  111. makeBuilding(1400, 100)
  112. makeBuilding(1500, 0)
  113. makeBuilding(1800, 200)
  114. makeBuilding(1950, 0)
  115. makeBuilding(2100, 0)
  116. makeBuilding(2250, 0)
  117. makeBuilding(3200, 0)
  118. makeBuilding(3200, 200)
  119. makeBuilding(4000, 300)
  120. makeBuilding(4400, 300)
  121. makeBuilding(4600, 300)
  122. for i = 1, 5 do
  123. ctx.enemies:add(Peasant, {x = 3150 + love.math.random() * 100, y = self.height - self.ground.height - 100})
  124. end
  125. for i = 1, 15 do
  126. ctx.enemies:add(Peasant, {x = 1600 + love.math.random() * 300, y = self.height - self.ground.height - 200})
  127. end
  128. for i = 1, 35 do
  129. ctx.enemies:add(Peasant, {x = 2300 + love.math.random() * 600, y = self.height - self.ground.height - 200})
  130. end
  131. for i = 1, 35 do
  132. ctx.enemies:add(Peasant, {x = 4000 + love.math.random() * 800, y = self.height - self.ground.height})
  133. end
  134. elseif self.index == 3 then
  135. for i = 1, 25 do
  136. ctx.enemies:add(Peasant, {x = 700 + love.math.random() * 400, y = self.height - self.ground.height})
  137. end
  138. makeBuilding(1300, 0)
  139. makeBuilding(1400, 0)
  140. makeBuilding(1500, 0)
  141. makeBuilding(1400, 100)
  142. makeBuilding(1350, 200)
  143. makeBuilding(1450, 200)
  144. makeBuilding(1400, 300)
  145. makeBuilding(1700, 0)
  146. makeBuilding(1850, 0)
  147. for i = 1, 25 do
  148. ctx.enemies:add(Peasant, {x = 2000 + love.math.random() * 500, y = self.height - self.ground.height})
  149. end
  150. for i = 1, 25 do
  151. ctx.enemies:add(Peasant, {x = 2700 + love.math.random() * 400, y = self.height - self.ground.height - 100})
  152. end
  153. makeBuilding(2900, 0)
  154. makeBuilding(3300, 200)
  155. for i = 1, 20 do
  156. ctx.enemies:add(Peasant, {x = 3700 + love.math.random() * 400, y = self.height - self.ground.height - 350})
  157. end
  158. makeBuilding(3600, 0)
  159. makeBuilding(3800, 0)
  160. for i = 1, 5 do
  161. ctx.enemies:add(Peasant, {x = 4100 + love.math.random() * 100, y = self.height - self.ground.height - 350})
  162. end
  163. makeBuilding(4400, 100)
  164. makeBuilding(4600, 100)
  165. for i = 1, 35 do
  166. ctx.enemies:add(Peasant, {x = 4900 + love.math.random() * 600, y = self.height - self.ground.height - 350})
  167. end
  168. makeBuilding(5100, 0)
  169. makeBuilding(5300, 0)
  170. makeBuilding(5500, 0)
  171. end
  172. end