Module: AdventureRL::Modifiers::Gravity
- Defined in:
- lib/AdventureRL/Modifiers/Gravity.rb
Constant Summary collapse
- DEFAULT_GRAVITY_SETTINGS =
include AdventureRL::Modifiers::Velocity # NOTE: This modifier relies on Modifiers::Velocity
Settings.new( gravity_force: 1000.0, gravity_direction: { x: 0.0, y: 1.0 } )
Instance Method Summary collapse
-
#gravitize ⇒ Object
Apply gravitational force.
- #initialize(settings = {}) ⇒ Object
-
#move ⇒ Object
Overwrite Modifiers::Velocity#move, so we can update the gravity.
Instance Method Details
#gravitize ⇒ Object
Apply gravitational force.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/AdventureRL/Modifiers/Gravity.rb', line 27 def gravitize previous_position = get_position.dup get_gravity_directions.each do |axis, multiplier| next if (@has_increased_velocity_for[axis]) set_position axis => (get_position(axis) + multiplier) unless (multiplier == 0) if (in_collision?) @velocity[axis] = 0.0 else #if ([0, @gravity_direction[axis].sign].include? get_velocity(axis).sign) increase_velocity_by( axis => ((@gravity_force * @gravity_direction[axis]) * @velocity_deltatime.dt), no_quick_turn_around: true ) end set_position previous_position end end |
#initialize(settings = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/AdventureRL/Modifiers/Gravity.rb', line 14 def initialize settings = {} @settings = DEFAULT_GRAVITY_SETTINGS.merge settings @gravity = 0.0 @gravity_force = @settings.get :gravity_force @gravity_direction = @settings.get :gravity_direction #@max_velocity = @max_velocity_original.dup super @settings @max_velocity_original[:y] = Float::INFINITY @max_velocity[:y] = @max_velocity_original[:y].dup @velocity_decay[:y] = 0 end |
#move ⇒ Object
Overwrite Modifiers::Velocity#move, so we can update the gravity.
46 47 48 49 |
# File 'lib/AdventureRL/Modifiers/Gravity.rb', line 46 def move super gravitize end |