root / processing / blacklight / Game.pde @ 18
Histórico | Ver | Anotar | Download (6,55 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 Game |
| 10 |
{
|
| 11 |
XMLElement xml; |
| 12 |
int width; |
| 13 |
int height; |
| 14 |
int background; |
| 15 |
int fill; |
| 16 |
Input[] inputs = {};
|
| 17 |
Level[] levels = {};
|
| 18 |
Level current = null; |
| 19 |
Intro intro = null; |
| 20 |
Logo logo = null; |
| 21 |
Winner winner = null; |
| 22 |
// SoundCipher ost = null; |
| 23 |
AudioChannel ost = null; |
| 24 |
AudioChannel sfx = null; |
| 25 |
Serial leds = null; |
| 26 |
|
| 27 |
int blackBattles = 0; |
| 28 |
int lightBattles = 0; |
| 29 |
|
| 30 |
|
| 31 |
PImage bgimage = null; |
| 32 |
|
| 33 |
void setup () |
| 34 |
{
|
| 35 |
this.xml = new XMLElement(_root_, "xml/config.xml"); |
| 36 |
this.loadXml (this.xml); |
| 37 |
// size (this.width, this.height); |
| 38 |
|
| 39 |
background (this.background); |
| 40 |
fill (this.fill); |
| 41 |
noStroke (); |
| 42 |
|
| 43 |
String [] ports = Serial.list (); |
| 44 |
|
| 45 |
|
| 46 |
/* Nunchuk on */ |
| 47 |
// for (int i = 0; i < ports.length; i++) |
| 48 |
// {
|
| 49 |
|
| 50 |
println ("ports found: " + ports.length);
|
| 51 |
|
| 52 |
Input input = new Input (); |
| 53 |
if (ports.length > 0) |
| 54 |
{
|
| 55 |
input.setup (ports [0]); |
| 56 |
} |
| 57 |
|
| 58 |
this.inputs = (Input []) append (this.inputs, input); |
| 59 |
|
| 60 |
if (ports.length > 1) |
| 61 |
{
|
| 62 |
this.leds = new Serial(_root_, ports [1], 9600); |
| 63 |
} |
| 64 |
// } |
| 65 |
/* Nunchuk off */ |
| 66 |
this.reset (); |
| 67 |
|
| 68 |
|
| 69 |
// this.current = this.levels [0]; |
| 70 |
// this.current.setup (); |
| 71 |
// this.current.game = this; |
| 72 |
// this.current.setup (); |
| 73 |
//this.bgimage = loadImage("images/egypt.png");
|
| 74 |
} |
| 75 |
void reset () |
| 76 |
{
|
| 77 |
this.intro = new Intro (); |
| 78 |
this.playIntro (); |
| 79 |
} |
| 80 |
|
| 81 |
void begin () |
| 82 |
{
|
| 83 |
this.intro = null; |
| 84 |
this.winner = null; |
| 85 |
this.logo = new Logo (); |
| 86 |
this.logo.setup (); |
| 87 |
|
| 88 |
|
| 89 |
Level level = new Level (); |
| 90 |
level.name = this.levels [0].name; |
| 91 |
level.width = this.levels [0].width; |
| 92 |
level.height = this.levels [0].height; |
| 93 |
|
| 94 |
this.current = level; |
| 95 |
this.current.game = this; |
| 96 |
this.current.setup (); |
| 97 |
|
| 98 |
this.playSoundtrack (); |
| 99 |
} |
| 100 |
|
| 101 |
void draw () |
| 102 |
{
|
| 103 |
if (this.intro != null) |
| 104 |
{
|
| 105 |
this.intro.draw (); |
| 106 |
return; |
| 107 |
} |
| 108 |
|
| 109 |
background (this.background); |
| 110 |
|
| 111 |
|
| 112 |
if (this.winner != null) |
| 113 |
this.winner.draw (); |
| 114 |
|
| 115 |
//image(this.bgimage, 0, 0); |
| 116 |
|
| 117 |
for (int i = 0; i < this.inputs.length; i++) |
| 118 |
this.inputs [i].draw (); |
| 119 |
|
| 120 |
if (this.current != null) |
| 121 |
this.current.draw (); |
| 122 |
|
| 123 |
if (this.logo != null) |
| 124 |
{
|
| 125 |
if (this.current != null) |
| 126 |
this.logo.draw (this.current.timer, this.current.battlefield.whites, this.current.battlefield.blacks); |
| 127 |
//else if (this.winner != null) |
| 128 |
//this.logo.draw ((this.winner.team == 0) ? 0 : 255, 0, 0); |
| 129 |
} |
| 130 |
|
| 131 |
} |
| 132 |
|
| 133 |
void loadXml (XMLElement node) |
| 134 |
{
|
| 135 |
println ("Loading Game XML...");
|
| 136 |
this.width = int (node.getChild ("screen/width").getContent ());
|
| 137 |
this.height = int (node.getChild ("screen/height").getContent ());
|
| 138 |
this.background = unhex (node.getChild ("screen/background").getContent ());
|
| 139 |
this.fill = unhex (node.getChild ("screen/fill").getContent ());
|
| 140 |
|
| 141 |
XMLElement levels_xml = node.getChild ("levels");
|
| 142 |
|
| 143 |
for (int i = 0; i < levels_xml.getChildCount (); i++) |
| 144 |
{
|
| 145 |
XMLElement level_xml = levels_xml.getChild (i); |
| 146 |
|
| 147 |
Level level = new Level (); |
| 148 |
level.game = this; |
| 149 |
level.loadXml (level_xml); |
| 150 |
this.levels = (Level [])append (this.levels, level); |
| 151 |
} |
| 152 |
|
| 153 |
println ("Game XML loaded.");
|
| 154 |
} |
| 155 |
|
| 156 |
void playSoundtrack () |
| 157 |
{
|
| 158 |
/* if (this.ost != null) |
| 159 |
this.ost.stop (); |
| 160 |
this.ost = new AudioChannel ("ost4real.wav");
|
| 161 |
this.ost.play (Ess.FOREVER);*/ |
| 162 |
} |
| 163 |
|
| 164 |
void playLightHit () |
| 165 |
{
|
| 166 |
/* if (this.sfx != null) |
| 167 |
this.sfx.stop (); |
| 168 |
this.sfx = new AudioChannel ("lightfire.wav");
|
| 169 |
this.sfx.play (); |
| 170 |
/* SoundCipher sc = new SoundCipher(_root_); |
| 171 |
sc.playNote(150, 50, 0.5);*/ |
| 172 |
} |
| 173 |
|
| 174 |
void playBlackFire () |
| 175 |
{
|
| 176 |
/* if (this.sfx != null) |
| 177 |
this.sfx.stop (); |
| 178 |
this.sfx = new AudioChannel ("blackfire.wav");
|
| 179 |
this.sfx.play (); |
| 180 |
/* SoundCipher sc = new SoundCipher(_root_); |
| 181 |
sc.playNote(10, 120, 0.5);*/ |
| 182 |
} |
| 183 |
|
| 184 |
void playBlackBomb () |
| 185 |
{
|
| 186 |
if (this.sfx != null) |
| 187 |
this.sfx.stop (); |
| 188 |
this.sfx = new AudioChannel ("blackbomb.wav");
|
| 189 |
this.sfx.play (); |
| 190 |
/* SoundCipher sc = new SoundCipher(_root_); |
| 191 |
sc.playNote(10, 120, 0.5); |
| 192 |
sc.playNote(20, 120, 0.5); |
| 193 |
sc.playNote(30, 120, 0.5); |
| 194 |
sc.playNote(40, 120, 0.5);*/ |
| 195 |
|
| 196 |
} |
| 197 |
|
| 198 |
void playBlackWins () |
| 199 |
{
|
| 200 |
if (this.ost != null) |
| 201 |
this.ost.stop (); |
| 202 |
|
| 203 |
this.ost = new AudioChannel ("blackwins.wav");
|
| 204 |
this.ost.play (); |
| 205 |
// this.ost.stop (); |
| 206 |
// this.ost = null; |
| 207 |
// SoundCipher sc = new SoundCipher(_root_); |
| 208 |
|
| 209 |
// sc.playAudioFile("ost.wav");
|
| 210 |
} |
| 211 |
|
| 212 |
void playLightWins () |
| 213 |
{
|
| 214 |
if (this.ost != null) |
| 215 |
this.ost.stop (); |
| 216 |
this.ost = new AudioChannel ("lightwins.wav");
|
| 217 |
this.ost.play (); |
| 218 |
// this.ost.stop (); |
| 219 |
// this.ost = null; |
| 220 |
} |
| 221 |
|
| 222 |
void playBlackPower () |
| 223 |
{
|
| 224 |
if (this.sfx != null) |
| 225 |
this.sfx.stop (); |
| 226 |
this.sfx = new AudioChannel ("blackhit.wav");
|
| 227 |
this.sfx.play (); |
| 228 |
// this.ost.stop (); |
| 229 |
// this.ost = null; |
| 230 |
} |
| 231 |
|
| 232 |
void playLightPower () |
| 233 |
{
|
| 234 |
if (this.sfx != null) |
| 235 |
this.sfx.stop (); |
| 236 |
this.sfx = new AudioChannel ("lighthit.wav");
|
| 237 |
this.sfx.play (); |
| 238 |
// this.ost.stop (); |
| 239 |
// this.ost = null; |
| 240 |
} |
| 241 |
|
| 242 |
void playIntro () |
| 243 |
{
|
| 244 |
if (this.ost != null) |
| 245 |
this.ost.stop (); |
| 246 |
this.ost = new AudioChannel ("intro.wav");
|
| 247 |
this.ost.play (); |
| 248 |
} |
| 249 |
|
| 250 |
void blackWins () |
| 251 |
{
|
| 252 |
if (this.ost != null) |
| 253 |
this.ost.stop (); |
| 254 |
println ("The new black.");
|
| 255 |
this.current = null; |
| 256 |
this.blackBattles ++; |
| 257 |
this.winner = new Winner (); |
| 258 |
this.winner.setup (0); |
| 259 |
this.playBlackWins (); |
| 260 |
} |
| 261 |
|
| 262 |
void lightWins () |
| 263 |
{
|
| 264 |
if (this.ost != null) |
| 265 |
this.ost.stop (); |
| 266 |
println ("Whitey.");
|
| 267 |
this.current = null; |
| 268 |
this.lightBattles ++; |
| 269 |
this.winner = new Winner (); |
| 270 |
this.winner.setup (1); |
| 271 |
this.playLightWins (); |
| 272 |
} |
| 273 |
|
| 274 |
void score (int power, int side) |
| 275 |
{
|
| 276 |
switch (side) |
| 277 |
{
|
| 278 |
case 0: fill (0, 120); stroke (100, 180); break; |
| 279 |
case 1: fill (255, 120); stroke (155, 180); break; |
| 280 |
} |
| 281 |
rectMode (CORNER); |
| 282 |
|
| 283 |
int cursorX = 10; |
| 284 |
for (int i = 0; i < power; i++) |
| 285 |
{
|
| 286 |
rect (cursorX, 60, (i + 1) * 15, 10); |
| 287 |
scale (-1, 1); |
| 288 |
rect ( -_game_.width + cursorX,60, (i + 1) * 15, 10); |
| 289 |
scale (-1, 1); |
| 290 |
cursorX += (i + 1) * 15 + 7; |
| 291 |
} |
| 292 |
|
| 293 |
} |
| 294 |
} |