Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo,

ich sitze jetzt hier seit Tagen an meinem Programm und verzweifle, weil ich einfach nicht weiter komme. Ich muss für die Schule ein Spiel programmieren und bin gerade dabei meine run-Methode zu erstellen, die wiefolgt aussieht:

public void run() {

while(true){

if(x==0)

ball.setzeXpos(ball.xpos + 1);

ball.setzeYpos(ball.ypos - 1);

//Ball fährt nach rechts oben

repaint();

try {

Thread.sleep(4);

} catch (InterruptedException e)

{

}

}

}

Also meine Frage: Könnt ihr mir bitte dabei helfen, wie ich meine Randbegrenzungen für meinen Frame erstellen kann, damit meine Kugel an den Wänden abprallt?

Vielen Dank im Vorraus

Matze1992

ich hab schon probiert mit:

if(x==100){

ball.setzeXpos(ball.xpos - 1);

ball.setzeYpos(ball.ypos - 1);

}

die Richtung an einer bestimmten Stelle zu ändern, aber egal was ich schreibe die Kugel fährt über den Rand hinaus. Könnte mir bitte einer den genauen if-Befehl schreiben?

Matze

if(x==100){

ball.setzeXpos(ball.xpos - 1);

ball.setzeYpos(ball.ypos - 1);

}

Vielleicht überlegst Du Dir einmal was Du prüfen musst. Du musst die aktuelle Position Deines Ball gegen die Grenzen prüfen und vor allem musst Du das getrennt für X- und Y-Koordinaten machen. Denke einmal selbst darüber nach.

Phil

das versuch ich ja die ganze Zeit aber ich bin noch Anfänger und verstehs nich...ich versuchs weiter.

Mfg Matze

Danke Phil!!!

Dank deinem Tipp, dass ich die Abfrage von X und Y trennen soll habe ich es hinbekommen!!! Danke :-)

Matze

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.