我想让球在任何给定的一侧单独与砖块碰撞,并且为此我设置了一个类来创建砖块并包括一个检测球和砖之间碰撞的功能,但它最终创建了隐形我设定的边界之外的对手。什么导致了隐形碰撞器?
我已经尝试更改碰撞参数的变量和坐标,以考虑每个砖块的中心和左上角,以防它是坐标的问题,但这只会使它变得更糟。我也尝试改变每块砖之间的距离,但也没有成功。我也尝试在不同的计算机上运行它无济于事,所以我不认为它与内部软件问题或bug有关。
int Posx = 150;
int Posy = 150;
int Velx = 5;
int Vely = 5;
int value = 0;
int BouncePosX = 800;
int BouncePosY = 900;
int BounceLeft = -35;
int BounceRight = 35;
int lifeCount = 3;
int points = 0;
int numBricks = 5;
Bricks[] bricks = new Bricks[numBricks];
//声明将跟踪屏幕周围形状的位置和速度的变量//
void setup() {
size(1600,1000);
frameRate(60);
for (int i = 0; i<numBricks; i++){
float x = 10 +(i*70);
float y = 100;
bricks[i] = new Bricks(x,y,50.0,30.0);
void draw(){
background(0,255,0);
fill(255,0,255);
rect(BouncePosX,BouncePosY, 100, 5);
fill(255,0,0);
arc(Posx,Posy,20,20,0,TWO_PI);
for (int i = 0; i<numBricks; i++){
bricks[i].display();
bricks[i].collide();
class Bricks {
float x,y;
float posBrickX,posBrickY;
Bricks[] others;
Bricks(float xin, float yin, float posBrickXin, float posBrickYin) {
x = xin;
y = yin;
posBrickX = posBrickXin;
posBrickY = posBrickYin;
}
void collide() {
if ((Posx <= x+25) && (Posy <= y+15) && (Posy >= y-15) || (Posx
>= x-25) && (Posy <= y+15) && (Posy >=y-15)) {
Velx= Velx*-1;
points = points++;
}
if ((Posy <= y+15) && (Posx <= x+25) && (Posx >= x-25) || (Posy
>= y-15) && (Posx <= x+25) && (Posx >= x-25)){
Vely = Vely*-1;
points = points++;
}
void display() {
rect(x,y,posBrickX,posBrickY);
}
我希望碰撞检测最终会通过使用坐标并将区域确定为碰撞来检测每个砖块的每一侧,但到目前为止,它只是在整个屏幕上创建了随机碰撞区域。