Class: Gosu::Square
- Inherits:
-
Object
- Object
- Gosu::Square
- Defined in:
- lib/gosu_android/physics/physicsObject.rb
Instance Attribute Summary collapse
-
#center ⇒ Object
readonly
Returns the value of attribute center.
-
#mass_inverted ⇒ Object
readonly
Returns the value of attribute mass_inverted.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#restitution ⇒ Object
readonly
Returns the value of attribute restitution.
-
#velocity ⇒ Object
Returns the value of attribute velocity.
Instance Method Summary collapse
- #draw ⇒ Object
- #generate_contact(other_object) ⇒ Object
-
#initialize(window, file_name, x, y, z, size, mass_inverted, velocity_x = 0, velocity_y = 0, restitution = 1, tileable = false) ⇒ Square
constructor
A new instance of Square.
- #integrate ⇒ Object
Constructor Details
#initialize(window, file_name, x, y, z, size, mass_inverted, velocity_x = 0, velocity_y = 0, restitution = 1, tileable = false) ⇒ Square
Returns a new instance of Square.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gosu_android/physics/physicsObject.rb', line 34 def initialize(window, file_name, x, y, z, size, mass_inverted, velocity_x = 0, velocity_y = 0, restitution = 1, tileable = false) @window = window @position = [x,y] @size = size / 2 @center = [@position[0] + @size, @position[1] + @size] @z = z @restitution = restitution @velocity = [velocity_x, velocity_y] @mass_inverted = mass_inverted @image = Gosu::Image.new(@window, file_name , tileable) @dt = @window.update_interval end |
Instance Attribute Details
#center ⇒ Object (readonly)
Returns the value of attribute center.
32 33 34 |
# File 'lib/gosu_android/physics/physicsObject.rb', line 32 def center @center end |
#mass_inverted ⇒ Object (readonly)
Returns the value of attribute mass_inverted.
33 34 35 |
# File 'lib/gosu_android/physics/physicsObject.rb', line 33 def mass_inverted @mass_inverted end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
32 33 34 |
# File 'lib/gosu_android/physics/physicsObject.rb', line 32 def position @position end |
#restitution ⇒ Object (readonly)
Returns the value of attribute restitution.
33 34 35 |
# File 'lib/gosu_android/physics/physicsObject.rb', line 33 def restitution @restitution end |
#velocity ⇒ Object
Returns the value of attribute velocity.
31 32 33 |
# File 'lib/gosu_android/physics/physicsObject.rb', line 31 def velocity @velocity end |
Instance Method Details
#draw ⇒ Object
71 72 73 |
# File 'lib/gosu_android/physics/physicsObject.rb', line 71 def draw @image.draw(@position[0], @position[1], @z) end |
#generate_contact(other_object) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/gosu_android/physics/physicsObject.rb', line 54 def generate_contact other_object if other_object.class == Square elsif other_object.class == Plane if @center[0] - @size < other_object.top_limit[0] and other_object.bottom_limit[0] < @center[0] + @size and @center[1] - @size < other_object.bottom_limit[1] and other_object.top_limit[1] < @center[1] + @size #Calculate new velocity, after the hit if other_object.type == :vertical @velocity[0] -= (1 + @restitution) * @velocity[0] else @velocity[1] -= (1 + @restitution) * @velocity[1] end #Call window event @window.object_collided( @position[0], @position[1], other_object ) end end end |
#integrate ⇒ Object
48 49 50 51 52 |
# File 'lib/gosu_android/physics/physicsObject.rb', line 48 def integrate @position[0] += @velocity[0]*@dt @position[1] += @velocity[1]*@dt @center = [@position[0] + @size, @position[1] + @size] end |