Class: Entity::Base
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
Methods inherited from Entity
#above, #accelerate, #all_state, #angle_to_vector, #as_json, #beneath, #bottom_cell_y, #cx, #cy, #destroy!, #direction, #direction_to, #doomed?, #draw, #draw_angle, #draw_animation, #draw_image, #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, #initialize, #left_cell_x, #move, #move_x, #move_y, #moving?, #next_to, #occupied_cells, #on_left, #on_right, #opaque, #pixel_x, #pixel_y, #release!, #right_cell_x, #sleep_now?, #slide_around, #slow_by, #slower_speed, #teleportable?, #to_s, #top_cell_y, #underfoot, #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, #to_s, #update_from_json
Constructor Details
This class inherits a constructor from Entity
Instance Method Details
#available? ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/game_2d/entity/base.rb', line 19 def available? return false unless space # Can't use entity.entities_obstructing() here, as that only # returns objects opaque to the receiver (the base). Players # aren't opaque to bases. We need to ensure there are no # solid (non-ghost) players occupying the space. # # This logic depends on the fact that anything transparent # to a base is also transparent to a player. If we ever allow # a base to go somewhere a player can't be, that's a problem. space.entities_overlapping(x, y).find_all do |e| e.is_a?(Player) && !e.is_a?(Entity::Ghost) end.empty? end |
#image_filename ⇒ Object
35 |
# File 'lib/game_2d/entity/base.rb', line 35 def image_filename; "base.png"; end |
#should_fall? ⇒ Boolean
8 |
# File 'lib/game_2d/entity/base.rb', line 8 def should_fall?; underfoot.empty?; end |
#update ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/game_2d/entity/base.rb', line 10 def update if should_fall? self.a = (direction || 180) + 180 else slow_by 1 end super end |