Class: GamesAndRpgParadise::EnemyTeam

Inherits:
Object
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_team.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(player) ⇒ EnemyTeam

initialize



13
14
15
16
17
18
19
20
21
22
# File 'lib/games_and_rpg_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_teamObject (readonly)

Returns the value of attribute enemy_team.



9
10
11
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_team.rb', line 9

def enemy_team
  @enemy_team
end

#explodedObject

Returns the value of attribute exploded.



10
11
12
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_team.rb', line 10

def exploded
  @exploded
end

#loc_xObject

Returns the value of attribute loc_x.



10
11
12
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_team.rb', line 10

def loc_x
  @loc_x
end

#loc_yObject

Returns the value of attribute loc_y.



10
11
12
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_team.rb', line 10

def loc_y
  @loc_y
end

#playerObject (readonly)

Returns the value of attribute player.



9
10
11
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_team.rb', line 9

def player
  @player
end

#time_hitObject

Returns the value of attribute time_hit.



10
11
12
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_team.rb', line 10

def time_hit
  @time_hit
end

Instance Method Details

#drawObject

draw



57
58
59
60
61
62
63
64
65
66
# File 'lib/games_and_rpg_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_tankObject

generate_tank



25
26
27
28
29
# File 'lib/games_and_rpg_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_and_rpg_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_aliveObject



45
46
47
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_team.rb', line 45

def select_alive
  @enemy_team.select! { |tank| tank.alive }
end

#updateObject

update



50
51
52
53
54
# File 'lib/games_and_rpg_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