Class: GamesAndRpgParadise::EnemyTank
- Inherits:
-
Tank
- Object
- Tank
- GamesAndRpgParadise::EnemyTank
- Defined in:
- lib/games_and_rpg_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.
Constructor Details
#initialize(team) ⇒ EnemyTank
#
initialize
#
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_tank.rb', line 16 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.
11 12 13 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_tank.rb', line 11 def alive @alive end |
#cannon ⇒ Object (readonly)
Returns the value of attribute cannon.
9 10 11 |
# File 'lib/games_and_rpg_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_and_rpg_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_and_rpg_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_and_rpg_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_and_rpg_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_and_rpg_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_and_rpg_paradise/gui/gosu/battle_city/enemy_tank.rb', line 9 def y @y end |
Instance Method Details
#cannon_timer(range) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_tank.rb', line 74 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
117 118 119 120 121 122 123 124 125 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_tank.rb', line 117 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
#
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_tank.rb', line 49 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
#
38 39 40 41 42 43 44 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_tank.rb', line 38 def reset super() @r = nil @cannon_active = false @cannon_fired = false @alive = true end |
#sense_brick ⇒ Object
99 100 101 102 103 104 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_tank.rb', line 99 def sense_brick unless @player.bricks.empty? nearest_brick = nearest_obj(@player.bricks) end sense_collide(nearest_brick) end |
#sense_teammate ⇒ Object
92 93 94 95 96 97 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_tank.rb', line 92 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
107 108 109 110 111 112 113 114 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/enemy_tank.rb', line 107 def update move @cannon.update cannon_timer(3..5) sense_collide(@player) sense_teammate sense_brick end |