Skip to content

Commit

Permalink
+ city lives
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed May 10, 2009
1 parent ec8d1a9 commit 46246e3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
3 changes: 3 additions & 0 deletions lib/city.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class City < Moveable

include EarthOriented
include Lives

def initialize window
super window
Expand All @@ -11,6 +12,8 @@ def initialize window

@shape = CP::Shape::Circle.new CP::Body.new(10.0, 75.0), 11.0, CP::Vec2.new(0, 0)
@shape.collision_type = :city

self.lives = 100
end

def validate_position
Expand Down
15 changes: 5 additions & 10 deletions lib/game_window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,10 @@ def setup_collisions
# just push it away
end
@space.add_collision_func :nuke, :ambient, &nil
@space.add_collision_func :bullet, :ambient, &nil

@space.add_collision_func :city, :earth, &nil

# @space.add_collision_func :bullet, :bullet do |bullet_shape1, bullet_shape2|
# remove bullet_shape1
# remove bullet_shape2
# end

@space.add_collision_func :ship, :earth do |ship_shape, earth_shape| end
@space.add_collision_func :ship, :nuke do |ship_shape, nuke_shape|
small_explosion nuke_shape
Expand All @@ -91,8 +87,7 @@ def setup_collisions
end

@space.add_collision_func :city, :explosion do |city_shape, explosion_shape|
remove city_shape
# TODO add points
@moveables.each { |city| city.shape == city_shape && city.hit! }
end
@space.add_collision_func :ship, :explosion do |ship_shape, explosion_shape|
@players.each { |player| player.shape == ship_shape && player.hit! }
Expand All @@ -111,7 +106,7 @@ def register moveable
# Note: Use as follows in a Moveable.
#
# def destroy
# Thread.new do
# threaded do
# 5.times { sleep 0.1; animate_explosion }
# @window.unregister self
# end
Expand Down Expand Up @@ -163,7 +158,7 @@ def add_player2
Gosu::Button::KbU => :away,
Gosu::Button::KbJ => :closer,
Gosu::Button::KbSpace => :shoot,
Gosu::Button::Kb2 => :revive
Gosu::Button::Kb7 => :revive
)

@players << @player2
Expand All @@ -184,7 +179,7 @@ def add_player3
Gosu::Button::KbUp => :away,
Gosu::Button::KbDown => :closer,
Gosu::Button::KbRightAlt => :shoot,
Gosu::Button::Kb3 => :revive
Gosu::Button::Kb0 => :revive
)

@players << @player3
Expand Down
2 changes: 1 addition & 1 deletion lib/lives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def lives= lives

def hit!
@lives -= 1
@score -= 1
@score -= 1 if @score
destroy if @lives <= 0
end

Expand Down
2 changes: 1 addition & 1 deletion lib/short_lived.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize window

threaded do
sleep self.lifetime
window.unregister self
self.destroy
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/small_explosion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize window

@image = Gosu::Image::load_tiles window, "media/small_explosion.png", 20, 20, false

@shape = CP::Shape::Circle.new CP::Body.new(10_000, 10_000), 5.0, CP::Vec2.new(0, 0)
@shape = CP::Shape::Circle.new CP::Body.new(1_000, 1_000), 5.0, CP::Vec2.new(0, 0)

@shape.collision_type = :explosion
end
Expand Down

0 comments on commit 46246e3

Please sign in to comment.