Class: Entity::Teleporter
- Defined in:
- lib/game_2d/entity/teleporter.rb
Constant Summary
Constants included from EntityConstants
EntityConstants::CELL_WIDTH_IN_PIXELS, EntityConstants::MAX_VELOCITY, EntityConstants::PIXEL_WIDTH, EntityConstants::WIDTH
Instance Attribute Summary
Attributes inherited from Entity
#a, #moving, #space, #x, #x_vel, #y, #y_vel
Instance Method Summary collapse
- #destroy! ⇒ Object
- #draw_zorder ⇒ Object
- #image_filename ⇒ Object
- #should_fall? ⇒ Boolean
- #to_s ⇒ Object
- #update ⇒ Object
Methods inherited from Entity
#accelerate, #all_state, #angle_to_vector, #as_json, #bottom_cell_y, #direction_to, #doomed?, #draw, #draw_angle, #drop_diagonal, #empty_above?, #empty_on_left?, #empty_on_right?, #empty_underneath?, #entities_obstructing, #going_past_entity, #grab!, #grabbed?, #harmed_by, #i_hit, #initialize, #left_cell_x, #move, #move_x, #move_y, #moving?, #next_to, #occupied_cells, #opaque, #pixel_x, #pixel_y, #release!, #right_cell_x, #sleep_now?, #top_cell_y, #update_from_json, #vector_to_angle, #wake!, #warp
Methods included from ClassMethods
#bottom_cell_y_at, #constrain_velocity, #left_cell_x_at, #right_cell_x_at, #top_cell_y_at
Methods included from Transparency
Methods included from Registerable
#nullsafe_registry_id, #registry_id, #registry_id=, #registry_id?, #registry_id_safe
Methods included from Serializable
#<=>, #==, #all_state, as_json, #eql?, from_json, #hash, #to_json, #update_from_json
Constructor Details
This class inherits a constructor from Entity
Instance Method Details
#destroy! ⇒ Object
30 31 32 |
# File 'lib/game_2d/entity/teleporter.rb', line 30 def destroy! # destroy destination end |
#draw_zorder ⇒ Object
36 |
# File 'lib/game_2d/entity/teleporter.rb', line 36 def draw_zorder; ZOrder::Teleporter end |
#image_filename ⇒ Object
34 |
# File 'lib/game_2d/entity/teleporter.rb', line 34 def image_filename; "tele.gif"; end |
#should_fall? ⇒ Boolean
7 |
# File 'lib/game_2d/entity/teleporter.rb', line 7 def should_fall?; false; end |
#to_s ⇒ Object
38 39 40 41 42 43 |
# File 'lib/game_2d/entity/teleporter.rb', line 38 def to_s destinations = space.possessions(self).collect do |d| "#{d.x}x#{d.y}" end.join(', ') "#{super} => [#{destinations}]" end |
#update ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/game_2d/entity/teleporter.rb', line 9 def update space.entities_overlapping(x, y).each do |overlap| next if overlap == self next if (overlap.x - x).abs > WIDTH/2 next if (overlap.y - y).abs > HEIGHT/2 dest = space.possessions(self) case dest.size when 1 then dest = dest.first if overlap.entities_obstructing(dest.x, dest.y).empty? overlap.warp(dest.x, dest.y) overlap.wake! end when 0 then $stderr.puts "#{self}: No destination" else $stderr.puts "#{self}: Multiple destinations: #{dest.inspect}" end end end |