Skip to content

Commit

Permalink
bonus perks wear off
Browse files Browse the repository at this point in the history
  • Loading branch information
txusty committed Jun 17, 2009
1 parent 510c654 commit 09e8c2f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
4 changes: 3 additions & 1 deletion classes/bonus/bonus.rb
@@ -1,10 +1,12 @@
class Bonus
attr_reader :x, :y, :perk
attr_reader :x, :y, :width, :height, :perk, :duration
@@bonuses = Array.new
def initialize(window,x,y)
@x, @y = x, y
@width, @height = 5,5
@window = window
@perk = nil
@duration = 4
@@bonuses << self
end

Expand Down
1 change: 1 addition & 0 deletions classes/bonus/double_speed_bonus.rb
Expand Up @@ -4,6 +4,7 @@ def initialize(window,x,y)
super
@img = Gosu::Image.new(@window, "media/double_speed_bonus.png", true)
@perk = DoubleSpeedPerk
@duration = 3
end

private
Expand Down
1 change: 1 addition & 0 deletions classes/bonus/triple_shot_bonus.rb
Expand Up @@ -4,6 +4,7 @@ def initialize(window,x,y)
super
@img = Gosu::Image.new(@window, "media/triple_shot_bonus.png", true)
@perk = TripleShotPerk
@duration = 2
end

private
Expand Down
12 changes: 9 additions & 3 deletions classes/game_window.rb
Expand Up @@ -87,6 +87,12 @@ def check_collisions
player_bullet.destroy
end
end
#Bonus.all.each do |bonus|
# if player_bullet.collides?(bonus) then
# player_bullet.destroy
# bonus.destroy
# end
#end
end
Bonus.all.each do |bonus|
if bonus.collides?(@player) then
Expand All @@ -100,15 +106,15 @@ def check_collisions
end

def initialize_events
double_shot_bonus_event = RandomEvent.new(15,0.2) do
double_shot_bonus_event = RandomEvent.new(5,0.2) do
DoubleShotBonus.new(self,rand * @width, -10)
end

triple_shot_bonus_event = RandomEvent.new(15,0.1) do
triple_shot_bonus_event = RandomEvent.new(5,0.1) do
TripleShotBonus.new(self, rand * width, -10)
end

double_speed_bonus_event = RandomEvent.new(15,0.3) do
double_speed_bonus_event = RandomEvent.new(5,0.3) do
DoubleSpeedBonus.new(self, rand * width, -10)
end

Expand Down
21 changes: 20 additions & 1 deletion classes/player.rb
Expand Up @@ -8,7 +8,9 @@ def initialize(window,options = {})
@height = 30
@x = @y = 0
@health = 2

@perk = DefaultPerk.new
@old_perk = @perk
@last_shot = Gosu::milliseconds

@image = Gosu::Image.new(@window, "media/ship.png", true)
Expand Down Expand Up @@ -72,7 +74,16 @@ def hurt(damage)
end

def add_bonus(bonus)
@old_perk = @perk
@perk = bonus.perk.new
_perk_wear_off_after(bonus.duration)
end

def remove_bonus
@perk = @old_perk
end
def reset_all_perks
@perk = DefaultPerk.new
end

def score(points)
Expand All @@ -99,10 +110,18 @@ def _shoot(type)
NormalBullet.new(@window,@x + (@width / 4), @y, :left)
NormalBullet.new(@window,@x + (@width / 2), @y)
NormalBullet.new(@window,(@x + @width) - (@width / 4), @y, :right)
Logger.log("Shot double bullet", self)
Logger.log("Shot triple bullet", self)
end
@last_shot = Gosu::milliseconds
end

def _perk_wear_off_after(seconds)
e = ScheduledEvent.new(seconds) do
reset_all_perks
e.destroy
end

end

end

0 comments on commit 09e8c2f

Please sign in to comment.