有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java简单的brakout游戏卡在颜色问题上,请

我正在做一个简单的突破游戏,我试图改变球与之碰撞的方块的颜色

它应该从绿色开始,然后变成橙色,然后是红色,最后是梨色

我弄明白了,但我搞不清楚颜色部分。我有3个类,BricksBallBat。其他一切都很好,但我不知道如何和如何让它工作

class Bricks {

    float x, y, w, h, count=1;
    int bNum = 10;
    boolean present;
    boolean red;
    color c ;
    int r, g, b;
    
    Bricks (int col, int row, int l, color clr) {
        
        c=clr;
        l= bNum;    
        w = width/l;
        h= 20 ;
        x = w * row ;
        y= h * col;
        present = true;
        red = false;
        g=255;
    }
        
    void display ( ) {

        fill(r, g, b);
        stroke(5);
        rectMode(CORNER);

        if (present) {
            rect(x, y, w, h);
        }
    }
    
    //check collision of ball agaings bricks
    void checkBounce (Ball ball) {

        if (present) {

            //top
            if (ball.y+ball.h >= y-15 && ball.y+ball.h <= y+(w/2) ) { 

                if (ball.x >= x && ball.x <= x+w) {
      
                    ball.vy *= -1;
                    r=255;
                    g=100;
                    b=0;

                    fill(r, g, b);

                    red=true;
                }
            }
      
            //left
            if (ball.x > this.x - ball.w &&ball.y> this.y&& ball.y < this.y+this.h && ball.x < x) {
                
                ball.vx *=-1;
                present=false;
            }

            //right 
            if (ball.x > this.x+w && ball.y > y && ball.y < y+h && ball.x < x+w+ball.w) {

                ball.vx *=-1;
                present=false;
            }

            //bottom
            if (ball.x> x && ball.x< x+w && ball.y < (this.y+h+ball.h) && ball.y>y+h) {
                ball.vy *=-1;
                count++;
      
                print(count);
                present=false;
            }
        }
    }    
}

共 (0) 个答案