Blame view

lib/bullet.rb 542 Bytes
fb5f9fd60   Marius Hanne   simple top-down s...
1
  class Bullet < Movable
0a4402566   Marius Hanne   use chipmunk libr...
2
    def initialize game, opts = {}
0a4402566   Marius Hanne   use chipmunk libr...
3
4
      opts.merge!(m: 10.0, ctype: :bullet)
      super(game, opts)
fb5f9fd60   Marius Hanne   simple top-down s...
5
    end
0a4402566   Marius Hanne   use chipmunk libr...
6
7
8
9
    def draw screen
      return hide if pos[0] < (0 - size[0]) || pos[1] < (0 - size[1]) ||
        pos[0] > @game.screen.size[0] || pos[1] > @game.screen.size[1]
      super screen
fb5f9fd60   Marius Hanne   simple top-down s...
10
11
12
    end
  
    def hit ship
0a4402566   Marius Hanne   use chipmunk libr...
13
14
      p = pos; @options[:dir] == :up ? p[1] -= @shape.r : p[1] += @shape.r
      Explosion.new(@game, p: p).show
a070906aa   Marius Hanne   weapons
15
16
      ship.take_damage(options[:damage])
      @options[:shooter].hit(ship, options[:damage])
fb5f9fd60   Marius Hanne   simple top-down s...
17
18
19
      hide
    end
  end