# To change this template, choose Tools | Templates
# and open the template in the editor.

class Spider  
  attr_reader :shape
  SUBSTEPS = 6

  def initialize(window, shape, angle, hvelocity, x, y)
    @image = Gosu::Image.new(window, "media/spider.png", false)
    @hit = 0
    @shape = shape
    @angle = angle
    #@shape.body.p = CP::Vec2.new(150, 390) # position
    @shape.body.p = CP::Vec2.new(x, y) # position
    @vertical_velocity = (8000000/30 ** 8)*-1
    if(@angle >= 4.6)
      @vertical_velocity =  0      
    end

    @horizontal_velocity = 300
    @shape.body.v = CP::Vec2.new(@horizontal_velocity, @vertical_velocity ) # velocity
    @shape.u = 0.0 # friction
    @shape.e = 0.85 # bounce
   
  end

  def detect_player(x, y)    
    if Gosu::distance(@shape.body.p.x,@shape.body.p.y,x,y) < 50 then         
      return true         
    end   
    return false
  end
  
  def draw(x,y)   
    @image.draw_rot(@shape.body.p.x, @shape.body.p.y, 0, 25 * Math.sin(Gosu::milliseconds / 133.7)) 
    if
      detect_player(x, y) == true
      return true
    else   
      return false
    end
  end
  
  def update
    
  end
  
  def get_velocity
    return @horizontal_velocity + @vertical_velocity
  end
end

