Class: GamesAndRpgParadise::GardenHero::Enemy
- Inherits:
-
Object
- Object
- GamesAndRpgParadise::GardenHero::Enemy
- Defined in:
- lib/games_and_rpg_paradise/gui/gosu/garden_hero/core/level/enemy.rb
Instance Attribute Summary collapse
-
#down_y ⇒ Object
readonly
Returns the value of attribute down_y.
-
#face ⇒ Object
readonly
Returns the value of attribute face.
-
#left_x ⇒ Object
readonly
Returns the value of attribute left_x.
-
#right_x ⇒ Object
readonly
Returns the value of attribute right_x.
-
#up_y ⇒ Object
readonly
Returns the value of attribute up_y.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
-
#draw ⇒ Object
# === draw ========================================================================= #.
-
#initialize(window, x, y, face = 'right') ⇒ Enemy
constructor
# === initialize ========================================================================= #.
-
#move ⇒ Object
# === move.
Constructor Details
#initialize(window, x, y, face = 'right') ⇒ Enemy
#
initialize
#
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/games_and_rpg_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 25 def initialize( window, x, y, face = 'right' ) @window, @x, @y, @face = window, x, y, face @left = Gosu::Image.new(window, "images/enemy/enemy-left.png", false) @right = Gosu::Image.new(window, "images/enemy/enemy-right.png", false) @up = Gosu::Image.new(window, "images/enemy/enemy-up.png", false) @down = Gosu::Image.new(window, "images/enemy/enemy-down.png", false) @right_x, @left_x, @down_y, @up_y = @x + 50, @x - 50, @y + 50, @y - 50 end |
Instance Attribute Details
#down_y ⇒ Object (readonly)
Returns the value of attribute down_y.
20 21 22 |
# File 'lib/games_and_rpg_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 20 def down_y @down_y end |
#face ⇒ Object (readonly)
Returns the value of attribute face.
16 17 18 |
# File 'lib/games_and_rpg_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 16 def face @face end |
#left_x ⇒ Object (readonly)
Returns the value of attribute left_x.
18 19 20 |
# File 'lib/games_and_rpg_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 18 def left_x @left_x end |
#right_x ⇒ Object (readonly)
Returns the value of attribute right_x.
17 18 19 |
# File 'lib/games_and_rpg_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 17 def right_x @right_x end |
#up_y ⇒ Object (readonly)
Returns the value of attribute up_y.
19 20 21 |
# File 'lib/games_and_rpg_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 19 def up_y @up_y end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
13 14 15 |
# File 'lib/games_and_rpg_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 13 def window @window end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
14 15 16 |
# File 'lib/games_and_rpg_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 14 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
15 16 17 |
# File 'lib/games_and_rpg_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 15 def y @y end |
Instance Method Details
#draw ⇒ Object
#
draw
#
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/games_and_rpg_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 42 def draw case face when 'left' @left.draw(@x, @y, 1) when 'right' @right.draw(@x, @y, 1) when 'up' @up.draw(@x, @y, 1) when 'down' @down.draw(@x, @y, 1) end end |
#move ⇒ Object
#
move
Enemy’s movement logic.
#
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/games_and_rpg_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 60 def move case face when 'right' @x += 0.5 if @x <= right_x @face = 'left' if @x == right_x when 'left' @x -= 0.5 if @x >= left_x @face = 'right' if @x == left_x when 'down' @y += 0.5 if @y <= down_y @face = 'up' if @y == down_y when 'up' @y -= 0.5 if @y >= up_y @face = 'down' if @y == up_y end end |