player.rb 910 Bytes
class Player < Ship

  attr_accessor :score

  def initialize game, options
    options[:type] = :fighter
    super game, options
    @score = 0
  end

  def move direction
    case direction
    when :up
      @body.p += CP::Vec2.new(0.0, -1.0 * @params[:speed] * 10)
    when :down
      @body.p += CP::Vec2.new(0.0, 1.0 * @params[:speed] * 10)
    when :left
      @body.p += CP::Vec2.new(-1.0 * @params[:speed] * 10, 0.0)
    when :right
      @body.p += CP::Vec2.new(1.0 * @params[:speed] * 10, 0.0)
    end
  end

  def draw *a
    p, v = pos, vel
    p[0], v[0] = 0, 0 if p[0] < 0
    p[1], v[1] = 0, 0 if p[1] < 0
    p[0], v[0] = screen.size[0], 0 if p[0] > screen.size[0]
    p[1], v[1] = screen.size[1], 0 if p[1] > screen.size[1]
    if pos != p
      @body.p = CP::Vec2.new(*p)
    end
    @body.v = CP::Vec2.new(0,0)
    super *a
  end

  def destroy
    @game.state = :lost
    super
  end

end