master
3009594 2024-09-19 17:36:13 +02:00
parent b741855c12
commit da1d2571d6
3 changed files with 22 additions and 3 deletions

View File

@ -8,12 +8,13 @@ import javax.swing.*;
public class GamePanel extends JPanel implements Runnable { public class GamePanel extends JPanel implements Runnable {
final static int WIDTH_WINDOW = 600; final static int WIDTH_WINDOW = 600;
final static int HEIGH_WINDOW = 900; final static int HEIGH_WINDOW = 800;
Dimension fensterSize = new Dimension(WIDTH_WINDOW, HEIGH_WINDOW); Dimension fensterSize = new Dimension(WIDTH_WINDOW, HEIGH_WINDOW);
DrawImages world; DrawImages world;
DrawImages flappy; DrawImages flappy;
DrawImages ground1,ground2; DrawImages ground1,ground2;
DrawImages bottompipe,toppipe;
Thread game; Thread game;
@ -32,6 +33,11 @@ public class GamePanel extends JPanel implements Runnable {
public void drawImage() { public void drawImage() {
world = new DrawImages(0, 0, WIDTH_WINDOW, HEIGH_WINDOW, new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Flappy_Bird\\world.png").getImage()); world = new DrawImages(0, 0, WIDTH_WINDOW, HEIGH_WINDOW, new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Flappy_Bird\\world.png").getImage());
flappy = new DrawImages(50, HEIGH_WINDOW / 2, 50, 50, new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Flappy_Bird\\flappy Bird.png").getImage()); flappy = new DrawImages(50, HEIGH_WINDOW / 2, 50, 50, new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Flappy_Bird\\flappy Bird.png").getImage());
toppipe = new DrawImages(WIDTH_WINDOW/2,0,40,HEIGH_WINDOW - 300,new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Flappy_Bird\\toppipe.png").getImage());
bottompipe = new DrawImages(WIDTH_WINDOW/2,HEIGH_WINDOW - 200,40,300,new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Flappy_Bird\\bottompipe.png").getImage());
// Zwei Bodenbilder nebeneinander zeichnen // Zwei Bodenbilder nebeneinander zeichnen
ground1 = new DrawImages(0, HEIGH_WINDOW - 100, WIDTH_WINDOW, 200, new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Flappy_Bird\\ground.png").getImage()); ground1 = new DrawImages(0, HEIGH_WINDOW - 100, WIDTH_WINDOW, 200, new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Flappy_Bird\\ground.png").getImage());
ground2 = new DrawImages(WIDTH_WINDOW, HEIGH_WINDOW - 100, WIDTH_WINDOW, 200, new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Flappy_Bird\\ground.png").getImage()); ground2 = new DrawImages(WIDTH_WINDOW, HEIGH_WINDOW - 100, WIDTH_WINDOW, 200, new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Flappy_Bird\\ground.png").getImage());
@ -41,6 +47,8 @@ public class GamePanel extends JPanel implements Runnable {
super.paint(g); super.paint(g);
world.draw(g); world.draw(g);
flappy.draw(g); flappy.draw(g);
toppipe.draw(g);
bottompipe.draw(g);
ground1.draw(g); ground1.draw(g);
ground2.draw(g); ground2.draw(g);
} }
@ -48,6 +56,7 @@ public class GamePanel extends JPanel implements Runnable {
public void move() { public void move() {
flappy.move(); flappy.move();
move_ground(); move_ground();
move_pips();
} }
public void move_ground() { public void move_ground() {
@ -65,9 +74,19 @@ public class GamePanel extends JPanel implements Runnable {
} }
} }
public void move_pips() {
toppipe.x -= 1;
bottompipe.x -= 1;
}
public void checkKollision() { public void checkKollision() {
if(flappy.intersects(ground1)) if(flappy.intersects(ground1))
gameOver = true; gameOver = true;
if (flappy.intersects(toppipe))
gameOver = true;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB