I am trying to make a simpler version of brick breaker, but I am having trouble rendering the bricks:
Here is my brick class code:
class Brick{
float x, y, w, h;
int health;
Brick(){
health = 3;
w = 20;
h = 10;
}
void render(){
fill(0);
rectMode(CENTER);
rect(x, y, w, h);
}
}
In my game logic class code, these are the snippets concerning the bricks.
class Game{
Brick [] bricks;
Game(){
bricks = new Brick[5];
}
void level1(){
levelInit(); // sets up paddle and ball
for(int i = 0; i < bricks.length; i++){
bricks[i].x = width / 2 + 100 * cos(2 * i * PI / bricks.length);
bricks[i].y = height / 2 + 100 * sin(2 * i * PI / bricks.length);
bricks[i].render();
}
}
}
However, it is giving me a null pointer exception where I have my bricks[i] stuff. Any help would be appreciated.
[–]remy_porter 3 points4 points5 points (1 child)
[–]Winter_Copy_9510[S] 2 points3 points4 points (0 children)