Class: GamesAndRpgParadise::BattleCity::Tank
- Inherits:
-
Object
- Object
- GamesAndRpgParadise::BattleCity::Tank
- Defined in:
- lib/games_and_rpg_paradise/gui/gosu/battle_city/tank.rb
Instance Method Summary collapse
-
#initialize ⇒ Tank
constructor
# === initialize ========================================================================= #.
-
#move_east ⇒ Object
# === move_east ========================================================================= #.
-
#move_north ⇒ Object
# === move_north ========================================================================= #.
-
#move_south ⇒ Object
move_south.
-
#move_west ⇒ Object
# === move_west ========================================================================= #.
-
#nearest_obj(objects) ⇒ Object
nearest_obj.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#sense_collide(obj) ⇒ Object
sense_collide.
Constructor Details
#initialize ⇒ Tank
#
initialize
#
14 15 16 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/tank.rb', line 14 def initialize reset end |
Instance Method Details
#move_east ⇒ Object
#
move_east
#
43 44 45 46 47 48 49 50 51 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/tank.rb', line 43 def move_east @head_west, @head_east, @head_north, @head_south = false, true, false, false @x += 1.3 @x -= 5 if @x + 56 > 800 if @collide_obj_left @x -= 5 @collide_obj_right, @collide_obj_left, @collide_obj_bottom, @collide_obj_top = [false] * 4 end end |
#move_north ⇒ Object
#
move_north
#
56 57 58 59 60 61 62 63 64 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/tank.rb', line 56 def move_north @head_west, @head_east, @head_north, @head_south = false, false, true, false @y -= 1.3 @y += 5 if @y < 0 if @collide_obj_bottom @y += 5 @collide_obj_right, @collide_obj_left, @collide_obj_bottom, @collide_obj_top = [false] * 4 end end |
#move_south ⇒ Object
move_south
67 68 69 70 71 72 73 74 75 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/tank.rb', line 67 def move_south @head_west, @head_east, @head_north, @head_south = false, false, false, true @y += 1.3 @y -= 5 if @y + 56 > 710 if @collide_obj_top @y -= 5 @collide_obj_right, @collide_obj_left, @collide_obj_bottom, @collide_obj_top = [false] * 4 end end |
#move_west ⇒ Object
#
move_west
#
30 31 32 33 34 35 36 37 38 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/tank.rb', line 30 def move_west @head_west, @head_east, @head_north, @head_south = true, false, false, false @x -= 1.3 @x += 5 if @x < 0 if @collide_obj_right @x += 5 @collide_obj_right, @collide_obj_left, @collide_obj_bottom, @collide_obj_top = [false] * 4 end end |
#nearest_obj(objects) ⇒ Object
nearest_obj
78 79 80 81 82 83 84 85 86 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/tank.rb', line 78 def nearest_obj(objects) distances = [] centre_loc = 20 if objects[0].class == Brick # centre location of brick centre_loc = 28 if objects[0].class.superclass == Tank objects.each { |obj| distances << ::Gosu.distance(obj.x + centre_loc, obj.y + centre_loc, @x + 28, @y + 28) } distances.delete(0) # not including self in team situation nearest_obj_index = distances.index(distances.min) objects[nearest_obj_index] end |
#reset ⇒ Object
#
reset
#
21 22 23 24 25 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/tank.rb', line 21 def reset @collide_obj_left = false @collide_obj_top = false @collide_obj_right = false end |
#sense_collide(obj) ⇒ Object
sense_collide
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/games_and_rpg_paradise/gui/gosu/battle_city/tank.rb', line 89 def sense_collide(obj) unless obj.nil? ox = obj.x oy = obj.y ow = oh = 40 if obj.class == Brick # obj width and height ow = oh = 56 if obj.class.superclass == Tank if oy + oh > @y && oy < @y + 56 && ox < @x && ox + ow > @x @collide_obj_right = true @x += 1 # remove from intersection instantly end if oy + oh > @y && oy < @y + 56 && ox < @x + 56 && ox + ow > @x + 56 @collide_obj_left = true @x -= 1 end if ox + ow > @x && ox < @x + 56 && oy < @y && oy + oh > @y @collide_obj_bottom = true @y += 1 end if ox + ow > @x && ox < @x + 56 && oy < @y + 56 && oy + oh > @y + 56 @collide_obj_top = true @y -= 1 end end end |