Class: Chingu::GameObject
- Inherits:
-
BasicGameObject
- Object
- BasicGameObject
- Chingu::GameObject
- Includes:
- Helpers::InputClient, Helpers::RotationCenter
- Defined in:
- lib/chingu/game_object.rb
Overview
GameObject inherits from BasicGameObject to get traits and some class-methods like .all and .destroy
On top of that, it encapsulates GOSUs Image#draw_rot and all its parameters.
In Chingu GameObject is a visual object, something to put on screen, centers around the .image-parameter.
If you wan’t a invisible object but with traits, use BasicGameObject.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#angle ⇒ Object
Returns the value of attribute angle.
-
#center ⇒ Object
, :rotation_center.
-
#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 ⇒ Object
, :rotation_center.
-
#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
#options, #parent, #paused, #visible
Instance Method Summary collapse
-
#alpha ⇒ Object
Get objects alpha-value (internally stored in @color.alpha).
-
#alpha=(value) ⇒ Object
Set objects alpha-value (internally stored in @color.alpha) If out of range, set to closest working value.
-
#distance_to(object) ⇒ Object
Calculates the distance from self to a given objevt.
- #draw ⇒ Object
-
#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 included from Helpers::RotationCenter
#rotation_center, #rotation_center=
Methods included from Helpers::InputClient
Methods inherited from BasicGameObject
all, create, #destroy, destroy_all, destroy_if, #draw_trait, has_trait, has_traits, #hide!, initialize_trait, #pause!, #paused?, #setup_trait, #show!, size, #trait_options, #unpause!, #update, #update_trait, #visible?
Methods included from Helpers::ClassInheritableAccessor
Constructor Details
#initialize(options = {}) ⇒ GameObject
Returns a new instance of GameObject.
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 77 78 79 |
# File 'lib/chingu/game_object.rb', line 40 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 = Gosu::Image[[:image]] end @x = [:x] || 0 @y = [:y] || 0 @angle = [:angle] || 0 self.factor = [:factor] || 1.0 @factor_x = [:factor_x] if [:factor_x] @factor_y = [:factor_y] if [:factor_y] self.center = [:center] || 0.5 @rotation_center = [:rotation_center] self.rotation_center([:rotation_center]) if [:rotation_center] @center_x = [:center_x] if [:center_x] @center_y = [:center_y] if [:center_y] if [:color].is_a?(Gosu::Color) @color = [:color] else @color = Gosu::Color.new([:color] || 0xFFFFFFFF) end self.alpha = [:alpha] if [:alpha] @mode = [:mode] || :default # :additive is also available. @zorder = [:zorder] || 100 #setup_trait(options) if self.respond_to?(:setup_trait) end |
Instance Attribute Details
#angle ⇒ Object
Returns the value of attribute angle.
34 35 36 |
# File 'lib/chingu/game_object.rb', line 34 def angle @angle end |
#center ⇒ Object
, :rotation_center
35 36 37 |
# File 'lib/chingu/game_object.rb', line 35 def center @center end |
#center_x ⇒ Object
Returns the value of attribute center_x.
34 35 36 |
# File 'lib/chingu/game_object.rb', line 34 def center_x @center_x end |
#center_y ⇒ Object
Returns the value of attribute center_y.
34 35 36 |
# File 'lib/chingu/game_object.rb', line 34 def center_y @center_y end |
#color ⇒ Object
Returns the value of attribute color.
34 35 36 |
# File 'lib/chingu/game_object.rb', line 34 def color @color end |
#factor ⇒ Object
, :rotation_center
35 36 37 |
# File 'lib/chingu/game_object.rb', line 35 def factor @factor end |
#factor_x ⇒ Object
Returns the value of attribute factor_x.
34 35 36 |
# File 'lib/chingu/game_object.rb', line 34 def factor_x @factor_x end |
#factor_y ⇒ Object
Returns the value of attribute factor_y.
34 35 36 |
# File 'lib/chingu/game_object.rb', line 34 def factor_y @factor_y end |
#image ⇒ Object
Returns the value of attribute image.
34 35 36 |
# File 'lib/chingu/game_object.rb', line 34 def image @image end |
#mode ⇒ Object
Returns the value of attribute mode.
34 35 36 |
# File 'lib/chingu/game_object.rb', line 34 def mode @mode end |
#x ⇒ Object
Returns the value of attribute x.
34 35 36 |
# File 'lib/chingu/game_object.rb', line 34 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
34 35 36 |
# File 'lib/chingu/game_object.rb', line 34 def y @y end |
#zorder ⇒ Object
Returns the value of attribute zorder.
34 35 36 |
# File 'lib/chingu/game_object.rb', line 34 def zorder @zorder end |
Instance Method Details
#alpha ⇒ Object
Get objects alpha-value (internally stored in @color.alpha)
94 95 96 |
# File 'lib/chingu/game_object.rb', line 94 def alpha @color.alpha end |
#alpha=(value) ⇒ Object
Set objects alpha-value (internally stored in @color.alpha) If out of range, set to closest working value. this makes fading simpler.
100 101 102 103 104 |
# File 'lib/chingu/game_object.rb', line 100 def alpha=(value) value = 0 if value < 0 value = 255 if value > 255 @color.alpha = value end |
#distance_to(object) ⇒ Object
Calculates the distance from self to a given objevt
118 119 120 |
# File 'lib/chingu/game_object.rb', line 118 def distance_to(object) distance(self.x, self.y, object.x, object.y) end |
#draw ⇒ Object
122 123 124 |
# File 'lib/chingu/game_object.rb', line 122 def draw @image.draw_rot(@x, @y, @zorder, @angle, @center_x, @center_y, @factor_x, @factor_y, @color, @mode) if @visible end |
#inside_window?(x = @x, y = @y) ⇒ Boolean
Returns true if object is inside the game window, false if outside
108 109 110 |
# File 'lib/chingu/game_object.rb', line 108 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
113 114 115 |
# File 'lib/chingu/game_object.rb', line 113 def outside_window?(x = @x, y = @y) not inside_window?(x,y) end |