Class: Asteroids::MissilePhysics
- Defined in:
- lib/asteroids/missile/missile_physics.rb
Instance Method Summary collapse
- #calculate_points(asteroid) ⇒ Object
- #detect_collision? ⇒ Boolean
-
#initialize(game_object, object_pool) ⇒ MissilePhysics
constructor
A new instance of MissilePhysics.
- #update ⇒ Object
Methods inherited from Component
Constructor Details
#initialize(game_object, object_pool) ⇒ MissilePhysics
Returns a new instance of MissilePhysics.
4 5 6 7 |
# File 'lib/asteroids/missile/missile_physics.rb', line 4 def initialize(game_object, object_pool) super(game_object) @object_pool = object_pool end |
Instance Method Details
#calculate_points(asteroid) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/asteroids/missile/missile_physics.rb', line 30 def calculate_points(asteroid) case asteroid.radius when 45 20 when 30 50 when 17.5 100 end end |
#detect_collision? ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/asteroids/missile/missile_physics.rb', line 19 def detect_collision? @object_pool.objects.each do |other_object| if other_object.is_a? Asteroids::Asteroid and Utils.collide(object, other_object) object.ship.add_score(calculate_points(other_object)) return true end end return false end |
#update ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/asteroids/missile/missile_physics.rb', line 9 def update object.mark_for_removal if detect_collision? object.x += Gosu::offset_x(object.angle, 10) + object.vel_x object.y += Gosu::offset_y(object.angle, 10) + object.vel_y object.x %= 800 object.y %= 600 object.lifespan -= 0.1 object.mark_for_removal if object.lifespan <= 0 end |