class SK::RigidBody

Attributes

body[R]
fixed_rotation[RW]
inertia[RW]
mass[RW]
static[RW]

Public Class Methods

new() click to toggle source
# File lib/shirokuro/standard_components/physics/rigid_body.rb, line 7
def initialize
        @mass = 1.0
        @inertia = 1.0
        @static = false
        @fixed_rotation = false
end

Public Instance Methods

add_force(force) click to toggle source
# File lib/shirokuro/standard_components/physics/rigid_body.rb, line 36
def add_force force
        @body.apply_force(force, CP::Vec2.new(0, 0))
end
add_impulse(impulse) click to toggle source
# File lib/shirokuro/standard_components/physics/rigid_body.rb, line 40
def add_impulse impulse
        @body.apply_impulse(impulse, CP::Vec2.new(0, 0))
end
add_torque(torque) click to toggle source
# File lib/shirokuro/standard_components/physics/rigid_body.rb, line 44
def add_torque torque
        @body.t += torque
end
set_rotation(rotation) click to toggle source
# File lib/shirokuro/standard_components/physics/rigid_body.rb, line 31
def set_rotation rotation
        transform.rotation = rotation
        @body.t = rotation
end
start() click to toggle source
# File lib/shirokuro/standard_components/physics/rigid_body.rb, line 14
def start
        if @static
                @body = CP::Body.new_static()
        else
                @body = CP::Body.new(@mass, @inertia)
                physics.space.add_body(@body)
        end
        teleport(transform.position.x, transform.position.y)
end
teleport(x, y) click to toggle source
# File lib/shirokuro/standard_components/physics/rigid_body.rb, line 24
def teleport x, y
        @body.p.x = x
        @body.p.y = y
        transform.position.x = x
        transform.position.y = y
end
update(dt) click to toggle source
# File lib/shirokuro/standard_components/physics/rigid_body.rb, line 48
def update dt
        if @fixed_rotation
                @body.a = 0.0
        end
        transform.position.x = @body.p.x
        transform.position.y = @body.p.y
        transform.rotation = @body.a
end