Projeto

Geral

Perfil

Estatísticas
| Revisão:

root / processing / blacklight / Level.pde @ 18

Histórico | Ver | Anotar | Download (4,54 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
  int timer = 0;
17
  
18
  Serial         port = null;
19

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

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

    
38
    this.timer = 1000;
39
    
40
    this.battlefield = new Battlefield (1024, 768);
41
    this.lightlord = new Lightlord ();
42
    this.blacklord = new Blacklord ();
43
    this.scoreboard = new Scoreboard ();
44
    
45

    
46
    this.battlefield.level = this;
47
    this.lightlord.level = this;
48
    this.blacklord.level = this;  
49
    this.scoreboard.level = this;
50

    
51
    this.battlefield.setup ();
52
    this.lightlord.setup ();
53
    this.blacklord.setup ();
54
    this.scoreboard.setup ();
55
    
56

    
57
    String[] ports =  Serial.list ();
58

    
59
    if (ports.length == 1)
60
      return;
61

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

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

    
75
  void draw ()
76
  {
77
    this.battlefield.draw ();
78
    this.blacklord.draw ();
79
    this.lightlord.draw ();
80

    
81

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

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

    
91
    for (int j = 0; j < this.blacklord.blackmatter.size (); j++)
92
    {
93
      Blackmatter b = (Blackmatter) this.blacklord.blackmatter.get (j);      
94
      Cell cell = this.battlefield.getCell (b.x, b.y);
95
      cell.update(1);
96
    }
97

    
98
    this.scoreboard.draw (); 
99

    
100
    //int balance = this.lightlord.balance ();
101

    
102
    // DESCOMENTAR!! LEDS
103
    //this.output (balance);
104
    if ( this.timer <= 0 ) this.outcome ();
105
    this.timer--;
106

    
107

    
108
    //    this.blacklord.attack ();
109

    
110
    //    this.lightlord.defend ();
111
  }
112

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

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

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

    
127
    //  value = value + increment;
128

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

    
134
    //  println (value);
135
  }
136

    
137
  void outcome ()
138
  {
139
    int score = this.battlefield.blacks - this.battlefield.whites;
140
    
141
    if ( score > 0 ) {
142
       _game_.blackWins ();
143
    } else if ( score < 0 ) {
144
      _game_.lightWins (); 
145
    } else {
146
     this.timer += 1000; 
147
    }
148
      
149
      
150
    
151
/*    this.rate--;
152

    
153
    if (this.rate == 0)
154
    {
155

    
156
      for (int i = 1; i < this.balances.length; i++)
157
        this.balances [this.balances.length - i] = this.balances [this.balances.length - i - 1];
158

    
159
      this.balances [0] = balance;
160
      if (balance == 0)
161
        _game_.playBlackPower ();
162
      else if (balance > 155)
163
        _game_.playLightPower ();
164

    
165
      this.rate = 60;
166
    }
167

    
168
    int total = 0;
169
    int blackpower = 0;
170
    int lightpower = 0;
171
    boolean consecutiveBlack = true;
172
    boolean consecutiveLight = true;
173
    for (int i = 0; i < this.balances.length; i++)
174
    {
175
      total += this.balances [i];
176

    
177
      if ((this.balances [i] == 0) && consecutiveBlack)
178
      {
179
        blackpower++;
180
        consecutiveLight = false;
181
      }
182
      else if ((this.balances [i] > 155) && consecutiveLight)
183
      {
184
        lightpower++;
185
        consecutiveBlack = false;
186
      }
187
      else
188
      {
189
        consecutiveLight = false;
190
        consecutiveBlack = false;
191
      }
192
    }
193

    
194
    if (blackpower > 0)
195
    {
196
      _game_.score (blackpower, 0);
197
    }
198
    else if (lightpower > 0)
199
    {
200
      _game_.score (lightpower, 1);
201
    }
202

    
203

    
204
    total = total / this.balances.length;
205

    
206
    if (blackpower == 6)
207
      _game_.blackWins ();
208
    else if (lightpower == 6)
209
      _game_.lightWins ();*/
210
  }
211
}
212