Module: Utils
- Defined in:
- lib/fantasy/utils.rb
Class Method Summary collapse
-
.collision?(actor_1, actor_2) ⇒ Boolean
https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection rubocop:disable Metrics/AbcSize.
- .collision_at?(actor, x, y) ⇒ Boolean
- .remap(value:, from_ini:, from_end:, to_ini:, to_end:) ⇒ Object
Class Method Details
.collision?(actor_1, actor_2) ⇒ Boolean
https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection rubocop:disable Metrics/AbcSize
6 7 8 9 10 11 12 13 |
# File 'lib/fantasy/utils.rb', line 6 def self.collision?(actor_1, actor_2) ( actor_1.position.x < (actor_2.position.x + actor_2.width) && (actor_1.position.x + actor_1.width) > actor_2.position.x && actor_1.position.y < (actor_2.position.y + actor_2.height) && actor_1.position.y + actor_1.height > actor_2.position.y ) end |
.collision_at?(actor, x, y) ⇒ Boolean
17 18 19 20 21 22 23 24 |
# File 'lib/fantasy/utils.rb', line 17 def self.collision_at?(actor, x, y) ( actor.position.x < x && (actor.position.x + actor.width) > x && actor.position.y < y && actor.position.y + actor.height > y ) end |
.remap(value:, from_ini:, from_end:, to_ini:, to_end:) ⇒ Object
26 27 28 |
# File 'lib/fantasy/utils.rb', line 26 def self.remap(value:, from_ini:, from_end:, to_ini:, to_end:) to_ini + (value - from_ini) * (to_end - to_ini) / (from_end - from_ini) end |