Class: GamesParadise::EnemyTank
- Defined in:
- lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb
Instance Attribute Summary collapse
-
#alive ⇒ Object
Returns the value of attribute alive.
-
#cannon ⇒ Object
readonly
Returns the value of attribute cannon.
-
#head_east ⇒ Object
readonly
Returns the value of attribute head_east.
-
#head_north ⇒ Object
readonly
Returns the value of attribute head_north.
-
#head_south ⇒ Object
readonly
Returns the value of attribute head_south.
-
#head_west ⇒ Object
readonly
Returns the value of attribute head_west.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #cannon_timer(range) ⇒ Object
-
#draw ⇒ Object
draw.
-
#initialize(team) ⇒ EnemyTank
constructor
# === initialize ========================================================================= #.
-
#move ⇒ Object
# === move ========================================================================= #.
-
#reset ⇒ Object
# === reset ========================================================================= #.
- #sense_brick ⇒ Object
- #sense_teammate ⇒ Object
-
#update ⇒ Object
update.
Methods inherited from Tank
#move_east, #move_north, #move_south, #move_west, #nearest_obj, #sense_collide
Constructor Details
#initialize(team) ⇒ EnemyTank
#
initialize
#
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 15 def initialize(team) super() @tank_west = ::Gosu::Image.new('media/red_tank_west.png') @tank_east = ::Gosu::Image.new('media/red_tank_east.png') @tank_north = ::Gosu::Image.new('media/red_tank_north.png') @tank_south = ::Gosu::Image.new('media/red_tank_south.png') @x = [20, 372, 724].sample @y = 10 @head_west, @head_east, @head_north, @head_south = false, false, false, true @moving = false @first_move = true @cannon = Cannon.new(self) @game_start = Time.now @team = team @teammates = @team.enemy_team @player = @team.player reset end |
Instance Attribute Details
#alive ⇒ Object
Returns the value of attribute alive.
10 11 12 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 10 def alive @alive end |
#cannon ⇒ Object (readonly)
Returns the value of attribute cannon.
9 10 11 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 9 def cannon @cannon end |
#head_east ⇒ Object (readonly)
Returns the value of attribute head_east.
9 10 11 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 9 def head_east @head_east end |
#head_north ⇒ Object (readonly)
Returns the value of attribute head_north.
9 10 11 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 9 def head_north @head_north end |
#head_south ⇒ Object (readonly)
Returns the value of attribute head_south.
9 10 11 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 9 def head_south @head_south end |
#head_west ⇒ Object (readonly)
Returns the value of attribute head_west.
9 10 11 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 9 def head_west @head_west end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
9 10 11 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 9 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
9 10 11 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 9 def y @y end |
Instance Method Details
#cannon_timer(range) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 73 def cannon_timer(range) unless @cannon_active @get_time = Time.now @game_duration = (@get_time - @game_start).to_i @num = rand(range) @r = @game_duration % @num if @game_duration > 1 # fire once within num seconds, but not right at the start end if @r == 0 && @cannon_fired == false @cannon_active = true @cannon.fire @cannon_fired = true end if Time.now - @get_time > @num @cannon_active = false @cannon_fired = false end end |
#draw ⇒ Object
draw
116 117 118 119 120 121 122 123 124 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 116 def draw case true when @head_west; @tank_west.draw(@x, @y, 1) when @head_east; @tank_east.draw(@x, @y, 1) when @head_north; @tank_north.draw(@x, @y, 1) when @head_south; @tank_south.draw(@x, @y, 1) end @cannon.draw end |
#move ⇒ Object
#
move
#
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 48 def move unless @moving @time_stamp = Time.now if @first_move # move away from the generation site. @duration = 1.5 @option = 3 @first_move = false else @duration = rand * 1.5 @option = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3].sample end end if Time.now - @time_stamp <= @duration case @option when 1; move_west when 2; move_east when 3; move_south when 4; move_north end @moving = true else @moving = false end end |
#reset ⇒ Object
#
reset
#
37 38 39 40 41 42 43 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 37 def reset super() @r = nil @cannon_active = false @cannon_fired = false @alive = true end |
#sense_brick ⇒ Object
98 99 100 101 102 103 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 98 def sense_brick unless @player.bricks.empty? nearest_brick = nearest_obj(@player.bricks) end sense_collide(nearest_brick) end |
#sense_teammate ⇒ Object
91 92 93 94 95 96 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 91 def sense_teammate if @teammates.length >= 2 # need at least 2 teammates nearest_tank = nearest_obj(@teammates) sense_collide(nearest_tank) end end |
#update ⇒ Object
update
106 107 108 109 110 111 112 113 |
# File 'lib/games_paradise/gui/gosu/battle_city/enemy_tank.rb', line 106 def update move @cannon.update cannon_timer(3..5) sense_collide(@player) sense_teammate sense_brick end |