Class: Pugnacious::FightScene

Inherits:
Ray::Scene
  • Object
show all
Defined in:
lib/pugnacious/fight_scene.rb

Instance Method Summary collapse

Instance Method Details

#clean_upObject



46
47
48
49
50
51
52
53
54
# File 'lib/pugnacious/fight_scene.rb', line 46

def clean_up
  @players.each do |player|
    player = nil
  end

  @players = nil

  Ray::ImageSet.clear
end

#registerObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pugnacious/fight_scene.rb', line 25

def register
  always do
    @players.each do |player|
      player.control_keys.values.each do |direction|
        if holding? direction then player.move direction end
      end
    end

    @molecules.each &:move        
    if @molecules.all?{|m| m.player == @player1} or @molecules.all?{|m| m.player == @player2}
      @winner = text("You are the winner!!", :at => [200, 200], :size => 30)
    end
  end
end

#render(window) ⇒ Object



40
41
42
43
44
# File 'lib/pugnacious/fight_scene.rb', line 40

def render(window)
  @molecules.each { |molecule| window.draw molecule.body}
  @players.each { |player| window.draw player.pointer }
  window.draw(@winner) unless @winner.nil?
end

#setup(number_of_molecules) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pugnacious/fight_scene.rb', line 5

def setup(number_of_molecules)
  @player1 = Player.new(
    color: Ray::Color.blue,
    position: [0, 0],
    control_keys: {:up => :up, :right => :right, :down => :down, :left => :left})

  @player2 = Player.new(
    color: Ray::Color.red,
    position: [0, 0],
    control_keys: {:up => :w, :right => :d, :down => :s, :left => :a})

  @player2.pointer.pos = [50, 300]
  @player1.pointer.pos = [450, 300]

  @game_map = GameMap.generate_empty_map(MAP_SIZE, MAP_SIZE)
  @molecules = GameMap.generate_molecules(@game_map, @player1, @player2, number_of_molecules)

  @players = [@player1, @player2]
end