Class: Chingu::GameObject
- Inherits:
-
BasicGameObject
- Object
- BasicGameObject
- Chingu::GameObject
- Defined in:
- lib/chingu/game_object.rb
Overview
GameObject is our BasisGameObject (class with framespecific stuff)
On top of that, it encapsulates GOSUs Image#draw_rot and all its parameters.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#angle ⇒ Object
Returns the value of attribute angle.
-
#center_x ⇒ Object
Returns the value of attribute center_x.
-
#center_y ⇒ Object
Returns the value of attribute center_y.
-
#color ⇒ Object
Returns the value of attribute color.
-
#factor_x ⇒ Object
Returns the value of attribute factor_x.
-
#factor_y ⇒ Object
Returns the value of attribute factor_y.
-
#image ⇒ Object
Returns the value of attribute image.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#zorder ⇒ Object
Returns the value of attribute zorder.
Attributes inherited from BasicGameObject
Instance Method Summary collapse
-
#center=(factor) ⇒ Object
Quick way of setting both center_x and center_y.
-
#distance_to(object) ⇒ Object
Calculates the distance from self to a given objevt.
- #draw ⇒ Object
-
#factor=(factor) ⇒ Object
Quick way of setting both factor_x and factor_y.
-
#initialize(options = {}) ⇒ GameObject
constructor
A new instance of GameObject.
-
#inside_window?(x = @x, y = @y) ⇒ Boolean
Returns true if object is inside the game window, false if outside.
-
#outside_window?(x = @x, y = @y) ⇒ Boolean
Returns true object is outside the game window.
Methods inherited from BasicGameObject
all, clear, #destroy!, destroy_if, has_trait, has_traits, #setup_trait, #update
Constructor Details
#initialize(options = {}) ⇒ GameObject
Returns a new instance of GameObject.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/chingu/game_object.rb', line 33 def initialize( = {}) super # All encapsulated draw_rot arguments can be set with hash-options at creation time if [:image].is_a?(Gosu::Image) @image = [:image] elsif [:image].is_a? String @image = Image[[:image]] end @x = [:x] || 0 @y = [:y] || 0 @angle = [:angle] || 0 @center_x = [:center_x] || [:center] || 0.5 @center_y = [:center_y] || [:center] || 0.5 @factor_x = [:factor_x] || [:factor] || 1.0 @factor_y = [:factor_y] || [:factor] || 1.0 # faster? #self.center = options[:center] || 0.5 #self.factor = options[:factor] || 1.0 #@center_x = options[:center_x] || 0.5 #@center_y = options[:center_y] || 0.5 #@factor_x = options[:factor_x] || 1.0 #@factor_y = options[:factor_y] || 1.0 if [:color].is_a?(Gosu::Color) @color = [:color] elsif [:color].is_a? Bignum @color = Gosu::Color.new([:color]) else @color = Gosu::Color.new(0xFFFFFFFF) end @mode = [:mode] || :default # :additive is also available. @zorder = [:zorder] || 100 # gameloop/framework logic (TODO: use or get rid of) @update = [:update] || true @draw = [:draw] || true setup_trait() if respond_to?(:setup_trait) end |
Instance Attribute Details
#angle ⇒ Object
Returns the value of attribute angle.
30 31 32 |
# File 'lib/chingu/game_object.rb', line 30 def angle @angle end |
#center_x ⇒ Object
Returns the value of attribute center_x.
30 31 32 |
# File 'lib/chingu/game_object.rb', line 30 def center_x @center_x end |
#center_y ⇒ Object
Returns the value of attribute center_y.
30 31 32 |
# File 'lib/chingu/game_object.rb', line 30 def center_y @center_y end |
#color ⇒ Object
Returns the value of attribute color.
30 31 32 |
# File 'lib/chingu/game_object.rb', line 30 def color @color end |
#factor_x ⇒ Object
Returns the value of attribute factor_x.
30 31 32 |
# File 'lib/chingu/game_object.rb', line 30 def factor_x @factor_x end |
#factor_y ⇒ Object
Returns the value of attribute factor_y.
30 31 32 |
# File 'lib/chingu/game_object.rb', line 30 def factor_y @factor_y end |
#image ⇒ Object
Returns the value of attribute image.
30 31 32 |
# File 'lib/chingu/game_object.rb', line 30 def image @image end |
#mode ⇒ Object
Returns the value of attribute mode.
30 31 32 |
# File 'lib/chingu/game_object.rb', line 30 def mode @mode end |
#x ⇒ Object
Returns the value of attribute x.
30 31 32 |
# File 'lib/chingu/game_object.rb', line 30 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
30 31 32 |
# File 'lib/chingu/game_object.rb', line 30 def y @y end |
#zorder ⇒ Object
Returns the value of attribute zorder.
30 31 32 |
# File 'lib/chingu/game_object.rb', line 30 def zorder @zorder end |
Instance Method Details
#center=(factor) ⇒ Object
Quick way of setting both center_x and center_y
84 85 86 |
# File 'lib/chingu/game_object.rb', line 84 def center=(factor) @center_x = @center_y = factor end |
#distance_to(object) ⇒ Object
Calculates the distance from self to a given objevt
99 100 101 |
# File 'lib/chingu/game_object.rb', line 99 def distance_to(object) distance(self.x, self.y, object.x, object.y) end |
#draw ⇒ Object
103 104 105 106 |
# File 'lib/chingu/game_object.rb', line 103 def draw super @image.draw_rot(@x, @y, @zorder, @angle, @center_x, @center_y, @factor_x, @factor_y, @color, @mode) end |
#factor=(factor) ⇒ Object
Quick way of setting both factor_x and factor_y
79 80 81 |
# File 'lib/chingu/game_object.rb', line 79 def factor=(factor) @factor_x = @factor_y = factor end |
#inside_window?(x = @x, y = @y) ⇒ Boolean
Returns true if object is inside the game window, false if outside
89 90 91 |
# File 'lib/chingu/game_object.rb', line 89 def inside_window?(x = @x, y = @y) x >= 0 && x <= $window.width && y >= 0 && y <= $window.height end |
#outside_window?(x = @x, y = @y) ⇒ Boolean
Returns true object is outside the game window
94 95 96 |
# File 'lib/chingu/game_object.rb', line 94 def outside_window?(x = @x, y = @y) not inside_window?(x,y) end |