Skip to content

Instantly share code, notes, and snippets.

@homelinen
Created December 16, 2012 01:52
Show Gist options
  • Save homelinen/4302225 to your computer and use it in GitHub Desktop.
Save homelinen/4302225 to your computer and use it in GitHub Desktop.
My animated objects in Chingu. Bullet doesn't animate, for some reason.
class Bullet < Chingu::GameObject
traits :velocity, :bounding_circle
trait :animation, :delay => 200, :size => [16,16], :width => 16
def initialize(options = {})
super(options.merge(:image => Image["cannon-ball.png"]))
end
def update
@image = self.animation.next if self.animation
if (self.velocity_x < 1 || self.velocity_y < 1) ||
(@x < 0 || @x > $window.width) ||
(@y < 0 || @y > $window.height)
self.destroy
end
end
end
class Sea < Chingu::GameObject
trait :animation, :delay => 200, :size => [64,64]
def initialize(options = {})
super(options.merge(:image => Image["sea.png"]))
end
def update
@image = self.animation.next if self.animation
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment