SHARE
TWEET

Ball Class

a guest Dec 30th, 2014 224 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require 'gosu'
  2. require 'chipmunk'
  3.  
  4. class Ball
  5.   attr_reader :shape #Shape is used for position/velocity characteristics of the player.
  6.   def initialize(parent, space)
  7.     @body = CP::StaticBody.new
  8.     @shape = CP::Shape::Circle.new(@body, 15, CP::Vec2.new(0.0, 0.0))
  9.     @image = Gosu::Image.new(parent, 'media/Ball.png', false)
  10.  
  11.     @shape.body.p = CP::Vec2.new(rand(SCREEN_WIDTH), rand(SCREEN_HEIGHT)) # position
  12.     @shape.collision_type = :ball
  13.  
  14.     #space.add_body(@body)
  15.     space.add_shape(@shape)
  16.  
  17.     #@shape.body.apply_impulse((CP::Vec2.new(30.0, 0.0) * ((SCREEN_WIDTH/2))), CP::Vec2.new(0.0, 0.0))
  18.     #Obviously this would not work on a static body.
  19.   end
  20.  
  21.   def draw
  22.     @image.draw(@shape.body.p.x - 15, @shape.body.p.y - 15, ZOrder::BALL)
  23.   end
  24. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top