Projeto

Geral

Perfil

Estatísticas
| Revisão:

root / grid / grid.pde @ 11

Histórico | Ver | Anotar | Download (2,99 KB)

1
/**************************************************
2
 *
3
 * Size of each cell calculated with a 
4
 * division of stage's width with a multiple of 8
5
 *
6
 * 1024 / 16 = 64
7
 * 768 / 16 = 43
8
 * 1280 / 16 = 80
9
 *
10
 **************************************************/
11
int videoScale = 80;
12
int width = 1280;
13
int height = 720;
14

    
15
int cols, rows;
16
Cell[][] cells = {
17
};
18

    
19
// Players x,y
20
int mX ;
21
int mY;
22

    
23
PFont _regular_;
24

    
25
BlackMinion blackminion;
26

    
27
void setup() {
28
  _regular_ = loadFont ("Code-Bold-48.vlw");
29
  size(width, height);  
30

    
31
  cols = width/videoScale;
32
  rows = height/videoScale;
33

    
34
  //noLoop();
35
  drawGrid();
36
  
37
  // Setup blackminion
38
  blackminion = new BlackMinion();
39
  blackminion.setup();
40
}
41

    
42
void draw() {
43
  background(159, 182, 205);
44

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

    
57
/**************************************************
58
 *
59
 * Draw grid once
60
 *
61
 **************************************************/
62
void drawGrid () {
63
  for (int i = 0; i < cols; i++) {
64
    Cell [] column = new Cell [rows];
65
    for (int j = 0; j < rows; j++) {
66

    
67
      // Scaling up to draw a rectangle at (x,y)
68
      int x = i*videoScale;
69
      int y = j*videoScale;
70

    
71
      Cell cell = new Cell (x, y, videoScale);
72
      column [j] = cell;
73
      //cell.setup();
74
    }
75
    this.cells = (Cell[][]) append (this.cells, column);
76
  }
77
}
78

    
79
/**************************************************
80
 *
81
 * Returns cell affected by player
82
 *
83
 **************************************************/
84
Cell getCell (int x, int y)
85
{
86
  int cellX = floor (cols * x) / this.width;
87
  int cellY = floor (rows * y) / this.height;
88

    
89
  //println ("cellX " + cellX + ", cellY " + cellY);
90
  return this.cells [cellX][cellY];
91
}
92

    
93

    
94
/**************************************************
95
 *
96
 * Simulated White Player
97
 *
98
 **************************************************/
99
void mouseMoved() {
100
  mX = mouseX;
101
  mY = mouseY;
102
  Cell cell = this.getCell ( mX, mY);
103
  cell.update(0);
104
}
105

    
106

    
107
void moveBlack() {
108
  // Bounce
109
  if ( blackminion.posX <= 0 )  keyCode = RIGHT;
110
  if ( blackminion.posX >= 1270 )  keyCode = LEFT;
111
  if ( blackminion.posY <= 0 )  keyCode = DOWN;
112
  if ( blackminion.posY >= 710 )  keyCode = UP;
113

    
114

    
115
  switch(keyCode) {
116
  case UP: 
117
    blackminion.posY -= 5; 
118
    break;
119
  case DOWN: 
120
    blackminion.posY += 5; 
121
    break;
122
  case LEFT: 
123
    blackminion.posX -= 5; 
124
    break;
125
  case RIGHT: 
126
    blackminion.posX += 5; 
127
    break;
128
  }
129

    
130
  Cell cell = this.getCell ( blackminion.posX, blackminion.posY);
131
  cell.update(1);
132
}
133
/**************************************************
134
 *
135
 * Simulated Black Player
136
 *
137
 **************************************************/
138
class BlackMinion {
139
  int posX = 0;
140
  int posY = 0;
141

    
142
  void setup() {
143
  };
144

    
145
  void draw() {
146
    display();
147
  }
148

    
149

    
150
  void display() {
151
    println("posY" + posY);
152
    fill(0);
153
    ellipse (posX, posY, 20, 20);
154
  }
155
}; 
156