Class: Player
- Inherits:
-
Object
- Object
- Player
- Defined in:
- lib/player.rb
Instance Attribute Summary collapse
-
#bombs ⇒ Object
readonly
Returns the value of attribute bombs.
-
#explosions ⇒ Object
readonly
Returns the value of attribute explosions.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize ⇒ Player
constructor
A new instance of Player.
- #no_collision?(target) ⇒ Boolean
- #update ⇒ Object
Constructor Details
#initialize ⇒ Player
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
#bombs ⇒ Object (readonly)
Returns the value of attribute bombs.
3 4 5 |
# File 'lib/player.rb', line 3 def bombs @bombs end |
#explosions ⇒ Object (readonly)
Returns the value of attribute explosions.
3 4 5 |
# File 'lib/player.rb', line 3 def explosions @explosions end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
3 4 5 |
# File 'lib/player.rb', line 3 def index @index end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
3 4 5 |
# File 'lib/player.rb', line 3 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
3 4 5 |
# File 'lib/player.rb', line 3 def y @y end |
Instance Method Details
#draw ⇒ Object
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
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 |
#update ⇒ Object
30 31 32 33 |
# File 'lib/player.rb', line 30 def update movement! bombs! end |