Projeto

Geral

Perfil

Estatísticas
| Revisão:

root / processing / blacklight / Level.pde @ 17

Histórico | Ver | Anotar | Download (4,23 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 (1024, 768);
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
    for (int j = 0; j < this.blacklord.blackmatter.size (); j++)
90
    {
91
    Blackmatter b = (Blackmatter) this.blacklord.blackmatter.get (j);      
92
    Cell cell = this.battlefield.getCell (b.x, b.y);
93
    cell.update(1);
94
    }
95

    
96
    this.scoreboard.draw (); 
97

    
98
    //int balance = this.lightlord.balance ();
99

    
100
    // DESCOMENTAR!! LEDS
101
    //this.output (balance);
102

    
103
    //this.outcome (balance);
104

    
105

    
106
    //    this.blacklord.attack ();
107

    
108
    //    this.lightlord.defend ();
109
  }
110

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

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

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

    
125
    //  value = value + increment;
126

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

    
132
    //  println (value);
133
  }
134

    
135
  void outcome (int balance)
136
  {
137
    this.rate--;
138

    
139
    if (this.rate == 0)
140
    {
141

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

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

    
151
      this.rate = 60;
152
    }
153

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

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

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

    
189

    
190
    total = total / this.balances.length;
191

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