Module: Chingu::Traits::Vectors
- Defined in:
- lib/vector.rb,
lib/actual_vectors.rb
Defined Under Namespace
Modules: ClassMethods Classes: Vector
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :position => [0, 0], :speed => [0, 0], :hastening => [0, 0] }
Instance Attribute Summary collapse
-
#hastening ⇒ Object
Hasteing (acceleration) of game object with [x,y] in pixels per second^2.
-
#last_position ⇒ Object
readonly
Position of game object in last tick.
-
#position ⇒ Object
Position of game object with [x,y] in pixel.
-
#speed ⇒ Object
Speed of game object with [x,y] in pixels per second.
Instance Method Summary collapse
- #draw_trait ⇒ Object
-
#moved? ⇒ Boolean
Checks if game object hast moved since last tick.
-
#setup_trait(options) ⇒ Object
Sets up the trait.
-
#stop ⇒ Object
Stopes the game object.
-
#stopped? ⇒ Boolean
Checks if game object is on move are hastening.
-
#update_trait ⇒ Object
Moves the game object apropriate to the time that passed since last tick.
Instance Attribute Details
#hastening ⇒ Object
Hasteing (acceleration) of game object with [x,y] in pixels per second^2
28 29 30 |
# File 'lib/actual_vectors.rb', line 28 def hastening @hastening end |
#last_position ⇒ Object (readonly)
Position of game object in last tick
31 32 33 |
# File 'lib/actual_vectors.rb', line 31 def last_position @last_position end |
#position ⇒ Object
Position of game object with [x,y] in pixel
22 23 24 |
# File 'lib/actual_vectors.rb', line 22 def position @position end |
#speed ⇒ Object
Speed of game object with [x,y] in pixels per second
25 26 27 |
# File 'lib/actual_vectors.rb', line 25 def speed @speed end |
Instance Method Details
#draw_trait ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/actual_vectors.rb', line 85 def draw_trait if [:vectors][:debug] x = position.x y = position.y #draw speed $window.draw_line(x, y, Gosu::Color::GREEN, x+speed.x, y+speed.y, Gosu::Color::GREEN, 1) #draw hastening $window.draw_line(x, y, Gosu::Color::CYAN, x+hastening.x, y+hastening.y, Gosu::Color::CYAN, 1) end super end |
#moved? ⇒ Boolean
Checks if game object hast moved since last tick
116 117 118 |
# File 'lib/actual_vectors.rb', line 116 def moved? last_position != position end |
#setup_trait(options) ⇒ Object
Sets up the trait. Possible options are position, speed and hastening (with defaults [0,0] respectively)
37 38 39 40 41 42 43 44 |
# File 'lib/actual_vectors.rb', line 37 def setup_trait puts "setup trait in vectors called" [:vectors] = DEFAULT_OPTIONS.merge() self.position = [:vectors][:position] self.speed = [:vectors][:speed] self.hastening = [:vectors][:hastening] super end |
#stop ⇒ Object
Stopes the game object. Speed = 0 and hastening = 0
100 101 102 103 |
# File 'lib/actual_vectors.rb', line 100 def stop self.speed = [0, 0] self.hastening = [0, 0] end |
#stopped? ⇒ Boolean
Checks if game object is on move are hastening
108 109 110 111 |
# File 'lib/actual_vectors.rb', line 108 def stopped? speed == [0, 0] hastening == [0, 0] end |
#update_trait ⇒ Object
Moves the game object apropriate to the time that passed since last tick
75 76 77 78 79 80 81 82 83 |
# File 'lib/actual_vectors.rb', line 75 def update_trait if [:vectors][:apply] seconds = $window.milliseconds_since_last_tick / 1000.0 @last_position = position self.position = position + (speed * seconds) self.speed = speed + (hastening * seconds) end super end |