
require 'chipmunk'
require 'gosu'
class Bullet
  attr_accessor :x,:y, :angle, :bullet_body, :bullet_shape, :velx, :vely

  def initialize(window,x,y,velx,vely,bulletimage)
    #create a new image on the arrow
   
    
   
   @bulletimage = bulletimage
   @angle = 0.0 
    
  
    @x = @y  = @angle = 0.0
    @velx = velx
    @vely = vely
    
    
    #chipmunk properties
    
      thevertices = [
      CP::Vec2.new(0,0), #x1 first corner
      CP::Vec2.new(0,10), #x2 second corner
      CP::Vec2.new(10,10), #x3 third corner
      CP::Vec2.new(10,0) #x4 fourth corner
    ]
    
    
    @bullet_body = CP::Body.new((1.0/0.0),(1.0/0.0))
    @bullet_body.m =4
    @bullet_body.i =5
   
   
    #create a square with the vertices as defined above
    @bullet_shape = CP::Shape::Poly.new(@bullet_body,thevertices,CP::Vec2.new(0.0,0.0))
 
    @bullet_shape.collision_type = :bullet
 
    @bullet_shape.body.p.x =x
    @bullet_shape.body.p.y =y
    
    @bullet_shape.body.v =CP::Vec2.new(velx,vely)
    @bullet_shape.body.a = 0.degrees_to_radians 
 
    
  end
  


  

  
 
  def draw

   
   @bulletimage.draw_rot( @bullet_shape.body.p.x+2.5, @bullet_shape.body.p.y+2.5, 1, @bullet_shape.body.a.radians_to_degrees,center_x = 0.5, center_y = 0.5, factor_x = 1, factor_y = 1, color = 0xffffffff, mode = :default)
    
  end
  
end