Projeto

Geral

Perfil

Estatísticas
| Revisão:

root / processing / blacklight / Battlefield.pde @ 16

Histórico | Ver | Anotar | Download (2,21 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 = 64;
12
  int width;
13
  int height;
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 = w;
26
    this.height = h;
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
   background(100);
40

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

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

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

    
62
  /**************************************************
63
   *
64
   * Draw grid once
65
   *
66
   **************************************************/
67
  void drawGrid () {
68
    for (int i = 0; i < cols; i++) {
69
      Cell [] column = new Cell [rows];
70
      for (int j = 0; j < rows; j++) {
71

    
72
        // Scaling up to draw a rectangle at (x,y)
73
        int x = i*videoScale;
74
        int y = j*videoScale;
75

    
76
        Cell cell = new Cell (x, y, videoScale);
77
        column [j] = cell;
78
        //cell.setup();
79
      }
80
      this.cells = (Cell[][]) append (this.cells, column);
81
    }
82
  }
83

    
84
  /**************************************************
85
   *
86
   * Returns cell affected by player
87
   *
88
   **************************************************/
89
  Cell getCell (int x, int y)
90
  {
91
    int cellX = floor (cols * x) / this.width;
92
    int cellY = floor (rows * y) / this.height;
93

    
94
    //println ("cellX " + cellX + ", cellY " + cellY);
95
    return this.cells [cellX][cellY];
96
  }
97
}
98