Revisão 15
Cell quads() are now regular rect(), prevent frame blinking while animating, correct color on flip
| Cell.pde | ||
|---|---|---|
| 15 | 15 |
int area = 0; |
| 16 | 16 |
|
| 17 | 17 |
int animX = 0; |
| 18 |
int animY = 0; |
|
| 18 | 19 |
|
| 19 | 20 |
// Propreties |
| 20 | 21 |
int lifeBar = 127; |
| ... | ... | |
| 41 | 42 |
void setup ( int lifeBar, Boolean animating ) {
|
| 42 | 43 |
this.lifeBar = lifeBar; |
| 43 | 44 |
this.animating = animating; |
| 45 |
this.side = side; |
|
| 44 | 46 |
|
| 45 | 47 |
// Don't let lifebar escalate |
| 46 | 48 |
if (this.lifeBar >= 255) this.lifeBar = 255; |
| ... | ... | |
| 50 | 52 |
strokeWeight (2); |
| 51 | 53 |
|
| 52 | 54 |
// paints cell according to side |
| 53 |
switch(side) {
|
|
| 55 |
switch(this.side) {
|
|
| 54 | 56 |
case 2: |
| 55 | 57 |
fill(127); |
| 56 | 58 |
break; |
| ... | ... | |
| 69 | 71 |
|
| 70 | 72 |
// if is not between animation draw cell and circle color |
| 71 | 73 |
if ( this.animating == false ) {
|
| 72 |
quad( |
|
| 73 |
this.posX, |
|
| 74 |
this.posY, |
|
| 75 |
|
|
| 76 |
this.posX + area, |
|
| 77 |
this.posY, |
|
| 78 |
|
|
| 79 |
this.posX + area, |
|
| 80 |
this.posY + area, |
|
| 81 |
|
|
| 82 |
this.posX, |
|
| 83 |
this.posY + area); |
|
| 84 |
if ( this.side == 1) {
|
|
| 85 |
fill(255); |
|
| 86 |
} |
|
| 87 |
|
|
| 74 |
rect ( posX, posY, area, area ); |
|
| 88 | 75 |
fill(lifeBar) ; |
| 89 | 76 |
noStroke(); |
| 90 | 77 |
// arc(this.posX + 40, this.posY + 40, 30, 30, 0, 360); |
| 91 | 78 |
ellipse(this.posX + 40, this.posY + 40, 30, 30); |
| 92 | 79 |
} |
| 93 | 80 |
|
| 94 |
|
|
| 95 | 81 |
// if white conquers plays animate white |
| 96 | 82 |
if (this.isWhite () && (this.side != 0)) {
|
| 97 | 83 |
this.lifeBar = 255; |
| ... | ... | |
| 103 | 89 |
this.lifeBar = 0; |
| 104 | 90 |
animateCell(0, 1); |
| 105 | 91 |
} |
| 106 |
|
|
| 107 | 92 |
} |
| 108 |
boolean isWhite () |
|
| 109 |
{
|
|
| 110 |
return (this.lifeBar >= 255); |
|
| 111 |
} |
|
| 112 |
|
|
| 113 |
boolean isBlack () |
|
| 114 |
{
|
|
| 115 |
return (this.lifeBar <= 0); |
|
| 116 |
} |
|
| 93 |
boolean isWhite () |
|
| 94 |
{
|
|
| 95 |
return (this.lifeBar >= 255); |
|
| 96 |
} |
|
| 117 | 97 |
|
| 98 |
boolean isBlack () |
|
| 99 |
{
|
|
| 100 |
return (this.lifeBar <= 0); |
|
| 101 |
} |
|
| 118 | 102 |
|
| 103 |
|
|
| 119 | 104 |
/************************************************** |
| 120 | 105 |
* |
| 121 | 106 |
* Updates cell conquer power |
| ... | ... | |
| 136 | 121 |
|
| 137 | 122 |
void updateWhite () {
|
| 138 | 123 |
this.lifeBar += 5; |
| 139 |
println(lifeBar); |
|
| 124 |
// println(lifeBar);
|
|
| 140 | 125 |
}; |
| 141 | 126 |
|
| 142 | 127 |
void updateBlack() {
|
| 143 |
println("updateBlack");
|
|
| 128 |
// println("updateBlack");
|
|
| 144 | 129 |
this.lifeBar -= 5; |
| 145 |
println(lifeBar); |
|
| 130 |
// println(lifeBar);
|
|
| 146 | 131 |
} |
| 147 | 132 |
|
| 148 | 133 |
/************************************************** |
| ... | ... | |
| 153 | 138 |
void animateCell( int clr, int side ) {
|
| 154 | 139 |
this.animating = true; |
| 155 | 140 |
if ( animX <= this.area) {
|
| 141 |
|
|
| 142 |
//this is a mess got to solve better |
|
| 156 | 143 |
if ( animX > area /2 ) {
|
| 157 | 144 |
fill(clr); |
| 158 |
print("animX " + animX);
|
|
| 159 |
} |
|
| 160 |
else {
|
|
| 145 |
//print("animX " + animX);
|
|
| 146 |
} else if ( this.side != 2 ) {
|
|
| 147 |
switch(this.side) {
|
|
| 148 |
case 0: |
|
| 149 |
fill(255); |
|
| 150 |
break; |
|
| 151 |
case 1: |
|
| 152 |
fill(0); |
|
| 153 |
break; |
|
| 154 |
} |
|
| 155 |
} else {
|
|
| 161 | 156 |
fill(127); |
| 162 | 157 |
} |
| 163 |
quad( |
|
| 164 |
this.posX+animX, |
|
| 165 |
this.posY, |
|
| 166 |
|
|
| 167 |
(this.posX + area) - animX, |
|
| 168 |
this.posY, |
|
| 169 |
|
|
| 170 |
(this.posX + area) -animX, |
|
| 171 |
this.posY + area, |
|
| 172 |
|
|
| 173 |
this.posX + animX, |
|
| 174 |
this.posY + area); |
|
| 175 |
} |
|
| 176 |
else {
|
|
| 158 |
|
|
| 159 |
rect ( posX + animX, posY, area - animX * 2, area); |
|
| 160 |
|
|
| 161 |
} else {
|
|
| 177 | 162 |
this.animating = false; |
| 178 | 163 |
this.side = side; |
| 179 | 164 |
animX = 0; |
| 165 |
|
|
| 166 |
// draw last frame animated to prevent blinking |
|
| 167 |
if ( this.side == 0 ) |
|
| 168 |
fill(255); |
|
| 169 |
else if ( this.side == 1 ) |
|
| 170 |
fill(0); |
|
| 171 |
|
|
| 172 |
rect ( posX + animX, posY, area - animX * 2, area); |
|
| 180 | 173 |
} |
| 181 | 174 |
animX +=3*0.7; |
| 175 |
animY += 3; |
|
| 182 | 176 |
}; |
| 183 |
} |
|
| 184 |
|
|
| 185 |
|
|
| 186 |
/*class Cell |
|
| 187 |
{
|
|
| 188 |
float x = 0; |
|
| 189 |
float y = 0; |
|
| 190 |
float width = 0; |
|
| 191 |
float height = 0; |
|
| 192 |
int balance = 0; |
|
| 193 |
|
|
| 194 |
Cell (float x, float y, float width, float height) |
|
| 195 |
{
|
|
| 196 |
this.x = x; |
|
| 197 |
this.y = y; |
|
| 198 |
this.width = width; |
|
| 199 |
this.height = height; |
|
| 200 |
} |
|
| 201 |
|
|
| 202 |
void draw () |
|
| 203 |
{
|
|
| 204 |
stroke (100); |
|
| 205 |
fill((this.balance / 2) + 127); |
|
| 206 |
rect (this.x, this.y, this.width - 1, this.height - 1); |
|
| 207 |
} |
|
| 208 |
|
|
| 209 |
}*/ |
|
| 177 |
|
|
| 178 |
} |
|
Também disponível em: Unified diff