Dieses Codefragment soll 3 Extrabälle erzeugen, die aber in eine jeweils andere Richtung wie der Ursprungsball
fliegen sollen. Es gibt vier grobe Richtungen,
Bewegung auf der X-Achse, positiv oder negativ,
Bewegung auf der Y-Achse, positiv oder negativ.
Ich habe das wie folgt gelöst:
Irgendwie hab ich das Gefühl das geht auch einfacher und fänd es interessant zu Wissen wie...
MFG, Chris
fliegen sollen. Es gibt vier grobe Richtungen,
Bewegung auf der X-Achse, positiv oder negativ,
Bewegung auf der Y-Achse, positiv oder negativ.
Ich habe das wie folgt gelöst:
Code:
Ball mother = b.get(0);
Point pos = mother.getPosition();
int mxd = mother.getDirectionX();
int myd = mother.getDirectionY();
int mdid = 0;
if (mxd < 0 && myd < 0) mdid = 0;
else if (mxd < 0 && myd > 0) mdid = 1;
else if (mxd > 0 && myd < 0) mdid = 2;
else if (mxd > 0 && myd > 0) mdid = 3;
for(int i=0; i<4 ; i++)
{
if(i != mdid)
{
Ball ball = new Ball(p, gf.getBlockList());
ball.setPosition(pos);
switch(i)
{
case 0:
ball.setDirectionX(-1);
ball.setDirectionY(-1);
break;
case 1:
ball.setDirectionX(-1);
ball.setDirectionY(1);
break;
case 2:
ball.setDirectionX(1);
ball.setDirectionY(-1);
break;
case 3:
ball.setDirectionX(1);
ball.setDirectionY(1);
break;
}
b.add(ball);
}
}
Irgendwie hab ich das Gefühl das geht auch einfacher und fänd es interessant zu Wissen wie...
MFG, Chris