Class: GamesAndRpgParadise::GardenHero::ApplePlayer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window, player) ⇒ ApplePlayer

Returns a new instance of ApplePlayer.



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

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.



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

def drawing
  @drawing
end

#last_directionObject

Returns the value of attribute last_direction.



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

def last_direction
  @last_direction
end

#playerObject (readonly)

Returns the value of attribute player.



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

def player
  @player
end

#xObject

Returns the value of attribute x.



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

def x
  @x
end

#yObject

Returns the value of attribute y.



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

def y
  @y
end

Instance Method Details

#drawObject

draw



22
23
24
# File 'lib/games_and_rpg_paradise/gui/gosu/garden_hero/core/player/apple_player.rb', line 22

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

#updateObject

update



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/games_and_rpg_paradise/gui/gosu/garden_hero/core/player/apple_player.rb', line 27

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