class EnemyPlayer

Constants

MAX_ATTACK_SPEED
POINT_VALUE_BASE
SPEED

Attributes

armor[RW]
attack_speed[RW]
cooldown_wait[RW]
health[RW]
x[RW]
y[RW]

Public Class Methods

new(scale, screen_width, screen_height, x = nil, y = nil, options = {}) click to toggle source
Calls superclass method GeneralObject::new
# File line-em-up/models/enemy_player.rb, line 16
def initialize scale, screen_width, screen_height, x = nil, y = nil, options = {}
  super(scale, x || rand(screen_width), y || 0, screen_width, screen_height, options)
  @cooldown_wait = 0
  @attack_speed = 0.5
  @health = 25
  @armor = 0
  @current_speed = (rand(5) * @scale).round + 1
end

Public Instance Methods

attack(player) click to toggle source
# File line-em-up/models/enemy_player.rb, line 38
def attack player
  return {
    projectiles: [EnemyBullet.new(@scale, @screen_width, @screen_height, self)],
    cooldown: EnemyBullet::COOLDOWN_DELAY
  }
end
drops() click to toggle source
# File line-em-up/models/enemy_player.rb, line 46
def drops
  [
    SmallExplosion.new(@scale, @screen_width, @screen_height, @x, @y, @image),
    Star.new(@scale, @screen_width, @screen_height, @x, @y)
  ]
end
get_draw_ordering() click to toggle source
# File line-em-up/models/enemy_player.rb, line 53
def get_draw_ordering
  ZOrder::Enemy
end
get_image() click to toggle source
# File line-em-up/models/enemy_player.rb, line 12
def get_image
  Gosu::Image.new("#{MEDIA_DIRECTORY}/airship1_color1_reverse.png")
end
get_points() click to toggle source
# File line-em-up/models/enemy_player.rb, line 25
def get_points
  return POINT_VALUE_BASE
end
get_speed() click to toggle source

SPEED = 1

# File line-em-up/models/enemy_player.rb, line 62
def get_speed
  @current_speed
end
is_alive() click to toggle source
# File line-em-up/models/enemy_player.rb, line 29
def is_alive
  @health > 0
end
take_damage(damage) click to toggle source
# File line-em-up/models/enemy_player.rb, line 34
def take_damage damage
  @health -= damage
end
update(mouse_x = nil, mouse_y = nil, player = nil, scroll_factor = 1) click to toggle source
# File line-em-up/models/enemy_player.rb, line 66
def update mouse_x = nil, mouse_y = nil, player = nil, scroll_factor = 1
  @cooldown_wait -= 1 if @cooldown_wait > 0
  if is_alive
    # Stay above the player
    if player.y < @y
        @y -= get_speed
    else
      if rand(2).even?
        @y += get_speed

        @y = @screen_height / 2 if @y > @screen_height / 2
      else
        @y -= get_speed

        @y = 0 + (get_height / 2) if @y < 0 + (get_height / 2)
      end
    end
    if rand(2).even?
      @x += get_speed
      @x = @screen_width if @x > @screen_width
    else
      @x -= get_speed
      @x = 0 + (get_width / 2) if @x < 0 + (get_width / 2)
    end


    @y < @screen_height + (get_height / 2)
  else
    false
  end
end