Home>
Creating a block break
I am a beginner who just started learning processing.
I am currently trying to make a block break using Processing.
I made a ball and a reflection board, but I don't know how to use the array and for, so I can't make the block well.
When I hit the blocks side by side, I want to erase the hit blocks while reflecting the ball.
Applicable source codefloat bx = 200;
float by = 370;
float bvx = random (1,3);
float bvy = random (-3, -2);
int i, j, blx, bly;
int [] ble = new int [36];
void setup () {
size (400,400);
rectMode (CENTER);
for (int i = 0;i<36;i ++) {
ble [i] = 1;
}
}
void draw () {
background (0);
Player ();
Ball ();
block ();
}
void block () {
for (int i = 0;i<36;i ++) {
if (ble [i] == 1) {
blx = (i% 6) * 60 + 50;
bly = (i/6) * 20 + 40;
if (! ((bx + 5>blx-20)&&(blx + 20<bx-5)&&(bly-10<by + 5)&&(bly + 10>by-5)))
{return;}
if ((blx-20<bx-5)&&(blx + 20>bx + 5)) {bvy = -bvy;return;}
if ((bly-10<by-5)&&(bly + 10>by + 5)) {bvx = -bvx;return;}
bvx = -bvx;
bvy = -bvy;
}
if (ble [i] == 1) {// 0: invisible 1: visible
rect (blx, bly, 40,20);
}
}
}
void Player () {
rect (mouseX, 380,30,10);
if (mouseX>385) {mouseX = 385;}
if (mouseX<15) {mouseX = 15;}
}
void Ball () {
ellipse (bx, by, 10,10);
bx = bx + bvx;
by = by + bvy;
if (bx<5 || 395<bx) {bvx = -bvx;}
if (by<5 || by == 370&mouseX-1115<bx&bx<mouseX + 1115) {bvy = -bvy;}
}
-
Answer # 1
Related articles
- i want to add processing to the controller created with devise
- c# - i was creating a block breaking game, but since the ball does not move, i want to solve the cause
- i want to move the bar in the unity block breaking game (2d)
- Block processing before mybatis executes SQL statements
- Use batch processing to delete files created (or modified) N days ago or a specified date and time (before and after)
Trends
Because it will not remain debugged if it is not drawn, it seems wasteful, but let's draw with a dedicated for first.
If there is
return;
in the function, the function is exited there. It is the same in for.There are
break;
andcontinue;
as commands that can be used in for.break;
is similar toreturn;
, but assumes that for has been terminated and jumps after for.continue;
goes to the next lap without going to the next line.(I ’m sorry for the poor explanation. Please check for details ^^;)