While we need to chipmunk for collision detection, we don't need it for physics currently for asteroids because the physic are simple, but we can optionally add it as well to clean it up.
Inherit Chipmunk Object and Defaultable
[ ] require 'game_objects/role/defaultable'
[ ] require 'game_objects/role/chipmunk_object'
[ ] include Defaultable
[ ] include ChipmunkObject
[ ] def _defaults { }
[ ] add params = {} to end of initialize parameters
[ ] add setup_defaults(params) in initialize
[ ] add setup_chipmunk ini initialize
Switch initial physic vars to _defaults and use chipmunk body properties
[ ] add :moment_of_inertia => 150, to defaults (this number is a guess but I think in this case it just has to have any number
[ ] add :mass => 50, to defaults (this number is a guess but I think in this case it just has to have any number
[ ] add :tier=1 to _defaults
[ ] remove @tier=tier from initialize (as this is now set by _defaults)
[ ] change tier references in initialize to @tier
[ ] remove tier parameter from intialize
[ ] add :init_x_pos = rand(0...@scene.width) to _defaults
[ ] add :init_y_pos = rand(0...@scene.height) to _defaults
[ ] remove x_position, y_position parameters and all associated logic in initialize
[ ] change all Asteroid.new to match new params, example:Asteroid.new(@scene, @x_position, @y_position, @tier+1) to Asteroid.new(@scene, init_x_pos: @x_position, init_y_pos:@y_position, tier:@tier+1)
[ ] change all references of x_position in Asteroid.rb to self.body.x that's because chipmunk is now the storage for the position.
[ ] change all references of y_position in Asteroid.rb to self.body.y that's because chipmunk is now the storage for the position.
[ ] change all references of rotation_angular in Asteroid.rb to self.body.a that's because chipmunk is now the storage for the rotation.
[ ] before assigning to self.body.a make sure gosu_to_radians is call on what's being assigned
[ ] before using self.body.a's value make sure to call radians_to_gosu off of a
[ ] add :init_rotate => rand(-10...10) to _defaults
While we need to chipmunk for collision detection, we don't need it for physics currently for asteroids because the physic are simple, but we can optionally add it as well to clean it up.
require 'game_objects/role/defaultable'
require 'game_objects/role/chipmunk_object'
include Defaultable
include ChipmunkObject
def _defaults { }
params = {}
to end ofinitialize
parameterssetup_defaults(params)
ininitialize
setup_chipmunk
iniinitialize
_defaults
and use chipmunk body properties:moment_of_inertia => 150,
to defaults (this number is a guess but I think in this case it just has to have any number:mass => 50,
to defaults (this number is a guess but I think in this case it just has to have any number:tier=1
to _defaults@tier=tier
frominitialize
(as this is now set by _defaults)tier
references ininitialize
to@tier
tier
parameter fromintialize
:init_x_pos = rand(0...@scene.width)
to _defaults:init_y_pos = rand(0...@scene.height)
to _defaultsx_position
,y_position
parameters and all associated logic ininitialize
Asteroid.new
to match new params, example:Asteroid.new(@scene, @x_position, @y_position, @tier+1)
toAsteroid.new(@scene, init_x_pos: @x_position, init_y_pos:@y_position, tier:@tier+1)
x_position
inAsteroid.rb
toself.body.x
that's because chipmunk is now the storage for the position.y_position
inAsteroid.rb
toself.body.y
that's because chipmunk is now the storage for the position.rotation_angular
inAsteroid.rb
toself.body.a
that's because chipmunk is now the storage for the rotation.self.body.a
make suregosu_to_radians
is call on what's being assignedself.body.a
's value make sure to callradians_to_gosu
off ofa
:init_rotate => rand(-10...10)
to _defaultsself.body.a = rand(-10...10).gosu_to_radians
:collision_type => "asteroid".to_sym,
:collision_sensor => true,
to _defaults (as asteroids don't collide with anything except when handled explicitly.:bit_plane => 0b11,
to _defaults (completes issue #21)self.body.velocity_func{ |b, g, d, dt| }
so dampening doesn't take effect.@x_velocity = rand(-100...100)
and@x_velocity = rand(-100...100)
frominitialize
self.body.v = CP::Vec2.new(rand(-100...100), rand(-100...100))
toinitialize
self.body.x = self.body.x + @x_velocity * update_in_seconds
fromupdate
self.body.y = self.body.y + @y_velocity * update_in_seconds
fromupdate
self.body.w = rand(-10...10) to
initialize`@rotation_momentum = rand(-10...10)
frominitialize
self.body.a = (self.body.a.radians_to_gosu + @rotation_momentum * @scene.update_interval / 1000.0).gosu_to_radians
fromupdate
update_in_seconds = @scene.update_interval / 1000.0
fromupdate