root / processing / blacklight / Battlefield.pde @ 15
Histórico | Ver | Anotar | Download (2,18 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 Battlefield |
| 10 |
{
|
| 11 |
int videoScale = 80; |
| 12 |
int width = 1280; |
| 13 |
int height = 720; |
| 14 |
|
| 15 |
int blacks = 0; |
| 16 |
int whites = 0; |
| 17 |
|
| 18 |
int cols, rows; |
| 19 |
Cell[][] cells = {
|
| 20 |
}; |
| 21 |
Level level = null; |
| 22 |
|
| 23 |
Battlefield (int w, int h) |
| 24 |
{
|
| 25 |
this.width = 1280; |
| 26 |
this.height = 720; |
| 27 |
|
| 28 |
println ("Battlefield " + this.width + "x" + this.height + " created");
|
| 29 |
} |
| 30 |
|
| 31 |
void setup() {
|
| 32 |
cols = width/videoScale; |
| 33 |
rows = height/videoScale; |
| 34 |
drawGrid(); |
| 35 |
} |
| 36 |
|
| 37 |
void draw() {
|
| 38 |
background(159, 182, 205); |
| 39 |
|
| 40 |
this.blacks = 0; |
| 41 |
this.whites = 0; |
| 42 |
|
| 43 |
for (int i = 0; i < this.cells.length; i++) {
|
| 44 |
//rows |
| 45 |
for (int j = 0; j < this.cells[i].length; j++) {
|
| 46 |
this.cells [i][j].setup ( this.cells[i][j].lifeBar, this.cells[i][j].animating ); |
| 47 |
this.cells [i][j].draw(); |
| 48 |
|
| 49 |
if (this.cells [i][j].isWhite ()) |
| 50 |
{
|
| 51 |
whites++; |
| 52 |
} |
| 53 |
else if (this.cells [i][j].isBlack ()) |
| 54 |
{
|
| 55 |
blacks++; |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
/************************************************** |
| 62 |
* |
| 63 |
* Draw grid once |
| 64 |
* |
| 65 |
**************************************************/ |
| 66 |
void drawGrid () {
|
| 67 |
for (int i = 0; i < cols; i++) {
|
| 68 |
Cell [] column = new Cell [rows]; |
| 69 |
for (int j = 0; j < rows; j++) {
|
| 70 |
|
| 71 |
// Scaling up to draw a rectangle at (x,y) |
| 72 |
int x = i*videoScale; |
| 73 |
int y = j*videoScale; |
| 74 |
|
| 75 |
Cell cell = new Cell (x, y, videoScale); |
| 76 |
column [j] = cell; |
| 77 |
//cell.setup(); |
| 78 |
} |
| 79 |
this.cells = (Cell[][]) append (this.cells, column); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
/************************************************** |
| 84 |
* |
| 85 |
* Returns cell affected by player |
| 86 |
* |
| 87 |
**************************************************/ |
| 88 |
Cell getCell (int x, int y) |
| 89 |
{
|
| 90 |
int cellX = floor (cols * x) / this.width; |
| 91 |
int cellY = floor (rows * y) / this.height; |
| 92 |
|
| 93 |
//println ("cellX " + cellX + ", cellY " + cellY);
|
| 94 |
return this.cells [cellX][cellY]; |
| 95 |
} |
| 96 |
} |
| 97 |
|