Blame view

lib/player.rb 711 Bytes
fb5f9fd60   Marius Hanne   simple top-down s...
1
2
3
  class Player < Ship
  
    attr_accessor :score
0a4402566   Marius Hanne   use chipmunk libr...
4
5
    def initialize game, options
      options[:type] = :fighter
736bcbbc3   Marius Hanne   use chipmunk to h...
6
      options[:a] = 180.0
0a4402566   Marius Hanne   use chipmunk libr...
7
      super game, options
fb5f9fd60   Marius Hanne   simple top-down s...
8
9
10
11
12
13
      @score = 0
    end
  
    def move direction
      case direction
      when :up
bb864358b   Marius Hanne   keep player insid...
14
        @body.p += CP::Vec2.new(0.0, -1.0 * @params[:speed] * 10)
fb5f9fd60   Marius Hanne   simple top-down s...
15
      when :down
bb864358b   Marius Hanne   keep player insid...
16
        @body.p += CP::Vec2.new(0.0, 1.0 * @params[:speed] * 10)
fb5f9fd60   Marius Hanne   simple top-down s...
17
      when :left
bb864358b   Marius Hanne   keep player insid...
18
        @body.p += CP::Vec2.new(-1.0 * @params[:speed] * 10, 0.0)
736bcbbc3   Marius Hanne   use chipmunk to h...
19
        # @body.a += 5
fb5f9fd60   Marius Hanne   simple top-down s...
20
      when :right
bb864358b   Marius Hanne   keep player insid...
21
        @body.p += CP::Vec2.new(1.0 * @params[:speed] * 10, 0.0)
736bcbbc3   Marius Hanne   use chipmunk to h...
22
        # @body.a -= 5
fb5f9fd60   Marius Hanne   simple top-down s...
23
      end
bb864358b   Marius Hanne   keep player insid...
24
25
26
    end
  
    def draw *a
4cd40077a   Marius Hanne   fix player drift
27
      @body.v = CP::Vec2.new(0,0)
bb864358b   Marius Hanne   keep player insid...
28
      super *a
fb5f9fd60   Marius Hanne   simple top-down s...
29
30
31
32
33
34
35
36
    end
  
    def destroy
      @game.state = :lost
      super
    end
  
  end