Class: GamesParadise::EnemyTeam
- Inherits:
-
Object
- Object
- GamesParadise::EnemyTeam
- Defined in:
- lib/games_paradise/gui/gosu/battle_city/enemy_team.rb
Instance Attribute Summary collapse
-
#enemy_team ⇒ Object
readonly
Returns the value of attribute enemy_team.
-
#exploded ⇒ Object
Returns the value of attribute exploded.
-
#loc_x ⇒ Object
Returns the value of attribute loc_x.
-
#loc_y ⇒ Object
Returns the value of attribute loc_y.
-
#player ⇒ Object
readonly
Returns the value of attribute player.
-
#time_hit ⇒ Object
Returns the value of attribute time_hit.
Instance Method Summary collapse
-
#draw ⇒ Object
draw.
-
#generate_tank ⇒ Object
generate_tank.
- #generate_tank_timer(sec) ⇒ Object
-
#initialize(player) ⇒ EnemyTeam
constructor
initialize.
- #select_alive ⇒ Object
-
#update ⇒ Object
update.
Constructor Details
#initialize(player) ⇒ EnemyTeam
initialize
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_team.rb', line 13 def initialize(player) @player = player @game_start = Time.now @generating_tank = false @enemy_team = [] @count = 0 @explosion = Gosu::Image.load_tiles("media/tank_explode.png", 72, 72) @exploded = false @time_hit = nil end |
Instance Attribute Details
#enemy_team ⇒ Object (readonly)
Returns the value of attribute enemy_team.
9 10 11 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_team.rb', line 9 def enemy_team @enemy_team end |
#exploded ⇒ Object
Returns the value of attribute exploded.
10 11 12 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_team.rb', line 10 def exploded @exploded end |
#loc_x ⇒ Object
Returns the value of attribute loc_x.
10 11 12 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_team.rb', line 10 def loc_x @loc_x end |
#loc_y ⇒ Object
Returns the value of attribute loc_y.
10 11 12 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_team.rb', line 10 def loc_y @loc_y end |
#player ⇒ Object (readonly)
Returns the value of attribute player.
9 10 11 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_team.rb', line 9 def player @player end |
#time_hit ⇒ Object
Returns the value of attribute time_hit.
10 11 12 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_team.rb', line 10 def time_hit @time_hit end |
Instance Method Details
#draw ⇒ Object
draw
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_team.rb', line 57 def draw @enemy_team.each { |tank| tank.draw } if @exploded # Show the dead tank explosion img = @explosion[Gosu::milliseconds / 40 % @explosion.size] img.draw(@loc_x - 8, @loc_y - 8, 2) # Minus is for adjusting the explosion image if Time.now - @time_hit > 0.5 @exploded = false end end end |
#generate_tank ⇒ Object
generate_tank
25 26 27 28 29 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_team.rb', line 25 def generate_tank @tank = EnemyTank.new(self) @enemy_team << @tank @count += 1 end |
#generate_tank_timer(sec) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_team.rb', line 31 def generate_tank_timer(sec) @game_duration = (Time.now - @game_start).to_i @r = @game_duration % sec if @r == 0 && @generating_tank == false if @count <= 49 generate_tank @generating_tank = true end end if @r != 0 @generating_tank = false end end |
#select_alive ⇒ Object
45 46 47 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_team.rb', line 45 def select_alive @enemy_team.select! { |tank| tank.alive } end |
#update ⇒ Object
update
50 51 52 53 54 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_team.rb', line 50 def update generate_tank_timer(3) select_alive # only show live tanks @enemy_team.each { |tank| tank.update } end |