![]() |
|
|
Themen-Optionen |
|
|
Nach oben #1 |
|
Neuer Benutzer
Registriert seit: 01.05.2008
Beiträge: 1
|
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[size]; 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[i] = 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].isHit()){ g.setColor(Color.green); g.fillRect(block[i].x, block[i].y, block[i].w, block[i].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].isHit()){ if ((this.x > block[i].x)&&(this.x+this.d<block[i].x+block[i].w)){ if ((this.y + this.d+dy > block[i].y)&&(this.y +dy <block[i].y+block[i].w)){ dy = -dy; block[i].setIsHit(true); } } if((this.y > block[i].y)&&(this.y +this.d <block[i].y+block[i].w)){ if ((this.x +this.d+dx > block[i].x)&&(this.x+dx <block[i].x+block[i].w)) { dx = -dx; block[i].setIsHit(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 isHit(){ return hit; } public void setIsHit(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! |
|
|
|
|
|
Nach oben #2 |
|
Projektleiter
Registriert seit: 30.11.2005
Ort: Bottrop
Beiträge: 1.084
|
Was für einer Fehlermeldung?
__________________
Patrick Gotthardts Weblog. |
|
|
|
|
|
Nach oben #3 |
|
Projektleiter
Registriert seit: 02.12.2004
Ort: Wildeshausen
Beiträge: 2.235
|
@daliuliu: bitte editiere deinen post und nutze den code-tag um den Code. Danke.
__________________
Umfragen: Wenn du dich in ein interessantes Thema eingearbeitet hast, dann lass andere daran teilhaben! Danke! |
|
|
|
|
|
Nach oben #4 |
|
Erfahrener Benutzer
Registriert seit: 30.03.2006
Ort: Pfinztal
Beiträge: 355
|
Ja, editiere das mal. Und dann erkläre, was du da machen willst und warum das ein Compile-Fehler gibt.
Code:
ball = new Ball(this);
__________________
Open Sourcing the Online Gaming Universe PHP/SQL/Java/C++/Assembler. Seit Jahren Mitglied und Entwickler in einem der wohl größten Java-Projekte der Welt: http://weblogs.java.net/blog/hansmul...e_desktop.html |
|
|
|
![]() |
| Lesezeichen |
| Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1) | |
| Themen-Optionen | |
|
|
Ähnliche Themen
|
||||
| Thema | Autor | Forum | Antworten | Letzter Beitrag |
| PHPeclipse - herausfinden, wo eine Methode aufgerufen wird | Ben | Eclipse | 3 | 12.03.2006 22:46 |
| Warum wird die run()-Methode nicht aufgerufen? | Ben | Desktop-Applikationen und Grafik | 0 | 09.02.2006 11:52 |
| makeActions wird nicht aufgerufen (RCP) | undefined | Desktop-Applikationen und Grafik | 0 | 02.01.2006 19:53 |
| Grafik-Link wenn aufgerufen verändert? | Magicman | HTML, XML und CSS | 10 | 04.10.2005 15:16 |
| Mein kleines Spiel | CyberHoney | Projekte unserer Mitglieder | 3 | 08.08.2005 21:22 |