class Core::Game::Combat::Battle

Attributes

background[R]
enemies[R]

Public Class Methods

new(party, enemies, bg, control=nil) click to toggle source
# File lib/game/combat/battle.rb, line 260
def initialize(party, enemies, bg, control=nil)
  @background = Background.new(bg)
  @enemies = []
  @party = Party.new(party)
  @control = control
  if @control
    @control.battle = self
  end
  @gui = GUI.new
  x = y = 0
  enemies.each { |e|
    # TODO this is crap too
    e = BattleEnemy.new(e, 64+(x*64)+rand(32), 128+(y*96)+rand(48), 50)
    y += 1
    if y >= 4
      y = 0
      x += 1
    end
    e.gui = @gui
    @enemies.push(e)
  }
end

Public Instance Methods

attack(attacker, target) click to toggle source
# File lib/game/combat/battle.rb, line 283
def attack(attacker, target)
  puts("STUB: Battle.attack(#{attacker.name}, #{target.name})")
end
draw() click to toggle source
# File lib/game/combat/battle.rb, line 326
def draw
  @background.draw
  @control.draw
  @enemies.each { |enemy|
    enemy.draw
  }
  @party.members.each { |actor|
    actor.draw
  }
  @gui.draw
end
item(attacker, target, item) click to toggle source
# File lib/game/combat/battle.rb, line 291
def item(attacker, target, item)
  puts("STUB: Battle.item(#{attacker.name}, #{target.name}, #{item.name})")
end
spell(attacker, targets, spell) click to toggle source
# File lib/game/combat/battle.rb, line 287
def spell(attacker, targets, spell)
  puts("STUB: Battle.spell(#{attacker.name}, #{targets.name}, #{spell.name})")
end
update() click to toggle source
# File lib/game/combat/battle.rb, line 295
def update
  pause = @gui.paused?
  @background.update
  @control.update
  if !@gui.attacking.empty?
    attack(@gui.attacking.first, @gui.attacking.last)
    @gui.attacked
  end
  if !@gui.casting.empty?
    spell(@gui.casting.first, @gui.casting[1], @gui.casting.last)
    @gui.spell_cast
  end
  if !@gui.using.empty?
    item(@gui.using.first, @gui.using[1], @gui.using.last)
    @gui.item_used
  end
  @enemies.each { |enemy|
    enemy.update(pause)
  }
  @party.members.each { |actor|
    actor.update(pause)
    if actor.ready? and !actor.ready_shown
      @gui.push(:ready, actor)
      actor.ready_shown = true
    elsif !actor.ready?
      actor.ready_shown = false
    end
  }
  @gui.update
end