The idea is that when we detect the mouse click, we also pick a random item and draw it behind the brown block. That way it’ll look like it is coming out of the block as it falls away.
Let’s start with a few coins of various colors.
boolean hit, brown_block, question_block=true;
float bb_x, bb_y, bb_dy;
void setup() {
size(600, 400);
reset_brown_block();
}
void draw() {
background(64);
pushMatrix();
translate(width/2,height/2);
draw_random_item();
popMatrix();
if( question_block ){
question_box_draw(width/2, height/2);
}
if( brown_block ){
if( bb_y > 1000 ){ brown_block = false; }
bb_dy += 0.32;
bb_y += bb_dy;
brown_box_draw(bb_x, bb_y);
}
if( hit ){
fill(255,0,0);
//ellipse(30,30,20,20);
}
}
void reset_brown_block(){
bb_dy = -5;
bb_y = height/2;
bb_x = width/2;
}
void brown_box_draw(float x, float y){
pushStyle();
pushMatrix();
translate(x, y);
fill(128, 64, 0);
strokeWeight(3);
stroke(0);
rectMode(CENTER);
rect(0, 0, 200, 200, 20);
fill(0);
translate(40,-30);
pushMatrix();
rotate(QUARTER_PI);
rect(0,0,10,60);
popMatrix();
translate(-80,0);
rotate(-QUARTER_PI);
rect(0,0,10,60);
popMatrix();
popStyle();
}
void question_box_draw(float x, float y) {
pushStyle();
pushMatrix();
translate(x, y);
fill(255, 255, 0);
strokeWeight(3);
stroke(0);
rectMode(CENTER);
rect(0, 0, 200, 200, 20);
textSize(196);
textAlign(CENTER);
translate(0, 70);
fill(0);
text("?", -2, 0);
text("?", 2, 0);
text("?", 0, -2);
text("?", 0, 2);
fill(255);
text("?", 0, 0);
popMatrix();
popStyle();
}
void mousePressed(){
if( !hit ){
hit = true;
brown_block = true;
question_block = false;
r_item = int(random(3));
} else {
hit = false;
brown_block = false;
question_block = true;
reset_brown_block();
}
}
void draw_random_item(){
switch(r_item){
case 0: // Yellow coin.
fill(255,255,0);
ellipse(0,0,80,80);
noFill();
ellipse(0,0,60,60);
rect(-5,-20,10,40);
break;
case 1: // Red coin.
fill(200,0,0);
ellipse(0,0,80,80);
noFill();
ellipse(0,0,60,60);
rect(-5,-20,10,40);
break;
case 2: // Blue coin.
fill(0,0,200);
ellipse(0,0,80,80);
noFill();
ellipse(0,0,60,60);
rect(-5,-20,10,40);
break;
default:
fill(255,0,255);
rect(0,0,20,20);
fill(0);
text("ERROR: unknown item number!", 0, 0);
break;
}
}
int r_item = 1;
And that’s enough help to get you started. Now it’s up to you to determine what items you want, or use images for them instead of drawing them yourself. Give it a go - post your code/images for more help.