root / processing / blacklight / Cell.pde @ 16
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 |
|
| 10 |
class Cell {
|
| 11 |
|
| 12 |
// Form |
| 13 |
int posX = 0; |
| 14 |
int posY = 0; |
| 15 |
int area = 0; |
| 16 |
|
| 17 |
int animX = 0; |
| 18 |
int animY = 0; |
| 19 |
|
| 20 |
int fillBlack = 0; |
| 21 |
int fillWhite = 255; |
| 22 |
int fillNeutral = 127; |
| 23 |
int opacity = 50; |
| 24 |
|
| 25 |
// Propreties |
| 26 |
int lifeBar = 127; |
| 27 |
Boolean animating = false; |
| 28 |
// 0 -> white |
| 29 |
// 1 -> black |
| 30 |
// 2-> null |
| 31 |
int side = 2; |
| 32 |
|
| 33 |
//Piece is a quad so receives x, y and quad area to deal later |
| 34 |
Cell ( int x, int y, int area) {
|
| 35 |
this.posX = x; |
| 36 |
this.posY = y; |
| 37 |
this.area = area; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
/************************************************** |
| 42 |
* |
| 43 |
* Upon creation it recieves the last lifeBar |
| 44 |
* and state from cell in same position |
| 45 |
* |
| 46 |
***************************************************/ |
| 47 |
void setup ( int lifeBar, Boolean animating, int cellArea ) {
|
| 48 |
this.lifeBar = lifeBar; |
| 49 |
this.animating = animating; |
| 50 |
this.side = side; |
| 51 |
|
| 52 |
// Don't let lifebar escalate |
| 53 |
if (this.lifeBar >= 255) this.lifeBar = 255; |
| 54 |
if (this.lifeBar <= 0) this.lifeBar = 0; |
| 55 |
|
| 56 |
stroke (150, this.opacity); |
| 57 |
strokeWeight (2); |
| 58 |
|
| 59 |
// paints cell according to side |
| 60 |
switch(this.side) {
|
| 61 |
case 2: |
| 62 |
fill( this.fillNeutral, this.opacity ); |
| 63 |
break; |
| 64 |
case 0: |
| 65 |
fill( this.fillWhite, this.opacity ); |
| 66 |
break; |
| 67 |
case 1: |
| 68 |
fill( this.fillBlack, this.opacity ); |
| 69 |
break; |
| 70 |
} |
| 71 |
}; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
void draw() {
|
| 76 |
|
| 77 |
// if is not between animation draw cell and circle color |
| 78 |
if ( this.animating == false ) {
|
| 79 |
fill(lifeBar, this.opacity + 20 ) ; |
| 80 |
rect ( posX, posY, area, area ); |
| 81 |
|
| 82 |
// noStroke(); |
| 83 |
// arc(this.posX + 40, this.posY + 40, 30, 30, 0, 360); |
| 84 |
//ellipse(this.posX + (this.area / 2 ), this.posY + ( this.area / 2), 30, 30); |
| 85 |
} |
| 86 |
|
| 87 |
// if white conquers plays animate white |
| 88 |
if (this.isWhite () && (this.side != 0)) {
|
| 89 |
this.lifeBar = 255; |
| 90 |
animateCell( this.fillWhite, 0); |
| 91 |
} |
| 92 |
|
| 93 |
// if black conquers plays animate black |
| 94 |
if (this.isBlack () && (this.side != 1)) {
|
| 95 |
this.lifeBar = 0; |
| 96 |
animateCell( this.fillBlack , 1); |
| 97 |
} |
| 98 |
} |
| 99 |
boolean isWhite () |
| 100 |
{
|
| 101 |
return (this.lifeBar >= 255); |
| 102 |
} |
| 103 |
|
| 104 |
boolean isBlack () |
| 105 |
{
|
| 106 |
return (this.lifeBar <= 0); |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
/************************************************** |
| 111 |
* |
| 112 |
* Updates cell conquer power |
| 113 |
* |
| 114 |
***************************************************/ |
| 115 |
void update (int player) {
|
| 116 |
if ( this.animating == false ) {
|
| 117 |
switch(player) {
|
| 118 |
case 0: |
| 119 |
updateWhite(); |
| 120 |
break; |
| 121 |
case 1: |
| 122 |
updateBlack(); |
| 123 |
break; |
| 124 |
} |
| 125 |
} |
| 126 |
}; |
| 127 |
|
| 128 |
void updateWhite () {
|
| 129 |
this.lifeBar += 5; |
| 130 |
// println(lifeBar); |
| 131 |
}; |
| 132 |
|
| 133 |
void updateBlack() {
|
| 134 |
// println("updateBlack");
|
| 135 |
this.lifeBar -= 5; |
| 136 |
// println(lifeBar); |
| 137 |
} |
| 138 |
|
| 139 |
/************************************************** |
| 140 |
* |
| 141 |
* Animates current cell |
| 142 |
* |
| 143 |
***************************************************/ |
| 144 |
void animateCell( int clr, int side ) {
|
| 145 |
this.animating = true; |
| 146 |
if ( animX <= this.area) {
|
| 147 |
fill(clr, this.opacity ); |
| 148 |
|
| 149 |
//this is a mess got to solve better |
| 150 |
/* if ( animX > area /2 ) {
|
| 151 |
fill(clr, this.opacity ); |
| 152 |
//print("animX " + animX);
|
| 153 |
} else if ( this.side != 2 ) {
|
| 154 |
switch(this.side) {
|
| 155 |
case 0: |
| 156 |
println("fillWhite");
|
| 157 |
fill( this.fillWhite, this.opacity ); |
| 158 |
break; |
| 159 |
case 1: |
| 160 |
fill( this.fillBlack, this.opacity ); |
| 161 |
break; |
| 162 |
} |
| 163 |
} else {
|
| 164 |
fill( this.fillNeutral, this.opacity ); |
| 165 |
}*/ |
| 166 |
|
| 167 |
noStroke(); |
| 168 |
rect ( posX + animX, posY, area - animX * 2, area); |
| 169 |
|
| 170 |
} else {
|
| 171 |
this.animating = false; |
| 172 |
this.side = side; |
| 173 |
animX = 0; |
| 174 |
|
| 175 |
// draw last frame animated to prevent blinking |
| 176 |
if ( this.side == 0 ) |
| 177 |
fill( this.fillWhite, this.opacity + 20 ); |
| 178 |
else if ( this.side == 1 ) |
| 179 |
fill( this.fillBlack, this.opacity + 20); |
| 180 |
|
| 181 |
rect ( posX + animX, posY, area - animX * 2, area); |
| 182 |
} |
| 183 |
animX +=5*0.9; |
| 184 |
animY += 5; |
| 185 |
}; |
| 186 |
|
| 187 |
} |