Class: Entity::OwnedEntity
- Defined in:
- lib/game_2d/entity/owned_entity.rb
Direct Known Subclasses
Constant Summary
Constants included from EntityConstants
EntityConstants::CELL_WIDTH_IN_PIXELS, EntityConstants::MAX_VELOCITY, EntityConstants::PIXEL_WIDTH, EntityConstants::WIDTH
Instance Attribute Summary collapse
-
#owner_id ⇒ Object
Returns the value of attribute owner_id.
Attributes inherited from Entity
#a, #moving, #space, #x, #x_vel, #y, #y_vel
Instance Method Summary collapse
- #all_state ⇒ Object
- #as_json ⇒ Object
- #owner ⇒ Object
- #owner=(new_owner) ⇒ Object
- #update_from_json(json) ⇒ Object
Methods inherited from Entity
#accelerate, #angle_to_vector, #bottom_cell_y, #destroy!, #direction_to, #doomed?, #draw, #draw_angle, #draw_zorder, #drop_diagonal, #empty_above?, #empty_on_left?, #empty_on_right?, #empty_underneath?, #entities_obstructing, #going_past_entity, #grab!, #grabbed?, #harmed_by, #i_hit, #image_filename, #initialize, #left_cell_x, #move, #move_x, #move_y, #moving?, #next_to, #occupied_cells, #opaque, #pixel_x, #pixel_y, #release!, #right_cell_x, #should_fall?, #sleep_now?, #to_s, #top_cell_y, #update, #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
#<=>, #==, as_json, #eql?, from_json, #hash, #to_json, #to_s
Constructor Details
This class inherits a constructor from Entity
Instance Attribute Details
#owner_id ⇒ Object
Returns the value of attribute owner_id.
6 7 8 |
# File 'lib/game_2d/entity/owned_entity.rb', line 6 def owner_id @owner_id end |
Instance Method Details
#all_state ⇒ Object
22 |
# File 'lib/game_2d/entity/owned_entity.rb', line 22 def all_state; super.push(owner_id); end |
#as_json ⇒ Object
23 |
# File 'lib/game_2d/entity/owned_entity.rb', line 23 def as_json; super.merge! :owner => owner_id; end |
#owner ⇒ Object
13 14 15 16 |
# File 'lib/game_2d/entity/owned_entity.rb', line 13 def owner fail "Can't look up owner when not in a space" unless @space @space[@owner_id] end |
#owner=(new_owner) ⇒ Object
18 19 20 |
# File 'lib/game_2d/entity/owned_entity.rb', line 18 def owner=(new_owner) self.owner_id = new_owner.nullsafe_registry_id end |
#update_from_json(json) ⇒ Object
24 25 26 27 |
# File 'lib/game_2d/entity/owned_entity.rb', line 24 def update_from_json(json) self.owner_id = json[:owner] if json[:owner] super end |