dummey / CS50-Cohort-Project-Redux

2 stars 0 forks source link

Make Asteroid a Chipmunk object #29

Closed jbtule closed 9 years ago

jbtule commented 9 years ago

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.

  1. 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
  2. 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
    • [ ] remove self.body.a = rand(-10...10).gosu_to_radians
  3. Add collision default parameters
    • [ ] add :collision_type => "asteroid".to_sym,
    • [ ] add :collision_sensor => true, to _defaults (as asteroids don't collide with anything except when handled explicitly.
    • [ ] add :bit_plane => 0b11, to _defaults (completes issue #21)
  4. (optional) Switch to using Chipmunk for velocity, may require playing with default values
    • [ ] override velocity function in initialize self.body.velocity_func{ |b, g, d, dt| } so dampening doesn't take effect.
    • [ ] remove @x_velocity = rand(-100...100) and @x_velocity = rand(-100...100) from initialize
    • [ ] add self.body.v = CP::Vec2.new(rand(-100...100), rand(-100...100)) to initialize
    • [ ] remove self.body.x = self.body.x + @x_velocity * update_in_seconds from update
    • [ ] remove self.body.y = self.body.y + @y_velocity * update_in_seconds from update
    • [ ] add self.body.w = rand(-10...10) toinitialize`
    • [ ] remove @rotation_momentum = rand(-10...10) from initialize
    • [ ] remove self.body.a = (self.body.a.radians_to_gosu + @rotation_momentum * @scene.update_interval / 1000.0).gosu_to_radians from update
    • [ ] remove update_in_seconds = @scene.update_interval / 1000.0 from update
jbtule commented 9 years ago

fixed by @dummey in commit 3a08cdf8dd8b1dcab94387468dcaef322d19c02a