added map tiles

This commit is contained in:
2025-11-26 21:34:49 +01:00
parent faeea23422
commit 9e6834b304
9 changed files with 58 additions and 5 deletions

BIN
assets/tiles/earth.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 614 B

BIN
assets/tiles/grass.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 616 B

BIN
assets/tiles/sand.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
assets/tiles/tree.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

BIN
assets/tiles/wall.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

BIN
assets/tiles/water.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 B

View File

@@ -1,6 +1,7 @@
package de.miaurizius.jgame2d.core; package de.miaurizius.jgame2d.core;
import de.miaurizius.jgame2d.entity.Player; import de.miaurizius.jgame2d.entity.Player;
import de.miaurizius.jgame2d.tile.TileManager;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@@ -21,15 +22,11 @@ public class GamePanel extends JPanel implements Runnable {
//FPS //FPS
int FPS = 60; int FPS = 60;
TileManager tileM = new TileManager(this);
KeyHandler keyH = new KeyHandler(); KeyHandler keyH = new KeyHandler();
Thread gameThread; Thread gameThread;
Player player = new Player(this, keyH); Player player = new Player(this, keyH);
//Default position
int playerX = 100;
int playerY = 100;
int playerSpeed = 4;
public GamePanel() { public GamePanel() {
this.setPreferredSize(new Dimension(screenWidth, screenHeight)); this.setPreferredSize(new Dimension(screenWidth, screenHeight));
this.setBackground(Color.black); this.setBackground(Color.black);
@@ -79,6 +76,9 @@ public class GamePanel extends JPanel implements Runnable {
public void paintComponent(Graphics graphics) { public void paintComponent(Graphics graphics) {
super.paintComponent(graphics); super.paintComponent(graphics);
Graphics2D graphics2d = (Graphics2D) graphics; Graphics2D graphics2d = (Graphics2D) graphics;
//Draw all components
tileM.draw(graphics2d);
player.draw(graphics2d); player.draw(graphics2d);
graphics.dispose(); graphics.dispose();
} }

View File

@@ -0,0 +1,10 @@
package de.miaurizius.jgame2d.tile;
import java.awt.image.BufferedImage;
public class Tile {
public BufferedImage image;
public boolean collision = false;
}

View File

@@ -0,0 +1,43 @@
package de.miaurizius.jgame2d.tile;
import de.miaurizius.jgame2d.core.GamePanel;
import javax.imageio.ImageIO;
import java.awt.*;
import java.io.FileInputStream;
import java.io.IOException;
public class TileManager {
GamePanel panel;
Tile[] tile;
public TileManager(GamePanel panel) {
this.panel = panel;
tile = new Tile[10];
getTileImage();
}
public void getTileImage() {
try {
tile[0] = new Tile();
tile[0].image = ImageIO.read(new FileInputStream("assets/tiles/grass.png"));
tile[1] = new Tile();
tile[1].image = ImageIO.read(new FileInputStream("assets/tiles/wall.png"));
tile[2] = new Tile();
tile[2].image = ImageIO.read(new FileInputStream("assets/tiles/grass.png"));
tile[3] = new Tile();
tile[3].image = ImageIO.read(new FileInputStream("assets/tiles/water.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void draw(Graphics2D graphics2D) {
graphics2D.drawImage(tile[0].image, 0, 0, panel.tileSize, panel.tileSize, null);
}
}