Class: Kawaii::Node
- Inherits:
-
Object
- Object
- Kawaii::Node
- Defined in:
- lib/kawaii/node.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#gravity ⇒ Object
Returns the value of attribute gravity.
-
#position ⇒ Object
Returns the value of attribute position.
-
#rotation ⇒ Object
Returns the value of attribute rotation.
-
#static ⇒ Object
Returns the value of attribute static.
-
#velocity ⇒ Object
Returns the value of attribute velocity.
Instance Method Summary collapse
- #add_child(node) ⇒ Object
- #count ⇒ Object
- #draw ⇒ Object
- #has_children? ⇒ Boolean
-
#initialize(static = false, position = Vector2.new, velocity = Vector2.new, gravity = Kawaii::Vector2.new(0, Kawaii::GRAVITY)) ⇒ Node
constructor
A new instance of Node.
- #remove_child(node) ⇒ Object
- #update(dt) ⇒ Object
Constructor Details
#initialize(static = false, position = Vector2.new, velocity = Vector2.new, gravity = Kawaii::Vector2.new(0, Kawaii::GRAVITY)) ⇒ Node
Returns a new instance of Node.
6 7 8 9 10 11 12 13 |
# File 'lib/kawaii/node.rb', line 6 def initialize static = false, position = Vector2.new, velocity = Vector2.new, gravity = Kawaii::Vector2.new(0, Kawaii::GRAVITY) @children = [] @rotation = 0.0 @position = position @velocity = velocity @gravity = gravity @static = static end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
4 5 6 |
# File 'lib/kawaii/node.rb', line 4 def children @children end |
#gravity ⇒ Object
Returns the value of attribute gravity.
4 5 6 |
# File 'lib/kawaii/node.rb', line 4 def gravity @gravity end |
#position ⇒ Object
Returns the value of attribute position.
4 5 6 |
# File 'lib/kawaii/node.rb', line 4 def position @position end |
#rotation ⇒ Object
Returns the value of attribute rotation.
4 5 6 |
# File 'lib/kawaii/node.rb', line 4 def rotation @rotation end |
#static ⇒ Object
Returns the value of attribute static.
4 5 6 |
# File 'lib/kawaii/node.rb', line 4 def static @static end |
#velocity ⇒ Object
Returns the value of attribute velocity.
4 5 6 |
# File 'lib/kawaii/node.rb', line 4 def velocity @velocity end |
Instance Method Details
#add_child(node) ⇒ Object
23 24 25 |
# File 'lib/kawaii/node.rb', line 23 def add_child node @children.push(node) end |
#count ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/kawaii/node.rb', line 15 def count sum = 1 @children.each do |child| sum += child.count end sum end |
#draw ⇒ Object
56 57 58 59 60 |
# File 'lib/kawaii/node.rb', line 56 def draw @children.each do |child| child.draw end end |
#has_children? ⇒ Boolean
31 32 33 |
# File 'lib/kawaii/node.rb', line 31 def has_children? @children.size > 0 end |
#remove_child(node) ⇒ Object
27 28 29 |
# File 'lib/kawaii/node.rb', line 27 def remove_child node @children.delete(node) end |
#update(dt) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/kawaii/node.rb', line 35 def update dt if self.class.method_defined? :before_update before_update dt end if !@static @velocity.x += @gravity.x * dt @velocity.y += @gravity.y * dt @position.x += @velocity.x * dt @position.y += @velocity.y * dt end @children.each do |child| child.update dt end if self.class.method_defined? :after_update after_update dt end end |