forked from fanta500/TetrisP5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shapegenerator.js
58 lines (56 loc) · 2.11 KB
/
shapegenerator.js
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
class Shapegenerator {
constructor(blockSize) {
this.blockSize = blockSize;
this.setShapes();
this.shapes = [this.squareShape, this.lineShape, this.tShape, this.lShape, this.jShape, this.sShape, this.zShape];
}
setShapes() {
this.squareShape = {
blockPos: [createVector(0,0), createVector(1,0), createVector(0,1), createVector(1,1)],
rotationPoint: createVector(1,1),
color: color(255,255,0),
type: "SQ"
}
this.lineShape = {
blockPos: [createVector(0,0), createVector(1,0), createVector(2,0), createVector(3,0)],
rotationPoint: createVector(2,1),
color: color(0,200,255),
type: "LINE"
}
this.tShape = {
blockPos: [createVector(0,0), createVector(1,0), createVector(2,0), createVector(1,1)],
rotationPoint: createVector(1.5,0.5),
color: color(255,0,255),
type: "T"
}
this.lShape = {
blockPos: [createVector(0,1), createVector(1,1), createVector(2,1), createVector(2,0)],
rotationPoint: createVector(1.5,1.5),
color: color(255,125,0),
type: "L"
}
this.jShape = {
blockPos: [createVector(0,0), createVector(0,1), createVector(1,1), createVector(2,1)],
rotationPoint: createVector(1.5,1.5),
color: color(0,0,255),
type: "J"
}
this.sShape = {
blockPos: [createVector(0,1), createVector(1,1), createVector(1,0), createVector(2,0)],
rotationPoint: createVector(1.5,1.5),
color: color(0,255,0),
type: "S"
}
this.zShape = {
blockPos: [createVector(0,0), createVector(1,0), createVector(1,1), createVector(2,1)],
rotationPoint: createVector(1.5,1.5),
color: color(255,0,0),
type: "Z"
}
}
generateShape() {
var shapeId = Math.floor(Math.random() * this.shapes.length);
var shape = new Shape(this.shapes[shapeId], this.blockSize);
return shape;
}
}