Hallo zusammen,
ich programmier grad das Spiel Breakout (Arkanoid) und bleib bei einer Fehlermeldung stecken. Kann mir jemand helfen? Wäre total nett. Hier sind die Codes:
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class Notarkanoid{
/**
* @param args
*/
private Ball ball;
public Notarkanoid() {
ball = new Ball(this);
}
public static void main(String[] args){
Notarkanoid notarkanoid = new Notarkanoid();
}
}
///////////////////////////UND:
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class Ball extends JPanel implements Runnable
{
private Thread t;
private int d;
private int x;
private int y;
private int dx;
private int dy;
private int size = 10;
private Block[] block= new Block;
private Bat bat;
public Ball()
{
super();
bat = new Bat();
this.x = bat.x+bat.w+10; // control the start point of x
this.y = bat.y+(bat.l/2); // control the start point of y
this.d = 20; // control the size of the ball
this.dx = 5; // control the speed of x
this.dy = 5; // control the speed of y
for (int i = 0; i < size; i++) {
block = new Block(400, 50+i*50, 49);
}
this.setOpaque(false);
this.setDoubleBuffered(true);
t = new Thread(this);
t.start();
}
protected void paintComponent(Graphics g)
{
g.setColor(Color.green);
g.fillRect(bat.x, bat.y, bat.w, bat.l);
for (int i = 0; i < size; i++) {
if (!block.i****()){
g.setColor(Color.green);
g.fillRect(block.x, block.y, block.w, block.w);
}
}
g.setColor(Color.red);
g.fillOval(this.x, this.y, this.d, this.d);
}
public void animate()
{
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event){
bat=new Bat();
}
});
addMouseMotionListener(new MouseMotionAdapter(){
public void mouseMoved(MouseEvent event){
bat.y=event.getY();
}
});
Rectangle bounds = this.getBounds();
for (int i = 0; i < size; i++) {
if (!block.i****()){
if ((this.x > block.x)&&(this.x+this.d<block.x+block.w)){
if ((this.y + this.d+dy > block.y)&&(this.y +dy <block.y+block.w)){
dy = -dy;
block.setI****(true);
}
}
if((this.y > block.y)&&(this.y +this.d <block.y+block.w)){
if ((this.x +this.d+dx > block.x)&&(this.x+dx <block.x+block.w)) {
dx = -dx;
block.setI****(true);
}
}
}
}
if(((this.y > bat.y)&&(this.y+this.d<bat.y+bat.l)) &&(this.x<bat.x+bat.w))dx= -dx;
if((this.x + this.d + dx > bounds.width))
dx = -dx;
if((this.y + dy < 0) || (this.y + this.d + dy > bounds.height))
dy = -dy;
if((this.x<10)) return;
this.x += dx;
this.y += dy;
this.repaint();
}
public void run()
{
while(true)
{
this.animate();
try
{
Thread.sleep(10);
}
catch (InterruptedException e) { }
}
}
}
class Block {
int w;
int x;
int y;
boolean hit;
public boolean i****(){
return hit;
}
public void setI****(boolean hit){
this.hit=hit;
}
public Block(int x, int y, int w) {
hit = false;
this.x = x;
this.y = y;
this.w = w;
}
}
class Bat {
int x;
int y;
int w;
int l;
public Bat() {
x = 10;
y = 200;
w = 20;
l = 100;
}
}
Danke schonmal!