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0 0 0 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4
|
||||||
4 4 4 4 4 4 4 4 1 3 3 3 1 4 4 4 4 4 4 4 4 4 0 0 0 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4
|
4 4 4 4 4 4 4 4 1 3 3 3 1 4 4 4 4 4 4 4 4 4 0 0 0 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4
|
||||||
4 4 4 4 4 4 4 4 1 3 3 3 1 4 4 4 4 4 4 4 4 4 4 5 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4
|
4 4 4 4 4 4 4 4 1 3 3 3 1 4 4 4 4 4 4 4 4 4 4 5 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4
|
||||||
|
|||||||
45
src/de/miaurizius/jgame2d/core/AssetSetter.java
Normal file
45
src/de/miaurizius/jgame2d/core/AssetSetter.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package de.miaurizius.jgame2d.core;
|
||||||
|
|
||||||
|
import de.miaurizius.jgame2d.object.ChestObj;
|
||||||
|
import de.miaurizius.jgame2d.object.DoorObj;
|
||||||
|
import de.miaurizius.jgame2d.object.KeyObj;
|
||||||
|
|
||||||
|
public class AssetSetter {
|
||||||
|
|
||||||
|
GamePanel panel;
|
||||||
|
|
||||||
|
public AssetSetter(GamePanel panel) {
|
||||||
|
this.panel = panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setObject() {
|
||||||
|
panel.obj[0] = new KeyObj();
|
||||||
|
panel.obj[0].worldX = 23 * panel.tileSize;
|
||||||
|
panel.obj[0].worldY = 7 * panel.tileSize;
|
||||||
|
|
||||||
|
panel.obj[1] = new KeyObj();
|
||||||
|
panel.obj[1].worldX = 23 * panel.tileSize;
|
||||||
|
panel.obj[1].worldY = 40 * panel.tileSize;
|
||||||
|
|
||||||
|
panel.obj[2] = new KeyObj();
|
||||||
|
panel.obj[2].worldX = 37 * panel.tileSize;
|
||||||
|
panel.obj[2].worldY = 7 * panel.tileSize;
|
||||||
|
|
||||||
|
panel.obj[3] = new DoorObj();
|
||||||
|
panel.obj[3].worldX = 10 * panel.tileSize;
|
||||||
|
panel.obj[3].worldY = 9 * panel.tileSize;
|
||||||
|
|
||||||
|
panel.obj[4] = new DoorObj();
|
||||||
|
panel.obj[4].worldX = 8 * panel.tileSize;
|
||||||
|
panel.obj[4].worldY = 28 * panel.tileSize;
|
||||||
|
|
||||||
|
panel.obj[5] = new DoorObj();
|
||||||
|
panel.obj[5].worldX = 12 * panel.tileSize;
|
||||||
|
panel.obj[5].worldY = 22 * panel.tileSize;
|
||||||
|
|
||||||
|
panel.obj[6] = new ChestObj();
|
||||||
|
panel.obj[6].worldX = 10 * panel.tileSize;
|
||||||
|
panel.obj[6].worldY = 7 * panel.tileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ public class Boot {
|
|||||||
window.setLocationRelativeTo(null);
|
window.setLocationRelativeTo(null);
|
||||||
window.setVisible(true);
|
window.setVisible(true);
|
||||||
|
|
||||||
|
gamePanel.setupGame();
|
||||||
gamePanel.startGameThread();
|
gamePanel.startGameThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
KeyHandler keyH = new KeyHandler();
|
KeyHandler keyH = new KeyHandler();
|
||||||
Thread gameThread;
|
Thread gameThread;
|
||||||
public CollisionHandler collisionH = new CollisionHandler(this);
|
public CollisionHandler collisionH = new CollisionHandler(this);
|
||||||
|
public AssetSetter assetSetter = new AssetSetter(this);;
|
||||||
public Player player = new Player(this, keyH);
|
public Player player = new Player(this, keyH);
|
||||||
public SuperObject[] obj = new SuperObject[10];
|
public SuperObject[] obj = new SuperObject[10];
|
||||||
|
|
||||||
@@ -44,6 +45,10 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
this.setFocusable(true);
|
this.setFocusable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setupGame() {
|
||||||
|
assetSetter.setObject();
|
||||||
|
}
|
||||||
|
|
||||||
public void startGameThread() {
|
public void startGameThread() {
|
||||||
gameThread = new Thread(this);
|
gameThread = new Thread(this);
|
||||||
gameThread.start();
|
gameThread.start();
|
||||||
@@ -71,7 +76,7 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
drawCount++;
|
drawCount++;
|
||||||
}
|
}
|
||||||
if(timer >= 1000000000) {
|
if(timer >= 1000000000) {
|
||||||
//System.out.println("FPS: " + drawCount);
|
System.out.println("FPS: " + drawCount);
|
||||||
drawCount = 0;
|
drawCount = 0;
|
||||||
timer = 0;
|
timer = 0;
|
||||||
}
|
}
|
||||||
@@ -88,6 +93,7 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
|
|
||||||
//Draw all components
|
//Draw all components
|
||||||
tileM.draw(graphics2d);
|
tileM.draw(graphics2d);
|
||||||
|
for (SuperObject superObject : obj) if (superObject != null) superObject.draw(graphics2d, this);
|
||||||
player.draw(graphics2d);
|
player.draw(graphics2d);
|
||||||
graphics.dispose();
|
graphics.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/de/miaurizius/jgame2d/object/ChestObj.java
Normal file
18
src/de/miaurizius/jgame2d/object/ChestObj.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package de.miaurizius.jgame2d.object;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ChestObj extends SuperObject {
|
||||||
|
|
||||||
|
public ChestObj() {
|
||||||
|
name = "chest";
|
||||||
|
try {
|
||||||
|
image = ImageIO.read(new FileInputStream("assets/objects/chest.png"));
|
||||||
|
} catch(IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
18
src/de/miaurizius/jgame2d/object/DoorObj.java
Normal file
18
src/de/miaurizius/jgame2d/object/DoorObj.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package de.miaurizius.jgame2d.object;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class DoorObj extends SuperObject {
|
||||||
|
|
||||||
|
public DoorObj() {
|
||||||
|
name = "door";
|
||||||
|
try {
|
||||||
|
image = ImageIO.read(new FileInputStream("assets/objects/door.png"));
|
||||||
|
} catch(IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@ package de.miaurizius.jgame2d.object;
|
|||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.Key;
|
|
||||||
|
|
||||||
public class KeyObj extends SuperObject {
|
public class KeyObj extends SuperObject {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package de.miaurizius.jgame2d.object;
|
package de.miaurizius.jgame2d.object;
|
||||||
|
|
||||||
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
public class SuperObject {
|
public class SuperObject {
|
||||||
@@ -9,4 +12,15 @@ public class SuperObject {
|
|||||||
public boolean collision = false;
|
public boolean collision = false;
|
||||||
public int worldX, worldY;
|
public int worldX, worldY;
|
||||||
|
|
||||||
|
public void draw(Graphics2D graphics2D, GamePanel panel) {
|
||||||
|
int screenX = worldX - panel.player.worldX + panel.player.screenX;
|
||||||
|
int screenY = worldY - panel.player.worldY + panel.player.screenY;
|
||||||
|
|
||||||
|
if(worldX + panel.tileSize > panel.player.worldX - panel.player.screenX &&
|
||||||
|
worldX - panel.tileSize < panel.player.worldX + panel.player.screenX &&
|
||||||
|
worldY + panel.tileSize > panel.player.worldY - panel.player.screenY &&
|
||||||
|
worldY - panel.tileSize < panel.player.worldY + panel.player.screenY
|
||||||
|
) graphics2D.drawImage(image, screenX, screenY, panel.tileSize, panel.tileSize, null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ public class TileManager {
|
|||||||
|
|
||||||
while(worldCol < panel.maxWorldCol && worldRow < panel.maxWorldRow) {
|
while(worldCol < panel.maxWorldCol && worldRow < panel.maxWorldRow) {
|
||||||
int tileNum = mapTileNum[worldCol][worldRow];
|
int tileNum = mapTileNum[worldCol][worldRow];
|
||||||
|
|
||||||
int worldX = worldCol * panel.tileSize;
|
int worldX = worldCol * panel.tileSize;
|
||||||
int worldY = worldRow * panel.tileSize;
|
int worldY = worldRow * panel.tileSize;
|
||||||
int screenX = worldX - panel.player.worldX + panel.player.screenX;
|
int screenX = worldX - panel.player.worldX + panel.player.screenX;
|
||||||
@@ -90,6 +91,7 @@ public class TileManager {
|
|||||||
) graphics2D.drawImage(tile[tileNum].image, screenX, screenY, panel.tileSize, panel.tileSize, null);
|
) graphics2D.drawImage(tile[tileNum].image, screenX, screenY, panel.tileSize, panel.tileSize, null);
|
||||||
|
|
||||||
worldCol++;
|
worldCol++;
|
||||||
|
|
||||||
if(worldCol == panel.maxWorldCol) {
|
if(worldCol == panel.maxWorldCol) {
|
||||||
worldCol = 0;
|
worldCol = 0;
|
||||||
worldRow++;
|
worldRow++;
|
||||||
|
|||||||
Reference in New Issue
Block a user