xxxxxxxxxx
112
const UNIT = 20;
let curShape;
let shapeIndex = 0;
let pastShapeIndex;
let y = -UNIT * 4
let first = true;
let occupied = []
const shape_L = [
[1, 0, 0],
[1, 0, 0],
[1, 1, 0]
]
const shape_T = [
[1, 1, 1],
[0, 1, 0],
[0, 1, 0]
]
const shape_BLOCK = [
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]
]
const shape_SMALLBLOCK = [
[1, 1, 0],
[1, 1, 0],
[0, 0, 0]
]
const shape_LINE = [
[1, 1, 1],
[0, 0, 0],
[0, 0, 0]
]
const letter_B = [
[1,1,1,0,0],
[1,0,0,1,0],
[1,0,0,1,0],
[1,1,1,0,0],
[1,0,0,1,0],
[1,0,0,1,0],
[1,1,1,0,0],
]
const pyth = [[1,0,0,0,1],[1,0,0,0,1],[1,1,1,1,1],[1,0,0,0,1],[1,0,0,0,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]
const shapes = [ shape_L, shape_T, shape_BLOCK, shape_LINE, shape_SMALLBLOCK]
const shapesLen = shapes.length
let blocks = []
let blockAmount = 2
function setup() {
createCanvas(400, 400);
frameRate(5)
for (let i = 0; i < blockAmount; i++) {
blocks[i] = new Block(UNIT * int(random(width/UNIT)), -UNIT * int(random(height/UNIT)), shapes[int(random(shapesLen))]);
}
//curShape = shapes[shapeIndex];
}
function draw() {
background(220);
for (let i = 0; i < blocks.length; i++) {
shape(blocks[i].x, blocks[i].y, UNIT, blocks[i].sh);
blocks[i].lower()
print(blocks[i].y)
print(i)
}
}
function shape(x, y, pixelSize, sh) {
for (let i = 0; i < sh.length; i++) {
for (let j = 0; j < sh.length; j++) {
if (sh[i][j] == 1) {
stroke(155, 0, 0);
strokeWeight(3);
fill(255, 0, 0);
rect(x + j * pixelSize, y + i * pixelSize, pixelSize, pixelSize)
}
}
}
}
function randomShape() {
return shapes[random(int(shapes.length))]
}
// function wait(sec) {
// const mil = millis();
// while (true) {
// if (mil + sec * 1000 < millis()) {
// return "a"
// }
// }
// }