public
Description: A simple clone of Asteroids written in Ruby using the Gosu game development framework
Homepage:
Clone URL: git://github.com/robc/gosu-asteroids.git
gosu-asteroids / bullet.rb
100644 39 lines (30 sloc) 0.91 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'game_object'
require 'game_constants'
require 'bounds'
 
class Bullet < GameObject
  include GameConstants
  
  attr_reader :bullet_life
  
  def initialize(bullet_image, bounding_sphere_radius)
    super(bullet_image, bounding_sphere_radius)
 
    @bullet_life = bullet_life
  end
 
  def update
    super
    @bullet_life = @bullet_life - 1
  end
 
  def prepare_bullet(bullet_life, location_x, location_y, velocity_x, velocity_y, angle)
    @bullet_life = bullet_life
    @location_x = location_x
    @location_y = location_y
    @velocity_x = velocity_x
    @velocity_y = velocity_y
    @angle = angle
    
    set_forward_velocity(BulletVelocity)
  end
  
  private
  def set_forward_velocity(velocity)
    angle_in_rad = Conversions.transform_degrees_to_radians(@angle - 90)
    
    @velocity_x = @velocity_x + Math.cos(angle_in_rad)
    @velocity_y = @velocity_y + Math.sin(angle_in_rad)
  end
end