Class: RoadToRubykaigi::Sprite::Attacks
- Inherits:
-
Object
- Object
- RoadToRubykaigi::Sprite::Attacks
- Extended by:
- Forwardable
- Defined in:
- lib/road_to_rubykaigi/sprite/attack.rb
Constant Summary collapse
- ATTACK_COUNT =
13
Instance Method Summary collapse
- #add(player) ⇒ Object
- #build_buffer(offset_x:) ⇒ Object
- #enforce_boundary(map, offset_x:) ⇒ Object
- #remain_attack? ⇒ Boolean
- #simulate_physics ⇒ Object
Instance Method Details
#add(player) ⇒ Object
14 15 16 |
# File 'lib/road_to_rubykaigi/sprite/attack.rb', line 14 def add(player) @attacks << Attack.new(*player.attack_position, player.current_direction) end |
#build_buffer(offset_x:) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/road_to_rubykaigi/sprite/attack.rb', line 28 def build_buffer(offset_x:) buffer = Array.new(Map::VIEWPORT_HEIGHT) { Array.new(Map::VIEWPORT_WIDTH) { "" } } @attacks.each do |attack| bounding_box = attack.bounding_box relative_x = bounding_box[:x] - offset_x - 1 relative_y = bounding_box[:y] - 1 next if relative_x < 1 attack.characters.each_with_index do |chara, j| buffer[relative_y][relative_x+j] = chara end end buffer end |
#enforce_boundary(map, offset_x:) ⇒ Object
22 23 24 25 26 |
# File 'lib/road_to_rubykaigi/sprite/attack.rb', line 22 def enforce_boundary(map, offset_x:) @attacks.reject! do |attack| attack.reach_border?(map, offset_x: offset_x) end end |
#remain_attack? ⇒ Boolean
10 11 12 |
# File 'lib/road_to_rubykaigi/sprite/attack.rb', line 10 def remain_attack? @attacks.size < ATTACK_COUNT end |
#simulate_physics ⇒ Object
18 19 20 |
# File 'lib/road_to_rubykaigi/sprite/attack.rb', line 18 def simulate_physics @attacks.each(&:move) end |