Hey
ich habe ein Problem, ich wollte das spiel Breakout mit dem Programm Processing schreiben aber ich kriege es nicht hin das die kugel an den Kästchen abspringt und die Kästchen dann weg gehen
Ich hoffe mir kann jemand helfen.
ich habe ein Problem, ich wollte das spiel Breakout mit dem Programm Processing schreiben aber ich kriege es nicht hin das die kugel an den Kästchen abspringt und die Kästchen dann weg gehen
Ich hoffe mir kann jemand helfen.
Java:
float f=0;
float geschwindigkeit_x = 5;
float geschwindigkeit_y = 5;
float a=255;
float b=0;
float pos_x=mouseX;
float pos_y=570;
int[][] level_1 = { {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
};
void setup()
{
size(600,577);
frameRate(70);
}
void draw()
{
background(#000000);
noStroke();
fill(255,200,0);
ellipse(pos_x,pos_y,20,20);
rectMode(CENTER);
rect(mouseX,560,120,20);
rectMode(CORNER);
fill(a);
stroke(0);
level();
// verändern von x
if (pos_x <= 25) {geschwindigkeit_x = random(6,13);}
if (pos_x >= 570) {geschwindigkeit_x = random(-6,-13);}
pos_x = pos_x + geschwindigkeit_x;
// verändern von y
if (pos_y <= 25) {geschwindigkeit_y = random(6,13);}
if (pos_y >= 545 && pos_x <= mouseX+50 && pos_x >= mouseX-50) {geschwindigkeit_y = random(-6,-13);}
pos_y = pos_y + geschwindigkeit_y;
if (pos_y >=600) {noLoop();}
}
int level()
{
int anzahl_pillen = 0;
for (int zeile = 0; zeile < (level_1.length); zeile++) // Reihe
{
for (int spalte = 0; spalte < (level_1[0].length); spalte++)// Spalte
{
// Hintergrund zeichnen
if (level_1[zeile][spalte] == 1)
{
fill(#FFFFFF);
rect (spalte*level_1.length,zeile*level_1.length,width/level_1.length,height/level_1.length);
}
if (level_1[zeile][spalte] == 3)
{
fill(#7fff00);
rect (spalte*level_1.length,zeile*level_1.length,width/level_1.length,height/level_1.length);
}
// Pillen zeichnen
if (level_1[zeile][spalte] == 2)
{
fill(#ffa500);
rect(spalte*level_1.length+level_1.length*0.5,zeile*level_1.length+level_1.length*0.5,5,5);
anzahl_pillen++;
}
}
}
return anzahl_pillen;
}
float abstand(float x1,float y1,float x2,float y2)
{return sqrt(sq(x2-x1)+sq(y2-y1));}
int gefangen()
{
if (abstand(pos_x, pos_y, pos_x, pos_y) < width/level_1.length)
{return 3;}
else
{return 0;}
}
void mousePressed() {
pos_x=mouseX;
pos_y=570;
loop();}
Zuletzt bearbeitet von einem Moderator: