int m = 5;
int h = 100/m;
int n = 10;
int w = 400/n;
int [][] bricks = new int [m][n];
color[] colors = {color(255), color(128)};
void setup () {
size(400, 400);
}
void draw() {
background(128);
int y = 100;
for (int i = 0; i < bricks.length; i++) {
int x = 0;
for (int j = 0; j < bricks[i].length; j++) {
fill (colors[bricks[i][j]]);
rect(x, y, w, h);
x = x + w;
}
y = y + h;
}
}
void mousePressed() {
int y = 100;
for (int i = 0; i < bricks.length; i++) {
int x = 0;
stroke(128);
for (int j = 0; j < bricks[i].length; j++) {
if (mouseX < x + w && mouseY < y + h && mouseX > x && mouseY > y) {
bricks[i][j] = (bricks[i][j] + 1)%2;
}
x = x + w;
}
y = y + h;
}
}
int x = mouseX+50;
int y = 335;
int speedX = 3;
int speedY = 4;
void setup() {
size(400, 400);
}
void draw() {
background(0);
fill(0, 255, 0);
rect(mouseX, 350, 100, 30);
drawBall();
}
void drawBall() {
fill(255);
ellipse(mouseX+50, 335, 25, 25);
}
void moveBall() {
x = x + speedX;
y = y + speedY;
}
void bounceBall() {
if (x > 375 || x < 25) {
speedX = -1*speedX;
}
if (y > 375 || y < 25) {
speedY = -1*speedY;
}
}
void mousePressed() {
moveBall();
}
int windowWidth = 400;
int windowHeight = 400;
int paddleWidth = 100;
int paddleX = 0;
void setup() {
size(windowWidth,windowHeight);
}
void draw() {
...
paddleX = mouseX;
if(mouseX > windowWidth-paddleWidth) paddleX = windowWidth-paddleWidth;
rect(mouseX, 350, 100, 30);
...
}
Well for the ball launch, isn't it because you are calling "ellipse(mouseX+50, 335, 25, 25)"? Shouldn't that be "ellipse(x, y, 25, 25);"? You are updating x and y but I don't see them where I would expect.
For the paddle moving off the screen, I suspect it's because you need to do bound checking. Your paddle is 100 units wide, so you need to stop it moving when it's 100 units from the right edge of the screen.
Consider doing something like
. code:
int windowWidth = 400;
int windowHeight = 400;
int paddleWidth = 100;
int paddleX = 0;
void setup() {
size(windowWidth,windowHeight);
}
void draw() {
...
paddleX = mouseX;
if(mouseX > windowWidth-paddleWidth) paddleX = windowWidth-paddleWidth;
rect(mouseX, 350, 100, 30);
...
}
Well for the ball launch, isn't it because you are calling "ellipse(mouseX+50, 335, 25, 25)"? Shouldn't that be "ellipse(x, y, 25, 25);"? You are updating x and y but I don't see them where I would expect.
For the paddle moving off the screen, I suspect it's because you need to do bound checking. Your paddle is 100 units wide, so you need to stop it moving when it's 100 units from the right edge of the screen.
Consider doing something like
. code:
int windowWidth = 400;
int windowHeight = 400;
int paddleWidth = 100;
int paddleX = 0;
void setup() {
size(windowWidth,windowHeight);
}
void draw() {
...
paddleX = mouseX;
if(mouseX > windowWidth-paddleWidth) paddleX = windowWidth-paddleWidth;
rect(mouseX, 350, 100, 30);
...
}
jesus mate try stackoverflow or something thats a lot of prerequisite info in order to help you out
Whoever is teaching you how to code is teaching you completely arbitrary shit.