Permalink
Browse files

added animations to flying chickens

  • Loading branch information...
1 parent da27aef commit 51781fc5bbf493a5a9f7ef33abe553bcd925ca17 Wilhelm Chung committed Feb 10, 2009
Showing with 26 additions and 4 deletions.
  1. +18 −2 boid.lua
  2. BIN images/left_chicken.png
  3. BIN images/right_chicken.png
  4. +3 −2 main.lua
  5. +5 −0 vector.lua
View
@@ -25,7 +25,12 @@ function Boid:new(x, y, vx, vy)
instance.velocity = Vector:new(vx, vy)
instance.position = Vector:new(x, y)
instance.velocity_delta = Vector:new(0, 0)
- instance.sprite = love.graphics.newImage("images/cow.png")
+
+ instance.left_sprite = love.graphics.newImage("images/left_chicken.png")
+ instance.left_anim = love.graphics.newAnimation(instance.left_sprite, 18, 18, 0.1)
+ instance.right_sprite = love.graphics.newImage("images/right_chicken.png")
+ instance.right_anim = love.graphics.newAnimation(instance.right_sprite, 18, 18, 0.1)
+ instance.anim = left_anim
return instance
end
@@ -112,6 +117,17 @@ function Boid:move()
self.position = self.position + self.velocity
end
+function Boid:update(dt)
+ if self.velocity.x <= 0 then
+ self.anim = self.left_anim
+ else
+ self.anim = self.right_anim
+ end
+
+ self.anim:update(dt)
+end
+
function Boid:draw()
- love.graphics.draw(self.sprite, self.position.x, self.position.y)
+ love.graphics.draw(self.anim, self.position.x, self.position.y,
+ math.deg(self.velocity:ang()), 1)
end
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -9,7 +9,7 @@ require 'boid'
function load()
math.randomseed(os.time())
- num_boids = 40
+ num_boids = 50
num_foodstuff = 5
boids = {}
foodstuffs = {}
@@ -34,7 +34,8 @@ function update(dt)
for _, boid in ipairs(boids) do
boid:navigate(boids, foodstuffs)
boid:move()
-
+ boid:update(dt)
+
-- see if each food is isEaten
for _, food in ipairs(foodstuffs) do
food:isEaten(boid)
View
@@ -65,8 +65,13 @@ function Vector:norm()
return Vector:new(self.x, self.y) / self:r()
end
+function Vector:ang()
+ return math.atan(self.y / self.x)
+end
-- a = Vector:new(2,2)
+-- print(a:toString())
+-- print(math.deg(a:ang()))
-- b = Vector:new(5,6)
-- print(a:to_s())
-- print(b:to_s())

0 comments on commit 51781fc

Please sign in to comment.