Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'gosu'
- require 'chipmunk'
- class Ball
- attr_reader :shape #Shape is used for position/velocity characteristics of the player.
- def initialize(parent, space)
- @body = CP::StaticBody.new
- @shape = CP::Shape::Circle.new(@body, 15, CP::Vec2.new(0.0, 0.0))
- @image = Gosu::Image.new(parent, 'media/Ball.png', false)
- @shape.body.p = CP::Vec2.new(rand(SCREEN_WIDTH), rand(SCREEN_HEIGHT)) # position
- @shape.collision_type = :ball
- #space.add_body(@body)
- space.add_shape(@shape)
- #@shape.body.apply_impulse((CP::Vec2.new(30.0, 0.0) * ((SCREEN_WIDTH/2))), CP::Vec2.new(0.0, 0.0))
- #Obviously this would not work on a static body.
- end
- def draw
- @image.draw(@shape.body.p.x - 15, @shape.body.p.y - 15, ZOrder::BALL)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement