https://habrahabr.ru/post/202556/
int time;
float strength = 0.05;
int fieldwidth = 500;
int fieldheight = 500;
int pos = 0;
float [][] blocks = new float[10000][2];
int statebool = 1;
int index1 = 0;
void setup(){
time = millis();
size(500,500);
background(0,0,0);
}
void draw(){
if (statebool == 1)
{
if(millis() - time >= 50){
if( random(1) < strength) {
blocks[index1][0] = random(1)*(fieldwidth-10);
blocks[index1][1] = 0;
index1++;
}
background(0,0,0);
rect(pos,fieldheight-50,10,40);
for(int i = 0; i < index1; i++){
rect(blocks[i][0],blocks[i][1],10,10);
if( blocks[i][1] > fieldwidth - 60 && blocks[i][1] < fieldheight - 10 && abs( pos - blocks[i][0]) < 10 )
{
statebool = 0;
}
if(! (blocks[i][1] > fieldheight) ){
blocks[i][1] += 5;
}
}
time = millis();
}
strength += 0.001;
}
else
{
background(0,0,0);
fill(0, 102, 153);
textSize(25);
text("Game over",0, fieldheight/2);
}
}
void mouseMoved() {
pos = (mouseX > 0) ? ((mouseX < fieldwidth) ? mouseX : fieldwidth-10) : 0;
}
|