Class: Spacewar::Star

Inherits:
Chingu::GameObject show all
Defined in:
lib/spacewar/spacewar.rb

Instance Method Summary collapse

Methods inherited from Chingu::GameObject

#adjust_gravity

Constructor Details

#initialize(options = {}) ⇒ Star

Returns a new instance of Star.



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/spacewar/spacewar.rb', line 184

def initialize(options={})
  super(:zorder => 1)
  @animation = Chingu::Animation.new(:file => media_path("Star.png"), :size => [25,25])
  @image = @animation.next
  self.color = Gosu::Color.new(0xff000000)
  self.color.red = rand(255 - 40) + 40
  self.color.green = rand(255 - 40) + 40
  self.color.blue = rand(255 - 40) + 40
  self.x = rand * $window.width
  self.y = rand * $window.height
  self.velocity_x = rand(10)
  self.velocity_y = rand(10)

  #
  # A cached bounding circle will not adapt to changes in size, but it will follow objects X / Y
  # Same is true for "cache_bounding_box"
  #
  cache_bounding_circle
end

Instance Method Details

#updateObject



204
205
206
207
208
209
210
211
# File 'lib/spacewar/spacewar.rb', line 204

def update
  @x %= $window.width # wrap around the screen
  @y %= $window.height

  # Move the animation forward by fetching the next frame and putting it into @image
  # @image is drawn by default by GameObject#draw
  @image = @animation.next
end