-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPlayer.pde
More file actions
109 lines (86 loc) · 2.61 KB
/
Player.pde
File metadata and controls
109 lines (86 loc) · 2.61 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
int currPieceType = 0;
int currPieceX = mapWidth / 2;
int currPieceY = -1;
int rotationState = 0;
color currPieceColor;
// Render the "ghost" piece that shows where your piece will land
void drawGhostPiece()
{
if(initialPause || gameOver) return;
int lastFitY = 0;
for(int y = 0; y < mapHeight + 2; y++)
{
if(checkIfPieceFits(currPieceX, currPieceY + y, rotationState))
{
lastFitY = currPieceY + y;
}
else
{
break;
}
}
pushMatrix();
translate(resX/2 - ((tileWidth * mapWidth) / 2), 68);
translate(tileWidth / 2, tileHeight / 2);
translate(tileWidth * currPieceX, tileHeight * lastFitY);
for(int y = 0; y < 4; y++)
{
for(int x = 0; x < 4; x++)
{
if(tetrominoes[currPieceType].charAt(rotate(x, y, rotationState)) == 'X')
{
//boxShape.setTexture(textures[currPieceType + 1]);
boxShape.setFill(color(255, 255, 255, 150));
boxShape.setStroke(color(0, 0, 0, 0));
shape(boxShape);
}
translate(tileWidth, 0);
}
translate(0, tileHeight);
translate(-(tileWidth * 4), 0);
}
popMatrix();
}
// Draw current falling tetronimo
void drawFallingPiece()
{
if(initialPause) return;
pushMatrix();
translate(resX/2 - ((tileWidth * mapWidth) / 2), 68);
translate(tileWidth / 2, tileHeight / 2);
translate(tileWidth * currPieceX, tileHeight * currPieceY);
for(int y = 0; y < 4; y++)
{
for(int x = 0; x < 4; x++)
{
if(tetrominoes[currPieceType].charAt(rotate(x, y, rotationState)) == 'X')
{
//boxShape.setTexture(textures[currPieceType + 1]);
boxShape.setFill(currPieceColor);
boxShape.setStroke(color(0, 0, 0, 255));
shape(boxShape);
}
translate(tileWidth, 0);
}
translate(0, tileHeight);
translate(-(tileWidth * 4), 0);
}
popMatrix();
}
void getNewPiece()
{
currPieceType = int(random(0, 6));
rotationState = 0;
currPieceX = mapWidth / 2 - 2;
if(currPieceType == 0 || currPieceType == 5 || currPieceType == 6)
{
// Makes it a little bit more fair for long pieces that would usually spawn in contact with the top of the playfield
currPieceY = -5;
}
else
{
currPieceY = -4;
}
currPieceColor = backgroundColor;
pushDownTimer = millis();
}