私はかなり処理が新しく、助けが必要です。私は単純なキックボールゲームを構築しようとしています。簡単なアイデア:ボールが黄色のバーに当たったとき、ボールはバウンスします。ボールを「生きている」状態に保つためには、ボールを黄色のバーでバウンスさせる必要があります。私は正常に弾球のコードを見つけました(今はウィンドウの底を跳ね返しています)。また、マウスで動くバーを作成しました。私がこれまでに作ることができなかったのは、ボールがバーの実際にバウンスすることです。 som helpをお探しですか?ありがとう!!処理中にmouseY/mouseXによって移動された他のオブジェクトのオブジェクトをバウンスさせる
float ballX = 100;
float ballY = 0;
float h = 50;
int x, y;
//create a variable for speed
float speedY = 2;
void setup() {
size(400,400);
smooth();
noStroke();
// change the mode we draw circles so they are
// aligned in the top left
ellipseMode(CORNER);
}
void draw() {
//clear the background and set the fill colour
background(0);
fill(255);
//draw the circle in it's current position
ellipse(ballX, ballY, h,h);
//add a little gravity to the speed
speedY = speedY + 0.5;
//add speed to the ball's
ballY = ballY + speedY;
//bar
x = mouseX;
y = mouseY;
fill(255, 255, 0);
rect(x, y, 50, 10);
if (ballY > height - h) {
// set the position to be on the floor
ballY = height - h;
// and make the y speed 90% of what it was,
// but in the opposite direction
speedY = speedY * -0.9;
//switch the direction
//speedY = speedY;
}
else if (ballY <= 0) {
// if the ball hits the top,
// make it bounce off
speedY = -speedY;
}
}