Class: Core::Game::Combat::Battle

Inherits:
Object
  • Object
show all
Defined in:
lib/game/combat/battle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(party, enemies, bg, control = nil) ⇒ Battle

Returns a new instance of Battle.



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# 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

Instance Attribute Details

#backgroundObject (readonly)

Returns the value of attribute background.



258
259
260
# File 'lib/game/combat/battle.rb', line 258

def background
  @background
end

#enemiesObject (readonly)

Returns the value of attribute enemies.



258
259
260
# File 'lib/game/combat/battle.rb', line 258

def enemies
  @enemies
end

Instance Method Details

#attack(attacker, target) ⇒ Object



283
284
285
# File 'lib/game/combat/battle.rb', line 283

def attack(attacker, target)
  puts("STUB: Battle.attack(#{attacker.name}, #{target.name})")
end

#drawObject



326
327
328
329
330
331
332
333
334
335
336
# 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) ⇒ Object



291
292
293
# 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) ⇒ Object



287
288
289
# File 'lib/game/combat/battle.rb', line 287

def spell(attacker, targets, spell)
  puts("STUB: Battle.spell(#{attacker.name}, #{targets.name}, #{spell.name})")
end

#updateObject



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# 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