Class: Player

Inherits:
Object
  • Object
show all
Defined in:
lib/player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlayer

Returns a new instance of Player.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/player.rb', line 4

def initialize
  @index        = Processor.has_at_least_one_player? ? 1 : 0
  @t_size       = Processor::TileSize
  #more animation to come
  @facing       = :down
  @animation_sprites = {:left  => Gosu::Image.load_tiles(Processor.window, BLAST_IMG_PATH + "player_left#{@index}.png", @t_size, @t_size, false),
                        :down  => Gosu::Image.load_tiles(Processor.window, BLAST_IMG_PATH + "player_down#{@index}.png", @t_size, @t_size, false),
                        :up    => Gosu::Image.load_tiles(Processor.window, BLAST_IMG_PATH + "player_up#{@index}.png", @t_size, @t_size, false),
                        :right => Gosu::Image.load_tiles(Processor.window, BLAST_IMG_PATH + "player_right#{@index}.png", @t_size, @t_size, false)}
  @bombs        = []
  @explosions   = []
  @move_control = {[Gosu::Button::KbA,       Gosu::Button::KbLeft] => [:left, [-1, 0],[0, 0, 0, 40]],
                  [Gosu::Button::KbD,        Gosu::Button::KbRight] => [:right, [1, 0], [40, 0, 40, 40]],
                  [Gosu::Button::KbW,        Gosu::Button::KbUp   ] => [:up, [0, -1],[40, 0, 0, 0]],
                  [Gosu::Button::KbS,        Gosu::Button::KbDown ] => [:down, [0, 1],[40, 40, 0, 40 ]]}
  @bomb_control = [Gosu::Button::KbSpace,    Gosu::Button::KbRightAlt]
  @img_counter  = 0
  @img_index    = 4

  @x = @y = [@t_size * 1 + 1, @t_size * 14 + 1][@index]
end

Instance Attribute Details

#bombsObject (readonly)

Returns the value of attribute bombs.



3
4
5
# File 'lib/player.rb', line 3

def bombs
  @bombs
end

#explosionsObject (readonly)

Returns the value of attribute explosions.



3
4
5
# File 'lib/player.rb', line 3

def explosions
  @explosions
end

#indexObject (readonly)

Returns the value of attribute index.



3
4
5
# File 'lib/player.rb', line 3

def index
  @index
end

#xObject (readonly)

Returns the value of attribute x.



3
4
5
# File 'lib/player.rb', line 3

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



3
4
5
# File 'lib/player.rb', line 3

def y
  @y
end

Instance Method Details

#drawObject



26
27
28
# File 'lib/player.rb', line 26

def draw
  @animation_sprites[@facing][@img_index].draw(@x, @y, 2)
end

#no_collision?(target) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
# File 'lib/player.rb', line 35

def no_collision?(target)
  target_x = @x+target[0]+target[2]
  target_y = @y+target[1]+target[3]
  !solid_at?(target_x, target_y) && !Processor.all_bombs.detect{|bomb| bomb.solid_at?(target_x, target_y)}
end

#updateObject



30
31
32
33
# File 'lib/player.rb', line 30

def update
  movement!
  bombs!
end