-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlock.pde
53 lines (44 loc) · 1.34 KB
/
Block.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* Written by Tommy Sebestyen
* Purpose: This class handles the individual blocks
* that make up the Tetris shapes.
*/
class Block {
float bx; // x location in the field
float by; // y location in the field
color col; // Block's color
boolean fall; // Whether the block is falling or not
// Default constructor (should not be used)
Block() {
col=color(0, 0, 0);
bx=0;
by=0;
fall=true;
println("ERROR: Something called an uninitialized Block. This should not happen.");
}
// Constructor
// c - the colour of the block
// x - the position of the block horizontally
// y - the position of the block vertically
Block(color c, float x, float y) {
// Set internal fields to constructor parameters
col=c;
bx=x;
by=y;
// All new Blocks always fall
fall=true;
// Log
println("New Block created");
println(" x = "+x);
println(" y = "+y);
}
// Add or subtract from the current colour towards the goal colour.
// I never use this method. Go figure.
// goal - the colour to move toward
color transformColour(color goal) {
// Select the direction (if they are equal, nothing happens)
if (col>goal) col++;
if (goal>col) col--;
// Return the current colour (so the function can stop being called if the colour has been reached)
return col;
}
}