Class: Enemy
- Inherits:
-
Object
- Object
- Enemy
- Defined in:
- lib/games_paradise/gui/gosu/garden_hero/core/level/enemy.rb
Overview
#
Enemy - main enemy class
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
A new instance of Enemy.
-
#move ⇒ Object
enemy’s movement logic.
Constructor Details
#initialize(window, x, y, face = 'right') ⇒ Enemy
Returns a new instance of Enemy.
8 9 10 11 12 13 14 15 |
# File 'lib/games_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 8 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.
17 18 19 |
# File 'lib/games_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 17 def down_y @down_y end |
#face ⇒ Object (readonly)
Returns the value of attribute face.
17 18 19 |
# File 'lib/games_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 17 def face @face end |
#left_x ⇒ Object (readonly)
Returns the value of attribute left_x.
17 18 19 |
# File 'lib/games_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 17 def left_x @left_x end |
#right_x ⇒ Object (readonly)
Returns the value of attribute right_x.
17 18 19 |
# File 'lib/games_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.
17 18 19 |
# File 'lib/games_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 17 def up_y @up_y end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
17 18 19 |
# File 'lib/games_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 17 def window @window end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
17 18 19 |
# File 'lib/games_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 17 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
17 18 19 |
# File 'lib/games_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 17 def y @y end |
Instance Method Details
#draw ⇒ Object
draw
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/games_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 20 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
enemy’s movement logic
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/games_paradise/gui/gosu/garden_hero/core/level/enemy.rb', line 34 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 |