bjorn 10 yıl önce
ebeveyn
işleme
eb49c70e7d
6 değiştirilmiş dosya ile 71 ekleme ve 20 silme
  1. 1 1
      caveman.lua
  2. 2 1
      main.lua
  3. 17 11
      map.lua
  4. 49 6
      menu.lua
  5. 1 1
      person.lua
  6. 1 0
      require.lua

+ 1 - 1
caveman.lua

@@ -46,7 +46,7 @@ Caveman.idle = {}
 Caveman.idle.walkRate = {.4, .5}
 function Caveman.idle:update()
   self.image = data.media.graphics.dinoland[self.gender]['normal' .. self.index]
-  if self:distanceTo(ctx.pigeon) < 300 then
+  if ctx.pigeon and self:distanceTo(ctx.pigeon) < 300 then
     self:changeState(love.math.random() < .5 and 'panic' or 'attack')
   end
 

+ 2 - 1
main.lua

@@ -2,5 +2,6 @@ require 'require'
 
 function love.load()
   data.load()
-  Context:bind(Game, 'Dinoland', 1)
+  Context:bind(Menu)
+  --Context:bind(Game, 'Dinoland', 1)
 end

+ 17 - 11
map.lua

@@ -1,9 +1,12 @@
 Map = class()
 
 function Map:init()
+  self.width = self.width or love.graphics.getWidth()
+  self.height = self.height or 900
+  self.obstacles = self.obstacles or {}
   self.ground = {}
   self.ground.width = self.width
-  self.ground.height = self.groundHeight
+  self.ground.height = self.groundHeight or 100
   self.ground.body = love.physics.newBody(ctx.world, self.width / 2, self.height - self.ground.height / 2, 'static')
   self.ground.shape = love.physics.newRectangleShape(self.width, self.ground.height)
 
@@ -13,7 +16,8 @@ function Map:init()
   self.ground.body:setUserData(self)
 
   self.clouds = {}
-  for i = 1, 8 do
+  local cloudCount = isa(ctx, Game) and 8 or 2
+  for i = 1, cloudCount do
     table.insert(self.clouds, {
       x = love.math.random(100, self.width),
       y = love.math.random(0, 450),
@@ -25,14 +29,14 @@ function Map:init()
   end
   self.cloudTimer = 15
 
-  ctx.view.xmax = self.width
-  ctx.view.ymax = self.height
-  ctx.event:emit('view.register', {object = self})
+  if ctx.view then
+    ctx.view.xmax = self.width
+    ctx.view.ymax = self.height
+    ctx.event:emit('view.register', {object = self})
+  end
 end
 
 function Map:update()
-  ctx.view.xmax = self:getMaxX()
-
   self.cloudTimer = timer.rot(self.cloudTimer, function()
     self:createCloud()
     return love.math.random(10, 25)
@@ -60,6 +64,8 @@ end
 
 function Map:draw()
   local g = love.graphics
+  local viewx = ctx.view and ctx.view.x or 0
+  local pigeonx = ctx.pigeon and ctx.pigeon.body:getX() or 0
 
   local function drawGrass(obstacle)
     local x, y = obstacle.body:getPosition()
@@ -89,15 +95,15 @@ function Map:draw()
   g.setColor(255, 255, 255)
   local image = data.media.graphics.dinoland.background.sky
   local scale = (600) / image:getHeight()
-  g.draw(image, ctx.view.x, self.height, 0, scale, scale, 0, image:getHeight())
+  g.draw(image, viewx, self.height, 0, scale, scale, 0, image:getHeight())
 
   local inc = image:getWidth() * scale
   for n = 4, 1, -1 do
     for x = -500, self.width, inc * 2 do
       image = data.media.graphics[ctx.map.name].background.left
-      g.draw(image, x + ctx.pigeon.body:getX() / 2, self.height, 0, scale, scale, 0, image:getHeight())
+      g.draw(image, x + pigeonx / 2, self.height, 0, scale, scale, 0, image:getHeight())
       image = data.media.graphics[ctx.map.name].background.right
-      g.draw(image, x + inc + ctx.pigeon.body:getX() / 2, self.height, 0, scale, scale, 0, image:getHeight())
+      g.draw(image, x + inc + pigeonx / 2, self.height, 0, scale, scale, 0, image:getHeight())
     end
   end
 
@@ -134,7 +140,7 @@ function Map:draw()
     g.setColor(255, 255, 255, cloud.alpha)
     local w, h = cloud.image:getDimensions()
     local scale = cloud.height / h
-    g.draw(cloud.image, cloud.x + ctx.pigeon.body:getX() / 4, cloud.y, 0, scale, scale, w / 2, h / 2)
+    g.draw(cloud.image, cloud.x + pigeonx / 4, cloud.y, 0, scale, scale, w / 2, h / 2)
   end)
 end
 

+ 49 - 6
menu.lua

@@ -1,20 +1,63 @@
 Menu = class()
-
-function Menu:init()
-  self.world = 1
-  self.index = 1
+Menu.categories = {
+  ground = 1,
+  building = 2,
+  person = 3,
+  pigeon = 4,
+  oneWayPlatform = 5,
+  debris = 6
+}
+
+function Menu:load()
+  self.worldIndex = 1
+  self.levelIndex = 1
+
+  self.world = love.physics.newWorld(0, 1000)
+  self.map = Map()
+  self.map.name = 'dinoland'
+  self.enemies = Manager()
+
+  for i = 1, 20 do
+    ctx.enemies:add(Caveman, {x = 0 + love.math.random() * love.graphics.getWidth(), y = self.map.height - self.map.ground.height})
+  end
 
   self.selectedButton = 'play'
 end
 
 function Menu:update()
-
+  self.map:update()
+  self.enemies:update()
+  self.world:update(ls.tickrate)
 end
 
 function Menu:draw()
-
+  local g = love.graphics
+  g.push()
+  g.translate(0, -300)
+  self.map:draw()
+  ctx.enemies:each(function(enemy)
+    enemy:draw()
+  end)
+  g.pop()
+
+  g.setColor(0, 0, 0, 100)
+  g.rectangle('fill', 0, 0, g.getDimensions())
+
+  g.setColor(255, 255, 255)
+  g.print('PIGEON', g.getWidth() / 2 - g.getFont():getWidth('PIGEON') / 2, 200)
 end
 
 function Menu:keypressed(key)
+  if key == 'escape' then love.event.quit() end
+
+  if key == 'left' then
+
+  elseif key == 'right' then
 
+  elseif key == ' ' then
+    local world = ({'Dinoland', 'Kingdumb'})[self.worldIndex]
+    Context:remove(ctx)
+    Context:add(Game, world, self.levelIndex)
+    return
+  end
 end

+ 1 - 1
person.lua

@@ -26,7 +26,7 @@ function Person:activate()
   self.screamed = false
   self.splatted = false
 
-  ctx.event:emit('view.register', {object = self})
+  if ctx.view then ctx.event:emit('view.register', {object = self}) end
 
   Enemy.activate(self)
 end

+ 1 - 0
require.lua

@@ -32,6 +32,7 @@ require 'kingdumb'
 require 'goal'
 require 'projectile'
 require 'spear'
+require 'menu'
 
 require 'hud'