Class: ApplePlayer

Inherits:
Object
  • Object
show all
Defined in:
lib/games_paradise/gui/gosu/garden_hero/core/player/apple_player.rb

Overview

#

ApplePlayer - apple class (player’s weapon)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window, player) ⇒ ApplePlayer

Returns a new instance of ApplePlayer.



8
9
10
11
12
# File 'lib/games_paradise/gui/gosu/garden_hero/core/player/apple_player.rb', line 8

def initialize window, player
  @window, @player, @x, @y = window, player, player.x - 6, player.y + 4
  @img = Gosu::Image.new window, "images/player/apple-player.png", true
  @drawing, @last_direction = false, 'left'
end

Instance Attribute Details

#drawingObject

Returns the value of attribute drawing.



15
16
17
# File 'lib/games_paradise/gui/gosu/garden_hero/core/player/apple_player.rb', line 15

def drawing
  @drawing
end

#last_directionObject

Returns the value of attribute last_direction.



15
16
17
# File 'lib/games_paradise/gui/gosu/garden_hero/core/player/apple_player.rb', line 15

def last_direction
  @last_direction
end

#playerObject (readonly)

Returns the value of attribute player.



14
15
16
# File 'lib/games_paradise/gui/gosu/garden_hero/core/player/apple_player.rb', line 14

def player
  @player
end

#xObject

Returns the value of attribute x.



15
16
17
# File 'lib/games_paradise/gui/gosu/garden_hero/core/player/apple_player.rb', line 15

def x
  @x
end

#yObject

Returns the value of attribute y.



15
16
17
# File 'lib/games_paradise/gui/gosu/garden_hero/core/player/apple_player.rb', line 15

def y
  @y
end

Instance Method Details

#drawObject

draw



18
19
20
# File 'lib/games_paradise/gui/gosu/garden_hero/core/player/apple_player.rb', line 18

def draw
  @img.draw(@x, @y, 1) if @drawing
end

#updateObject

update



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/games_paradise/gui/gosu/garden_hero/core/player/apple_player.rb', line 23

def update
  if @drawing
    case @last_direction
    when 'left'
      @x -= 5 if @x >= 2
    when 'right'
      @x += 5 if @x <= 632
    when 'up'
      @y -= 5 if @y >= 2
    when 'down'
      @y += 5 if @y <= 476
    end
    if @x <= 4 || @x >= 630 || @y <= 4 || @y >= 476
      @drawing = false
      @last_direction = player.face
    end
  end
end