Projeto

Geral

Perfil

Revisão 15

Adicionado por Dinis Adriano Domingosmais de 9 anos atrás

Cell quads() are now regular rect(), prevent frame blinking while animating, correct color on flip

Ver diferenças:

processing/blacklight/Logo.pde
16 16
  void draw (int balance, int whites, int blacks)
17 17
    {
18 18
      
19
      println ("drawing!");
19
     //println ("drawing!");
20 20
     fill (255);
21 21
     
22 22
     textFont (_bold_, 48);
......
34 34
     text ("LIGHT", -_game_.width + 150, 48);
35 35
     scale (-1, 1);
36 36
    }
37
  }
37
  }
processing/blacklight/Level.pde
77 77
    this.lightlord.draw ();
78 78

  
79 79

  
80

  
81

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

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

  
......
195 193
      _game_.lightWins ();
196 194
  }
197 195
}
198

  
196

  
processing/blacklight/Battlefield.pde
11 11
  int videoScale = 80;
12 12
  int width = 1280;
13 13
  int height = 720;
14
  
14

  
15 15
  int blacks = 0;
16 16
  int whites = 0;
17 17

  
......
29 29
  }
30 30

  
31 31
  void setup() {
32

  
33 32
    cols = width/videoScale;
34 33
    rows = height/videoScale;
35

  
36

  
37 34
    drawGrid();
38 35
  }
39 36

  
40 37
  void draw() {
41 38
    background(159, 182, 205);
42 39

  
40
    this.blacks = 0;
41
    this.whites = 0;
43 42

  
44
  this.blacks = 0;
45
  this.whites = 0;
46

  
47
  
48

  
49
       for (int i = 0; i < this.cells.length; i++) { //rows
43
    for (int i = 0; i < this.cells.length; i++) { 
44
      //rows
50 45
      for (int j = 0; j < this.cells[i].length; j++) {
51 46
        this.cells [i][j].setup ( this.cells[i][j].lifeBar, this.cells[i][j].animating );
52 47
        this.cells [i][j].draw();
53
        
48

  
54 49
        if (this.cells [i][j].isWhite ())
55
          {
50
        {
56 51
          whites++;
57
          }
52
        }
58 53
        else if (this.cells [i][j].isBlack ())
59
          {
54
        {
60 55
          blacks++;
61
          }
56
        }
62 57
      }
63 58
    }
64
    
65 59
  }
66 60

  
67 61
  /**************************************************
......
100 94
    return this.cells [cellX][cellY];
101 95
  }
102 96
}
103

  
97

  
processing/blacklight/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