ラクランミューア:
基本的に私は、可動物体オフサークルバウンスを作成する方法についていくつかの指導をしたいです。イムは、問題を抱えて、3時間しようとしているため、支援のためのフォーラムになっています。文が、明らかに私はどれも正しく理解していないのですが作業している「場合は、」私は、複数の試みてきました。ありがとうございました :)
私は、if文異なるとこれを理解するために3時間しようとしています。
float x;
float easing = 1;
float circle_x = 1;
float circle_y = 30;
float rad = 12.5;
float gravity = 0.98;
float move_x = 5;
float move_y = 5;
void setup() {
size(640, 480);
frameRate(60);
}
void draw() {
background(#87CEEB);
fill(#7cfc00);
rect(0, 430, 640, 80);
float targetX = mouseX;
float dx = targetX - x;
x += dx * easing;
fill(#000000);
rect(x, 400, 30, 30);
rect(x-20, 390, 70, 10);
rect(x, 430, 5, 20);
rect(x+25, 430, 5, 20);
ellipse(circle_x, circle_y, 25, 25);
circle_x = circle_x + move_x;
circle_y = circle_y + move_y;
if (circle_x > width) {
circle_x = width;
move_x = -move_x;
}
if (circle_y > height) {
circle_y = height;
move_y = -move_y;
}
if (circle_x < 0) {
circle_x = 0;
move_x = -move_x;
}
if (circle_y < 0) {
circle_y = 0;
move_y= -move_y;
}
}
ボールが私のマウスカーソル(オブジェクトではありません)、グリッチサークルとstuttery画像によって跳ね返されている:文とだけ背受けた場合に任意の変数を挿入します。
Rabbid76:
xは、ボールの座標かを判断しなければならない(オブジェクトの範囲内にあるobjW
オブジェクトの幅です)。
circle_x > x && circle_x < x + objW
Yは、ボールの座標を有する場合に達するオブジェクトのレベルを(objH
オブジェクトのレベルであり、circleR
ボールの半径です)。
circle_y > objH - circleR
さらに、最初のヒットテストを行うために、オブジェクトが後に地面を跳ねている場合、テストを行うことが重要です。良いスタイルはでこれを行うことですelse if
声明:
int objX1 = -20;
int objX2 = 70;
int objH = 390;
int circleR = 25/2;
if (circle_x > x + objX1 && circle_x < x + objX2 && circle_y > objH - circleR ) {
circle_y = objH-circleR;
move_y = -move_y;
}
else if (circle_y > height) {
circle_y = height;
move_y = -move_y;
}
else if (circle_y < 0) {
circle_y = 0;
move_y= -move_y;
}
また、私は最初のボールの位置を計算して、IST現在の位置でボールを描画することをお勧めします:
float x;
float easing = 1;
float circle_x = 1;
float circle_y = 30;
float rad = 12.5;
float gravity = 0.98;
float move_x = 5;
float move_y = 5;
void setup() {
size(640, 480);
frameRate(60);
}
void draw() {
background(#87CEEB);
fill(#7cfc00);
rect(0, 430, 640, 80);
float targetX = mouseX;
float dx = targetX - x;
x += dx * easing;
circle_x = circle_x + move_x;
circle_y = circle_y + move_y;
if (circle_x > width) {
circle_x = width;
move_x = -move_x;
}
else if (circle_x < 0) {
circle_x = 0;
move_x = -move_x;
}
int objW = 70;
int objH = 390;
int circleR = 25/2;
if (circle_x > x && circle_x < x + objW && circle_y > objH-circleR ) {
circle_y = objH-circleR;
move_y = -move_y;
}
else if (circle_y > height) {
circle_y = height;
move_y = -move_y;
}
else if (circle_y < 0) {
circle_y = 0;
move_y= -move_y;
}
fill(#000000);
rect(x, 400, 30, 30);
rect(x-20, 390, 70, 10);
rect(x, 430, 5, 20);
rect(x+25, 430, 5, 20);
ellipse(circle_x, circle_y, 25, 25);
}