Compare commits
9 Commits
a5ca52310c
...
ff82d8f7e6
| Author | SHA1 | Date | |
|---|---|---|---|
|
ff82d8f7e6
|
|||
|
1bc9ad9923
|
|||
|
b890eb7a58
|
|||
|
02066640e2
|
|||
|
038fbb14db
|
|||
|
a17ca8853c
|
|||
|
d294d76ca5
|
|||
|
e69809df4c
|
|||
|
c00cb61e08
|
3
.gitignore
vendored
@@ -1,5 +1,7 @@
|
|||||||
### IntelliJ IDEA ###
|
### IntelliJ IDEA ###
|
||||||
out/
|
out/
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
!**/src/main/**/out/
|
!**/src/main/**/out/
|
||||||
!**/src/test/**/out/
|
!**/src/test/**/out/
|
||||||
.kotlin
|
.kotlin
|
||||||
@@ -25,7 +27,6 @@ bin/
|
|||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
||||||
.idea/
|
|
||||||
|
|
||||||
### Mac OS ###
|
### Mac OS ###
|
||||||
.DS_Store
|
.DS_Store
|
||||||
50
assets/maps/testmap2.map
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 12 12 12 12 12 12 12 13 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 13 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 13 12 12 12 12 12 12 12 13 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 13 12 12 12 12 12 12 13 12 12 12 12 12 12 13 12 12 12 12 12 12 12 12 13 12 12 12 12 12 12 12 12 12 12 12 12 12 13 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 12 12 13 12 12 12 12 12 13 12 12 12 12 12 12 12 13 12 12 12 12 12 12 12 13 12 12 13 12 12 12 13 12 12 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 13 12 12 12 12 12 12 12 13 12 12 12 12 12 12 13 12 12 12 12 12 12 13 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 13 22 20 20 20 20 20 20 20 23 12 12 12 22 20 20 20 20 20 20 20 20 23 12 12 12 22 20 20 20 20 20 20 20 20 20 20 23 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 18 41 40 40 40 40 40 41 19 20 20 20 21 41 10 10 11 10 10 10 10 19 20 20 20 21 41 10 35 33 33 33 33 33 33 36 17 12 12 13 12 12 12 12
|
||||||
|
12 12 13 12 12 12 18 41 40 39 39 39 40 41 41 41 41 41 41 41 10 14 15 15 15 16 10 41 41 41 41 41 41 41 31 26 26 26 26 26 26 30 17 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 18 41 40 39 39 39 40 41 41 41 41 41 41 41 10 17 12 12 12 18 10 41 41 41 41 41 41 41 31 26 26 26 26 26 26 30 17 12 12 12 12 12 12 12
|
||||||
|
12 12 12 13 12 12 18 41 40 39 39 39 40 41 41 41 41 41 41 41 10 17 12 12 12 18 11 41 41 41 41 41 41 41 31 26 26 26 26 26 26 30 17 12 13 12 12 12 12 12
|
||||||
|
12 12 12 12 13 12 18 41 40 39 39 39 40 41 41 41 41 41 41 41 10 19 20 20 20 21 10 41 41 41 41 41 41 41 31 26 26 26 26 26 26 30 17 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 18 41 40 40 39 40 40 41 41 41 41 41 41 41 11 10 35 33 36 10 10 41 41 41 41 41 41 41 37 28 28 29 26 27 28 38 17 13 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 18 41 41 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 14 15 25 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 13 12 18 41 41 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 17 12 12 12 12 13 12 12 12 12
|
||||||
|
12 12 12 12 12 12 24 15 16 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 17 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 12 18 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 17 12 12 12 12 12 13 12 12 12
|
||||||
|
12 12 13 12 12 12 12 22 21 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 35 33 34 26 30 17 12 12 13 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 18 10 10 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 31 26 26 26 30 17 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 13 12 12 12 18 10 41 41 41 41 41 41 41 41 41 41 41 41 10 31 26 30 10 41 41 41 41 41 41 41 41 41 31 26 27 28 38 17 12 13 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 18 10 41 41 41 10 35 33 33 33 33 33 33 33 33 34 26 32 33 33 33 33 33 33 33 33 33 33 34 26 30 10 41 17 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 13 12 18 10 41 41 41 11 31 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 30 10 14 25 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 13 18 10 10 41 41 10 37 28 28 28 28 28 28 28 28 29 26 27 28 28 28 28 28 28 28 28 28 28 29 26 30 10 17 12 13 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 24 16 10 41 41 10 41 41 41 41 41 41 41 41 10 31 26 30 10 41 41 41 41 41 41 41 41 41 31 26 30 10 17 12 12 12 12 13 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 12 18 10 41 41 10 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 31 26 30 11 17 12 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 13 12 22 21 10 41 41 10 10 10 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 31 26 30 10 17 12 12 12 13 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 18 10 10 41 41 41 41 10 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 31 26 30 10 17 12 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 13 12 12 12 18 10 41 41 41 41 41 10 41 41 41 41 41 41 41 31 26 30 41 41 10 41 41 41 41 41 41 41 31 26 30 10 17 12 13 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 18 10 41 41 41 41 41 10 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 10 41 41 41 41 31 26 30 10 17 12 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 13 18 10 10 10 10 10 10 10 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 10 41 41 41 41 37 28 38 10 17 12 12 12 12 13 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 18 10 10 11 10 10 10 10 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 10 41 14 25 12 12 13 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 24 16 10 10 10 10 10 10 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 10 10 10 17 12 12 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 13 12 12 18 10 10 10 10 11 10 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 10 10 10 17 12 12 12 12 12 12 12 13 12 12 12
|
||||||
|
12 12 12 12 12 12 12 12 18 11 10 10 10 10 10 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 10 10 11 17 12 12 13 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 12 18 10 10 10 10 10 10 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 10 10 10 17 12 12 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 13 12 12 22 21 41 41 41 41 41 41 41 41 41 41 41 41 41 37 28 38 41 41 41 41 41 41 41 41 41 41 11 10 10 19 23 12 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 18 41 41 41 41 41 41 41 41 41 41 41 10 10 10 10 10 10 10 10 41 41 41 41 41 41 41 10 10 10 10 10 19 23 12 12 12 13 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 13 18 41 41 41 41 41 41 41 41 41 41 10 10 10 10 10 10 10 10 10 10 41 41 10 41 41 10 10 10 10 10 10 10 17 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 18 10 41 41 41 41 41 41 41 41 41 10 11 10 10 10 10 10 11 10 10 41 41 41 41 10 10 10 10 10 11 10 10 17 12 13 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 18 10 41 41 41 41 10 41 41 41 41 10 10 11 10 10 10 10 10 10 10 10 41 41 41 10 10 10 10 10 41 10 10 17 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 13 12 12 12 12 18 10 41 41 41 41 41 41 41 41 41 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 41 10 10 10 10 10 17 12 12 12 12 13 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 18 10 41 41 41 41 10 41 14 15 15 16 10 10 10 10 10 11 10 10 14 15 15 16 10 10 10 10 10 10 10 11 10 17 12 12 12 12 12 12 13 12 12
|
||||||
|
12 12 12 12 12 12 12 18 41 41 41 41 41 41 14 25 12 12 24 16 10 10 10 10 10 10 14 25 12 12 18 10 10 41 10 10 41 10 10 10 17 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 13 12 12 24 15 15 15 15 15 15 25 12 12 12 12 24 15 15 15 15 15 15 25 12 13 12 24 16 10 11 10 10 10 10 14 15 25 12 13 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 13 12 12 12 12 12 12 12 12 12 12 12 12 24 15 15 15 15 15 15 25 12 12 12 12 12 12 12 13 12 12 12
|
||||||
|
12 12 12 12 12 12 12 12 12 12 12 13 12 12 12 12 13 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 13 12 12 12 12 12 12 13 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 13 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 13 12 12 12 12 13 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 12 12 12 12 12 12 12 13 12 12 12 12 12 13 12 12 12 12 12 12 12 12 12 12 12 13 12 12 12 12 12 12 13 12 12 12 12 12 12 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 13 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 13 12 12 12 12
|
||||||
|
12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12
|
||||||
|
Before Width: | Height: | Size: 614 B After Width: | Height: | Size: 6.0 KiB |
BIN
assets/tiles/floor01.png
Normal file
|
After Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 616 B |
BIN
assets/tiles/grass00.png
Normal file
|
After Width: | Height: | Size: 6.2 KiB |
BIN
assets/tiles/grass01.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
assets/tiles/hut.png
Normal file
|
After Width: | Height: | Size: 6.6 KiB |
BIN
assets/tiles/road00.png
Normal file
|
After Width: | Height: | Size: 6.7 KiB |
BIN
assets/tiles/road01.png
Normal file
|
After Width: | Height: | Size: 6.2 KiB |
BIN
assets/tiles/road02.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
assets/tiles/road03.png
Normal file
|
After Width: | Height: | Size: 6.1 KiB |
BIN
assets/tiles/road04.png
Normal file
|
After Width: | Height: | Size: 6.1 KiB |
BIN
assets/tiles/road05.png
Normal file
|
After Width: | Height: | Size: 6.1 KiB |
BIN
assets/tiles/road06.png
Normal file
|
After Width: | Height: | Size: 6.1 KiB |
BIN
assets/tiles/road07.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
assets/tiles/road08.png
Normal file
|
After Width: | Height: | Size: 6.2 KiB |
BIN
assets/tiles/road09.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
assets/tiles/road10.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
assets/tiles/road11.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
assets/tiles/road12.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
assets/tiles/table01.png
Normal file
|
After Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 619 B |
BIN
assets/tiles/water00.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
assets/tiles/water01.png
Normal file
|
After Width: | Height: | Size: 6.3 KiB |
BIN
assets/tiles/water02.png
Normal file
|
After Width: | Height: | Size: 6.2 KiB |
BIN
assets/tiles/water03.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
assets/tiles/water04.png
Normal file
|
After Width: | Height: | Size: 6.2 KiB |
BIN
assets/tiles/water05.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
assets/tiles/water06.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
assets/tiles/water07.png
Normal file
|
After Width: | Height: | Size: 6.1 KiB |
BIN
assets/tiles/water08.png
Normal file
|
After Width: | Height: | Size: 5.7 KiB |
BIN
assets/tiles/water09.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.6 KiB |
BIN
assets/tiles/water11.png
Normal file
|
After Width: | Height: | Size: 5.6 KiB |
BIN
assets/tiles/water12.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
assets/tiles/water13.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
@@ -1,10 +1,5 @@
|
|||||||
package de.miaurizius.jgame2d.core;
|
package de.miaurizius.jgame2d.core;
|
||||||
|
|
||||||
import de.miaurizius.jgame2d.object.BootsObj;
|
|
||||||
import de.miaurizius.jgame2d.object.ChestObj;
|
|
||||||
import de.miaurizius.jgame2d.object.DoorObj;
|
|
||||||
import de.miaurizius.jgame2d.object.KeyObj;
|
|
||||||
|
|
||||||
public class AssetSetter {
|
public class AssetSetter {
|
||||||
|
|
||||||
GamePanel panel;
|
GamePanel panel;
|
||||||
@@ -14,37 +9,7 @@ public class AssetSetter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setObject() {
|
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 = 11 * 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;
|
|
||||||
|
|
||||||
panel.obj[7] = new BootsObj();
|
|
||||||
panel.obj[7].worldX = 37 * panel.tileSize;
|
|
||||||
panel.obj[7].worldY = 42 * panel.tileSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package de.miaurizius.jgame2d.core;
|
package de.miaurizius.jgame2d.core;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class Boot {
|
public class Boot {
|
||||||
|
|
||||||
public static void main() {
|
public static final Logger logger = Logger.getLogger("JDGame2D");
|
||||||
|
|
||||||
|
static void main() {
|
||||||
JFrame window = new JFrame();
|
JFrame window = new JFrame();
|
||||||
window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
window.setResizable(false);
|
window.setResizable(false);
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import de.miaurizius.jgame2d.tile.TileManager;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class GamePanel extends JPanel implements Runnable {
|
public class GamePanel extends JPanel implements Runnable {
|
||||||
|
|
||||||
@@ -29,7 +31,7 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
|
|
||||||
// SYSTEM
|
// SYSTEM
|
||||||
TileManager tileM = new TileManager(this);
|
TileManager tileM = new TileManager(this);
|
||||||
KeyHandler keyH = new KeyHandler();
|
KeyHandler keyH = new KeyHandler(this);
|
||||||
Sound se = new Sound();
|
Sound se = new Sound();
|
||||||
Sound music = new Sound();
|
Sound music = new Sound();
|
||||||
public CollisionHandler collisionH = new CollisionHandler(this);
|
public CollisionHandler collisionH = new CollisionHandler(this);
|
||||||
@@ -41,6 +43,9 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
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];
|
||||||
|
|
||||||
|
// GAME STATE
|
||||||
|
public GameState gameState;
|
||||||
|
|
||||||
public GamePanel() {
|
public GamePanel() {
|
||||||
this.setPreferredSize(new Dimension(screenWidth, screenHeight));
|
this.setPreferredSize(new Dimension(screenWidth, screenHeight));
|
||||||
this.setBackground(Color.black);
|
this.setBackground(Color.black);
|
||||||
@@ -52,6 +57,7 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
public void setupGame() {
|
public void setupGame() {
|
||||||
assetSetter.setObject();
|
assetSetter.setObject();
|
||||||
playMusic(0); //Play main theme
|
playMusic(0); //Play main theme
|
||||||
|
gameState = GameState.PLAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startGameThread() {
|
public void startGameThread() {
|
||||||
@@ -89,18 +95,41 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
player.update();
|
switch(gameState) {
|
||||||
|
case PLAY:
|
||||||
|
player.update();
|
||||||
|
break;
|
||||||
|
case PAUSE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paintComponent(Graphics graphics) {
|
public void paintComponent(Graphics graphics) {
|
||||||
super.paintComponent(graphics);
|
super.paintComponent(graphics);
|
||||||
Graphics2D graphics2d = (Graphics2D) graphics;
|
Graphics2D graphics2d = (Graphics2D) graphics;
|
||||||
|
|
||||||
|
// DEBUG
|
||||||
|
long drawStart = 0;
|
||||||
|
drawStart = System.nanoTime();
|
||||||
|
|
||||||
//Draw all components
|
//Draw all components
|
||||||
tileM.draw(graphics2d);
|
tileM.draw(graphics2d);
|
||||||
for (SuperObject superObject : obj) if (superObject != null) superObject.draw(graphics2d, this);
|
for (SuperObject superObject : obj) if (superObject != null) superObject.draw(graphics2d, this);
|
||||||
player.draw(graphics2d);
|
player.draw(graphics2d);
|
||||||
ui.draw(graphics2d);
|
ui.draw(graphics2d);
|
||||||
|
|
||||||
|
long drawEnd = System.nanoTime();
|
||||||
|
long passed = drawEnd - drawStart;
|
||||||
|
|
||||||
|
// DEBUG
|
||||||
|
if(keyH.checkDrawTime) {
|
||||||
|
graphics2d.setColor(Color.white);
|
||||||
|
graphics2d.drawString("Draw Time: " + passed, 10, 400);
|
||||||
|
System.out.println("Draw Time: " + passed);
|
||||||
|
Logger.getLogger("DEBUG").log(Level.FINE, "Draw Time: " + passed);
|
||||||
|
}
|
||||||
|
|
||||||
|
// END
|
||||||
graphics.dispose();
|
graphics.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
src/de/miaurizius/jgame2d/core/GameState.java
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package de.miaurizius.jgame2d.core;
|
||||||
|
|
||||||
|
public enum GameState {
|
||||||
|
|
||||||
|
PLAY,
|
||||||
|
PAUSE;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,6 +6,13 @@ import java.awt.event.KeyListener;
|
|||||||
public class KeyHandler implements KeyListener {
|
public class KeyHandler implements KeyListener {
|
||||||
|
|
||||||
public boolean upPressed, downPressed, leftPressed, rightPressed;
|
public boolean upPressed, downPressed, leftPressed, rightPressed;
|
||||||
|
public GamePanel panel;
|
||||||
|
// DEBUG
|
||||||
|
public boolean checkDrawTime = false;
|
||||||
|
|
||||||
|
public KeyHandler(GamePanel panel) {
|
||||||
|
this.panel = panel;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(KeyEvent e) {}
|
public void keyTyped(KeyEvent e) {}
|
||||||
@@ -14,18 +21,17 @@ public class KeyHandler implements KeyListener {
|
|||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
int code = e.getKeyCode();
|
int code = e.getKeyCode();
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case KeyEvent.VK_W, KeyEvent.VK_UP:
|
// CONTROLS
|
||||||
upPressed = true;
|
case KeyEvent.VK_W, KeyEvent.VK_UP -> upPressed = true;
|
||||||
break;
|
case KeyEvent.VK_S, KeyEvent.VK_DOWN -> downPressed = true;
|
||||||
case KeyEvent.VK_S, KeyEvent.VK_DOWN:
|
case KeyEvent.VK_A, KeyEvent.VK_LEFT -> leftPressed = true;
|
||||||
downPressed = true;
|
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> rightPressed = true;
|
||||||
break;
|
|
||||||
case KeyEvent.VK_A, KeyEvent.VK_LEFT:
|
// DEBUG OPTIONS
|
||||||
leftPressed = true;
|
case KeyEvent.VK_T -> checkDrawTime = !checkDrawTime;
|
||||||
break;
|
|
||||||
case KeyEvent.VK_D, KeyEvent.VK_RIGHT:
|
// GAME STATES
|
||||||
rightPressed = true;
|
case KeyEvent.VK_ESCAPE -> panel.gameState = (panel.gameState == GameState.PAUSE) ? GameState.PLAY : GameState.PAUSE;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,18 +39,10 @@ public class KeyHandler implements KeyListener {
|
|||||||
public void keyReleased(KeyEvent e) {
|
public void keyReleased(KeyEvent e) {
|
||||||
int code = e.getKeyCode();
|
int code = e.getKeyCode();
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case KeyEvent.VK_W, KeyEvent.VK_UP:
|
case KeyEvent.VK_W, KeyEvent.VK_UP -> upPressed = false;
|
||||||
upPressed = false;
|
case KeyEvent.VK_S, KeyEvent.VK_DOWN -> downPressed = false;
|
||||||
break;
|
case KeyEvent.VK_A, KeyEvent.VK_LEFT -> leftPressed = false;
|
||||||
case KeyEvent.VK_S, KeyEvent.VK_DOWN:
|
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> rightPressed = false;
|
||||||
downPressed = false;
|
|
||||||
break;
|
|
||||||
case KeyEvent.VK_A, KeyEvent.VK_LEFT:
|
|
||||||
leftPressed = false;
|
|
||||||
break;
|
|
||||||
case KeyEvent.VK_D, KeyEvent.VK_RIGHT:
|
|
||||||
rightPressed = false;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import javax.sound.sampled.Clip;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class Sound {
|
public class Sound {
|
||||||
|
|
||||||
@@ -20,7 +22,7 @@ public class Sound {
|
|||||||
soundURL[3] = new File("assets/sounds/unlock.wav").toURI().toURL();
|
soundURL[3] = new File("assets/sounds/unlock.wav").toURI().toURL();
|
||||||
soundURL[4] = new File("assets/sounds/fanfare.wav").toURI().toURL();
|
soundURL[4] = new File("assets/sounds/fanfare.wav").toURI().toURL();
|
||||||
} catch(MalformedURLException e) {
|
} catch(MalformedURLException e) {
|
||||||
e.printStackTrace();
|
Boot.logger.log(Level.SEVERE, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +1,26 @@
|
|||||||
package de.miaurizius.jgame2d.core;
|
package de.miaurizius.jgame2d.core;
|
||||||
|
|
||||||
import de.miaurizius.jgame2d.object.KeyObj;
|
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
public class UI {
|
public class UI {
|
||||||
|
|
||||||
GamePanel panel;
|
GamePanel panel;
|
||||||
|
Graphics graphics2d;
|
||||||
Font arial_40, arial_80B;
|
Font arial_40, arial_80B;
|
||||||
BufferedImage keyImage;
|
DecimalFormat df = new DecimalFormat("#0.00");
|
||||||
|
|
||||||
public boolean messageOn = false;
|
public boolean messageOn = false;
|
||||||
public String message;
|
public String message;
|
||||||
int msgC = 0;
|
|
||||||
public boolean gameFinished = false;
|
public boolean gameFinished = false;
|
||||||
|
|
||||||
|
int msgC = 0;
|
||||||
double playTime;
|
double playTime;
|
||||||
DecimalFormat df = new DecimalFormat("#0.00");
|
|
||||||
|
|
||||||
public UI(GamePanel panel) {
|
public UI(GamePanel panel) {
|
||||||
this.panel = panel;
|
this.panel = panel;
|
||||||
arial_40 = new Font("Arial", Font.PLAIN, 40);
|
arial_40 = new Font("Arial", Font.PLAIN, 40);
|
||||||
arial_80B = new Font("Arial", Font.BOLD, 80);
|
arial_80B = new Font("Arial", Font.BOLD, 80);
|
||||||
keyImage = new KeyObj().image;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showMessage(String text) {
|
public void showMessage(String text) {
|
||||||
@@ -32,52 +29,28 @@ public class UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Graphics graphics2d) {
|
public void draw(Graphics graphics2d) {
|
||||||
if(gameFinished) {
|
this.graphics2d = graphics2d;
|
||||||
graphics2d.setFont(arial_40);
|
|
||||||
graphics2d.setColor(Color.white);
|
|
||||||
String text = "You found the treasure!";
|
|
||||||
int textLength = (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth();
|
|
||||||
int x,y;
|
|
||||||
x = panel.screenWidth/2 - textLength/2;
|
|
||||||
y = panel.screenHeight/2 - (panel.tileSize*3);
|
|
||||||
graphics2d.drawString(text, x, y);
|
|
||||||
|
|
||||||
text = "Your time is: " + df.format(playTime) + "!";
|
|
||||||
textLength = (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth();
|
|
||||||
x = panel.screenWidth/2 - textLength/2;
|
|
||||||
y = panel.screenHeight/2 + (panel.tileSize*4);
|
|
||||||
graphics2d.drawString(text, x, y);
|
|
||||||
|
|
||||||
graphics2d.setFont(arial_80B);
|
|
||||||
graphics2d.setColor(Color.yellow);
|
|
||||||
text = "Congratulations!";
|
|
||||||
textLength = (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth();
|
|
||||||
x = panel.screenWidth/2 - textLength/2;
|
|
||||||
y = panel.screenHeight/2 + (panel.tileSize*2);
|
|
||||||
graphics2d.drawString(text, x, y);
|
|
||||||
|
|
||||||
panel.gameThread = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// MESSAGE
|
|
||||||
graphics2d.setFont(arial_40);
|
graphics2d.setFont(arial_40);
|
||||||
graphics2d.setColor(Color.white);
|
graphics2d.setColor(Color.white);
|
||||||
graphics2d.drawImage(keyImage, panel.tileSize/2, panel.tileSize/2, panel.tileSize, panel.tileSize, null);
|
|
||||||
graphics2d.drawString("x " + panel.player.hasKey, 74, 65);
|
|
||||||
|
|
||||||
// TIME
|
switch (panel.gameState) {
|
||||||
playTime += (double) 1/panel.FPS;
|
case PLAY:
|
||||||
graphics2d.drawString("Time: " + df.format(playTime), panel.tileSize*11, 65);
|
|
||||||
|
|
||||||
if(messageOn) {
|
break;
|
||||||
graphics2d.setFont(panel.getFont().deriveFont(30F));
|
case PAUSE:
|
||||||
graphics2d.drawString(message, panel.tileSize/2, panel.tileSize*5);
|
drawPauseScreen();
|
||||||
msgC++;
|
break;
|
||||||
if(msgC <= 120) return; //text stays 2 seconds
|
|
||||||
msgC = 0;
|
|
||||||
messageOn = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void drawPauseScreen() {
|
||||||
|
String text = "PAUSED";
|
||||||
|
int y = panel.screenHeight / 2;
|
||||||
|
graphics2d.drawString(text, getCenteredX(text), y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCenteredX(String text) {
|
||||||
|
return panel.screenWidth / 2 - (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth() / 2;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/de/miaurizius/jgame2d/core/Utility.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package de.miaurizius.jgame2d.core;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
public class Utility {
|
||||||
|
|
||||||
|
public static BufferedImage scaleImage(BufferedImage img, int width, int height) {
|
||||||
|
BufferedImage scl = new BufferedImage(width, height, img.getType());
|
||||||
|
scl = new BufferedImage(width, height, img.getType());
|
||||||
|
scl.createGraphics().drawImage(img, 0, 0, width, height, null);
|
||||||
|
return scl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
package de.miaurizius.jgame2d.entity;
|
package de.miaurizius.jgame2d.entity;
|
||||||
|
|
||||||
import de.miaurizius.jgame2d.core.Direction;
|
import de.miaurizius.jgame2d.core.*;
|
||||||
import de.miaurizius.jgame2d.core.GamePanel;
|
|
||||||
import de.miaurizius.jgame2d.core.KeyHandler;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Player extends Entity {
|
public class Player extends Entity {
|
||||||
|
|
||||||
@@ -45,18 +44,23 @@ public class Player extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void getPlayerImage() {
|
public void getPlayerImage() {
|
||||||
|
up1 = initPlayerImage("boy_up_1");
|
||||||
|
up2 = initPlayerImage("boy_up_2");
|
||||||
|
down1 = initPlayerImage("boy_down_1");
|
||||||
|
down2 = initPlayerImage("boy_down_2");
|
||||||
|
left1 = initPlayerImage("boy_left_1");
|
||||||
|
left2 = initPlayerImage(("boy_left_2"));
|
||||||
|
right1 = initPlayerImage(("boy_right_1"));
|
||||||
|
right2 = initPlayerImage(("boy_right_2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage initPlayerImage(String name) {
|
||||||
try {
|
try {
|
||||||
up1 = ImageIO.read(new FileInputStream("assets/player/boy_up_1.png"));
|
return Utility.scaleImage(ImageIO.read(new FileInputStream("assets/player/" + name + ".png")), panel.tileSize, panel.tileSize);
|
||||||
up2 = ImageIO.read(new FileInputStream("assets/player/boy_up_2.png"));
|
|
||||||
down1 = ImageIO.read(new FileInputStream("assets/player/boy_down_1.png"));
|
|
||||||
down2 = ImageIO.read(new FileInputStream("assets/player/boy_down_2.png"));
|
|
||||||
left1 = ImageIO.read(new FileInputStream("assets/player/boy_left_1.png"));
|
|
||||||
left2 = ImageIO.read(new FileInputStream("assets/player/boy_left_2.png"));
|
|
||||||
right1 = ImageIO.read(new FileInputStream("assets/player/boy_right_1.png"));
|
|
||||||
right2 = ImageIO.read(new FileInputStream("assets/player/boy_right_2.png"));
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
Boot.logger.log(Level.SEVERE, "Could not load player-image", e);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
@@ -130,7 +134,7 @@ public class Player extends Entity {
|
|||||||
case LEFT -> (spriteNum == 1) ? left1 : left2;
|
case LEFT -> (spriteNum == 1) ? left1 : left2;
|
||||||
case RIGHT -> (spriteNum == 1) ? right1 : right2;
|
case RIGHT -> (spriteNum == 1) ? right1 : right2;
|
||||||
};
|
};
|
||||||
graphics2d.drawImage(image, screenX, screenY, panel.tileSize, panel.tileSize, null);
|
graphics2d.drawImage(image, screenX, screenY, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,25 @@
|
|||||||
package de.miaurizius.jgame2d.object;
|
package de.miaurizius.jgame2d.object;
|
||||||
|
|
||||||
|
import de.miaurizius.jgame2d.core.Boot;
|
||||||
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
|
import de.miaurizius.jgame2d.core.Utility;
|
||||||
|
|
||||||
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.util.logging.Level;
|
||||||
|
|
||||||
public class BootsObj extends SuperObject {
|
public class BootsObj extends SuperObject {
|
||||||
|
|
||||||
public BootsObj() {
|
GamePanel panel;
|
||||||
|
|
||||||
|
public BootsObj(GamePanel panel) {
|
||||||
|
this.panel = panel;
|
||||||
name = "boots";
|
name = "boots";
|
||||||
try {
|
try {
|
||||||
image = ImageIO.read(new FileInputStream("assets/objects/boots.png"));
|
image = Utility.scaleImage(ImageIO.read(new FileInputStream("assets/objects/boots.png")), panel.tileSize, panel.tileSize);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
Boot.logger.log(Level.SEVERE, "Could not load image", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,25 @@
|
|||||||
package de.miaurizius.jgame2d.object;
|
package de.miaurizius.jgame2d.object;
|
||||||
|
|
||||||
|
import de.miaurizius.jgame2d.core.Boot;
|
||||||
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
|
import de.miaurizius.jgame2d.core.Utility;
|
||||||
|
|
||||||
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.util.logging.Level;
|
||||||
|
|
||||||
public class ChestObj extends SuperObject {
|
public class ChestObj extends SuperObject {
|
||||||
|
|
||||||
public ChestObj() {
|
GamePanel panel;
|
||||||
|
|
||||||
|
public ChestObj(GamePanel panel) {
|
||||||
|
this.panel = panel;
|
||||||
name = "chest";
|
name = "chest";
|
||||||
try {
|
try {
|
||||||
image = ImageIO.read(new FileInputStream("assets/objects/chest.png"));
|
image = Utility.scaleImage(ImageIO.read(new FileInputStream("assets/objects/chest.png")), panel.tileSize, panel.tileSize);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
Boot.logger.log(Level.SEVERE, "Could not load image", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,25 @@
|
|||||||
package de.miaurizius.jgame2d.object;
|
package de.miaurizius.jgame2d.object;
|
||||||
|
|
||||||
|
import de.miaurizius.jgame2d.core.Boot;
|
||||||
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
|
import de.miaurizius.jgame2d.core.Utility;
|
||||||
|
|
||||||
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.util.logging.Level;
|
||||||
|
|
||||||
public class DoorObj extends SuperObject {
|
public class DoorObj extends SuperObject {
|
||||||
|
|
||||||
public DoorObj() {
|
GamePanel panel;
|
||||||
|
|
||||||
|
public DoorObj(GamePanel panel) {
|
||||||
|
this.panel = panel;
|
||||||
name = "door";
|
name = "door";
|
||||||
try {
|
try {
|
||||||
image = ImageIO.read(new FileInputStream("assets/objects/door.png"));
|
image = Utility.scaleImage(ImageIO.read(new FileInputStream("assets/objects/door.png")), panel.tileSize, panel.tileSize);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
Boot.logger.log(Level.SEVERE, "Could not load image", e);
|
||||||
}
|
}
|
||||||
collision = true;
|
collision = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,25 @@
|
|||||||
package de.miaurizius.jgame2d.object;
|
package de.miaurizius.jgame2d.object;
|
||||||
|
|
||||||
|
import de.miaurizius.jgame2d.core.Boot;
|
||||||
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
|
import de.miaurizius.jgame2d.core.Utility;
|
||||||
|
|
||||||
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.util.logging.Level;
|
||||||
|
|
||||||
public class KeyObj extends SuperObject {
|
public class KeyObj extends SuperObject {
|
||||||
|
|
||||||
public KeyObj() {
|
GamePanel panel;
|
||||||
|
|
||||||
|
public KeyObj(GamePanel panel) {
|
||||||
|
this.panel = panel;
|
||||||
name = "key";
|
name = "key";
|
||||||
try {
|
try {
|
||||||
image = ImageIO.read(new FileInputStream("assets/objects/key.png"));
|
image = Utility.scaleImage(ImageIO.read(new FileInputStream("assets/objects/key.png")), panel.tileSize, panel.tileSize);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
Boot.logger.log(Level.SEVERE, "Could not load image", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package de.miaurizius.jgame2d.tile;
|
package de.miaurizius.jgame2d.tile;
|
||||||
|
|
||||||
|
import de.miaurizius.jgame2d.core.Boot;
|
||||||
import de.miaurizius.jgame2d.core.GamePanel;
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
|
import de.miaurizius.jgame2d.core.Utility;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class TileManager {
|
public class TileManager {
|
||||||
|
|
||||||
@@ -14,36 +18,79 @@ public class TileManager {
|
|||||||
|
|
||||||
public TileManager(GamePanel panel) {
|
public TileManager(GamePanel panel) {
|
||||||
this.panel = panel;
|
this.panel = panel;
|
||||||
tile = new Tile[10];
|
tile = new Tile[50];
|
||||||
mapTileNum = new int[panel.maxWorldCol][panel.maxWorldRow];
|
mapTileNum = new int[panel.maxWorldCol][panel.maxWorldRow];
|
||||||
getTileImage();
|
getTileImage();
|
||||||
loadMap("testworld");
|
loadMap("testmap2");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeTile(int i, String name, boolean col) {
|
||||||
|
try {
|
||||||
|
tile[i] = new Tile();
|
||||||
|
tile[i].image = ImageIO.read(new FileInputStream("assets/tiles/" + name + ".png"));
|
||||||
|
tile[i].collision = col;
|
||||||
|
} catch(IOException e) {
|
||||||
|
Boot.logger.log(Level.SEVERE, "Could not load tile", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getTileImage() {
|
public void getTileImage() {
|
||||||
try {
|
// PLACEHOLDER
|
||||||
tile[0] = new Tile();
|
initializeTile(0, "grass00", false);
|
||||||
tile[0].image = ImageIO.read(new FileInputStream("assets/tiles/grass.png"));
|
initializeTile(2, "grass00", false);
|
||||||
|
initializeTile(3, "grass00", false);
|
||||||
|
initializeTile(4, "grass00", false);
|
||||||
|
initializeTile(5, "grass00", false);
|
||||||
|
initializeTile(6, "grass00", false);
|
||||||
|
initializeTile(7, "grass00", false);
|
||||||
|
initializeTile(8, "grass00", false);
|
||||||
|
initializeTile(9, "grass00", false);
|
||||||
|
|
||||||
tile[1] = new Tile();
|
// GRASS
|
||||||
tile[1].image = ImageIO.read(new FileInputStream("assets/tiles/wall.png"));
|
initializeTile(10, "grass00", false);
|
||||||
tile[1].collision = true;
|
initializeTile(11, "grass01", false);
|
||||||
|
|
||||||
tile[2] = new Tile();
|
// WATER
|
||||||
tile[2].image = ImageIO.read(new FileInputStream("assets/tiles/water.png"));
|
initializeTile(12, "water00", true);
|
||||||
tile[2].collision = true;
|
initializeTile(13, "water01", true);
|
||||||
|
initializeTile(14, "water02", true);
|
||||||
|
initializeTile(15, "water03", true);
|
||||||
|
initializeTile(16, "water04", true);
|
||||||
|
initializeTile(17, "water05", true);
|
||||||
|
initializeTile(18, "water06", true);
|
||||||
|
initializeTile(19, "water07", true);
|
||||||
|
initializeTile(20, "water08", true);
|
||||||
|
initializeTile(21, "water09", true);
|
||||||
|
initializeTile(22, "water10", true);
|
||||||
|
initializeTile(23, "water11", true);
|
||||||
|
initializeTile(24, "water12", true);
|
||||||
|
initializeTile(25, "water13", true);
|
||||||
|
|
||||||
tile[3] = new Tile();
|
// ROAD
|
||||||
tile[3].image = ImageIO.read(new FileInputStream("assets/tiles/earth.png"));
|
initializeTile(26, "road00", false);
|
||||||
|
initializeTile(27, "road01", false);
|
||||||
|
initializeTile(28, "road02", false);
|
||||||
|
initializeTile(29, "road03", false);
|
||||||
|
initializeTile(30, "road04", false);
|
||||||
|
initializeTile(31, "road05", false);
|
||||||
|
initializeTile(32, "road06", false);
|
||||||
|
initializeTile(33, "road07", false);
|
||||||
|
initializeTile(34, "road08", false);
|
||||||
|
initializeTile(35, "road09", false);
|
||||||
|
initializeTile(36, "road10", false);
|
||||||
|
initializeTile(37, "road11", false);
|
||||||
|
initializeTile(38, "road12", false);
|
||||||
|
|
||||||
tile[4] = new Tile();
|
// WORLD
|
||||||
tile[4].image = ImageIO.read(new FileInputStream("assets/tiles/tree.png"));
|
initializeTile(39, "earth", false);
|
||||||
tile[4].collision = true;
|
initializeTile(40, "wall", true);
|
||||||
|
initializeTile(41, "tree", true);
|
||||||
|
|
||||||
tile[5] = new Tile();
|
|
||||||
tile[5].image = ImageIO.read(new FileInputStream("assets/tiles/sand.png"));
|
BufferedImage scaledImage;
|
||||||
} catch (IOException e) {
|
for (Tile tile : tile) {
|
||||||
e.printStackTrace();
|
if(tile == null) continue;
|
||||||
|
tile.image = Utility.scaleImage(tile.image, panel.tileSize, panel.tileSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +115,7 @@ public class TileManager {
|
|||||||
}
|
}
|
||||||
bReader.close();
|
bReader.close();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
Boot.logger.log(Level.SEVERE, "Could not load map", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +135,7 @@ public class TileManager {
|
|||||||
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 &&
|
||||||
worldY - panel.tileSize < panel.player.worldY + panel.player.screenY
|
worldY - panel.tileSize < panel.player.worldY + panel.player.screenY
|
||||||
) graphics2D.drawImage(tile[tileNum].image, screenX, screenY, panel.tileSize, panel.tileSize, null);
|
) graphics2D.drawImage(tile[tileNum].image, screenX, screenY, null);
|
||||||
|
|
||||||
worldCol++;
|
worldCol++;
|
||||||
|
|
||||||
|
|||||||