We're making the game Breakout in my comp sci. class but I cannot figure out how to make the bricks appear, and then automatically make the specific block(s) disappear when the ball collides into them. (We're currently using intersect() to detect collisions).
Currently, I can get the ball to bounce off both the paddle and the walls, but not off of the bricks. There are no compilation errors; the bricks just don't show.
Any help would be greatly appreciated!
Thanks!
BrickCollection.java
Brick.java
Currently, I can get the ball to bounce off both the paddle and the walls, but not off of the bricks. There are no compilation errors; the bricks just don't show.
Any help would be greatly appreciated!
Thanks!
BrickCollection.java
Code:
import apcslib.*;
import chn.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Random;
public class BrickCollection
{
// int l = n.gotLength();
// int w = n.gotWidth();
ArrayList<Brick> bricklist=
new ArrayList<Brick>();
public void add(Brick k)
{
bricklist.add(k);
}
public void Show(Graphics g)
{
for(Brick k:bricklist)
{
int x=100;
int y=100;
Brick bk = new Brick(x,y);
k.show(g);
}
}
public void Remove(Brick k)
{
bricklist.remove(k);
}
// public Rectangle getBounds(){
// int width=(int)w;
// int length=(int)h;
// return new Rectangle(x,y,width,length);
// }
}
Brick.java
Code:
import apcslib.*;
import chn.util.*;
import java.awt.*;
import java.awt.event.*;
public class Brick extends DrawableRegularPolygon
{
int h,w;
public Brick(int x, int y)
{
this.x = x;
this.y = y;
}
public void move()
{
}
public void show(Graphics g)
{
w = 50;
h = 10;
g.setColor(Color.black);
g.drawRect(x,y,w,h);
g.fillRect(x,y,w,h);
}
public Rectangle getBounds()
{
return new Rectangle(x,y,w,h);
}
}