Projeto

Geral

Perfil

Estatísticas
| Revisão:

root / processing / blacklight / Level.pde @ 15

Histórico | Ver | Anotar | Download (4,16 KB)

1
/*
2
BLACKLIGHT v1.0
3
 Project made for Mestrado de Comunicação Multimédia, Ramo Multimédia Interactivo at Departamento de Comunicação e Arte at Universidade de Aveiro.
4
 
5
 Author: Nuno Simaria - nsimaria@ua.pt - #23652
6
 Other workgroup members: Ana Filipa Lacerda, Daniela Rei, Renato Costa, Julien Cuenin
7
 */
8

    
9
class Level
10
{
11
  Game game = null;
12
  Battlefield battlefield = null;
13
  Blacklord      blacklord   = null;
14
  Lightlord      lightlord   = null;
15
  Scoreboard scoreboard = null;
16
  
17
  Serial         port = null;
18

    
19
  //  Blackmatter [] blackmatter = {};
20
  //  Lightmatter [] lightmatter = null;
21
  String name = "Level Name";
22
  int width = 0;
23
  int height = 0;
24
  int[] balances = {
25
    127, 127, 127, 127, 127, 127
26
  };
27
  int rate = 60;
28

    
29
  void setup ()
30
  {
31
    if (this.game == null)
32
    {
33
      println ("No Game defined for this Level");
34
      return;
35
    }  
36

    
37

    
38
    this.battlefield = new Battlefield (this.width, this.height);
39
    this.lightlord = new Lightlord ();
40
    this.blacklord = new Blacklord ();
41
    this.scoreboard = new Scoreboard ();
42
    
43

    
44
    this.battlefield.level = this;
45
    this.lightlord.level = this;
46
    this.blacklord.level = this;  
47
    this.scoreboard.level = this;
48

    
49
    this.battlefield.setup ();
50
    this.lightlord.setup ();
51
    this.blacklord.setup ();
52
    this.scoreboard.setup ();
53
    
54

    
55
    String[] ports =  Serial.list ();
56

    
57
    if (ports.length == 1)
58
      return;
59

    
60
    if (_game_.leds != null)
61
    {
62
      this.port = _game_.leds;
63
    }
64
    
65
    
66
  }
67

    
68
  int balance ()
69
    {
70
    return this.battlefield.whites - this.battlefield.blacks;
71
    }
72

    
73
  void draw ()
74
  {
75
    this.battlefield.draw ();
76
    this.blacklord.draw ();
77
    this.lightlord.draw ();
78

    
79

    
80
    for (int i = 0; i < this.lightlord.minions [0].lighted.size (); i++)
81
    {
82
      int[] coords = (int []) this.lightlord.minions [0].lighted.get (i);
83

    
84
      Cell cell = this.battlefield.getCell (coords[0], coords[1]);
85
      //println ("balancing");
86
      cell.update(0);
87
    }
88

    
89
    Blackminion b = (Blackminion) this.blacklord.minions [0];      
90
    Cell cell = this.battlefield.getCell (b.x, b.y);
91
    cell.update(1);
92

    
93

    
94
    this.scoreboard.draw (); 
95

    
96
    //int balance = this.lightlord.balance ();
97

    
98
    // DESCOMENTAR!! LEDS
99
    //this.output (balance);
100

    
101
    //this.outcome (balance);
102

    
103

    
104
    //    this.blacklord.attack ();
105

    
106
    //    this.lightlord.defend ();
107
  }
108

    
109
  void loadXml (XMLElement node)
110
  {
111
    this.name       = node.getChild ("name").getContent ();
112
    this.width      = int (node.getChild ("width").getContent ());
113
    this.height     = int (node.getChild ("height").getContent ());    
114

    
115
    println ("Level " + name + ": " + this.width + "x" + this.height);
116
  }
117

    
118
  void output (int value)
119
  {
120
    if (this.port != null)
121
      this.port.write (value);
122

    
123
    //  value = value + increment;
124

    
125
    //  if (value >= 255)
126
    //    increment = -1;
127
    //  if (value <= 0)
128
    //    increment = 1;
129

    
130
    //  println (value);
131
  }
132

    
133
  void outcome (int balance)
134
  {
135
    this.rate--;
136

    
137
    if (this.rate == 0)
138
    {
139

    
140
      for (int i = 1; i < this.balances.length; i++)
141
        this.balances [this.balances.length - i] = this.balances [this.balances.length - i - 1];
142

    
143
      this.balances [0] = balance;
144
      if (balance == 0)
145
        _game_.playBlackPower ();
146
      else if (balance > 155)
147
        _game_.playLightPower ();
148

    
149
      this.rate = 60;
150
    }
151

    
152
    int total = 0;
153
    int blackpower = 0;
154
    int lightpower = 0;
155
    boolean consecutiveBlack = true;
156
    boolean consecutiveLight = true;
157
    for (int i = 0; i < this.balances.length; i++)
158
    {
159
      total += this.balances [i];
160

    
161
      if ((this.balances [i] == 0) && consecutiveBlack)
162
      {
163
        blackpower++;
164
        consecutiveLight = false;
165
      }
166
      else if ((this.balances [i] > 155) && consecutiveLight)
167
      {
168
        lightpower++;
169
        consecutiveBlack = false;
170
      }
171
      else
172
      {
173
        consecutiveLight = false;
174
        consecutiveBlack = false;
175
      }
176
    }
177

    
178
    if (blackpower > 0)
179
    {
180
      _game_.score (blackpower, 0);
181
    }
182
    else if (lightpower > 0)
183
    {
184
      _game_.score (lightpower, 1);
185
    }
186

    
187

    
188
    total = total / this.balances.length;
189

    
190
    if (blackpower == 6)
191
      _game_.blackWins ();
192
    else if (lightpower == 6)
193
      _game_.lightWins ();
194
  }
195
}
196