Browse Source

Decorations;

bjorn 10 years ago
parent
commit
691daca02a
3 changed files with 55 additions and 12 deletions
  1. 13 10
      dinoland.lua
  2. 35 0
      map.lua
  3. 7 2
      pigeon.lua

+ 13 - 10
dinoland.lua

@@ -26,14 +26,17 @@ function Dinoland:init()
 
   table.insert(self.obstacles, obstacle)
 
-  obstacle = {}
-  obstacle.width, obstacle.height = 550, 300
-  obstacle.body = love.physics.newBody(ctx.world, 550 / 2, 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)
-
-  table.insert(self.obstacles, obstacle)
-
-  return Map.init(self)
+  Map.init(self)
+
+  self.decorations = {}
+  for i = 1, 10 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() + love.math.random() * obstacle.width / 2, y = obstacle.body:getY() - obstacle.height / 2, height = 50 + love.math.random() * 60, direction = love.math.random() > .5 and -1 or 1})
+  end
 end

+ 35 - 0
map.lua

@@ -2,6 +2,7 @@ Map = class()
 
 function Map:init()
   self.ground = {}
+  self.ground.width = self.width
   self.ground.height = self.groundHeight
   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)
@@ -31,6 +32,26 @@ end
 function Map:draw()
   local g = love.graphics
 
+  local function drawGrass(obstacle)
+    local x, y = obstacle.body:getPosition()
+    local x1, x2 = x - obstacle.width / 2, x + obstacle.width / 2
+    local image = data.media.graphics.dinoland.grassLeft
+    local scale = 32 / image:getHeight()
+    local xx = x1 + image:getWidth() * scale
+    g.setColor(255, 255, 255)
+    while xx < x2 do
+      local image = data.media.graphics.dinoland['grassMid' .. love.math.random(1, 2)]
+      g.draw(image, math.min(xx, x2 - image:getWidth() * scale * 2), y - obstacle.height / 2, 0, scale, scale)
+      xx = xx + image:getWidth() * scale
+    end
+    local image = data.media.graphics.dinoland.grassLeft
+    local scale = 32 / image:getHeight()
+    g.setColor(255, 255, 255)
+    g.draw(image, x1, y - obstacle.height / 2, 0, scale, scale)
+    local image = data.media.graphics.dinoland.grassRight
+    g.draw(image, x2, y - obstacle.height / 2, 0, scale, scale, image:getWidth())
+  end
+
   g.setColor(255, 255, 255)
   local image = data.media.graphics.dinoland.dinolandBackground1
   local scale = self.height / image:getHeight()
@@ -44,8 +65,22 @@ function Map:draw()
   g.setColor(136, 87, 44)
   physics.draw('fill', self.ground)
 
+  drawGrass(self.ground)
+
+  local seed = love.math.getRandomSeed()
   table.each(self.obstacles, function(obstacle)
+    love.math.setRandomSeed(obstacle.body:getX() + obstacle.width)
+    g.setColor(136, 87, 44)
     physics.draw('fill', obstacle)
+
+    drawGrass(obstacle)
+  end)
+  love.math.setRandomSeed(seed)
+
+  table.each(self.decorations, function(d)
+    local scale = d.height / d.image:getHeight()
+    g.setColor(255, 255, 255)
+    g.draw(d.image, d.x, d.y, 0, scale * d.direction, scale, d.image:getWidth() / 2, d.image:getHeight())
   end)
 end
 

+ 7 - 2
pigeon.lua

@@ -18,7 +18,7 @@ Pigeon.laserChargeDuration = 2
 ----------------
 function Pigeon:init()
   self.shapeSize = 50
-  self.body = love.physics.newBody(ctx.world, 300, ctx.map.height - ctx.map.ground.height - self.shapeSize / 2 - 300, 'dynamic')
+  self.body = love.physics.newBody(ctx.world, 100, ctx.map.height - ctx.map.ground.height - self.shapeSize / 2, 'dynamic')
   self.shape = love.physics.newRectangleShape(self.shapeSize, self.shapeSize)
   self.fixture = love.physics.newFixture(self.body, self.shape)
 
@@ -493,7 +493,12 @@ function Pigeon.laser:update()
 
       return 1
     end)
-  end
 
+    if love.keyboard.isDown('up', 'right') then
+      self.laser.direction = self.laser.direction - self.laserTurnSpeed * ls.tickrate * math.sign(math.pi / 2 - self.laser.direction) * .1
+    elseif love.keyboard.isDown('down', 'left') then
+      self.laser.direction = self.laser.direction + self.laserTurnSpeed * ls.tickrate * math.sign(math.pi / 2 - self.laser.direction) * .1
+    end
+  end
 end