added map tiles
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package de.miaurizius.jgame2d.core;
|
||||
|
||||
import de.miaurizius.jgame2d.entity.Player;
|
||||
import de.miaurizius.jgame2d.tile.TileManager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -21,15 +22,11 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
//FPS
|
||||
int FPS = 60;
|
||||
|
||||
TileManager tileM = new TileManager(this);
|
||||
KeyHandler keyH = new KeyHandler();
|
||||
Thread gameThread;
|
||||
Player player = new Player(this, keyH);
|
||||
|
||||
//Default position
|
||||
int playerX = 100;
|
||||
int playerY = 100;
|
||||
int playerSpeed = 4;
|
||||
|
||||
public GamePanel() {
|
||||
this.setPreferredSize(new Dimension(screenWidth, screenHeight));
|
||||
this.setBackground(Color.black);
|
||||
@@ -79,6 +76,9 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
public void paintComponent(Graphics graphics) {
|
||||
super.paintComponent(graphics);
|
||||
Graphics2D graphics2d = (Graphics2D) graphics;
|
||||
|
||||
//Draw all components
|
||||
tileM.draw(graphics2d);
|
||||
player.draw(graphics2d);
|
||||
graphics.dispose();
|
||||
}
|
||||
|
||||
10
src/de/miaurizius/jgame2d/tile/Tile.java
Normal file
10
src/de/miaurizius/jgame2d/tile/Tile.java
Normal 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;
|
||||
|
||||
}
|
||||
43
src/de/miaurizius/jgame2d/tile/TileManager.java
Normal file
43
src/de/miaurizius/jgame2d/tile/TileManager.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user