diff --git a/.VSCodeCounter/2023-11-19_20-17-30/details.md b/.VSCodeCounter/2023-11-19_20-17-30/details.md new file mode 100644 index 0000000..7007e30 --- /dev/null +++ b/.VSCodeCounter/2023-11-19_20-17-30/details.md @@ -0,0 +1,25 @@ +# Details + +Date : 2023-11-19 20:17:30 + +Directory c:\\Users\\User\\Documents\\My Programs\\Java\\Trident\\src + +Total : 10 files, 1396 codes, 11 comments, 109 blanks, all 1516 lines + +[Summary](results.md) / Details / [Diff Summary](diff.md) / [Diff Details](diff-details.md) + +## Files +| filename | language | code | comment | blank | total | +| :--- | :--- | ---: | ---: | ---: | ---: | +| [src/main/Main.java](/src/main/Main.java) | Java | 202 | 2 | 16 | 220 | +| [src/main/MainPanel.java](/src/main/MainPanel.java) | Java | 48 | 1 | 19 | 68 | +| [src/project/Project.java](/src/project/Project.java) | Java | 849 | 8 | 21 | 878 | +| [src/project/Scene.java](/src/project/Scene.java) | Java | 118 | 0 | 6 | 124 | +| [src/project/TridEntity.java](/src/project/TridEntity.java) | Java | 52 | 0 | 14 | 66 | +| [src/project/ent/BoxColl.java](/src/project/ent/BoxColl.java) | Java | 30 | 0 | 8 | 38 | +| [src/project/ent/BoxNoColl.java](/src/project/ent/BoxNoColl.java) | Java | 38 | 0 | 8 | 46 | +| [src/project/ent/CustomEntity.java](/src/project/ent/CustomEntity.java) | Java | 14 | 0 | 4 | 18 | +| [src/project/ent/InvisColl.java](/src/project/ent/InvisColl.java) | Java | 24 | 0 | 7 | 31 | +| [src/project/ent/PlrStart.java](/src/project/ent/PlrStart.java) | Java | 21 | 0 | 6 | 27 | + +[Summary](results.md) / Details / [Diff Summary](diff.md) / [Diff Details](diff-details.md) \ No newline at end of file diff --git a/.VSCodeCounter/2023-11-19_20-17-30/diff-details.md b/.VSCodeCounter/2023-11-19_20-17-30/diff-details.md new file mode 100644 index 0000000..cfdee8e --- /dev/null +++ b/.VSCodeCounter/2023-11-19_20-17-30/diff-details.md @@ -0,0 +1,15 @@ +# Diff Details + +Date : 2023-11-19 20:17:30 + +Directory c:\\Users\\User\\Documents\\My Programs\\Java\\Trident\\src + +Total : 0 files, 0 codes, 0 comments, 0 blanks, all 0 lines + +[Summary](results.md) / [Details](details.md) / [Diff Summary](diff.md) / Diff Details + +## Files +| filename | language | code | comment | blank | total | +| :--- | :--- | ---: | ---: | ---: | ---: | + +[Summary](results.md) / [Details](details.md) / [Diff Summary](diff.md) / Diff Details \ No newline at end of file diff --git a/.VSCodeCounter/2023-11-19_20-17-30/diff.csv b/.VSCodeCounter/2023-11-19_20-17-30/diff.csv new file mode 100644 index 0000000..b7d8d75 --- /dev/null +++ b/.VSCodeCounter/2023-11-19_20-17-30/diff.csv @@ -0,0 +1,2 @@ +"filename", "language", "", "comment", "blank", "total" +"Total", "-", , 0, 0, 0 \ No newline at end of file diff --git a/.VSCodeCounter/2023-11-19_20-17-30/diff.md b/.VSCodeCounter/2023-11-19_20-17-30/diff.md new file mode 100644 index 0000000..8cf6bd7 --- /dev/null +++ b/.VSCodeCounter/2023-11-19_20-17-30/diff.md @@ -0,0 +1,19 @@ +# Diff Summary + +Date : 2023-11-19 20:17:30 + +Directory c:\\Users\\User\\Documents\\My Programs\\Java\\Trident\\src + +Total : 0 files, 0 codes, 0 comments, 0 blanks, all 0 lines + +[Summary](results.md) / [Details](details.md) / Diff Summary / [Diff Details](diff-details.md) + +## Languages +| language | files | code | comment | blank | total | +| :--- | ---: | ---: | ---: | ---: | ---: | + +## Directories +| path | files | code | comment | blank | total | +| :--- | ---: | ---: | ---: | ---: | ---: | + +[Summary](results.md) / [Details](details.md) / Diff Summary / [Diff Details](diff-details.md) \ No newline at end of file diff --git a/.VSCodeCounter/2023-11-19_20-17-30/diff.txt b/.VSCodeCounter/2023-11-19_20-17-30/diff.txt new file mode 100644 index 0000000..63622b2 --- /dev/null +++ b/.VSCodeCounter/2023-11-19_20-17-30/diff.txt @@ -0,0 +1,22 @@ +Date : 2023-11-19 20:17:30 +Directory : c:\Users\User\Documents\My Programs\Java\Trident\src +Total : 0 files, 0 codes, 0 comments, 0 blanks, all 0 lines + +Languages ++----------+------------+------------+------------+------------+------------+ +| language | files | code | comment | blank | total | ++----------+------------+------------+------------+------------+------------+ ++----------+------------+------------+------------+------------+------------+ + +Directories ++------+------------+------------+------------+------------+------------+ +| path | files | code | comment | blank | total | ++------+------------+------------+------------+------------+------------+ ++------+------------+------------+------------+------------+------------+ + +Files ++----------+----------+------------+------------+------------+------------+ +| filename | language | code | comment | blank | total | ++----------+----------+------------+------------+------------+------------+ +| Total | | 0 | 0 | 0 | 0 | ++----------+----------+------------+------------+------------+------------+ \ No newline at end of file diff --git a/.VSCodeCounter/2023-11-19_20-17-30/results.csv b/.VSCodeCounter/2023-11-19_20-17-30/results.csv new file mode 100644 index 0000000..3cf3833 --- /dev/null +++ b/.VSCodeCounter/2023-11-19_20-17-30/results.csv @@ -0,0 +1,12 @@ +"filename", "language", "Java", "comment", "blank", "total" +"c:\Users\User\Documents\My Programs\Java\Trident\src\main\Main.java", "Java", 202, 2, 16, 220 +"c:\Users\User\Documents\My Programs\Java\Trident\src\main\MainPanel.java", "Java", 48, 1, 19, 68 +"c:\Users\User\Documents\My Programs\Java\Trident\src\project\Project.java", "Java", 849, 8, 21, 878 +"c:\Users\User\Documents\My Programs\Java\Trident\src\project\Scene.java", "Java", 118, 0, 6, 124 +"c:\Users\User\Documents\My Programs\Java\Trident\src\project\TridEntity.java", "Java", 52, 0, 14, 66 +"c:\Users\User\Documents\My Programs\Java\Trident\src\project\ent\BoxColl.java", "Java", 30, 0, 8, 38 +"c:\Users\User\Documents\My Programs\Java\Trident\src\project\ent\BoxNoColl.java", "Java", 38, 0, 8, 46 +"c:\Users\User\Documents\My Programs\Java\Trident\src\project\ent\CustomEntity.java", "Java", 14, 0, 4, 18 +"c:\Users\User\Documents\My Programs\Java\Trident\src\project\ent\InvisColl.java", "Java", 24, 0, 7, 31 +"c:\Users\User\Documents\My Programs\Java\Trident\src\project\ent\PlrStart.java", "Java", 21, 0, 6, 27 +"Total", "-", 1396, 11, 109, 1516 \ No newline at end of file diff --git a/.VSCodeCounter/2023-11-19_20-17-30/results.json b/.VSCodeCounter/2023-11-19_20-17-30/results.json new file mode 100644 index 0000000..e384d12 --- /dev/null +++ b/.VSCodeCounter/2023-11-19_20-17-30/results.json @@ -0,0 +1 @@ +{"file:///c%3A/Users/User/Documents/My%20Programs/Java/Trident/src/project/Scene.java":{"language":"Java","code":118,"comment":0,"blank":6},"file:///c%3A/Users/User/Documents/My%20Programs/Java/Trident/src/project/TridEntity.java":{"language":"Java","code":52,"comment":0,"blank":14},"file:///c%3A/Users/User/Documents/My%20Programs/Java/Trident/src/project/ent/PlrStart.java":{"language":"Java","code":21,"comment":0,"blank":6},"file:///c%3A/Users/User/Documents/My%20Programs/Java/Trident/src/project/Project.java":{"language":"Java","code":849,"comment":8,"blank":21},"file:///c%3A/Users/User/Documents/My%20Programs/Java/Trident/src/project/ent/InvisColl.java":{"language":"Java","code":24,"comment":0,"blank":7},"file:///c%3A/Users/User/Documents/My%20Programs/Java/Trident/src/project/ent/CustomEntity.java":{"language":"Java","code":14,"comment":0,"blank":4},"file:///c%3A/Users/User/Documents/My%20Programs/Java/Trident/src/project/ent/BoxNoColl.java":{"language":"Java","code":38,"comment":0,"blank":8},"file:///c%3A/Users/User/Documents/My%20Programs/Java/Trident/src/project/ent/BoxColl.java":{"language":"Java","code":30,"comment":0,"blank":8},"file:///c%3A/Users/User/Documents/My%20Programs/Java/Trident/src/main/MainPanel.java":{"language":"Java","code":48,"comment":1,"blank":19},"file:///c%3A/Users/User/Documents/My%20Programs/Java/Trident/src/main/Main.java":{"language":"Java","code":202,"comment":2,"blank":16}} \ No newline at end of file diff --git a/.VSCodeCounter/2023-11-19_20-17-30/results.md b/.VSCodeCounter/2023-11-19_20-17-30/results.md new file mode 100644 index 0000000..bb7a85d --- /dev/null +++ b/.VSCodeCounter/2023-11-19_20-17-30/results.md @@ -0,0 +1,25 @@ +# Summary + +Date : 2023-11-19 20:17:30 + +Directory c:\\Users\\User\\Documents\\My Programs\\Java\\Trident\\src + +Total : 10 files, 1396 codes, 11 comments, 109 blanks, all 1516 lines + +Summary / [Details](details.md) / [Diff Summary](diff.md) / [Diff Details](diff-details.md) + +## Languages +| language | files | code | comment | blank | total | +| :--- | ---: | ---: | ---: | ---: | ---: | +| Java | 10 | 1,396 | 11 | 109 | 1,516 | + +## Directories +| path | files | code | comment | blank | total | +| :--- | ---: | ---: | ---: | ---: | ---: | +| . | 10 | 1,396 | 11 | 109 | 1,516 | +| main | 2 | 250 | 3 | 35 | 288 | +| project | 8 | 1,146 | 8 | 74 | 1,228 | +| project (Files) | 3 | 1,019 | 8 | 41 | 1,068 | +| project\\ent | 5 | 127 | 0 | 33 | 160 | + +Summary / [Details](details.md) / [Diff Summary](diff.md) / [Diff Details](diff-details.md) \ No newline at end of file diff --git a/.VSCodeCounter/2023-11-19_20-17-30/results.txt b/.VSCodeCounter/2023-11-19_20-17-30/results.txt new file mode 100644 index 0000000..e85173a --- /dev/null +++ b/.VSCodeCounter/2023-11-19_20-17-30/results.txt @@ -0,0 +1,38 @@ +Date : 2023-11-19 20:17:30 +Directory : c:\Users\User\Documents\My Programs\Java\Trident\src +Total : 10 files, 1396 codes, 11 comments, 109 blanks, all 1516 lines + +Languages ++----------+------------+------------+------------+------------+------------+ +| language | files | code | comment | blank | total | ++----------+------------+------------+------------+------------+------------+ +| Java | 10 | 1,396 | 11 | 109 | 1,516 | ++----------+------------+------------+------------+------------+------------+ + +Directories ++------------------------------------------------------------------------------------+------------+------------+------------+------------+------------+ +| path | files | code | comment | blank | total | ++------------------------------------------------------------------------------------+------------+------------+------------+------------+------------+ +| . | 10 | 1,396 | 11 | 109 | 1,516 | +| main | 2 | 250 | 3 | 35 | 288 | +| project | 8 | 1,146 | 8 | 74 | 1,228 | +| project (Files) | 3 | 1,019 | 8 | 41 | 1,068 | +| project\ent | 5 | 127 | 0 | 33 | 160 | ++------------------------------------------------------------------------------------+------------+------------+------------+------------+------------+ + +Files ++------------------------------------------------------------------------------------+----------+------------+------------+------------+------------+ +| filename | language | code | comment | blank | total | ++------------------------------------------------------------------------------------+----------+------------+------------+------------+------------+ +| c:\Users\User\Documents\My Programs\Java\Trident\src\main\Main.java | Java | 202 | 2 | 16 | 220 | +| c:\Users\User\Documents\My Programs\Java\Trident\src\main\MainPanel.java | Java | 48 | 1 | 19 | 68 | +| c:\Users\User\Documents\My Programs\Java\Trident\src\project\Project.java | Java | 849 | 8 | 21 | 878 | +| c:\Users\User\Documents\My Programs\Java\Trident\src\project\Scene.java | Java | 118 | 0 | 6 | 124 | +| c:\Users\User\Documents\My Programs\Java\Trident\src\project\TridEntity.java | Java | 52 | 0 | 14 | 66 | +| c:\Users\User\Documents\My Programs\Java\Trident\src\project\ent\BoxColl.java | Java | 30 | 0 | 8 | 38 | +| c:\Users\User\Documents\My Programs\Java\Trident\src\project\ent\BoxNoColl.java | Java | 38 | 0 | 8 | 46 | +| c:\Users\User\Documents\My Programs\Java\Trident\src\project\ent\CustomEntity.java | Java | 14 | 0 | 4 | 18 | +| c:\Users\User\Documents\My Programs\Java\Trident\src\project\ent\InvisColl.java | Java | 24 | 0 | 7 | 31 | +| c:\Users\User\Documents\My Programs\Java\Trident\src\project\ent\PlrStart.java | Java | 21 | 0 | 6 | 27 | +| Total | | 1,396 | 11 | 109 | 1,516 | ++------------------------------------------------------------------------------------+----------+------------+------------+------------+------------+ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e112a70 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/bin/main/Main$1.class b/bin/main/Main$1.class new file mode 100644 index 0000000..d812b40 Binary files /dev/null and b/bin/main/Main$1.class differ diff --git a/bin/main/Main$2.class b/bin/main/Main$2.class new file mode 100644 index 0000000..25ac815 Binary files /dev/null and b/bin/main/Main$2.class differ diff --git a/bin/main/Main$3.class b/bin/main/Main$3.class new file mode 100644 index 0000000..7e37b18 Binary files /dev/null and b/bin/main/Main$3.class differ diff --git a/bin/main/Main$4.class b/bin/main/Main$4.class new file mode 100644 index 0000000..9ee43ad Binary files /dev/null and b/bin/main/Main$4.class differ diff --git a/bin/main/Main$5.class b/bin/main/Main$5.class new file mode 100644 index 0000000..a423b69 Binary files /dev/null and b/bin/main/Main$5.class differ diff --git a/bin/main/Main$6.class b/bin/main/Main$6.class new file mode 100644 index 0000000..0ab7c74 Binary files /dev/null and b/bin/main/Main$6.class differ diff --git a/bin/main/Main$7.class b/bin/main/Main$7.class new file mode 100644 index 0000000..bb12caa Binary files /dev/null and b/bin/main/Main$7.class differ diff --git a/bin/main/Main$8.class b/bin/main/Main$8.class new file mode 100644 index 0000000..702f2e3 Binary files /dev/null and b/bin/main/Main$8.class differ diff --git a/bin/main/Main.class b/bin/main/Main.class new file mode 100644 index 0000000..1435f97 Binary files /dev/null and b/bin/main/Main.class differ diff --git a/bin/main/MainPanel$InputListener.class b/bin/main/MainPanel$InputListener.class new file mode 100644 index 0000000..f7f523c Binary files /dev/null and b/bin/main/MainPanel$InputListener.class differ diff --git a/bin/main/MainPanel$ServerListener.class b/bin/main/MainPanel$ServerListener.class new file mode 100644 index 0000000..0c600da Binary files /dev/null and b/bin/main/MainPanel$ServerListener.class differ diff --git a/bin/main/MainPanel.class b/bin/main/MainPanel.class new file mode 100644 index 0000000..644480e Binary files /dev/null and b/bin/main/MainPanel.class differ diff --git a/bin/project/Project.class b/bin/project/Project.class new file mode 100644 index 0000000..9c2abce Binary files /dev/null and b/bin/project/Project.class differ diff --git a/bin/project/Scene.class b/bin/project/Scene.class new file mode 100644 index 0000000..631de6c Binary files /dev/null and b/bin/project/Scene.class differ diff --git a/bin/project/TridEntity.class b/bin/project/TridEntity.class new file mode 100644 index 0000000..f83f2ae Binary files /dev/null and b/bin/project/TridEntity.class differ diff --git a/bin/project/ent/BoxColl.class b/bin/project/ent/BoxColl.class new file mode 100644 index 0000000..a0437ca Binary files /dev/null and b/bin/project/ent/BoxColl.class differ diff --git a/bin/project/ent/BoxNoColl.class b/bin/project/ent/BoxNoColl.class new file mode 100644 index 0000000..5e4895b Binary files /dev/null and b/bin/project/ent/BoxNoColl.class differ diff --git a/bin/project/ent/CustomEntity.class b/bin/project/ent/CustomEntity.class new file mode 100644 index 0000000..f86a1ee Binary files /dev/null and b/bin/project/ent/CustomEntity.class differ diff --git a/bin/project/ent/InvisColl.class b/bin/project/ent/InvisColl.class new file mode 100644 index 0000000..2c2b619 Binary files /dev/null and b/bin/project/ent/InvisColl.class differ diff --git a/bin/project/ent/Light.class b/bin/project/ent/Light.class new file mode 100644 index 0000000..4040ffd Binary files /dev/null and b/bin/project/ent/Light.class differ diff --git a/bin/project/ent/PlrStart.class b/bin/project/ent/PlrStart.class new file mode 100644 index 0000000..70a618b Binary files /dev/null and b/bin/project/ent/PlrStart.class differ diff --git a/bin/project/ent/Trigger.class b/bin/project/ent/Trigger.class new file mode 100644 index 0000000..b4a3645 Binary files /dev/null and b/bin/project/ent/Trigger.class differ diff --git a/data/icon.png b/data/icon.png new file mode 100644 index 0000000..75679b4 Binary files /dev/null and b/data/icon.png differ diff --git a/data/images/crosshair.png b/data/images/crosshair.png new file mode 100644 index 0000000..7fae063 Binary files /dev/null and b/data/images/crosshair.png differ diff --git a/data/images/cursors/move.png b/data/images/cursors/move.png new file mode 100644 index 0000000..5ab64e7 Binary files /dev/null and b/data/images/cursors/move.png differ diff --git a/data/images/cursors/resize.png b/data/images/cursors/resize.png new file mode 100644 index 0000000..3345522 Binary files /dev/null and b/data/images/cursors/resize.png differ diff --git a/data/images/cursors/select.png b/data/images/cursors/select.png new file mode 100644 index 0000000..4c88674 Binary files /dev/null and b/data/images/cursors/select.png differ diff --git a/data/images/dropdown/box.png b/data/images/dropdown/box.png new file mode 100644 index 0000000..f946bbd Binary files /dev/null and b/data/images/dropdown/box.png differ diff --git a/data/images/dropdown/boxColl.png b/data/images/dropdown/boxColl.png new file mode 100644 index 0000000..ccfc5b8 Binary files /dev/null and b/data/images/dropdown/boxColl.png differ diff --git a/data/images/dropdown/collision.png b/data/images/dropdown/collision.png new file mode 100644 index 0000000..d31d02d Binary files /dev/null and b/data/images/dropdown/collision.png differ diff --git a/data/images/dropdown/customEnt.png b/data/images/dropdown/customEnt.png new file mode 100644 index 0000000..e0f5e4f Binary files /dev/null and b/data/images/dropdown/customEnt.png differ diff --git a/data/images/dropdown/delete.png b/data/images/dropdown/delete.png new file mode 100644 index 0000000..e4970c8 Binary files /dev/null and b/data/images/dropdown/delete.png differ diff --git a/data/images/dropdown/duplicate.png b/data/images/dropdown/duplicate.png new file mode 100644 index 0000000..e59f01b Binary files /dev/null and b/data/images/dropdown/duplicate.png differ diff --git a/data/images/dropdown/edit.png b/data/images/dropdown/edit.png new file mode 100644 index 0000000..4e41203 Binary files /dev/null and b/data/images/dropdown/edit.png differ diff --git a/data/images/dropdown/light.png b/data/images/dropdown/light.png new file mode 100644 index 0000000..3b5ad16 Binary files /dev/null and b/data/images/dropdown/light.png differ diff --git a/data/images/dropdown/move.png b/data/images/dropdown/move.png new file mode 100644 index 0000000..374f8f5 Binary files /dev/null and b/data/images/dropdown/move.png differ diff --git a/data/images/dropdown/plrStart.png b/data/images/dropdown/plrStart.png new file mode 100644 index 0000000..48ccdc4 Binary files /dev/null and b/data/images/dropdown/plrStart.png differ diff --git a/data/images/dropdown/quit.png b/data/images/dropdown/quit.png new file mode 100644 index 0000000..b92905d Binary files /dev/null and b/data/images/dropdown/quit.png differ diff --git a/data/images/dropdown/reset.png b/data/images/dropdown/reset.png new file mode 100644 index 0000000..e935838 Binary files /dev/null and b/data/images/dropdown/reset.png differ diff --git a/data/images/dropdown/resize.png b/data/images/dropdown/resize.png new file mode 100644 index 0000000..439bb16 Binary files /dev/null and b/data/images/dropdown/resize.png differ diff --git a/data/images/dropdown/select.png b/data/images/dropdown/select.png new file mode 100644 index 0000000..51e6156 Binary files /dev/null and b/data/images/dropdown/select.png differ diff --git a/data/images/dropdown/trigger.png b/data/images/dropdown/trigger.png new file mode 100644 index 0000000..c7ec401 Binary files /dev/null and b/data/images/dropdown/trigger.png differ diff --git a/data/images/player/idleE.png b/data/images/player/idleE.png new file mode 100644 index 0000000..fc1896b Binary files /dev/null and b/data/images/player/idleE.png differ diff --git a/data/images/player/idleN.png b/data/images/player/idleN.png new file mode 100644 index 0000000..e86f6cc Binary files /dev/null and b/data/images/player/idleN.png differ diff --git a/data/images/player/idleS.png b/data/images/player/idleS.png new file mode 100644 index 0000000..cb923cc Binary files /dev/null and b/data/images/player/idleS.png differ diff --git a/data/images/player/idleW.png b/data/images/player/idleW.png new file mode 100644 index 0000000..e706b7d Binary files /dev/null and b/data/images/player/idleW.png differ diff --git a/data/images/player/walkE.png b/data/images/player/walkE.png new file mode 100644 index 0000000..b9e2df3 Binary files /dev/null and b/data/images/player/walkE.png differ diff --git a/data/images/player/walkN.png b/data/images/player/walkN.png new file mode 100644 index 0000000..63aef9b Binary files /dev/null and b/data/images/player/walkN.png differ diff --git a/data/images/player/walkS.png b/data/images/player/walkS.png new file mode 100644 index 0000000..ff3366a Binary files /dev/null and b/data/images/player/walkS.png differ diff --git a/data/images/player/walkW.png b/data/images/player/walkW.png new file mode 100644 index 0000000..3ab625d Binary files /dev/null and b/data/images/player/walkW.png differ diff --git a/data/images/trident/box.png b/data/images/trident/box.png new file mode 100644 index 0000000..2095f6a Binary files /dev/null and b/data/images/trident/box.png differ diff --git a/data/images/trident/boxColl.png b/data/images/trident/boxColl.png new file mode 100644 index 0000000..e63707b Binary files /dev/null and b/data/images/trident/boxColl.png differ diff --git a/data/images/trident/collision.png b/data/images/trident/collision.png new file mode 100644 index 0000000..77597a8 Binary files /dev/null and b/data/images/trident/collision.png differ diff --git a/data/images/trident/consolebg.png b/data/images/trident/consolebg.png new file mode 100644 index 0000000..fc0a33e Binary files /dev/null and b/data/images/trident/consolebg.png differ diff --git a/data/images/trident/customEnt.png b/data/images/trident/customEnt.png new file mode 100644 index 0000000..bb10f72 Binary files /dev/null and b/data/images/trident/customEnt.png differ diff --git a/data/images/trident/light.png b/data/images/trident/light.png new file mode 100644 index 0000000..6f7887c Binary files /dev/null and b/data/images/trident/light.png differ diff --git a/data/images/trident/plrStart.png b/data/images/trident/plrStart.png new file mode 100644 index 0000000..58d0ff2 Binary files /dev/null and b/data/images/trident/plrStart.png differ diff --git a/data/images/trident/splash.png b/data/images/trident/splash.png new file mode 100644 index 0000000..0d40d89 Binary files /dev/null and b/data/images/trident/splash.png differ diff --git a/data/images/trident/trigger.png b/data/images/trident/trigger.png new file mode 100644 index 0000000..fcb46cd Binary files /dev/null and b/data/images/trident/trigger.png differ diff --git a/data/libraries/BLib.jar b/data/libraries/BLib.jar new file mode 100644 index 0000000..99e9d99 Binary files /dev/null and b/data/libraries/BLib.jar differ diff --git a/data/libraries/JHLabs Filters.jar b/data/libraries/JHLabs Filters.jar new file mode 100644 index 0000000..2ce3ec6 Binary files /dev/null and b/data/libraries/JHLabs Filters.jar differ diff --git a/data/projectRegistry.bson b/data/projectRegistry.bson new file mode 100644 index 0000000..2777d63 --- /dev/null +++ b/data/projectRegistry.bson @@ -0,0 +1,2 @@ +{ projects +} diff --git a/data/templates/blank2d/data/animations/intro.anim b/data/templates/blank2d/data/animations/intro.anim new file mode 100644 index 0000000..e93c287 --- /dev/null +++ b/data/templates/blank2d/data/animations/intro.anim @@ -0,0 +1,17 @@ +intro +false +1.0 +0.0 +0.0 +0.0 +1000 +0.0 +0.0 +0.0 +0.0 +3000 +0.0 +0.0 +1.0 +0.0 +1000 diff --git a/data/templates/blank2d/data/icon.png b/data/templates/blank2d/data/icon.png new file mode 100644 index 0000000..75679b4 Binary files /dev/null and b/data/templates/blank2d/data/icon.png differ diff --git a/data/templates/blank2d/data/images/player/idleE.png b/data/templates/blank2d/data/images/player/idleE.png new file mode 100644 index 0000000..fc1896b Binary files /dev/null and b/data/templates/blank2d/data/images/player/idleE.png differ diff --git a/data/templates/blank2d/data/images/player/idleN.png b/data/templates/blank2d/data/images/player/idleN.png new file mode 100644 index 0000000..e86f6cc Binary files /dev/null and b/data/templates/blank2d/data/images/player/idleN.png differ diff --git a/data/templates/blank2d/data/images/player/idleS.png b/data/templates/blank2d/data/images/player/idleS.png new file mode 100644 index 0000000..cb923cc Binary files /dev/null and b/data/templates/blank2d/data/images/player/idleS.png differ diff --git a/data/templates/blank2d/data/images/player/idleW.png b/data/templates/blank2d/data/images/player/idleW.png new file mode 100644 index 0000000..e706b7d Binary files /dev/null and b/data/templates/blank2d/data/images/player/idleW.png differ diff --git a/data/templates/blank2d/data/images/player/walkE.png b/data/templates/blank2d/data/images/player/walkE.png new file mode 100644 index 0000000..b9e2df3 Binary files /dev/null and b/data/templates/blank2d/data/images/player/walkE.png differ diff --git a/data/templates/blank2d/data/images/player/walkN.png b/data/templates/blank2d/data/images/player/walkN.png new file mode 100644 index 0000000..63aef9b Binary files /dev/null and b/data/templates/blank2d/data/images/player/walkN.png differ diff --git a/data/templates/blank2d/data/images/player/walkS.png b/data/templates/blank2d/data/images/player/walkS.png new file mode 100644 index 0000000..ff3366a Binary files /dev/null and b/data/templates/blank2d/data/images/player/walkS.png differ diff --git a/data/templates/blank2d/data/images/player/walkW.png b/data/templates/blank2d/data/images/player/walkW.png new file mode 100644 index 0000000..3ab625d Binary files /dev/null and b/data/templates/blank2d/data/images/player/walkW.png differ diff --git a/data/templates/blank2d/data/images/trident/box.png b/data/templates/blank2d/data/images/trident/box.png new file mode 100644 index 0000000..2095f6a Binary files /dev/null and b/data/templates/blank2d/data/images/trident/box.png differ diff --git a/data/templates/blank2d/data/images/trident/boxColl.png b/data/templates/blank2d/data/images/trident/boxColl.png new file mode 100644 index 0000000..e63707b Binary files /dev/null and b/data/templates/blank2d/data/images/trident/boxColl.png differ diff --git a/data/templates/blank2d/data/images/trident/collision.png b/data/templates/blank2d/data/images/trident/collision.png new file mode 100644 index 0000000..77597a8 Binary files /dev/null and b/data/templates/blank2d/data/images/trident/collision.png differ diff --git a/data/templates/blank2d/data/images/trident/consolebg.png b/data/templates/blank2d/data/images/trident/consolebg.png new file mode 100644 index 0000000..fc0a33e Binary files /dev/null and b/data/templates/blank2d/data/images/trident/consolebg.png differ diff --git a/data/templates/blank2d/data/images/trident/customEnt.png b/data/templates/blank2d/data/images/trident/customEnt.png new file mode 100644 index 0000000..bb10f72 Binary files /dev/null and b/data/templates/blank2d/data/images/trident/customEnt.png differ diff --git a/data/templates/blank2d/data/images/trident/light.png b/data/templates/blank2d/data/images/trident/light.png new file mode 100644 index 0000000..6f7887c Binary files /dev/null and b/data/templates/blank2d/data/images/trident/light.png differ diff --git a/data/templates/blank2d/data/images/trident/plrStart.png b/data/templates/blank2d/data/images/trident/plrStart.png new file mode 100644 index 0000000..58d0ff2 Binary files /dev/null and b/data/templates/blank2d/data/images/trident/plrStart.png differ diff --git a/data/templates/blank2d/data/images/trident/splash.png b/data/templates/blank2d/data/images/trident/splash.png new file mode 100644 index 0000000..0d40d89 Binary files /dev/null and b/data/templates/blank2d/data/images/trident/splash.png differ diff --git a/data/templates/blank2d/data/images/trident/trigger.png b/data/templates/blank2d/data/images/trident/trigger.png new file mode 100644 index 0000000..fcb46cd Binary files /dev/null and b/data/templates/blank2d/data/images/trident/trigger.png differ diff --git a/data/templates/blank2d/data/scenes/default.bson b/data/templates/blank2d/data/scenes/default.bson new file mode 100644 index 0000000..d98016b --- /dev/null +++ b/data/templates/blank2d/data/scenes/default.bson @@ -0,0 +1,43 @@ +string name default +string dir east +int light 25 +{ bgColor +int 255 +int 255 +int 255 +} +{ entities +string boxcoll +double -200 +double 0 +boolean true +int 100 +int 100 +int 0 +int 255 +int 0 +string plrstart +double -300 +double 0 +boolean false +string inviscoll +double -200 +double 100 +boolean true +int 100 +int 100 +string boxnocoll +double -200 +double -100 +boolean false +int 100 +int 100 +int 255 +int 0 +int 0 +string light +double -200 +double 200 +boolean false +int 100 +} diff --git a/data/templates/blank2d/src/ent/ExampleEntity.java b/data/templates/blank2d/src/ent/ExampleEntity.java new file mode 100644 index 0000000..98fabb0 --- /dev/null +++ b/data/templates/blank2d/src/ent/ExampleEntity.java @@ -0,0 +1,36 @@ +package ent; + +import blib.util.*; +import trident.*; +import javax.swing.*; +import java.awt.*; +public class ExampleEntity extends TridEntity { + + // Constructor, runs when the entity is created + public ExampleEntity(Position pos){ + super(pos); + } + // Registry constructor, used only for adding to the registry + public ExampleEntity(){ + super("example", false, 0); + } + // Custom constructor, used by the engine when building a scene + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new ExampleEntity(pos); + } + + // Render while in game + public void render(Graphics g, JPanel panel, int x, int y){ + + } + + // Runs every tick while the game is running + public void update(long elapsedTime){ + + } + + // Runs at the beginning of the scene + public void sceneStart(String scene){ + + } +} diff --git a/data/templates/blank2d/src/trident/Main.java b/data/templates/blank2d/src/trident/Main.java new file mode 100644 index 0000000..59bfae9 --- /dev/null +++ b/data/templates/blank2d/src/trident/Main.java @@ -0,0 +1,18 @@ +package trident; + +import javax.swing.*; +import java.awt.*; +public class Main{ + protected static JFrame window = new JFrame("blank2d"); + public static void main(String[] args){ + window.setSize(700, 500); + window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + window.setMinimumSize(new Dimension(700, 500)); + window.setIconImage(new ImageIcon("data/icon.png").getImage()); + // panel + MainPanel panel = new MainPanel(); + window.add(panel); + // + window.setVisible(true); + } +} diff --git a/data/templates/blank2d/src/trident/MainPanel.java b/data/templates/blank2d/src/trident/MainPanel.java new file mode 100644 index 0000000..20afddf --- /dev/null +++ b/data/templates/blank2d/src/trident/MainPanel.java @@ -0,0 +1,226 @@ +package trident; + +import javax.swing.*; +import java.awt.*; +import blib.game.*; +import blib.util.*; +import java.awt.event.*; +import blib.input.*; +import java.util.ArrayList; +import blib.anim.*; +import trident.ent.*; +import update.*; +public class MainPanel extends JPanel { + + protected FrameManager frameManager = new FrameManager(); + public static Server server; + protected KeyManager km = new InputListener(this); + private Animator introAnim; + public static Position introPos = new Position(); + public static ImageIcon splash = new ImageIcon("data/images/trident/splash.png"); + public static boolean inIntro = false; + private RenderingThread rendThread = new RenderingThread(); + + public MainPanel(){ + + System.setProperty("sun.java2d.opengl", "true"); // hardware acceleration? + + setBackground(Color.black); + + Trident.player = new Player(new Position(), km, 0.1, this, "data/images/player", 16, 16); + Trident.player.camera.setDimension = new Dimension(frameManager.WIDTH, frameManager.HEIGHT); + Trident.player.resizeImages(32, 32); + Trident.currentScene = new Scene("Test Scene"); + Trident.camShake = new CamShake(Trident.player.camera); + Trident.lightManager.blur.setRadius(100); + + Trident.addCustomEntity(new BoxColl()); + Trident.addCustomEntity(new BoxNoColl()); + Trident.addCustomEntity(new InvisColl()); + Trident.addCustomEntity(new PlrStart()); + Trident.addCustomEntity(new Trigger()); + Trident.addCustomEntity(new TridLight()); + + setFocusTraversalKeysEnabled(false); + + Update.setup(); + + Trident.setupScenes(); + + Trident.loadScene(Trident.defaultScene); + + for(String s: Update.fonts){ + BTools.addFont(s, this); + } + + try{ + ArrayList anims = new ArrayList(); + anims.add(new Animation("data/animations/intro")); + + introAnim = new Animator(introPos, anims); + }catch(Exception e){ + Trident.intro = false; + } + if(Trident.intro){ + introAnim.play("intro"); + inIntro = true; + } + if(Trident.splash != null && BTools.hasImage(Trident.splash)){ + BTools.resizeImgIcon(Trident.splash, 160, 160); + } + + Trident.consoleError = false; + rendThread.start(); + + server = new Server(new ServerListener(), this); + } + + public void paintComponent(Graphics graphics){ + super.paintComponent(graphics); + Graphics g = frameManager.newFrame(); + + frameManager.bgColor = Trident.currentScene.bgColor; + + if(rendThread.lastFrame != null){ + g.drawImage(rendThread.lastFrame, 0, 0, null); + } + + frameManager.renderFrame(this, graphics); + } + + public MainPanel panel = this; + private class InputListener extends InputAdapter { + public InputListener(JPanel panel){ + super(panel); + } + + public void onKeyPressed(int key){ + if(key == KeyEvent.VK_F12){ + frameManager.saveScreenshot("data/screenshots"); + Update.tridentEvent(Trident.EVENT_SCREENSHOT); + } + if(key == KeyEvent.VK_F11){ + Trident.fullscreen = !Trident.fullscreen; + Main.window = BTools.getWindowFullscreen(Main.window, Trident.fullscreen, panel); + return; + } + if(!inIntro){ + if(key == 192 && Trident.consoleEnabled){ + Trident.consoleOpen = !Trident.consoleOpen; + Trident.consoleType = ""; + Trident.consoleError = false; + } + if(Trident.consoleOpen){ + if(key >= KeyEvent.VK_A && key <= KeyEvent.VK_Z){ + char c = KeyEvent.getKeyText(key).charAt(0); + if(!km.getKeyDown(KeyEvent.VK_SHIFT)){ + c = Character.toLowerCase(c); + } + Trident.consoleType += c; + } + if(key >= KeyEvent.VK_0 && key <= KeyEvent.VK_9){ + char c = KeyEvent.getKeyText(key).charAt(0); + Trident.consoleType += c; + } + if(key == KeyEvent.VK_SPACE){ + Trident.consoleType += " "; + } + if(key == KeyEvent.VK_MINUS){ + Trident.consoleType += "-"; + } + if(key == KeyEvent.VK_PERIOD){ + Trident.consoleType += "."; + } + if(key == KeyEvent.VK_BACK_SPACE){ + if(Trident.consoleType.length() > 0) Trident.consoleType = Trident.consoleType.substring(0, Trident.consoleType.length() - 1); + } + if(key == KeyEvent.VK_UP){ + Trident.consoleType = Trident.lastCommand; + } + + if(key == KeyEvent.VK_ENTER){ + Trident.runCommand(Trident.consoleType); + Trident.consoleType = ""; + } + return; + } + Inputs.keyPressed(key); + } + } + + public void onMousePressed(int mb, Point mousePos){ + mousePos = frameManager.getMousePos(panel, mousePos); + Position worldPos = Trident.player.camera.mouseToPos(mousePos); + if(!inIntro) Inputs.mousePressed(mb, mousePos, worldPos); + } + + public void onScroll(int scroll){ + if(!inIntro) Inputs.onScroll(scroll); + } + } + + private class ServerListener implements ActionListener { + public void actionPerformed(ActionEvent event){ + if(inIntro){ + introAnim.update(server.getElapsedTime()); + if(!introAnim.isPlaying()){ + inIntro = false; + } + repaint(); + return; + } + + if(!hasFocus()) km.reset(); + + if(!Trident.consoleOpen){ + Trident.mousePos = frameManager.getMousePos(panel, km.getMousePos()); + Trident.mouseDelta = km.getMouseDelta(); + Trident.mouseWorldPos = Trident.player.camera.mouseToPos(Trident.mousePos); + + Trident.camShake.update(server.getElapsedTime()); + + if(!Trident.noclip) Trident.player.updateWithCollision(server.getElapsedTime(), Trident.currentScene.getCollision()); + else Trident.player.update(server.getElapsedTime()); + + for(int i = 0; i < Trident.getEntities().size(); i++){ + TridEntity e = Trident.getEntities().get(i); + e.update(server.getElapsedTime()); + if(e instanceof Trigger){ + Trigger trig = (Trigger)e; + if(trig.containsPos(Trident.player.getPos())){ + Update.trigger(trig.id); + } + } + } + + if(Trident.reset){ + km.reset(); + Trident.reset = false; + } + for(int i = 0; i < 255; i++){ + Trident.keys[i] = km.getKeyDown(i); + } + Trident.m1 = km.getMouseDown(1); + Trident.m2 = km.getMouseDown(2); + Trident.m3 = km.getMouseDown(3); + Trident.m4 = km.getMouseDown(4); + Trident.m5 = km.getMouseDown(5); + + if(Trident.newSprite != null){ + Trident.player = new Player(Trident.player.getPos(), km, 0.2, panel, Trident.newSprite, 16, 16); + Trident.newSprite = null; + Trident.player.resizeImages(32, 32); + Trident.player.camera.setDimension = new Dimension(frameManager.WIDTH, frameManager.HEIGHT); + Trident.camShake = new CamShake(Trident.player.camera); + Trident.player.shortCollision = true; + } + + Update.update(server.getElapsedTime()); + } + + + + try {Trident.getEntities().sort((o1, o2) -> o2.compareSort(o1));} catch(Exception e){} + } + } +} diff --git a/data/templates/blank2d/src/trident/RenderingThread.java b/data/templates/blank2d/src/trident/RenderingThread.java new file mode 100644 index 0000000..65220e3 --- /dev/null +++ b/data/templates/blank2d/src/trident/RenderingThread.java @@ -0,0 +1,148 @@ +package trident; + +import java.awt.image.*; +import java.util.ArrayList; +import java.util.ConcurrentModificationException; +import blib.util.*; +import java.awt.*; +import blib.game.*; +import javax.swing.*; +public class RenderingThread extends Thread { + + public BufferedImage lastFrame = null; + private long elapsedTime, previousStartTime = -1; + + private ImageIcon consoleBg = new ImageIcon("data/images/trident/consolebg.png"); + private long errorFlashTime = 0; + + public RenderingThread(){ + BTools.resizeImgIcon(consoleBg, Trident.getFrameWidth(), 483); + } + + public void run(){ + while(true){ + try{ + + long now = System.currentTimeMillis(); + elapsedTime = previousStartTime != -1 ? now - previousStartTime : 0; + previousStartTime = now; + int WIDTH = Trident.getFrameWidth(), HEIGHT = Trident.getFrameHeight(); + int offX, offY; + offX = Trident.camShake.offX; + offY = Trident.camShake.offY; + BufferedImage newFrame = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB); + Graphics g = newFrame.getGraphics(); + + if(Trident.engineDraw){ + for(TridEntity e: Trident.currentScene.entities){ + Point p = Trident.player.camera.worldToScreen(e.position); + e.engineRender(g, null, p.x, p.y); + } + } + + ArrayList> splitEnt = Trident.player.camera.splitEntities(Trident.tridArrToEntArr(Trident.currentScene.entities), 16); + if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(2), offX, offY); + if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(0), offX, offY); + if(Trident.drawPlayer){ + Trident.player.render(null, g, WIDTH / 2 - offX, HEIGHT / 2 - offY); + } + if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(1), offX, offY); + + Trident.lightManager.render(Trident.player.camera, Trident.lights, g, offX, offY); + + if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(3), offX, offY); + + + + + if(Trident.drawCollision){ + g.setColor(Color.red); + ArrayList collision = Trident.currentScene.getCollision(); + collision.add(Trident.player.getCollision()); + for(Rectangle r: collision){ + Point p = Trident.player.camera.worldToScreen(new Position(r.x, r.y)); + g.drawRect(p.x, p.y, r.width, r.height); + g.drawLine(p.x, p.y, p.x + r.width, p.y + r.height); + } + } + + if(Trident.drawPos){ + g.setColor(Trident.debugColor); + g.setFont(new Font("Arial", Font.ITALIC, 10)); + TextBox.draw(Trident.player.getPos().toStringSimple(), g, 10, 20); + } + if(Trident.drawFrames){ + g.setColor(Trident.debugColor); + g.setFont(new Font("Arial", Font.ITALIC, 10)); + TextBox.draw("TPS: " + (1000 / Math.max(MainPanel.server.getElapsedTime(), 1)) + " (" + MainPanel.server.getElapsedTime() + " ms)", g, 10, 30); + TextBox.draw("FPS: " + (1000 / Math.max(elapsedTime, 1)) + " (" + elapsedTime + " ms)", g, 10, 40); + } + + // Apply Post Processing + if(Trident.enableExposure){ + Trident.exposure.filter(newFrame, newFrame); + } + if(Trident.enableBloom){ + Trident.bloom.filter(newFrame, newFrame); + } + + if(MainPanel.inIntro){ + g.setColor(Color.black); + g.fillRect(0, 0, 700, 500); + + if(Trident.splash != null && BTools.hasImage(Trident.splash)){ + // Trident splash + custom splash + MainPanel.splash.paintIcon(null, g, WIDTH / 2 - 80, 40); + Trident.splash.paintIcon(null, g, WIDTH / 2 - 80, HEIGHT - 200); + }else{ + // Trident splash only + MainPanel.splash.paintIcon(null, g, WIDTH / 2 - 80, HEIGHT / 2 - 80); + } + + float alpha = (float)MainPanel.introPos.x; + g.setColor(new Color(0f, 0f, 0f, alpha)); + g.fillRect(0, 0, 700, 500); + } + + if(Trident.consoleOpen){ + // bg + consoleBg.paintIcon(null, g, 0, -252); + g.setColor(new Color(0f, 0f, 0f, 0.7f)); + g.fillRect(0, 0, Trident.getFrameWidth(), Trident.getFrameHeight() / 2); + + // text + g.setColor(Color.white); + g.setFont(new Font("Arial", Font.PLAIN, 10)); + for(int i = 0; i < Trident.consoleLines.size(); i++){ + int index = BTools.flip(i, Trident.consoleLines.size() - 1); + TextBox.draw(Trident.consoleLines.get(index), g, 5, Trident.getFrameHeight() / 2 - 25 - (i * 10)); + } + + // borders + g.setColor(new Color(32, 12, 121)); + g.drawRect(0, 0, Trident.getFrameWidth() - 1, Trident.getFrameHeight() / 2); + g.drawLine(0, Trident.getFrameHeight() / 2 - 10, Trident.getFrameWidth(), Trident.getFrameHeight() / 2 - 10); + + // text entry box + g.setColor(Color.white); + g.setFont(new Font("Arial", Font.PLAIN, 10)); + TextBox.draw("> " + Trident.consoleType + "_", g, 3, Trident.getFrameHeight() / 2 - 5); + } + if(Trident.consoleError){ + errorFlashTime += elapsedTime; + g.setColor(new Color(1f, (float)(Math.min(1, Math.sin(errorFlashTime / 500.0) / 2 + 0.5)), (float)(Math.min(1, Math.sin(errorFlashTime / 500.0) / 2 + 0.5)))); + g.setFont(new Font("Arial", Font.BOLD, 20)); + TextBox.draw("ERROR\nOpen console with [~](tilde)", g, Trident.getFrameWidth() / 2, 10, TextBox.CENTER); + } + + lastFrame = newFrame; + }catch(Exception e){ + if(!(e instanceof ConcurrentModificationException)){ + e.printStackTrace(); + } + } + + + } + } +} diff --git a/data/templates/blank2d/src/trident/Scene.java b/data/templates/blank2d/src/trident/Scene.java new file mode 100644 index 0000000..e456f8f --- /dev/null +++ b/data/templates/blank2d/src/trident/Scene.java @@ -0,0 +1,104 @@ +package trident; + +import java.util.ArrayList; +import java.awt.*; +import java.io.*; +import blib.bson.*; +import blib.util.*; +import trident.ent.*; +import blib.game.*; +public class Scene { + + public final String name; + public ArrayList entities; + protected Position plrStart = new Position(); + protected int plrDir = Player.SOUTH; + protected Color bgColor = Color.white; + protected int defaultLight = 255; + + public Scene(String n){ // Empty scene + name = n; + entities = new ArrayList(); + } + public Scene(File f) throws IOException{ + entities = new ArrayList(); + ArrayList objects = BSonParser.readFile(f.getAbsolutePath()); + BSonObject obj = BSonParser.getObject("name", objects); + name = obj.getString(); + obj = BSonParser.getObject("dir", objects); + if(obj != null){ + String str = obj.getString(); + if(str.equals("west")) plrDir = Player.WEST; + if(str.equals("north")) plrDir = Player.NORTH; + if(str.equals("east")) plrDir = Player.EAST; + } + obj = BSonParser.getObject("bgColor", objects); + BSonList asList = (BSonList)obj; + int r, g, b; + r = asList.list.get(0).getInt(); + g = asList.list.get(1).getInt(); + b = asList.list.get(2).getInt(); + bgColor = new Color(r, g, b); + obj = BSonParser.getObject("light", objects); + defaultLight = obj.getInt(); + obj = BSonParser.getObject("entities", objects); + asList = (BSonList)obj; + for(int i = 0; i < asList.list.size(); i++){ + String objName = asList.list.get(i).getString(); + i++; + boolean foundEnt = false; + for(TridEntity e: Trident.entRegistry){ + if(e.name.equals(objName)){ + double x, y; + x = asList.list.get(i).getDouble(); + i++; + y = asList.list.get(i).getDouble(); + i++; + int w = 0, h = 0; + i++; + if(e.HASCOLLISION){ + w = asList.list.get(i).getInt(); + i++; + h = asList.list.get(i).getInt(); + i++; + } + int[] data = new int[e.numData]; + for(int j = 0; j < e.numData; j++){ + data[j] = asList.list.get(i).getInt(); + i++; + } + i--; + entities.add(e.construct(new Position(x, y), (e.HASCOLLISION ? (new Dimension(w, h)) : null), data)); + foundEnt = true; + break; + } + } + if(!foundEnt) Trident.printConsole("ERROR: no entity type '" + objName + "' found"); + } + + // Check for plrstart + for(TridEntity e: entities){ + if(e instanceof PlrStart){ + plrStart = e.position.copy(); + break; + } + } + } + + public static Scene loadScene(String path){ // stub method ::: Load a scene from a file + return null; + } + + public ArrayList getCollision(){ + ArrayList collision = new ArrayList(); + for(int i = 0; i < entities.size(); i++){ + TridEntity e = entities.get(i); + if(e.HASCOLLISION){ + collision.add(e.getCollision()); + } + } + + return collision; + } + +} diff --git a/data/templates/blank2d/src/trident/TridEntity.java b/data/templates/blank2d/src/trident/TridEntity.java new file mode 100644 index 0000000..9e172c4 --- /dev/null +++ b/data/templates/blank2d/src/trident/TridEntity.java @@ -0,0 +1,101 @@ +package trident; + +import blib.game.*; +import blib.util.*; + +import javax.swing.*; +import java.awt.*; +public class TridEntity extends Entity { + + public final boolean HASCOLLISION; + private final Dimension collision; + public String engineRenderData = ""; + private ImageIcon engineImg = new ImageIcon("data/images/trident/customEnt.png"); + protected String name; + protected int numData; + + public TridEntity(Position pos){ + super(pos); + HASCOLLISION = false; + collision = null; + } + public TridEntity(Position pos, Dimension collision){ + super(pos); + if(collision.equals(new Dimension(0, 0))) HASCOLLISION = false; + else HASCOLLISION = true; + this.collision = collision; + } + public TridEntity(String n, boolean hasColl, int numData){ + super(new Position()); + HASCOLLISION = hasColl; + collision = null; + name = n; + this.numData = numData; + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + System.out.println("Error: tried to create an empty entity"); + return null; + } + + public Rectangle getCollision(){ + return new Rectangle((int)position.x - (collision.width / 2), (int)position.y - (collision.height / 2), collision.width, collision.height); + } + + public void render(Graphics g, JPanel panel, int x, int y){ + + } + + protected void engineRender(Graphics g, JPanel panel, int x, int y){ + if(HASCOLLISION){ + g.setColor(Color.red); + g.drawRect(x - getCollision().width / 2, y - getCollision().height / 2, getCollision().width, getCollision().height); + g.drawLine(x - getCollision().width / 2, y - getCollision().height / 2, x + getCollision().width / 2, y + getCollision().height / 2); + } + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } + + public void update(long elapsedTime){ + + } + + public void sceneStart(String scene){ + + } + + public int getRendDatSort(){ + if(renderType == Entity.TALL){ + return 2; + } + if(renderType == Entity.UNDER){ + return 1; + } + if(renderType == Entity.ABOVE){ + return 3; + } + if(renderType == Entity.BOTTOMPRIORITY){ + return 0; + } + if(renderType == Entity.TOPPRIORITY){ + return 4; + } + return 2; + } + + public int compareSort(TridEntity e){ + if(e.getRendDatSort() > getRendDatSort()){ + // e should be above + return 1; + }else if(e.getRendDatSort() < getRendDatSort()){ + return -1; + } + + if(e.position.y > position.y){ + return 1; + }else if(e.position.y < position.y){ + return -1; + } + + return 0; + } + +} diff --git a/data/templates/blank2d/src/trident/Trident.java b/data/templates/blank2d/src/trident/Trident.java new file mode 100644 index 0000000..695f873 --- /dev/null +++ b/data/templates/blank2d/src/trident/Trident.java @@ -0,0 +1,516 @@ +package trident; + +import blib.game.*; +import blib.util.*; +import java.awt.*; +import java.util.ArrayList; +import java.util.Scanner; + +import javax.swing.*; +import update.*; +import java.io.*; +import trident.ent.*; +import com.jhlabs.image.GlowFilter; +import com.jhlabs.image.ExposureFilter; +public class Trident { + + // Debug Settings + public static boolean drawPos = false; + public static boolean drawCollision = false; + public static boolean noclip = false; + public static boolean engineDraw = false; + public static Color debugColor = Color.red; + public static boolean intro = true; + public static ImageIcon splash = null; + public static boolean drawFrames = false; + public static boolean consoleEnabled = true; + public static boolean consoleOpen = false; + public static boolean consoleError = false; + public static String lastCommand = ""; + + // Public Variables + public static Point mousePos; + public static Point mouseDelta; + public static boolean drawPlayer = true; + public static Position mouseWorldPos = new Position(); + public static boolean enableBloom = true, enableExposure = true; + + + // Trident Variables + protected static Player player; + protected static Scene currentScene; + protected static boolean fullscreen = false; + protected static ArrayList loadedScenes = new ArrayList(); + protected static ArrayList entRegistry = new ArrayList(); + protected static String defaultScene = "default"; + protected static boolean m1 = false, m2 = false, m3 = false, m4 = false, m5 = false; + protected static boolean[] keys = new boolean[255]; + protected static CamShake camShake; + protected static ArrayList lights = new ArrayList(); + protected static LightManager lightManager = new LightManager(255); + protected static GlowFilter bloom = new GlowFilter(); + protected static ExposureFilter exposure = new ExposureFilter(); + protected static boolean reset = false; + protected static String newSprite = null; + + // Trident events + public static final int EVENT_SCREENSHOT = 0; + + + // Setting methods + public static void setPlrSpeed(double speed){ + player.speed = speed; + } + public static void setPlrPos(Position pos){ + player.goToPos(pos); + } + public static void setShortCollision(boolean b){ + player.shortCollision = b; + } + public static void setWindowTitle(String title){ + Main.window.setTitle(title); + } + public static void setupScenes(){ + try{ + loadedScenes = new ArrayList(); + File dir = new File("data/scenes"); + File[] files = dir.listFiles(); + ArrayList sceneFiles = new ArrayList(); + for(File f: files){ + if(BTools.hasExtension(f, "bson")) sceneFiles.add(f); + } + + for(File f: sceneFiles){ + loadedScenes.add(new Scene(f)); + } + }catch(Exception e){ + printException("Error setting up scenes", e); + } + + } + public static void loadScene(String name){ + lights = new ArrayList(); + for(Scene s: loadedScenes){ + if(s.name.equals(name)){ + currentScene = s; + player.goToPos(s.plrStart); + player.setDirection(s.plrDir); + for(TridEntity e: s.entities){ + if(e instanceof TridLight){ + TridLight asLight = (TridLight)e; + lights.add(new Light(asLight.position, asLight.radius)); + } + e.sceneStart(s.name); + } + lightManager.defaultLight = s.defaultLight; + Update.sceneStart(name); + return; + } + } + printConsole("***********************************************************************************"); + printConsole("Error loading scene: No scene with name '" + name + "' found."); + printError("***********************************************************************************"); + } + public static void addCustomEntity(TridEntity e){ // Add a cutsom entity to the registry + entRegistry.add(e); + } + public static void spawnEntity(TridEntity e){ + currentScene.entities.add(e); + } + public static void setDefaultScene(String s){ + defaultScene = s; + } + public static void destroy(TridEntity object){ + getEntities().remove(object); + } + public static void shakeCam(double intensity){ + camShake.addTrauma(intensity); + } + public static void removeShake(){ + camShake.trauma = 0; + } + public static void setShakeStrength(int str){ + camShake.strength = str; + } + public static void setShakeLoss(double loss){ + camShake.traumaLoss = loss; + } + public static void setBloom(double amount){ + bloom.setAmount((float)amount); + } + public static void setExposure(double exp){ + exposure.setExposure((float)exp); + } + public static void setLightBlur(int level){ + lightManager.blur.setIterations(level); + } + public static void addLight(Light l){ + lights.add(l); + } + public static void resetKeys(){ + reset = true; + } + public static void setPlrSprite(String path){ + newSprite = path; + } + public static void removeLight(Light l){ + lights.remove(l); + } + public static void setDefaultLight(int level){ + lightManager.defaultLight = level; + } + public static void stopShake(){ + camShake.trauma = 0; + } + + // Getting methods + public static double getPlrSpeed(){ + return player.speed; + } + public static Position getPlrPos(){ + return player.getPos().copy(); + } + public static Scene getCurrentScene(){ + return currentScene; + } + public static boolean getFullscreen(){ + return fullscreen; + } + public static ArrayList tridArrToEntArr(ArrayList entities){ + ArrayList newEntities = new ArrayList(); + for(TridEntity e: entities){ + newEntities.add((Entity)e); + } + return newEntities; + } + public static ArrayList entArrToTridArr(ArrayList entities){ + ArrayList newEntities = new ArrayList(); + for(Entity e: entities){ + newEntities.add((TridEntity)e); + } + return newEntities; + } + public static ArrayList getEntities(){ + return currentScene.entities; + } + public static ArrayList getCollision(){ + return currentScene.getCollision(); + } + public static boolean getMouseDown(int mb){ + if(mb == 1){ + return m1; + } + if(mb == 2){ + return m2; + } + if(mb == 3){ + return m3; + } + if(mb == 4){ + return m4; + } + if(mb == 5){ + return m5; + } + return false; + } + public static boolean getKeyDown(int key){ + return keys[key]; + } + public static Player getPlr(){ + return player; + } + public static int getFrameWidth(){ + return 684; + } + public static int getFrameHeight(){ + return 462; + } + public static Point getShakeOffset(){ + return new Point(camShake.offX, camShake.offY); + } + + + // Commands + public static ArrayList consoleLines = new ArrayList(); + public static String consoleType = ""; // What the user is typing + + public static void runCommand(String command){ + if(command != null && command.length() > 0){ + lastCommand = command; + printConsole(" > " + command); + + ArrayList cmdParts = new ArrayList(); + Scanner scanner = new Scanner(command); + while(scanner.hasNext()){ + cmdParts.add(scanner.next()); + } + scanner.close(); + + if(cmdParts.size() == 0) return; + try{ + switch(cmdParts.get(0)){ + case "drawCollision": + if(cmdParts.size() == 1){ + printConsole("drawCollision is " + Trident.drawCollision); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.drawCollision = true; + printConsole("set drawCollision to " + Trident.drawCollision); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.drawCollision = false; + printConsole("set drawCollision to " + Trident.drawCollision); + } + break; + case "engineDraw": + if(cmdParts.size() == 1){ + printConsole("engineDraw is " + Trident.engineDraw); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.engineDraw = true; + printConsole("set engineDraw to " + Trident.engineDraw); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.engineDraw = false; + printConsole("set engineDraw to " + Trident.engineDraw); + } + break; + case "drawPos": + if(cmdParts.size() == 1){ + printConsole("drawPos is " + Trident.drawPos); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.drawPos = true; + printConsole("set drawPos to " + Trident.drawPos); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.drawPos = false; + printConsole("set drawPos to " + Trident.drawPos); + } + break; + case "noclip": + if(cmdParts.size() == 1){ + printConsole("noclip is " + Trident.noclip); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.noclip = true; + printConsole("set noclip to " + Trident.noclip); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.noclip = false; + printConsole("set noclip to " + Trident.noclip); + } + break; + case "tp": + int x = Integer.parseInt(cmdParts.get(1)); + int y = Integer.parseInt(cmdParts.get(2)); + Trident.setPlrPos(new Position(x, y)); + printConsole("teleported player to (" + x + ", " + y + ")"); + break; + case "loadMap": + String map = ""; + for(int i = 1; i < cmdParts.size(); i++){ + map += cmdParts.get(i); + if(i != cmdParts.size() - 1) map += " "; + } + Trident.loadScene(map); + break; + case "drawFrames": + if(cmdParts.size() == 1){ + printConsole("drawFrames is " + Trident.drawFrames); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.drawFrames = true; + printConsole("set drawFrames to " + Trident.drawFrames); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.drawFrames = false; + printConsole("set drawFrames to " + Trident.drawFrames); + } + break; + case "debugColor": + int r, g, b; + float alpha = -1; + r = Integer.parseInt(cmdParts.get(1)); + g = Integer.parseInt(cmdParts.get(2)); + b = Integer.parseInt(cmdParts.get(3)); + if(cmdParts.size() == 5){ + alpha = Float.parseFloat(cmdParts.get(4)); + } + if(alpha != -1){ + Trident.debugColor = new Color(r / 255f, g / 255f, b / 255f, alpha); + printConsole("set debugColor to (" + r + ", " + g + ", " + b + ", " + alpha + ")"); + }else{ + Trident.debugColor = new Color(r, g, b); + printConsole("set debugColor to (" + r + ", " + g + ", " + b + ")"); + } + break; + case "enableBloom": + if(cmdParts.size() == 1){ + printConsole("enableBloom is " + Trident.enableBloom); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.enableBloom = true; + printConsole("set enableBloom to " + Trident.enableBloom); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.enableBloom = false; + printConsole("set enableBloom to " + Trident.enableBloom); + } + break; + case "enableExposure": + if(cmdParts.size() == 1){ + printConsole("enableExposure is " + Trident.enableExposure); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.enableExposure = true; + printConsole("set enableExposure to " + Trident.enableExposure); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.enableExposure = false; + printConsole("set enableExposure to " + Trident.enableExposure); + } + break; + case "setBloom": + double amount = Double.parseDouble(cmdParts.get(1)); + Trident.setBloom(amount); + printConsole("set bloom to " + amount); + break; + case "setExposure": + double expo = Double.parseDouble(cmdParts.get(1)); + Trident.setExposure(expo); + printConsole("set exposure to " + expo); + break; + case "setLightBlur": + int blurLevel = Integer.parseInt(cmdParts.get(1)); + Trident.setLightBlur(blurLevel); + printConsole("set lightBlur to " + blurLevel + " (recommended: 1)"); + break; + case "clear": + consoleLines = new ArrayList(); + break; + case "help": + int page = 1; + if(cmdParts.size() > 1) page = Integer.parseInt(cmdParts.get(1)); + printHelp(page); + break; + case "customHelp": + int p = 1; + if(cmdParts.size() > 1) p = Integer.parseInt(cmdParts.get(1)); + printCustomHelp(p); + break; + case "credits": + runCommand("clear"); + printConsole("Trident Engine built in Java by Blocky"); + printConsole("---"); + printConsole("Github: @HeyIts-Blocky"); + printConsole("Insta: @heyits_blocky"); + printConsole("Itch.io: blockmanblue.itch.io "); + printConsole("---"); + printConsole(""); + break; + case "openItch": + BTools.openWebsite("https://blockmanblue.itch.io/"); + break; + case "errorTest": + consoleOpen = false; + printError("Error test"); + break; + case "roll": + printConsole("You got " + BTools.randInt(0, 101) + " points"); + break; + default: + int cmd = Update.command(cmdParts); + if(cmd != 0){ + printConsole("Unknown command: " + cmdParts.get(0)); + } + break; + } + }catch(Exception e){ + printConsole("Something went wrong while running your command."); + printException("", e); + } + } + } + public static void printConsole(String text){ + consoleLines.add(text); + if(consoleLines.size() > 30) consoleLines.remove(0); + } + public static void printError(String text){ + consoleError = true; + printConsole(text); + } + public static void printException(String text, Exception e){ + consoleError = true; + printConsole(text); + printConsole("Error type: " + e.getClass().getName()); + } + public static void printExceptionSilent(String text, Exception e){ + printConsole(text); + printConsole("Error type: " + e.getClass().getName()); + } + private static String[] cmds = { + "credits", + "drawCollision [0/1, false/true]", + "engineDraw [0/1, false/true]", + "drawPos [0/1, false/true]", + "noclip [0/1, false/true]", + "tp ", + "loadMap ", + "drawFrames [0/1, false/true]", + "debugColor [a]", + "enableBloom [0/1, false/true]", + "enableExposure [0/1, false/true]", + "setBloom ", + "setExposure ", + "setLightBlur ", + "clear", + "help [page]", + "customHelp [page]", + "errorTest", + "roll", + }; + + public static void printHelp(int page){ + int startIndex = (page - 1) * 10; + if(startIndex > cmds.length - 1){ + printConsole("page beyond bounds: " + page); + printConsole("number of pages: " + (cmds.length / 10 + ((cmds.length % 10 != 0) ? 1 : 0))); + return; + } + + printConsole("-- BUILT-IN COMMANDS --"); + printConsole("Page " + page + " of " + (cmds.length / 10 + ((cmds.length % 10 != 0) ? 1 : 0))); + printConsole(""); + for(int i = startIndex; (i < cmds.length && i < startIndex + 10); i++){ + printConsole("} " + cmds[i]); + } + printConsole(""); + } + + public static void printCustomHelp(int page){ + int startIndex = (page - 1) * 10; + if(startIndex > Update.commands.length - 1){ + printConsole("page beyond bounds: " + page); + printConsole("number of pages: " + (Update.commands.length / 10 + ((Update.commands.length % 10 != 0) ? 1 : 0))); + return; + } + + printConsole("-- GAME-SPECIFIC COMMANDS --"); + printConsole("Page " + page + " of " + (Update.commands.length / 10 + ((Update.commands.length % 10 != 0) ? 1 : 0))); + printConsole(""); + for(int i = startIndex; (i < Update.commands.length && i < startIndex + 10); i++){ + printConsole("} " + Update.commands[i]); + } + printConsole(""); + } + +} diff --git a/data/templates/blank2d/src/trident/ent/BoxColl.java b/data/templates/blank2d/src/trident/ent/BoxColl.java new file mode 100644 index 0000000..8201a9d --- /dev/null +++ b/data/templates/blank2d/src/trident/ent/BoxColl.java @@ -0,0 +1,37 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import trident.*; +public class BoxColl extends TridEntity{ + + public Color color = Color.white; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/boxColl.png"); + + public BoxColl(Position pos, Dimension size, Color c){ + super(pos, size); + color = c; + } + public BoxColl(Position pos, Dimension size){ + super(pos, size); + } + public BoxColl(){ + super("boxcoll", true, 3); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new BoxColl(pos, collision, new Color(data[0], data[1], data[2])); + } + + public void render(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.fillRect(x - getCollision().width / 2, y - getCollision().height / 2, getCollision().width, getCollision().height); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + render(g, panel, x, y); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/templates/blank2d/src/trident/ent/BoxNoColl.java b/data/templates/blank2d/src/trident/ent/BoxNoColl.java new file mode 100644 index 0000000..e12beb7 --- /dev/null +++ b/data/templates/blank2d/src/trident/ent/BoxNoColl.java @@ -0,0 +1,45 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; +import blib.game.*; + +import trident.*; +public class BoxNoColl extends TridEntity{ + + public Color color = Color.white; + public int width, height; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/box.png"); + + public BoxNoColl(Position pos, Color c, int w, int h){ + super(pos); + color = c; + width = w; + height = h; + renderType = Entity.UNDER; + } + public BoxNoColl(Position pos, int w, int h){ + super(pos); + width = w; + height = h; + renderType = Entity.UNDER; + } + public BoxNoColl(){ + super("boxnocoll", false, 5); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new BoxNoColl(pos, new Color(data[2], data[3], data[4]), data[0], data[1]); + } + + public void render(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.fillRect(x - width / 2, y - height / 2, width, height); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + render(g, panel, x, y); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/templates/blank2d/src/trident/ent/InvisColl.java b/data/templates/blank2d/src/trident/ent/InvisColl.java new file mode 100644 index 0000000..7736536 --- /dev/null +++ b/data/templates/blank2d/src/trident/ent/InvisColl.java @@ -0,0 +1,30 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import trident.*; +public class InvisColl extends TridEntity{ + + public Color color = Color.red; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/collision.png"); + + public InvisColl(Position pos, Dimension size){ + super(pos, size); + } + public InvisColl(){ + super("inviscoll", true, 0); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new InvisColl(pos, collision); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.drawRect(x - getCollision().width / 2, y - getCollision().height / 2, getCollision().width, getCollision().height); + g.drawLine(x - getCollision().width / 2, y - getCollision().height / 2, x + getCollision().width / 2, y + getCollision().height / 2); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/templates/blank2d/src/trident/ent/PlrStart.java b/data/templates/blank2d/src/trident/ent/PlrStart.java new file mode 100644 index 0000000..26fe13d --- /dev/null +++ b/data/templates/blank2d/src/trident/ent/PlrStart.java @@ -0,0 +1,26 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import trident.*; +public class PlrStart extends TridEntity{ + public Color color = Color.red; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/plrStart.png"); + + public PlrStart(Position pos){ + super(pos); + } + public PlrStart(){ + super("plrstart", false, 0); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new PlrStart(pos); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/templates/blank2d/src/trident/ent/TridLight.java b/data/templates/blank2d/src/trident/ent/TridLight.java new file mode 100644 index 0000000..888bf49 --- /dev/null +++ b/data/templates/blank2d/src/trident/ent/TridLight.java @@ -0,0 +1,28 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import trident.*; +public class TridLight extends TridEntity{ + + public int radius; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/light.png"); + + public TridLight(Position pos, int r){ + super(pos); + radius = r; + } + public TridLight(){ + super("light", false, 1); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new TridLight(pos, data[0]); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/templates/blank2d/src/trident/ent/Trigger.java b/data/templates/blank2d/src/trident/ent/Trigger.java new file mode 100644 index 0000000..d52126d --- /dev/null +++ b/data/templates/blank2d/src/trident/ent/Trigger.java @@ -0,0 +1,41 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import trident.*; +public class Trigger extends TridEntity{ + + public Color color = Color.blue; + public Dimension box; + public int id; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/trigger.png"); + + public Trigger(Position pos, Dimension size, int i){ + super(pos); + name = "trigger"; + box = size; + id = i; + } + public Trigger(){ + super("trigger", false, 3); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new Trigger(pos, new Dimension(data[0], data[1]), data[2]); + } + + public boolean containsPos(Position pos){ + Point p = new Point((int)pos.x, (int)pos.y); + Rectangle rect = new Rectangle((int)position.x - box.width / 2, (int)position.y - box.height / 2, box.width, box.height); + return rect.contains(p); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.drawRect(x - box.width / 2, y - box.height / 2, box.width, box.height); + g.drawLine(x - box.width / 2, y - box.height / 2, x + box.width / 2, y + box.height / 2); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/templates/blank2d/src/update/Inputs.java b/data/templates/blank2d/src/update/Inputs.java new file mode 100644 index 0000000..0fc6ecc --- /dev/null +++ b/data/templates/blank2d/src/update/Inputs.java @@ -0,0 +1,19 @@ +package update; + +import java.awt.*; +import java.awt.event.*; +import blib.util.*; +public class Inputs { + + public static void keyPressed(int key){ + + } + + public static void mousePressed(int mb, Point mousePos, Position worldPos){ + + } + + public static void onScroll(int scroll){ + + } +} diff --git a/data/templates/blank2d/src/update/Update.java b/data/templates/blank2d/src/update/Update.java new file mode 100644 index 0000000..57a2e9b --- /dev/null +++ b/data/templates/blank2d/src/update/Update.java @@ -0,0 +1,59 @@ +package update; + +import trident.*; +import ent.*; +import java.util.ArrayList; +public class Update { + + public static final String[] fonts = {}; // add fonts here + + public static void setup(){ + // Add custom entities to the registry here. Required in order to load them properly + Trident.addCustomEntity(new ExampleEntity()); // Use the empty constructor + + // Set settings + Trident.setPlrSpeed(0.2); + Trident.setShortCollision(true); + + // Post Processing + Trident.setBloom(0.2); + Trident.setExposure(1); + Trident.enableBloom = false; + Trident.enableExposure = false; + Trident.setLightBlur(1); + } + + public static void sceneStart(String scene){ + + } + + public static void update(long elapsedTime){ + + } + + public static void trigger(int id){ + + } + + public static void tridentEvent(int id){ + if(id == Trident.EVENT_SCREENSHOT){ + Trident.printConsole("Took a screenshot!"); + } + } + + public static int command(ArrayList cmdParts){ // cmdParts.get(0) is the command, while the rest are arguments for the command. + switch(cmdParts.get(0)){ + case "helloWorld": + Trident.printConsole("Hello, World!"); + return 0; + case "ping": + Trident.printConsole("pong"); + return 0; + } + return 1; // return 1 if command is not recognized + } + public static String[] commands = { // Fill this with the format for all custom commands + "helloWorld", + "ping", + }; +} diff --git a/data/templates/blank3d/data/animations/intro.anim b/data/templates/blank3d/data/animations/intro.anim new file mode 100644 index 0000000..e93c287 --- /dev/null +++ b/data/templates/blank3d/data/animations/intro.anim @@ -0,0 +1,17 @@ +intro +false +1.0 +0.0 +0.0 +0.0 +1000 +0.0 +0.0 +0.0 +0.0 +3000 +0.0 +0.0 +1.0 +0.0 +1000 diff --git a/data/templates/blank3d/data/icon.png b/data/templates/blank3d/data/icon.png new file mode 100644 index 0000000..75679b4 Binary files /dev/null and b/data/templates/blank3d/data/icon.png differ diff --git a/data/templates/blank3d/data/images/npc/puter.png b/data/templates/blank3d/data/images/npc/puter.png new file mode 100644 index 0000000..6965266 Binary files /dev/null and b/data/templates/blank3d/data/images/npc/puter.png differ diff --git a/data/templates/blank3d/data/images/npc/station.png b/data/templates/blank3d/data/images/npc/station.png new file mode 100644 index 0000000..20091d3 Binary files /dev/null and b/data/templates/blank3d/data/images/npc/station.png differ diff --git a/data/templates/blank3d/data/images/player/idleE.png b/data/templates/blank3d/data/images/player/idleE.png new file mode 100644 index 0000000..fc1896b Binary files /dev/null and b/data/templates/blank3d/data/images/player/idleE.png differ diff --git a/data/templates/blank3d/data/images/player/idleN.png b/data/templates/blank3d/data/images/player/idleN.png new file mode 100644 index 0000000..e86f6cc Binary files /dev/null and b/data/templates/blank3d/data/images/player/idleN.png differ diff --git a/data/templates/blank3d/data/images/player/idleS.png b/data/templates/blank3d/data/images/player/idleS.png new file mode 100644 index 0000000..cb923cc Binary files /dev/null and b/data/templates/blank3d/data/images/player/idleS.png differ diff --git a/data/templates/blank3d/data/images/player/idleW.png b/data/templates/blank3d/data/images/player/idleW.png new file mode 100644 index 0000000..e706b7d Binary files /dev/null and b/data/templates/blank3d/data/images/player/idleW.png differ diff --git a/data/templates/blank3d/data/images/player/walkE.png b/data/templates/blank3d/data/images/player/walkE.png new file mode 100644 index 0000000..b9e2df3 Binary files /dev/null and b/data/templates/blank3d/data/images/player/walkE.png differ diff --git a/data/templates/blank3d/data/images/player/walkN.png b/data/templates/blank3d/data/images/player/walkN.png new file mode 100644 index 0000000..63aef9b Binary files /dev/null and b/data/templates/blank3d/data/images/player/walkN.png differ diff --git a/data/templates/blank3d/data/images/player/walkS.png b/data/templates/blank3d/data/images/player/walkS.png new file mode 100644 index 0000000..ff3366a Binary files /dev/null and b/data/templates/blank3d/data/images/player/walkS.png differ diff --git a/data/templates/blank3d/data/images/player/walkW.png b/data/templates/blank3d/data/images/player/walkW.png new file mode 100644 index 0000000..3ab625d Binary files /dev/null and b/data/templates/blank3d/data/images/player/walkW.png differ diff --git a/data/templates/blank3d/data/images/prop/puter.png b/data/templates/blank3d/data/images/prop/puter.png new file mode 100644 index 0000000..6965266 Binary files /dev/null and b/data/templates/blank3d/data/images/prop/puter.png differ diff --git a/data/templates/blank3d/data/images/textures/dirtymetal.jpg b/data/templates/blank3d/data/images/textures/dirtymetal.jpg new file mode 100644 index 0000000..70bd4fc Binary files /dev/null and b/data/templates/blank3d/data/images/textures/dirtymetal.jpg differ diff --git a/data/templates/blank3d/data/images/textures/door.jpg b/data/templates/blank3d/data/images/textures/door.jpg new file mode 100644 index 0000000..5da16e1 Binary files /dev/null and b/data/templates/blank3d/data/images/textures/door.jpg differ diff --git a/data/templates/blank3d/data/images/textures/panel.jpg b/data/templates/blank3d/data/images/textures/panel.jpg new file mode 100644 index 0000000..906c1df Binary files /dev/null and b/data/templates/blank3d/data/images/textures/panel.jpg differ diff --git a/data/templates/blank3d/data/images/textures/warning.jpg b/data/templates/blank3d/data/images/textures/warning.jpg new file mode 100644 index 0000000..9a064e4 Binary files /dev/null and b/data/templates/blank3d/data/images/textures/warning.jpg differ diff --git a/data/templates/blank3d/data/images/trident/box.png b/data/templates/blank3d/data/images/trident/box.png new file mode 100644 index 0000000..2095f6a Binary files /dev/null and b/data/templates/blank3d/data/images/trident/box.png differ diff --git a/data/templates/blank3d/data/images/trident/boxColl.png b/data/templates/blank3d/data/images/trident/boxColl.png new file mode 100644 index 0000000..e63707b Binary files /dev/null and b/data/templates/blank3d/data/images/trident/boxColl.png differ diff --git a/data/templates/blank3d/data/images/trident/collision.png b/data/templates/blank3d/data/images/trident/collision.png new file mode 100644 index 0000000..77597a8 Binary files /dev/null and b/data/templates/blank3d/data/images/trident/collision.png differ diff --git a/data/templates/blank3d/data/images/trident/consolebg.png b/data/templates/blank3d/data/images/trident/consolebg.png new file mode 100644 index 0000000..fc0a33e Binary files /dev/null and b/data/templates/blank3d/data/images/trident/consolebg.png differ diff --git a/data/templates/blank3d/data/images/trident/customEnt.png b/data/templates/blank3d/data/images/trident/customEnt.png new file mode 100644 index 0000000..bb10f72 Binary files /dev/null and b/data/templates/blank3d/data/images/trident/customEnt.png differ diff --git a/data/templates/blank3d/data/images/trident/light.png b/data/templates/blank3d/data/images/trident/light.png new file mode 100644 index 0000000..6f7887c Binary files /dev/null and b/data/templates/blank3d/data/images/trident/light.png differ diff --git a/data/templates/blank3d/data/images/trident/plrStart.png b/data/templates/blank3d/data/images/trident/plrStart.png new file mode 100644 index 0000000..58d0ff2 Binary files /dev/null and b/data/templates/blank3d/data/images/trident/plrStart.png differ diff --git a/data/templates/blank3d/data/images/trident/splash.png b/data/templates/blank3d/data/images/trident/splash.png new file mode 100644 index 0000000..0d40d89 Binary files /dev/null and b/data/templates/blank3d/data/images/trident/splash.png differ diff --git a/data/templates/blank3d/data/images/trident/trigger.png b/data/templates/blank3d/data/images/trident/trigger.png new file mode 100644 index 0000000..fcb46cd Binary files /dev/null and b/data/templates/blank3d/data/images/trident/trigger.png differ diff --git a/data/templates/blank3d/data/resources.bson b/data/templates/blank3d/data/resources.bson new file mode 100644 index 0000000..a759422 --- /dev/null +++ b/data/templates/blank3d/data/resources.bson @@ -0,0 +1,13 @@ +{ wallTextures +string dirtymetal.jpg +string panel.jpg +string warning.jpg +string door.jpg +} +{ npcTextures +string station.png +string puter.png +} +{ propTextures +string puter.png +} \ No newline at end of file diff --git a/data/templates/blank3d/data/scenes/default.bson b/data/templates/blank3d/data/scenes/default.bson new file mode 100644 index 0000000..69aed40 --- /dev/null +++ b/data/templates/blank3d/data/scenes/default.bson @@ -0,0 +1,57 @@ +string name default +string dir south +int light 255 +{ bgColor +int 255 +int 255 +int 255 +} +{ entities +string plrstart +double -300.0 +double 0.0 +boolean false +string boxcoll +double -268.0 +double -128.0 +boolean true +int 426 +int 59 +int 0 +int 0 +int 255 +string boxcoll +double -240.5 +double 152.0 +boolean true +int 86 +int 53 +int 0 +int 255 +int 0 +string boxcoll +double -381.5 +double 90.0 +boolean true +int 46 +int 101 +int 255 +int 0 +int 0 +string rend3d +double -171.0 +double 2.0 +boolean false +string hud +double -169.0 +double 49.0 +boolean false +string texWall +double -584.0 +double 138.0 +boolean true +int 91 +int 245 +int 0 +int 100 +} diff --git a/data/templates/blank3d/src/custom/Dialog.java b/data/templates/blank3d/src/custom/Dialog.java new file mode 100644 index 0000000..4661ae0 --- /dev/null +++ b/data/templates/blank3d/src/custom/Dialog.java @@ -0,0 +1,37 @@ +package custom; + +import java.awt.Font; + +import javax.swing.*; +import blib.util.*; +public class Dialog { + + public String text, name; + long scrollTime = 25; + Font customFont = new Font("Porky's", Font.PLAIN, 25); + + public Dialog(String txt, String name){ + text = txt; + this.name = name; + } + public Dialog(String txt, String name, long t){ + text = txt; + this.name = name; + scrollTime = t; + } + public Dialog(String txt, String name, Font f){ + text = txt; + this.name = name; + customFont = f; + } + public Dialog(String txt, String name, long t, Font f){ + text = txt; + this.name = name; + scrollTime = t; + customFont = f; + } + + public String getText(){ + return text; + } +} diff --git a/data/templates/blank3d/src/custom/DialogString.java b/data/templates/blank3d/src/custom/DialogString.java new file mode 100644 index 0000000..b8e6652 --- /dev/null +++ b/data/templates/blank3d/src/custom/DialogString.java @@ -0,0 +1,111 @@ +package custom; + +import java.awt.Font; +import java.util.ArrayList; +import blib.util.*; +import javax.swing.*; +public class DialogString { + + public static DialogString[] dialogStrings = { + new DialogString(new Dialog[]{ // 0 + new Dialog("Hello World!", "Test"), + new Dialog("I am a wall", "Wall"), + new Dialog("HELP I'M TRAPPED IN THIS WALL I CAN'T BREATHE AAAAAAAAAAAAAAAAAAAAAAAAA", "Oland"), + }), + new DialogString(new Dialog[]{ // 1 + new Dialog("Yoooo no way its me I'm in the game", "Blocky"), + new Dialog("I feel a little s t r e t c h e d though", "Blocky"), + new Dialog("idk it's prolly fine", "Blocky"), + new Dialog("also why is transparency so hard :<", "Blocky"), + }), + new DialogString(new Dialog[]{ // 2 + new Dialog("Hello I'm OLand", "OLand"), + new Dialog("I took forever to get to render properly because Blocky kept running into infinite loops", "OLand"), + }), + new DialogString(new Dialog[]{ // 3 + new Dialog("Hai hai cafegoer!", "Blocky"), + new Dialog("Yo what's good", "Oland"), + new Dialog("Welcome to chat-1", "Blocky"), + new Dialog("Don't let the crowd scare you off, I promise it's chill once you get used to it!", "Blocky"), + }), + }; + + public ArrayList dialogs = new ArrayList(); + private int currentDialog = 0; + private int dialogPos = 0; + private long dialogTime = 0; + + public DialogString(Dialog[] dia){ + for(Dialog d: dia){ + dialogs.add(d); + } + } + public static DialogString get(int i){ + return dialogStrings[i]; + } + + public void addDialog(Dialog d){ + dialogs.add(d); + } + + public void update(long elapsedTime){ + if(currentDialog >= dialogs.size()) return; + if(dialogPos >= dialogs.get(currentDialog).getText().length()){ + dialogPos = dialogs.get(currentDialog).getText().length(); + return; + } + dialogTime += elapsedTime; + while(dialogTime >= dialogs.get(currentDialog).scrollTime){ + dialogTime -= dialogs.get(currentDialog).scrollTime; + dialogPos++; + if(dialogPos >= dialogs.get(currentDialog).getText().length()){ + dialogPos = dialogs.get(currentDialog).getText().length(); + return; + } + } + } + + public void next(){ + if(dialogPos < dialogs.get(currentDialog).getText().length()){ + dialogPos = dialogs.get(currentDialog).getText().length(); + return; + } + dialogPos = 0; + dialogTime = 0; + currentDialog++; + } + + public String getText(){ + if(currentDialog >= dialogs.size()) return ""; + String text = dialogs.get(currentDialog).getText(); + String scrolledText = ""; + for(int i = 0; i < dialogPos; i++){ + scrolledText += text.charAt(i); + } + return scrolledText; + } + + public boolean scrollDone(){ + return dialogPos == dialogs.get(currentDialog).getText().length(); + } + + public String getName(){ + return dialogs.get(currentDialog).name; + } + + public Font getFont(){ + if(currentDialog >= dialogs.size()) return null; + return dialogs.get(currentDialog).customFont; + } + + public boolean moreText(){ + if(currentDialog >= dialogs.size()) return false; + return true; + } + + public void reset(){ + dialogPos = 0; + dialogTime = 0; + currentDialog = 0; + } +} diff --git a/data/templates/blank3d/src/custom/WallManager.java b/data/templates/blank3d/src/custom/WallManager.java new file mode 100644 index 0000000..f180150 --- /dev/null +++ b/data/templates/blank3d/src/custom/WallManager.java @@ -0,0 +1,10 @@ +package custom; + +import java.util.ArrayList; +import blib.b3d.*; +import blib.util.*; +public class WallManager { + + public static ArrayList walls = null; + public static Camera camera = new Camera(new Position(), 0); +} diff --git a/data/templates/blank3d/src/ent/ExampleEntity.java b/data/templates/blank3d/src/ent/ExampleEntity.java new file mode 100644 index 0000000..98fabb0 --- /dev/null +++ b/data/templates/blank3d/src/ent/ExampleEntity.java @@ -0,0 +1,36 @@ +package ent; + +import blib.util.*; +import trident.*; +import javax.swing.*; +import java.awt.*; +public class ExampleEntity extends TridEntity { + + // Constructor, runs when the entity is created + public ExampleEntity(Position pos){ + super(pos); + } + // Registry constructor, used only for adding to the registry + public ExampleEntity(){ + super("example", false, 0); + } + // Custom constructor, used by the engine when building a scene + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new ExampleEntity(pos); + } + + // Render while in game + public void render(Graphics g, JPanel panel, int x, int y){ + + } + + // Runs every tick while the game is running + public void update(long elapsedTime){ + + } + + // Runs at the beginning of the scene + public void sceneStart(String scene){ + + } +} diff --git a/data/templates/blank3d/src/ent/HUD.java b/data/templates/blank3d/src/ent/HUD.java new file mode 100644 index 0000000..a9f4295 --- /dev/null +++ b/data/templates/blank3d/src/ent/HUD.java @@ -0,0 +1,82 @@ +package ent; + +import blib.util.*; +import trident.*; +import javax.swing.*; +import java.awt.*; +import custom.*; +public class HUD extends TridEntity { + + public static DialogString currentDialog = null; + + // Constructor, runs when the entity is created + public HUD(Position pos){ + super(pos); + renderType = TOPPRIORITY; + } + // Registry constructor, used only for adding to the registry + public HUD(){ + super("hud", false, 0); + } + // Custom constructor, used by the engine when building a scene + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new HUD(pos); + } + + // Render while in game + public void render(Graphics g, JPanel panel, int x, int y){ + try{ + if(currentDialog != null && currentDialog.getText() != null){ + g.setColor(Color.black); + g.fillRect(0, Trident.getFrameHeight() - 150, Trident.getFrameWidth(), 150); + g.setColor(Color.white); + g.setFont(currentDialog.getFont()); + TextBox.draw(currentDialog.getText(), g, 10, Trident.getFrameHeight() - 150 + currentDialog.getFont().getSize() / 2, TextBox.LEFT, (int)(Trident.getFrameWidth() * 0.75)); + g.setFont(new Font("Arial", Font.BOLD, 20)); + int width = g.getFontMetrics().stringWidth(currentDialog.getName()); + g.setColor(Color.black); + g.fillRect(5, Trident.getFrameHeight() - 175, width + 10, 25); + g.setColor(Color.white); + TextBox.draw(currentDialog.getName(), g, 10, Trident.getFrameHeight() - 160); + + if(currentDialog.scrollDone()){ + TextBox.draw("V", g, Trident.getFrameWidth() - 5, Trident.getFrameHeight() - 15, TextBox.RIGHT); + } + }else{ + for(TridEntity e: Trident.getEntities()){ + if(e instanceof NPC){ + NPC npc = (NPC)e; + if(BTools.getDistance(Trident.getPlrPos(), npc.position) < 200){ + double dir = BTools.normalizeRadians(BTools.getAngle(Trident.getPlrPos(), npc.position)); + double dirDiff = Math.abs(dir - WallManager.camera.direction); + if(dirDiff < Math.toRadians(45)){ + g.setColor(Color.white); + g.setFont(new Font("Arial", Font.PLAIN, 25)); + TextBox.draw("Talk\n(E)", g, Trident.getFrameWidth() / 2, Trident.getFrameHeight() / 2 + 15, TextBox.CENTER); + break; + } + + } + } + } + } + }catch(Exception e){} + + } + + // Runs every tick while the game is running + public void update(long elapsedTime){ + position = new Position(Trident.getPlrPos().x, Trident.getPlrPos().y + 10); + if(currentDialog != null){ + currentDialog.update(elapsedTime); + if(!currentDialog.moreText()){ + currentDialog.reset(); + currentDialog = null; + } + } + } + + public static void setDialog(int dia){ + currentDialog = DialogString.get(dia); + } +} diff --git a/data/templates/blank3d/src/ent/NPC.java b/data/templates/blank3d/src/ent/NPC.java new file mode 100644 index 0000000..11afe8f --- /dev/null +++ b/data/templates/blank3d/src/ent/NPC.java @@ -0,0 +1,82 @@ +package ent; + +import blib.util.*; +import custom.WallManager; +import trident.*; +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; + +import blib.b3d.*; +import blib.bson.BSonList; +import blib.bson.BSonObject; +import blib.bson.BSonParser; +public class NPC extends TridEntity { + + private static ImageIcon[] imgs; + private static boolean loadedTextures = false; + + Wall wall; + public int dialog; + + boolean addedWalls = false; + + // Constructor, runs when the entity is created + public NPC(Position pos, int dia, int tex){ + super(pos, new Dimension(64, 64)); + if(!loadedTextures) loadTextures(); + wall = new Wall(new Position(-16, 0), new Position(16, 0), Color.magenta, true, imgs[tex], 64, true); + dialog = dia; + } + // Registry constructor, used only for adding to the registry + public NPC(){ + super("npc", false, 2); + } + // Custom constructor, used by the engine when building a scene + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new NPC(pos, data[0], data[1]); + } + + // Runs every tick while the game is running + public void update(long elapsedTime){ + if(!addedWalls){ + if(WallManager.walls != null){ + WallManager.walls.add(wall); + addedWalls = true; + } + } + + double dir = BTools.getAngle(position, Trident.getPlrPos()); + double startDir = dir + Math.PI / 2; + double endDir = dir - Math.PI / 2; + + Position start = BTools.angleToVector(startDir); + start.x *= 32; + start.y *= 32; + start.x += position.x; + start.y += position.y; + Position end = BTools.angleToVector(endDir); + end.x *= 32; + end.y *= 32; + end.x += position.x; + end.y += position.y; + + wall.start = start; + wall.end = end; + } + + private static void loadTextures(){ + ArrayList objects = BSonParser.readFile("data/resources.bson"); + BSonObject obj = BSonParser.getObject("npcTextures", objects); + BSonList asList = (BSonList)obj; + imgs = new ImageIcon[asList.list.size()]; + for(int i = 0; i < asList.list.size(); i++){ + imgs[i] = new ImageIcon("data/images/npc/" + asList.list.get(i).getString()); + } + loadedTextures = true; + } + + public void sceneStart(String scene){ + addedWalls = false; + } +} diff --git a/data/templates/blank3d/src/ent/Prop.java b/data/templates/blank3d/src/ent/Prop.java new file mode 100644 index 0000000..b06a8d3 --- /dev/null +++ b/data/templates/blank3d/src/ent/Prop.java @@ -0,0 +1,80 @@ +package ent; + +import blib.util.*; +import custom.WallManager; +import trident.*; +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; + +import blib.b3d.*; +import blib.bson.BSonList; +import blib.bson.BSonObject; +import blib.bson.BSonParser; +public class Prop extends TridEntity { + + private static ImageIcon[] imgs; + private static boolean loadedTextures = false; + + Wall wall; + + boolean addedWalls = false; + + // Constructor, runs when the entity is created + public Prop(Position pos, int tex){ + super(pos, new Dimension(64, 64)); + if(!loadedTextures) loadTextures(); + wall = new Wall(new Position(-16, 0), new Position(16, 0), Color.magenta, true, imgs[tex], 64, true); + } + // Registry constructor, used only for adding to the registry + public Prop(){ + super("prop", false, 1); + } + // Custom constructor, used by the engine when building a scene + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new Prop(pos, data[0]); + } + + // Runs every tick while the game is running + public void update(long elapsedTime){ + if(!addedWalls){ + if(WallManager.walls != null){ + WallManager.walls.add(wall); + addedWalls = true; + } + } + + double dir = BTools.getAngle(position, Trident.getPlrPos()); + double startDir = dir + Math.PI / 2; + double endDir = dir - Math.PI / 2; + + Position start = BTools.angleToVector(startDir); + start.x *= 32; + start.y *= 32; + start.x += position.x; + start.y += position.y; + Position end = BTools.angleToVector(endDir); + end.x *= 32; + end.y *= 32; + end.x += position.x; + end.y += position.y; + + wall.start = start; + wall.end = end; + } + + private static void loadTextures(){ + ArrayList objects = BSonParser.readFile("data/resources.bson"); + BSonObject obj = BSonParser.getObject("propTextures", objects); + BSonList asList = (BSonList)obj; + imgs = new ImageIcon[asList.list.size()]; + for(int i = 0; i < asList.list.size(); i++){ + imgs[i] = new ImageIcon("data/images/prop/" + asList.list.get(i).getString()); + } + loadedTextures = true; + } + + public void sceneStart(String scene){ + addedWalls = false; + } +} diff --git a/data/templates/blank3d/src/ent/Rend3D.java b/data/templates/blank3d/src/ent/Rend3D.java new file mode 100644 index 0000000..f8c6ec2 --- /dev/null +++ b/data/templates/blank3d/src/ent/Rend3D.java @@ -0,0 +1,53 @@ +package ent; + +import blib.util.*; +import trident.*; +import javax.swing.*; +import java.awt.*; +import custom.*; +public class Rend3D extends TridEntity { + + public static int offset = 0; + public static double totalMovement = 0; + public static boolean enabled = true; + + // Constructor, runs when the entity is created + public Rend3D(Position pos){ + super(pos); + renderType = TOPPRIORITY; + alwaysRender = true; + } + // Registry constructor, used only for adding to the registry + public Rend3D(){ + super("rend3d", false, 0); + } + // Custom constructor, used by the engine when building a scene + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new Rend3D(pos); + } + + // Render while in game + public void render(Graphics g, JPanel panel, int x, int y){ + WallManager.camera.render(panel, g, WallManager.walls, offset); + if(Trident.drawCollision){ + Line leftSide = Line.ray(new Position(x, y), WallManager.camera.direction - WallManager.camera.fov / 2, WallManager.camera.rendDist); + Line rightSide = Line.ray(new Position(x, y), WallManager.camera.direction + WallManager.camera.fov / 2, WallManager.camera.rendDist); + + g.setColor(Color.blue); + g.drawLine((int)leftSide.start.x, (int)leftSide.start.y, (int)leftSide.end.x, (int)leftSide.end.y); + g.setColor(Color.cyan); + g.drawLine((int)rightSide.start.x, (int)rightSide.start.y, (int)rightSide.end.x, (int)rightSide.end.y); + } + } + + // Runs every tick while the game is running + public void update(long elapsedTime){ + WallManager.camera.position = Trident.getPlrPos(); + position = Trident.getPlrPos(); + } + + // Runs at the beginning of the scene + public void sceneStart(String scene){ + enabled = true; + } +} diff --git a/data/templates/blank3d/src/ent/TexWall.java b/data/templates/blank3d/src/ent/TexWall.java new file mode 100644 index 0000000..0751f28 --- /dev/null +++ b/data/templates/blank3d/src/ent/TexWall.java @@ -0,0 +1,42 @@ +package ent; + +import blib.util.*; +import trident.*; +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; +import blib.bson.*; +public class TexWall extends TridEntity { + + private static ImageIcon[] textures; + public ImageIcon texture; + public int texLen; + private static boolean loadedTextures = false; + + // Constructor, runs when the entity is created + public TexWall(Position pos, Dimension coll, int tex, int length){ + super(pos, coll); + if(!loadedTextures) loadTextures(); + texture = textures[tex]; + texLen = length; + } + // Registry constructor, used only for adding to the registry + public TexWall(){ + super("texWall", true, 2); + } + // Custom constructor, used by the engine when building a scene + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new TexWall(pos, collision, data[0], data[1]); + } + + public static void loadTextures(){ + ArrayList objects = BSonParser.readFile("data/resources.bson"); + BSonObject obj = BSonParser.getObject("wallTextures", objects); + BSonList asList = (BSonList)obj; + textures = new ImageIcon[asList.list.size()]; + for(int i = 0; i < asList.list.size(); i++){ + textures[i] = new ImageIcon("data/images/textures/" + asList.list.get(i).getString()); + } + loadedTextures = true; + } +} diff --git a/data/templates/blank3d/src/ent/TexWallT.java b/data/templates/blank3d/src/ent/TexWallT.java new file mode 100644 index 0000000..61dce57 --- /dev/null +++ b/data/templates/blank3d/src/ent/TexWallT.java @@ -0,0 +1,42 @@ +package ent; + +import blib.util.*; +import trident.*; +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; +import blib.bson.*; +public class TexWallT extends TridEntity { + + private static ImageIcon[] textures; + public ImageIcon texture; + public int texLen; + private static boolean loadedTextures = false; + + // Constructor, runs when the entity is created + public TexWallT(Position pos, Dimension coll, int tex, int length){ + super(pos, coll); + if(!loadedTextures) loadTextures(); + texture = textures[tex]; + texLen = length; + } + // Registry constructor, used only for adding to the registry + public TexWallT(){ + super("texWallT", true, 2); + } + // Custom constructor, used by the engine when building a scene + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new TexWallT(pos, collision, data[0], data[1]); + } + + public static void loadTextures(){ + ArrayList objects = BSonParser.readFile("data/resources.bson"); + BSonObject obj = BSonParser.getObject("wallTextures", objects); + BSonList asList = (BSonList)obj; + textures = new ImageIcon[asList.list.size()]; + for(int i = 0; i < asList.list.size(); i++){ + textures[i] = new ImageIcon("data/images/textures/" + asList.list.get(i).getString()); + } + loadedTextures = true; + } +} diff --git a/data/templates/blank3d/src/trident/Main.java b/data/templates/blank3d/src/trident/Main.java new file mode 100644 index 0000000..59bfae9 --- /dev/null +++ b/data/templates/blank3d/src/trident/Main.java @@ -0,0 +1,18 @@ +package trident; + +import javax.swing.*; +import java.awt.*; +public class Main{ + protected static JFrame window = new JFrame("blank2d"); + public static void main(String[] args){ + window.setSize(700, 500); + window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + window.setMinimumSize(new Dimension(700, 500)); + window.setIconImage(new ImageIcon("data/icon.png").getImage()); + // panel + MainPanel panel = new MainPanel(); + window.add(panel); + // + window.setVisible(true); + } +} diff --git a/data/templates/blank3d/src/trident/MainPanel.java b/data/templates/blank3d/src/trident/MainPanel.java new file mode 100644 index 0000000..20afddf --- /dev/null +++ b/data/templates/blank3d/src/trident/MainPanel.java @@ -0,0 +1,226 @@ +package trident; + +import javax.swing.*; +import java.awt.*; +import blib.game.*; +import blib.util.*; +import java.awt.event.*; +import blib.input.*; +import java.util.ArrayList; +import blib.anim.*; +import trident.ent.*; +import update.*; +public class MainPanel extends JPanel { + + protected FrameManager frameManager = new FrameManager(); + public static Server server; + protected KeyManager km = new InputListener(this); + private Animator introAnim; + public static Position introPos = new Position(); + public static ImageIcon splash = new ImageIcon("data/images/trident/splash.png"); + public static boolean inIntro = false; + private RenderingThread rendThread = new RenderingThread(); + + public MainPanel(){ + + System.setProperty("sun.java2d.opengl", "true"); // hardware acceleration? + + setBackground(Color.black); + + Trident.player = new Player(new Position(), km, 0.1, this, "data/images/player", 16, 16); + Trident.player.camera.setDimension = new Dimension(frameManager.WIDTH, frameManager.HEIGHT); + Trident.player.resizeImages(32, 32); + Trident.currentScene = new Scene("Test Scene"); + Trident.camShake = new CamShake(Trident.player.camera); + Trident.lightManager.blur.setRadius(100); + + Trident.addCustomEntity(new BoxColl()); + Trident.addCustomEntity(new BoxNoColl()); + Trident.addCustomEntity(new InvisColl()); + Trident.addCustomEntity(new PlrStart()); + Trident.addCustomEntity(new Trigger()); + Trident.addCustomEntity(new TridLight()); + + setFocusTraversalKeysEnabled(false); + + Update.setup(); + + Trident.setupScenes(); + + Trident.loadScene(Trident.defaultScene); + + for(String s: Update.fonts){ + BTools.addFont(s, this); + } + + try{ + ArrayList anims = new ArrayList(); + anims.add(new Animation("data/animations/intro")); + + introAnim = new Animator(introPos, anims); + }catch(Exception e){ + Trident.intro = false; + } + if(Trident.intro){ + introAnim.play("intro"); + inIntro = true; + } + if(Trident.splash != null && BTools.hasImage(Trident.splash)){ + BTools.resizeImgIcon(Trident.splash, 160, 160); + } + + Trident.consoleError = false; + rendThread.start(); + + server = new Server(new ServerListener(), this); + } + + public void paintComponent(Graphics graphics){ + super.paintComponent(graphics); + Graphics g = frameManager.newFrame(); + + frameManager.bgColor = Trident.currentScene.bgColor; + + if(rendThread.lastFrame != null){ + g.drawImage(rendThread.lastFrame, 0, 0, null); + } + + frameManager.renderFrame(this, graphics); + } + + public MainPanel panel = this; + private class InputListener extends InputAdapter { + public InputListener(JPanel panel){ + super(panel); + } + + public void onKeyPressed(int key){ + if(key == KeyEvent.VK_F12){ + frameManager.saveScreenshot("data/screenshots"); + Update.tridentEvent(Trident.EVENT_SCREENSHOT); + } + if(key == KeyEvent.VK_F11){ + Trident.fullscreen = !Trident.fullscreen; + Main.window = BTools.getWindowFullscreen(Main.window, Trident.fullscreen, panel); + return; + } + if(!inIntro){ + if(key == 192 && Trident.consoleEnabled){ + Trident.consoleOpen = !Trident.consoleOpen; + Trident.consoleType = ""; + Trident.consoleError = false; + } + if(Trident.consoleOpen){ + if(key >= KeyEvent.VK_A && key <= KeyEvent.VK_Z){ + char c = KeyEvent.getKeyText(key).charAt(0); + if(!km.getKeyDown(KeyEvent.VK_SHIFT)){ + c = Character.toLowerCase(c); + } + Trident.consoleType += c; + } + if(key >= KeyEvent.VK_0 && key <= KeyEvent.VK_9){ + char c = KeyEvent.getKeyText(key).charAt(0); + Trident.consoleType += c; + } + if(key == KeyEvent.VK_SPACE){ + Trident.consoleType += " "; + } + if(key == KeyEvent.VK_MINUS){ + Trident.consoleType += "-"; + } + if(key == KeyEvent.VK_PERIOD){ + Trident.consoleType += "."; + } + if(key == KeyEvent.VK_BACK_SPACE){ + if(Trident.consoleType.length() > 0) Trident.consoleType = Trident.consoleType.substring(0, Trident.consoleType.length() - 1); + } + if(key == KeyEvent.VK_UP){ + Trident.consoleType = Trident.lastCommand; + } + + if(key == KeyEvent.VK_ENTER){ + Trident.runCommand(Trident.consoleType); + Trident.consoleType = ""; + } + return; + } + Inputs.keyPressed(key); + } + } + + public void onMousePressed(int mb, Point mousePos){ + mousePos = frameManager.getMousePos(panel, mousePos); + Position worldPos = Trident.player.camera.mouseToPos(mousePos); + if(!inIntro) Inputs.mousePressed(mb, mousePos, worldPos); + } + + public void onScroll(int scroll){ + if(!inIntro) Inputs.onScroll(scroll); + } + } + + private class ServerListener implements ActionListener { + public void actionPerformed(ActionEvent event){ + if(inIntro){ + introAnim.update(server.getElapsedTime()); + if(!introAnim.isPlaying()){ + inIntro = false; + } + repaint(); + return; + } + + if(!hasFocus()) km.reset(); + + if(!Trident.consoleOpen){ + Trident.mousePos = frameManager.getMousePos(panel, km.getMousePos()); + Trident.mouseDelta = km.getMouseDelta(); + Trident.mouseWorldPos = Trident.player.camera.mouseToPos(Trident.mousePos); + + Trident.camShake.update(server.getElapsedTime()); + + if(!Trident.noclip) Trident.player.updateWithCollision(server.getElapsedTime(), Trident.currentScene.getCollision()); + else Trident.player.update(server.getElapsedTime()); + + for(int i = 0; i < Trident.getEntities().size(); i++){ + TridEntity e = Trident.getEntities().get(i); + e.update(server.getElapsedTime()); + if(e instanceof Trigger){ + Trigger trig = (Trigger)e; + if(trig.containsPos(Trident.player.getPos())){ + Update.trigger(trig.id); + } + } + } + + if(Trident.reset){ + km.reset(); + Trident.reset = false; + } + for(int i = 0; i < 255; i++){ + Trident.keys[i] = km.getKeyDown(i); + } + Trident.m1 = km.getMouseDown(1); + Trident.m2 = km.getMouseDown(2); + Trident.m3 = km.getMouseDown(3); + Trident.m4 = km.getMouseDown(4); + Trident.m5 = km.getMouseDown(5); + + if(Trident.newSprite != null){ + Trident.player = new Player(Trident.player.getPos(), km, 0.2, panel, Trident.newSprite, 16, 16); + Trident.newSprite = null; + Trident.player.resizeImages(32, 32); + Trident.player.camera.setDimension = new Dimension(frameManager.WIDTH, frameManager.HEIGHT); + Trident.camShake = new CamShake(Trident.player.camera); + Trident.player.shortCollision = true; + } + + Update.update(server.getElapsedTime()); + } + + + + try {Trident.getEntities().sort((o1, o2) -> o2.compareSort(o1));} catch(Exception e){} + } + } +} diff --git a/data/templates/blank3d/src/trident/RenderingThread.java b/data/templates/blank3d/src/trident/RenderingThread.java new file mode 100644 index 0000000..b1dbaa3 --- /dev/null +++ b/data/templates/blank3d/src/trident/RenderingThread.java @@ -0,0 +1,152 @@ +package trident; + +import java.awt.image.*; +import java.util.ArrayList; +import java.util.ConcurrentModificationException; +import blib.util.*; +import java.awt.*; +import blib.game.*; +import javax.swing.*; +import ent.*; +public class RenderingThread extends Thread { + + public BufferedImage lastFrame = null; + private long elapsedTime, previousStartTime = -1; + + private ImageIcon consoleBg = new ImageIcon("data/images/trident/consolebg.png"); + private long errorFlashTime = 0; + + public RenderingThread(){ + BTools.resizeImgIcon(consoleBg, Trident.getFrameWidth(), 483); + } + + public void run(){ + while(true){ + try{ + + long now = System.currentTimeMillis(); + elapsedTime = previousStartTime != -1 ? now - previousStartTime : 0; + previousStartTime = now; + int WIDTH = Trident.getFrameWidth(), HEIGHT = Trident.getFrameHeight(); + int offX, offY; + offX = Trident.camShake.offX; + offY = Trident.camShake.offY; + BufferedImage newFrame = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB); + Graphics g = newFrame.getGraphics(); + + if(Trident.engineDraw){ + for(TridEntity e: Trident.currentScene.entities){ + Point p = Trident.player.camera.worldToScreen(e.position); + e.engineRender(g, null, p.x, p.y); + } + } + + ArrayList> splitEnt = Trident.player.camera.splitEntities(Trident.tridArrToEntArr(Trident.currentScene.entities), 16); + if(!Rend3D.enabled){ + if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(2), offX, offY); + if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(0), offX, offY); + if(Trident.drawPlayer){ + Trident.player.render(null, g, WIDTH / 2 - offX, HEIGHT / 2 - offY); + } + if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(1), offX, offY); + + Trident.lightManager.render(Trident.player.camera, Trident.lights, g, offX, offY); + } + + + if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(3), offX, offY); + + + + + if(Trident.drawCollision){ + g.setColor(Color.red); + ArrayList collision = Trident.currentScene.getCollision(); + collision.add(Trident.player.getCollision()); + for(Rectangle r: collision){ + Point p = Trident.player.camera.worldToScreen(new Position(r.x, r.y)); + g.drawRect(p.x, p.y, r.width, r.height); + g.drawLine(p.x, p.y, p.x + r.width, p.y + r.height); + } + } + + if(Trident.drawPos){ + g.setColor(Trident.debugColor); + g.setFont(new Font("Arial", Font.ITALIC, 10)); + TextBox.draw(Trident.player.getPos().toStringSimple(), g, 10, 20); + } + if(Trident.drawFrames){ + g.setColor(Trident.debugColor); + g.setFont(new Font("Arial", Font.ITALIC, 10)); + TextBox.draw("TPS: " + (1000 / Math.max(MainPanel.server.getElapsedTime(), 1)) + " (" + MainPanel.server.getElapsedTime() + " ms)", g, 10, 30); + TextBox.draw("FPS: " + (1000 / Math.max(elapsedTime, 1)) + " (" + elapsedTime + " ms)", g, 10, 40); + } + + // Apply Post Processing + if(Trident.enableExposure){ + Trident.exposure.filter(newFrame, newFrame); + } + if(Trident.enableBloom){ + Trident.bloom.filter(newFrame, newFrame); + } + + if(MainPanel.inIntro){ + g.setColor(Color.black); + g.fillRect(0, 0, 700, 500); + + if(Trident.splash != null && BTools.hasImage(Trident.splash)){ + // Trident splash + custom splash + MainPanel.splash.paintIcon(null, g, WIDTH / 2 - 80, 40); + Trident.splash.paintIcon(null, g, WIDTH / 2 - 80, HEIGHT - 200); + }else{ + // Trident splash only + MainPanel.splash.paintIcon(null, g, WIDTH / 2 - 80, HEIGHT / 2 - 80); + } + + float alpha = (float)MainPanel.introPos.x; + g.setColor(new Color(0f, 0f, 0f, alpha)); + g.fillRect(0, 0, 700, 500); + } + + if(Trident.consoleOpen){ + // bg + consoleBg.paintIcon(null, g, 0, -252); + g.setColor(new Color(0f, 0f, 0f, 0.7f)); + g.fillRect(0, 0, Trident.getFrameWidth(), Trident.getFrameHeight() / 2); + + // text + g.setColor(Color.white); + g.setFont(new Font("Arial", Font.PLAIN, 10)); + for(int i = 0; i < Trident.consoleLines.size(); i++){ + int index = BTools.flip(i, Trident.consoleLines.size() - 1); + TextBox.draw(Trident.consoleLines.get(index), g, 5, Trident.getFrameHeight() / 2 - 25 - (i * 10)); + } + + // borders + g.setColor(new Color(32, 12, 121)); + g.drawRect(0, 0, Trident.getFrameWidth() - 1, Trident.getFrameHeight() / 2); + g.drawLine(0, Trident.getFrameHeight() / 2 - 10, Trident.getFrameWidth(), Trident.getFrameHeight() / 2 - 10); + + // text entry box + g.setColor(Color.white); + g.setFont(new Font("Arial", Font.PLAIN, 10)); + TextBox.draw("> " + Trident.consoleType + "_", g, 3, Trident.getFrameHeight() / 2 - 5); + } + if(Trident.consoleError){ + errorFlashTime += elapsedTime; + g.setColor(new Color(1f, (float)(Math.min(1, Math.sin(errorFlashTime / 500.0) / 2 + 0.5)), (float)(Math.min(1, Math.sin(errorFlashTime / 500.0) / 2 + 0.5)))); + g.setFont(new Font("Arial", Font.BOLD, 20)); + TextBox.draw("ERROR\nOpen console with [~](tilde)", g, Trident.getFrameWidth() / 2, 10, TextBox.CENTER); + } + + lastFrame = newFrame; + }catch(Exception e){ + if(!(e instanceof ConcurrentModificationException)){ + e.printStackTrace(); + } + } + + + } + } +} diff --git a/data/templates/blank3d/src/trident/Scene.java b/data/templates/blank3d/src/trident/Scene.java new file mode 100644 index 0000000..fb4fb5c --- /dev/null +++ b/data/templates/blank3d/src/trident/Scene.java @@ -0,0 +1,104 @@ +package trident; + +import java.util.ArrayList; +import java.awt.*; +import java.io.*; +import blib.bson.*; +import blib.util.*; +import trident.ent.*; +import blib.game.*; +public class Scene { + + public final String name; + public ArrayList entities; + protected Position plrStart = new Position(); + public int plrDir = Player.SOUTH; + protected Color bgColor = Color.white; + protected int defaultLight = 255; + + public Scene(String n){ // Empty scene + name = n; + entities = new ArrayList(); + } + public Scene(File f) throws IOException{ + entities = new ArrayList(); + ArrayList objects = BSonParser.readFile(f.getAbsolutePath()); + BSonObject obj = BSonParser.getObject("name", objects); + name = obj.getString(); + obj = BSonParser.getObject("dir", objects); + if(obj != null){ + String str = obj.getString(); + if(str.equals("west")) plrDir = Player.WEST; + if(str.equals("north")) plrDir = Player.NORTH; + if(str.equals("east")) plrDir = Player.EAST; + } + obj = BSonParser.getObject("bgColor", objects); + BSonList asList = (BSonList)obj; + int r, g, b; + r = asList.list.get(0).getInt(); + g = asList.list.get(1).getInt(); + b = asList.list.get(2).getInt(); + bgColor = new Color(r, g, b); + obj = BSonParser.getObject("light", objects); + defaultLight = obj.getInt(); + obj = BSonParser.getObject("entities", objects); + asList = (BSonList)obj; + for(int i = 0; i < asList.list.size(); i++){ + String objName = asList.list.get(i).getString(); + i++; + boolean foundEnt = false; + for(TridEntity e: Trident.entRegistry){ + if(e.name.equals(objName)){ + double x, y; + x = asList.list.get(i).getDouble(); + i++; + y = asList.list.get(i).getDouble(); + i++; + int w = 0, h = 0; + i++; + if(e.HASCOLLISION){ + w = asList.list.get(i).getInt(); + i++; + h = asList.list.get(i).getInt(); + i++; + } + int[] data = new int[e.numData]; + for(int j = 0; j < e.numData; j++){ + data[j] = asList.list.get(i).getInt(); + i++; + } + i--; + entities.add(e.construct(new Position(x, y), (e.HASCOLLISION ? (new Dimension(w, h)) : null), data)); + foundEnt = true; + break; + } + } + if(!foundEnt) Trident.printConsole("ERROR: no entity type '" + objName + "' found"); + } + + // Check for plrstart + for(TridEntity e: entities){ + if(e instanceof PlrStart){ + plrStart = e.position.copy(); + break; + } + } + } + + public static Scene loadScene(String path){ // stub method ::: Load a scene from a file + return null; + } + + public ArrayList getCollision(){ + ArrayList collision = new ArrayList(); + for(int i = 0; i < entities.size(); i++){ + TridEntity e = entities.get(i); + if(e.HASCOLLISION){ + collision.add(e.getCollision()); + } + } + + return collision; + } + +} diff --git a/data/templates/blank3d/src/trident/TridEntity.java b/data/templates/blank3d/src/trident/TridEntity.java new file mode 100644 index 0000000..9e172c4 --- /dev/null +++ b/data/templates/blank3d/src/trident/TridEntity.java @@ -0,0 +1,101 @@ +package trident; + +import blib.game.*; +import blib.util.*; + +import javax.swing.*; +import java.awt.*; +public class TridEntity extends Entity { + + public final boolean HASCOLLISION; + private final Dimension collision; + public String engineRenderData = ""; + private ImageIcon engineImg = new ImageIcon("data/images/trident/customEnt.png"); + protected String name; + protected int numData; + + public TridEntity(Position pos){ + super(pos); + HASCOLLISION = false; + collision = null; + } + public TridEntity(Position pos, Dimension collision){ + super(pos); + if(collision.equals(new Dimension(0, 0))) HASCOLLISION = false; + else HASCOLLISION = true; + this.collision = collision; + } + public TridEntity(String n, boolean hasColl, int numData){ + super(new Position()); + HASCOLLISION = hasColl; + collision = null; + name = n; + this.numData = numData; + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + System.out.println("Error: tried to create an empty entity"); + return null; + } + + public Rectangle getCollision(){ + return new Rectangle((int)position.x - (collision.width / 2), (int)position.y - (collision.height / 2), collision.width, collision.height); + } + + public void render(Graphics g, JPanel panel, int x, int y){ + + } + + protected void engineRender(Graphics g, JPanel panel, int x, int y){ + if(HASCOLLISION){ + g.setColor(Color.red); + g.drawRect(x - getCollision().width / 2, y - getCollision().height / 2, getCollision().width, getCollision().height); + g.drawLine(x - getCollision().width / 2, y - getCollision().height / 2, x + getCollision().width / 2, y + getCollision().height / 2); + } + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } + + public void update(long elapsedTime){ + + } + + public void sceneStart(String scene){ + + } + + public int getRendDatSort(){ + if(renderType == Entity.TALL){ + return 2; + } + if(renderType == Entity.UNDER){ + return 1; + } + if(renderType == Entity.ABOVE){ + return 3; + } + if(renderType == Entity.BOTTOMPRIORITY){ + return 0; + } + if(renderType == Entity.TOPPRIORITY){ + return 4; + } + return 2; + } + + public int compareSort(TridEntity e){ + if(e.getRendDatSort() > getRendDatSort()){ + // e should be above + return 1; + }else if(e.getRendDatSort() < getRendDatSort()){ + return -1; + } + + if(e.position.y > position.y){ + return 1; + }else if(e.position.y < position.y){ + return -1; + } + + return 0; + } + +} diff --git a/data/templates/blank3d/src/trident/Trident.java b/data/templates/blank3d/src/trident/Trident.java new file mode 100644 index 0000000..2096c6f --- /dev/null +++ b/data/templates/blank3d/src/trident/Trident.java @@ -0,0 +1,519 @@ +package trident; + +import blib.game.*; +import blib.util.*; +import ent.Rend3D; + +import java.awt.*; +import java.util.ArrayList; +import java.util.Scanner; + +import javax.swing.*; +import update.*; +import java.io.*; +import trident.ent.*; +import com.jhlabs.image.GlowFilter; +import com.jhlabs.image.ExposureFilter; +public class Trident { + + // Debug Settings + public static boolean drawPos = false; + public static boolean drawCollision = false; + public static boolean noclip = false; + public static boolean engineDraw = false; + public static Color debugColor = Color.red; + public static boolean intro = true; + public static ImageIcon splash = null; + public static boolean drawFrames = false; + public static boolean consoleEnabled = true; + public static boolean consoleOpen = false; + public static boolean consoleError = false; + public static String lastCommand = ""; + + // Public Variables + public static Point mousePos; + public static Point mouseDelta; + public static boolean drawPlayer = true; + public static Position mouseWorldPos = new Position(); + public static boolean enableBloom = true, enableExposure = true; + + + // Trident Variables + protected static Player player; + protected static Scene currentScene; + protected static boolean fullscreen = false; + protected static ArrayList loadedScenes = new ArrayList(); + protected static ArrayList entRegistry = new ArrayList(); + protected static String defaultScene = "default"; + protected static boolean m1 = false, m2 = false, m3 = false, m4 = false, m5 = false; + protected static boolean[] keys = new boolean[255]; + protected static CamShake camShake; + protected static ArrayList lights = new ArrayList(); + protected static LightManager lightManager = new LightManager(255); + protected static GlowFilter bloom = new GlowFilter(); + protected static ExposureFilter exposure = new ExposureFilter(); + protected static boolean reset = false; + protected static String newSprite = null; + + // Trident events + public static final int EVENT_SCREENSHOT = 0; + + + // Setting methods + public static void setPlrSpeed(double speed){ + player.speed = speed; + } + public static void setPlrPos(Position pos){ + player.goToPos(pos); + } + public static void setShortCollision(boolean b){ + player.shortCollision = b; + } + public static void setWindowTitle(String title){ + Main.window.setTitle(title); + } + public static void setupScenes(){ + try{ + loadedScenes = new ArrayList(); + File dir = new File("data/scenes"); + File[] files = dir.listFiles(); + ArrayList sceneFiles = new ArrayList(); + for(File f: files){ + if(BTools.hasExtension(f, "bson")) sceneFiles.add(f); + } + + for(File f: sceneFiles){ + loadedScenes.add(new Scene(f)); + } + }catch(Exception e){ + printException("Error setting up scenes", e); + } + + } + public static void loadScene(String name){ + Rend3D.enabled = false; + lights = new ArrayList(); + for(Scene s: loadedScenes){ + if(s.name.equals(name)){ + currentScene = s; + player.goToPos(s.plrStart); + player.setDirection(s.plrDir); + for(TridEntity e: s.entities){ + if(e instanceof TridLight){ + TridLight asLight = (TridLight)e; + lights.add(new Light(asLight.position, asLight.radius)); + } + e.sceneStart(s.name); + } + lightManager.defaultLight = s.defaultLight; + Update.sceneStart(name); + return; + } + } + printConsole("***********************************************************************************"); + printConsole("Error loading scene: No scene with name '" + name + "' found."); + printError("***********************************************************************************"); + } + public static void addCustomEntity(TridEntity e){ // Add a cutsom entity to the registry + entRegistry.add(e); + } + public static void spawnEntity(TridEntity e){ + currentScene.entities.add(e); + } + public static void setDefaultScene(String s){ + defaultScene = s; + } + public static void destroy(TridEntity object){ + getEntities().remove(object); + } + public static void shakeCam(double intensity){ + camShake.addTrauma(intensity); + } + public static void removeShake(){ + camShake.trauma = 0; + } + public static void setShakeStrength(int str){ + camShake.strength = str; + } + public static void setShakeLoss(double loss){ + camShake.traumaLoss = loss; + } + public static void setBloom(double amount){ + bloom.setAmount((float)amount); + } + public static void setExposure(double exp){ + exposure.setExposure((float)exp); + } + public static void setLightBlur(int level){ + lightManager.blur.setIterations(level); + } + public static void addLight(Light l){ + lights.add(l); + } + public static void resetKeys(){ + reset = true; + } + public static void setPlrSprite(String path){ + newSprite = path; + } + public static void removeLight(Light l){ + lights.remove(l); + } + public static void setDefaultLight(int level){ + lightManager.defaultLight = level; + } + public static void stopShake(){ + camShake.trauma = 0; + } + + // Getting methods + public static double getPlrSpeed(){ + return player.speed; + } + public static Position getPlrPos(){ + return player.getPos().copy(); + } + public static Scene getCurrentScene(){ + return currentScene; + } + public static boolean getFullscreen(){ + return fullscreen; + } + public static ArrayList tridArrToEntArr(ArrayList entities){ + ArrayList newEntities = new ArrayList(); + for(TridEntity e: entities){ + newEntities.add((Entity)e); + } + return newEntities; + } + public static ArrayList entArrToTridArr(ArrayList entities){ + ArrayList newEntities = new ArrayList(); + for(Entity e: entities){ + newEntities.add((TridEntity)e); + } + return newEntities; + } + public static ArrayList getEntities(){ + return currentScene.entities; + } + public static ArrayList getCollision(){ + return currentScene.getCollision(); + } + public static boolean getMouseDown(int mb){ + if(mb == 1){ + return m1; + } + if(mb == 2){ + return m2; + } + if(mb == 3){ + return m3; + } + if(mb == 4){ + return m4; + } + if(mb == 5){ + return m5; + } + return false; + } + public static boolean getKeyDown(int key){ + return keys[key]; + } + public static Player getPlr(){ + return player; + } + public static int getFrameWidth(){ + return 684; + } + public static int getFrameHeight(){ + return 462; + } + public static Point getShakeOffset(){ + return new Point(camShake.offX, camShake.offY); + } + + + // Commands + public static ArrayList consoleLines = new ArrayList(); + public static String consoleType = ""; // What the user is typing + + public static void runCommand(String command){ + if(command != null && command.length() > 0){ + lastCommand = command; + printConsole(" > " + command); + + ArrayList cmdParts = new ArrayList(); + Scanner scanner = new Scanner(command); + while(scanner.hasNext()){ + cmdParts.add(scanner.next()); + } + scanner.close(); + + if(cmdParts.size() == 0) return; + try{ + switch(cmdParts.get(0)){ + case "drawCollision": + if(cmdParts.size() == 1){ + printConsole("drawCollision is " + Trident.drawCollision); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.drawCollision = true; + printConsole("set drawCollision to " + Trident.drawCollision); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.drawCollision = false; + printConsole("set drawCollision to " + Trident.drawCollision); + } + break; + case "engineDraw": + if(cmdParts.size() == 1){ + printConsole("engineDraw is " + Trident.engineDraw); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.engineDraw = true; + printConsole("set engineDraw to " + Trident.engineDraw); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.engineDraw = false; + printConsole("set engineDraw to " + Trident.engineDraw); + } + break; + case "drawPos": + if(cmdParts.size() == 1){ + printConsole("drawPos is " + Trident.drawPos); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.drawPos = true; + printConsole("set drawPos to " + Trident.drawPos); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.drawPos = false; + printConsole("set drawPos to " + Trident.drawPos); + } + break; + case "noclip": + if(cmdParts.size() == 1){ + printConsole("noclip is " + Trident.noclip); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.noclip = true; + printConsole("set noclip to " + Trident.noclip); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.noclip = false; + printConsole("set noclip to " + Trident.noclip); + } + break; + case "tp": + int x = Integer.parseInt(cmdParts.get(1)); + int y = Integer.parseInt(cmdParts.get(2)); + Trident.setPlrPos(new Position(x, y)); + printConsole("teleported player to (" + x + ", " + y + ")"); + break; + case "loadMap": + String map = ""; + for(int i = 1; i < cmdParts.size(); i++){ + map += cmdParts.get(i); + if(i != cmdParts.size() - 1) map += " "; + } + Trident.loadScene(map); + break; + case "drawFrames": + if(cmdParts.size() == 1){ + printConsole("drawFrames is " + Trident.drawFrames); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.drawFrames = true; + printConsole("set drawFrames to " + Trident.drawFrames); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.drawFrames = false; + printConsole("set drawFrames to " + Trident.drawFrames); + } + break; + case "debugColor": + int r, g, b; + float alpha = -1; + r = Integer.parseInt(cmdParts.get(1)); + g = Integer.parseInt(cmdParts.get(2)); + b = Integer.parseInt(cmdParts.get(3)); + if(cmdParts.size() == 5){ + alpha = Float.parseFloat(cmdParts.get(4)); + } + if(alpha != -1){ + Trident.debugColor = new Color(r / 255f, g / 255f, b / 255f, alpha); + printConsole("set debugColor to (" + r + ", " + g + ", " + b + ", " + alpha + ")"); + }else{ + Trident.debugColor = new Color(r, g, b); + printConsole("set debugColor to (" + r + ", " + g + ", " + b + ")"); + } + break; + case "enableBloom": + if(cmdParts.size() == 1){ + printConsole("enableBloom is " + Trident.enableBloom); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.enableBloom = true; + printConsole("set enableBloom to " + Trident.enableBloom); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.enableBloom = false; + printConsole("set enableBloom to " + Trident.enableBloom); + } + break; + case "enableExposure": + if(cmdParts.size() == 1){ + printConsole("enableExposure is " + Trident.enableExposure); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.enableExposure = true; + printConsole("set enableExposure to " + Trident.enableExposure); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.enableExposure = false; + printConsole("set enableExposure to " + Trident.enableExposure); + } + break; + case "setBloom": + double amount = Double.parseDouble(cmdParts.get(1)); + Trident.setBloom(amount); + printConsole("set bloom to " + amount); + break; + case "setExposure": + double expo = Double.parseDouble(cmdParts.get(1)); + Trident.setExposure(expo); + printConsole("set exposure to " + expo); + break; + case "setLightBlur": + int blurLevel = Integer.parseInt(cmdParts.get(1)); + Trident.setLightBlur(blurLevel); + printConsole("set lightBlur to " + blurLevel + " (recommended: 1)"); + break; + case "clear": + consoleLines = new ArrayList(); + break; + case "help": + int page = 1; + if(cmdParts.size() > 1) page = Integer.parseInt(cmdParts.get(1)); + printHelp(page); + break; + case "customHelp": + int p = 1; + if(cmdParts.size() > 1) p = Integer.parseInt(cmdParts.get(1)); + printCustomHelp(p); + break; + case "credits": + runCommand("clear"); + printConsole("Trident Engine built in Java by Blocky"); + printConsole("---"); + printConsole("Github: @HeyIts-Blocky"); + printConsole("Insta: @heyits_blocky"); + printConsole("Itch.io: blockmanblue.itch.io "); + printConsole("---"); + printConsole(""); + break; + case "openItch": + BTools.openWebsite("https://blockmanblue.itch.io/"); + break; + case "errorTest": + consoleOpen = false; + printError("Error test"); + break; + case "roll": + printConsole("You got " + BTools.randInt(0, 101) + " points"); + break; + default: + int cmd = Update.command(cmdParts); + if(cmd != 0){ + printConsole("Unknown command: " + cmdParts.get(0)); + } + break; + } + }catch(Exception e){ + printConsole("Something went wrong while running your command."); + printException("", e); + } + } + } + public static void printConsole(String text){ + consoleLines.add(text); + if(consoleLines.size() > 30) consoleLines.remove(0); + } + public static void printError(String text){ + consoleError = true; + printConsole(text); + } + public static void printException(String text, Exception e){ + consoleError = true; + printConsole(text); + printConsole("Error type: " + e.getClass().getName()); + } + public static void printExceptionSilent(String text, Exception e){ + printConsole(text); + printConsole("Error type: " + e.getClass().getName()); + } + private static String[] cmds = { + "credits", + "drawCollision [0/1, false/true]", + "engineDraw [0/1, false/true]", + "drawPos [0/1, false/true]", + "noclip [0/1, false/true]", + "tp ", + "loadMap ", + "drawFrames [0/1, false/true]", + "debugColor [a]", + "enableBloom [0/1, false/true]", + "enableExposure [0/1, false/true]", + "setBloom ", + "setExposure ", + "setLightBlur ", + "clear", + "help [page]", + "customHelp [page]", + "errorTest", + "roll", + }; + + public static void printHelp(int page){ + int startIndex = (page - 1) * 10; + if(startIndex > cmds.length - 1){ + printConsole("page beyond bounds: " + page); + printConsole("number of pages: " + (cmds.length / 10 + ((cmds.length % 10 != 0) ? 1 : 0))); + return; + } + + printConsole("-- BUILT-IN COMMANDS --"); + printConsole("Page " + page + " of " + (cmds.length / 10 + ((cmds.length % 10 != 0) ? 1 : 0))); + printConsole(""); + for(int i = startIndex; (i < cmds.length && i < startIndex + 10); i++){ + printConsole("} " + cmds[i]); + } + printConsole(""); + } + + public static void printCustomHelp(int page){ + int startIndex = (page - 1) * 10; + if(startIndex > Update.commands.length - 1){ + printConsole("page beyond bounds: " + page); + printConsole("number of pages: " + (Update.commands.length / 10 + ((Update.commands.length % 10 != 0) ? 1 : 0))); + return; + } + + printConsole("-- GAME-SPECIFIC COMMANDS --"); + printConsole("Page " + page + " of " + (Update.commands.length / 10 + ((Update.commands.length % 10 != 0) ? 1 : 0))); + printConsole(""); + for(int i = startIndex; (i < Update.commands.length && i < startIndex + 10); i++){ + printConsole("} " + Update.commands[i]); + } + printConsole(""); + } + +} diff --git a/data/templates/blank3d/src/trident/ent/BoxColl.java b/data/templates/blank3d/src/trident/ent/BoxColl.java new file mode 100644 index 0000000..8201a9d --- /dev/null +++ b/data/templates/blank3d/src/trident/ent/BoxColl.java @@ -0,0 +1,37 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import trident.*; +public class BoxColl extends TridEntity{ + + public Color color = Color.white; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/boxColl.png"); + + public BoxColl(Position pos, Dimension size, Color c){ + super(pos, size); + color = c; + } + public BoxColl(Position pos, Dimension size){ + super(pos, size); + } + public BoxColl(){ + super("boxcoll", true, 3); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new BoxColl(pos, collision, new Color(data[0], data[1], data[2])); + } + + public void render(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.fillRect(x - getCollision().width / 2, y - getCollision().height / 2, getCollision().width, getCollision().height); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + render(g, panel, x, y); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/templates/blank3d/src/trident/ent/BoxNoColl.java b/data/templates/blank3d/src/trident/ent/BoxNoColl.java new file mode 100644 index 0000000..e12beb7 --- /dev/null +++ b/data/templates/blank3d/src/trident/ent/BoxNoColl.java @@ -0,0 +1,45 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; +import blib.game.*; + +import trident.*; +public class BoxNoColl extends TridEntity{ + + public Color color = Color.white; + public int width, height; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/box.png"); + + public BoxNoColl(Position pos, Color c, int w, int h){ + super(pos); + color = c; + width = w; + height = h; + renderType = Entity.UNDER; + } + public BoxNoColl(Position pos, int w, int h){ + super(pos); + width = w; + height = h; + renderType = Entity.UNDER; + } + public BoxNoColl(){ + super("boxnocoll", false, 5); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new BoxNoColl(pos, new Color(data[2], data[3], data[4]), data[0], data[1]); + } + + public void render(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.fillRect(x - width / 2, y - height / 2, width, height); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + render(g, panel, x, y); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/templates/blank3d/src/trident/ent/InvisColl.java b/data/templates/blank3d/src/trident/ent/InvisColl.java new file mode 100644 index 0000000..7736536 --- /dev/null +++ b/data/templates/blank3d/src/trident/ent/InvisColl.java @@ -0,0 +1,30 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import trident.*; +public class InvisColl extends TridEntity{ + + public Color color = Color.red; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/collision.png"); + + public InvisColl(Position pos, Dimension size){ + super(pos, size); + } + public InvisColl(){ + super("inviscoll", true, 0); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new InvisColl(pos, collision); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.drawRect(x - getCollision().width / 2, y - getCollision().height / 2, getCollision().width, getCollision().height); + g.drawLine(x - getCollision().width / 2, y - getCollision().height / 2, x + getCollision().width / 2, y + getCollision().height / 2); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/templates/blank3d/src/trident/ent/PlrStart.java b/data/templates/blank3d/src/trident/ent/PlrStart.java new file mode 100644 index 0000000..26fe13d --- /dev/null +++ b/data/templates/blank3d/src/trident/ent/PlrStart.java @@ -0,0 +1,26 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import trident.*; +public class PlrStart extends TridEntity{ + public Color color = Color.red; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/plrStart.png"); + + public PlrStart(Position pos){ + super(pos); + } + public PlrStart(){ + super("plrstart", false, 0); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new PlrStart(pos); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/templates/blank3d/src/trident/ent/TridLight.java b/data/templates/blank3d/src/trident/ent/TridLight.java new file mode 100644 index 0000000..888bf49 --- /dev/null +++ b/data/templates/blank3d/src/trident/ent/TridLight.java @@ -0,0 +1,28 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import trident.*; +public class TridLight extends TridEntity{ + + public int radius; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/light.png"); + + public TridLight(Position pos, int r){ + super(pos); + radius = r; + } + public TridLight(){ + super("light", false, 1); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new TridLight(pos, data[0]); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/templates/blank3d/src/trident/ent/Trigger.java b/data/templates/blank3d/src/trident/ent/Trigger.java new file mode 100644 index 0000000..d52126d --- /dev/null +++ b/data/templates/blank3d/src/trident/ent/Trigger.java @@ -0,0 +1,41 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import trident.*; +public class Trigger extends TridEntity{ + + public Color color = Color.blue; + public Dimension box; + public int id; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/trigger.png"); + + public Trigger(Position pos, Dimension size, int i){ + super(pos); + name = "trigger"; + box = size; + id = i; + } + public Trigger(){ + super("trigger", false, 3); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new Trigger(pos, new Dimension(data[0], data[1]), data[2]); + } + + public boolean containsPos(Position pos){ + Point p = new Point((int)pos.x, (int)pos.y); + Rectangle rect = new Rectangle((int)position.x - box.width / 2, (int)position.y - box.height / 2, box.width, box.height); + return rect.contains(p); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.drawRect(x - box.width / 2, y - box.height / 2, box.width, box.height); + g.drawLine(x - box.width / 2, y - box.height / 2, x + box.width / 2, y + box.height / 2); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/templates/blank3d/src/update/Inputs.java b/data/templates/blank3d/src/update/Inputs.java new file mode 100644 index 0000000..d84fb42 --- /dev/null +++ b/data/templates/blank3d/src/update/Inputs.java @@ -0,0 +1,50 @@ +package update; + +import java.awt.*; +import java.awt.event.*; +import blib.util.*; +import trident.*; +import ent.*; +import custom.*; +public class Inputs { + + public static void keyPressed(int key){ + if(HUD.currentDialog != null){ + if(key == KeyEvent.VK_E){ + HUD.currentDialog.next(); + } + }else{ + if(key == KeyEvent.VK_E){ + // look for npc + for(TridEntity e: Trident.getEntities()){ + if(e instanceof NPC){ + NPC npc = (NPC)e; + + if(BTools.getDistance(Trident.getPlrPos(), npc.position) < 200){ + double dir = BTools.normalizeRadians(BTools.getAngle(Trident.getPlrPos(), npc.position)); + double dirDiff = Math.abs(dir - WallManager.camera.direction); + if(dirDiff < Math.toRadians(45)){ + if(npc.dialog >= 0){ + HUD.setDialog(npc.dialog); + }else{ + Update.trigger(npc.dialog); + } + + } + } + } + } + } + // if(key == KeyEvent.VK_DOWN) Rend3D.offset++; + // if(key == KeyEvent.VK_UP) Rend3D.offset--; + } + } + + public static void mousePressed(int mb, Point mousePos, Position worldPos){ + + } + + public static void onScroll(int scroll){ + + } +} diff --git a/data/templates/blank3d/src/update/Update.java b/data/templates/blank3d/src/update/Update.java new file mode 100644 index 0000000..60e1941 --- /dev/null +++ b/data/templates/blank3d/src/update/Update.java @@ -0,0 +1,168 @@ +package update; + +import trident.*; +import trident.ent.*; +import ent.*; +import java.util.ArrayList; +import blib.b3d.*; +import blib.game.*; +import blib.util.*; +import custom.*; +import java.awt.*; +import java.awt.event.*; +public class Update { + + public static final String[] fonts = {}; // add fonts here + + public static void setup(){ + // Add custom entities to the registry here. Required in order to load them properly + Trident.addCustomEntity(new ExampleEntity()); // Use the empty constructor + Trident.addCustomEntity(new Rend3D()); + Trident.addCustomEntity(new TexWall()); + Trident.addCustomEntity(new TexWallT()); + Trident.addCustomEntity(new HUD()); + Trident.addCustomEntity(new NPC()); + Trident.addCustomEntity(new Prop()); + + // Set settings + Trident.setShortCollision(false); + WallManager.camera.size = new Dimension(Trident.getFrameWidth(), Trident.getFrameHeight()); + WallManager.camera.rendDist = 2000; + WallManager.camera.fhp = -25; + + // Post Processing + Trident.setBloom(0.2); + Trident.setExposure(1); + Trident.enableBloom = false; + Trident.enableExposure = false; + Trident.setLightBlur(1); + } + + public static void sceneStart(String scene){ + WallManager.walls = new ArrayList(); + for(TridEntity e: Trident.getEntities()){ + if(e instanceof BoxColl){ + BoxColl box = (BoxColl)e; + Wall[] walls = Wall.rectToWalls(box.getCollision(), box.color); + for(Wall w: walls) WallManager.walls.add(w); + } + if(e instanceof TexWall){ + TexWall box = (TexWall)e; + Wall[] walls = Wall.rectToWalls(box.getCollision(), Color.magenta, box.texture, box.texLen); + for(Wall w: walls) WallManager.walls.add(w); + } + if(e instanceof TexWallT){ + TexWallT box = (TexWallT)e; + Wall[] walls = Wall.rectToWalls(box.getCollision(), Color.magenta, box.texture, box.texLen, true); + for(Wall w: walls) WallManager.walls.add(w); + } + } + + Wall.lightWalls(WallManager.walls, Math.toRadians(50)); + + int plrDir = Trident.getCurrentScene().plrDir; + if(plrDir == Player.EAST){ + WallManager.camera.direction = 0; + } + if(plrDir == Player.SOUTH){ + WallManager.camera.direction = Math.toRadians(90); + } + if(plrDir == Player.NORTH){ + WallManager.camera.direction = Math.toRadians(-90); + } + if(plrDir == Player.WEST){ + WallManager.camera.direction = Math.toRadians(180); + } + + Trident.resetKeys(); + } + + public static void update(long elapsedTime){ + if(Rend3D.enabled){ + + Trident.setPlrSpeed(0); + if(HUD.currentDialog == null){ // only move when there's no dialog + if(Trident.getKeyDown(KeyEvent.VK_LEFT)){ + WallManager.camera.direction -= Math.toRadians(0.1) * elapsedTime; + } + if(Trident.getKeyDown(KeyEvent.VK_RIGHT)){ + WallManager.camera.direction += Math.toRadians(0.1) * elapsedTime; + } + + Position startPos = Trident.getPlrPos().copy(); + Point move = new Point(); + if(Trident.getKeyDown(KeyEvent.VK_W)) move.y++; + if(Trident.getKeyDown(KeyEvent.VK_S)) move.y--; + if(Trident.getKeyDown(KeyEvent.VK_A)) move.x++; + if(Trident.getKeyDown(KeyEvent.VK_D)) move.x--; + if(!move.equals(new Point())){ + Position mov = new Position(move.x, move.y); + double dir = BTools.vectorToAngle(mov) - Math.toRadians(90); + dir += WallManager.camera.direction; + mov = BTools.angleToVector(dir); + Trident.getPlr().move(mov.x * 0.1 * elapsedTime, mov.y * 0.1 * elapsedTime); + } + if(!Trident.noclip){ + Rectangle plrRect = Trident.getPlr().getCollision(); + for(Rectangle rect: Trident.getCollision()){ + // check x + if(rect.intersects(plrRect)){ + Position pos = Trident.getPlr().getPos().copy(); + Trident.getPlr().goToPos(startPos.x, Trident.getPlr().getY()); + plrRect = Trident.getPlr().getCollision(); + if(rect.intersects(plrRect)){ + Trident.getPlr().goToPos(pos); + plrRect = Trident.getPlr().getCollision(); + } + } + // check y + if(rect.intersects(plrRect)){ + Trident.getPlr().goToPos(Trident.getPlr().getX(), startPos.y); + plrRect = Trident.getPlr().getCollision(); + + // check x + if(rect.intersects(plrRect)){ + Trident.getPlr().goToPos(startPos.x, Trident.getPlr().getY()); + plrRect = Trident.getPlr().getCollision(); + } + } + } + } + + + double moveDist = BTools.getDistance(startPos, Trident.getPlrPos()) * 0.1; + Rend3D.totalMovement += moveDist; + Rend3D.offset = (int)(Math.sin(Rend3D.totalMovement) * 2); + } + }else{ + Trident.setPlrSpeed(0.2); + } + + } + + public static void trigger(int id){ + + } + + public static void tridentEvent(int id){ + if(id == Trident.EVENT_SCREENSHOT){ + Trident.printConsole("Took a screenshot!"); + } + } + + public static int command(ArrayList cmdParts){ // cmdParts.get(0) is the command, while the rest are arguments for the command. + switch(cmdParts.get(0)){ + case "helloWorld": + Trident.printConsole("Hello, World!"); + return 0; + case "ping": + Trident.printConsole("pong"); + return 0; + } + return 1; // return 1 if command is not recognized + } + public static String[] commands = { // Fill this with the format for all custom commands + "helloWorld", + "ping", + }; +} diff --git a/lib/BLib.jar b/lib/BLib.jar new file mode 100644 index 0000000..99e9d99 Binary files /dev/null and b/lib/BLib.jar differ diff --git a/src/main/Main.java b/src/main/Main.java new file mode 100644 index 0000000..0750527 --- /dev/null +++ b/src/main/Main.java @@ -0,0 +1,260 @@ +package main; + +import javax.swing.*; +import project.*; +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import java.nio.file.Files; +public class Main { + public static Image icon = new ImageIcon("data/icon.png").getImage(); + public static void main(String[] args){ + + Project.loadRegistry(); + + JFrame selWindow = new JFrame("Trident"); + selWindow.setSize(400, 200); + selWindow.setResizable(false); + selWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + selWindow.setIconImage(icon); + selWindow.setLayout(new GridLayout(2, 3)); + selWindow.setLocation(400, 300); + + JButton loadButton = new JButton("Load Project"); + loadButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + selWindow.dispose(); + selection(0); + } + }); + loadButton.setBackground(new Color(0, 0, 50)); + loadButton.setForeground(Color.white); + selWindow.add(loadButton); + JButton newButton = new JButton("New Project"); + newButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + selWindow.dispose(); + selection(1); + } + }); + newButton.setBackground(new Color(0, 0, 50)); + newButton.setForeground(Color.white); + selWindow.add(newButton); + JButton importButton = new JButton("Import Project"); + importButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + selWindow.dispose(); + selection(2); + } + }); + importButton.setBackground(new Color(0, 0, 50)); + importButton.setForeground(Color.white); + selWindow.add(importButton); + + JTextArea loadText = new JTextArea("Load a project"); + loadText.setEditable(false); + loadText.setBackground(new Color(0, 0, 100)); + loadText.setForeground(Color.white); + selWindow.add(loadText); + JTextArea newText = new JTextArea("Create a new project"); + newText.setEditable(false); + newText.setBackground(new Color(0, 0, 100)); + newText.setForeground(Color.white); + selWindow.add(newText); + JTextArea importText = new JTextArea("Get a project put\ninto the registry"); + importText.setEditable(false); + importText.setBackground(new Color(0, 0, 100)); + importText.setForeground(Color.white); + selWindow.add(importText); + + selWindow.setVisible(true); + + } + + public static int loadSel = 0; + + public static void selection(int sel){ + if(sel == 0){ // Load project + + if(Project.projRegistry.length == 0){ + JOptionPane.showMessageDialog(null, "You don't have any projects!", "Trident", JOptionPane.ERROR_MESSAGE); + main(new String[0]); + return; + } + + JFrame selWindow = new JFrame("Trident"); + selWindow.setSize(500, 200); + selWindow.setResizable(false); + selWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + selWindow.setIconImage(icon); + selWindow.setLayout(new GridLayout(2, 3)); + selWindow.setLocation(400, 300); + + JTextField text = new JTextField(Project.projRegistry[0] + "\n(1/" + Project.projRegistry.length + ")"); + text.setEditable(false); + text.setBackground(new Color(0, 0, 100)); + text.setForeground(Color.white); + JButton prevButton = new JButton("<"); + prevButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + loadSel--; + if(loadSel < 0){ + loadSel = Project.projRegistry.length - 1; + } + text.setText(Project.projRegistry[loadSel] + "\n(" + (loadSel + 1) + "/" + Project.projRegistry.length + ")"); + } + }); + prevButton.setBackground(new Color(0, 0, 50)); + prevButton.setForeground(Color.white); + selWindow.add(prevButton); + selWindow.add(text); + JButton nextButton = new JButton(">"); + nextButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + loadSel++; + if(loadSel > Project.projRegistry.length - 1){ + loadSel = 0; + } + text.setText(Project.projRegistry[loadSel] + "\n(" + (loadSel + 1) + "/" + Project.projRegistry.length + ")"); + } + }); + nextButton.setBackground(new Color(0, 0, 50)); + nextButton.setForeground(Color.white); + selWindow.add(nextButton); + JButton loadButton = new JButton("Load"); + loadButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + selWindow.dispose(); + loadProject(loadSel); + } + }); + loadButton.setBackground(new Color(0, 0, 50)); + loadButton.setForeground(Color.white); + selWindow.add(loadButton); + JButton deleteButton = new JButton("Delete Project"); + deleteButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + + int sel = JOptionPane.showConfirmDialog(selWindow, "Are you sure you want to delete this project?", "Trident", JOptionPane.YES_NO_OPTION); + + if(sel == 0){ + deleteDir(new File("data/projects/" + Project.projRegistry[loadSel])); + + String[] newRegistry = new String[Project.projRegistry.length - 1]; + for(int i = 0, j = 0; i < Project.projRegistry.length; i++){ + if(i != loadSel){ + newRegistry[j] = Project.projRegistry[i]; + j++; + } + } + Project.projRegistry = newRegistry; + loadSel = 0; + Project.saveRegistry(); + + JOptionPane.showMessageDialog(selWindow, "Deleted the project.", "Trident", JOptionPane.INFORMATION_MESSAGE); + + if(Project.projRegistry.length == 0){ + selWindow.dispose(); + main(new String[0]); + return; + } + text.setText(Project.projRegistry[loadSel] + "\n(" + (loadSel + 1) + "/" + Project.projRegistry.length + ")"); + } + + + } + }); + deleteButton.setBackground(new Color(0, 0, 50)); + deleteButton.setForeground(Color.white); + selWindow.add(deleteButton); + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + selWindow.dispose(); + main(new String[0]); + } + }); + cancelButton.setBackground(new Color(0, 0, 50)); + cancelButton.setForeground(Color.white); + selWindow.add(cancelButton); + + + selWindow.setVisible(true); + } + if(sel == 1){ // New project + String[] options = {"Cancel", "Blank 2D", "Blank 3D", "Custom"}; + int selection = JOptionPane.showOptionDialog(null, "Select the type of project:", "Trident", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); + if(selection == 0){ + main(new String[0]); + return; + } + String customTemp = ""; + if(selection == options.length - 1){ + customTemp = JOptionPane.showInputDialog(null, "Enter the custom template name.", "Trident", JOptionPane.QUESTION_MESSAGE); + if(customTemp == null){ + main(new String[0]); + return; + } + } + String name = JOptionPane.showInputDialog(null, "Enter the project name. If a project already exists with that name, keep in mind that it will replace it.", "Trident", JOptionPane.QUESTION_MESSAGE); + if(name == null){ + main(new String[0]); + return; + } + String[] newRegistry = new String[Project.projRegistry.length + 1]; + for(int i = 0; i < Project.projRegistry.length; i++){ + newRegistry[i] = Project.projRegistry[i]; + } + newRegistry[newRegistry.length - 1] = name; + Project.projRegistry = newRegistry; + Project.saveRegistry(); + new Project(name, selection, customTemp); + JOptionPane.showMessageDialog(null, "Project successfully created.", "Trident", JOptionPane.INFORMATION_MESSAGE); + main(new String[0]); + } + if(sel == 2){ // Import project + String name = JOptionPane.showInputDialog(null, "Enter the project name. Make sure it's in the projects folder before you open it.", "Trident", JOptionPane.QUESTION_MESSAGE); + if(name == null){ + main(new String[0]); + return; + } + String[] newRegistry = new String[Project.projRegistry.length + 1]; + for(int i = 0; i < Project.projRegistry.length; i++){ + newRegistry[i] = Project.projRegistry[i]; + } + newRegistry[newRegistry.length - 1] = name; + Project.projRegistry = newRegistry; + Project.saveRegistry(); + main(new String[0]); + } + } + + public static void deleteDir(File file) { + if(!file.exists()) return; + + File[] contents = file.listFiles(); + if (contents != null) { + for (File f : contents) { + if (! Files.isSymbolicLink(f.toPath())) { + deleteDir(f); + } + } + } + file.delete(); + } + + public static JFrame window; + + public static void loadProject(int proj){ + window = new JFrame("Trident Editor"); + window.setSize(700, 500); + window.setMinimumSize(new Dimension(700, 500)); + window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + window.setIconImage(icon); + // panel + MainPanel panel = new MainPanel(new Project(proj)); + window.add(panel); + // + window.setVisible(true); + } +} diff --git a/src/main/MainPanel.java b/src/main/MainPanel.java new file mode 100644 index 0000000..7c67975 --- /dev/null +++ b/src/main/MainPanel.java @@ -0,0 +1,631 @@ +package main; + +import javax.swing.*; +import project.*; +import blib.util.*; +import blib.input.*; +import java.awt.event.*; +import java.awt.*; +import blib.game.*; +import java.io.*; +import project.ent.*; +import project.ent.Light; +public class MainPanel extends JPanel { + + Project project; + Server server; + FrameManager frameManager = new FrameManager(); + KeyManager km = new InputListener(this); + Camera cam; + ImageIcon icon = new ImageIcon("data/icon.png"); + int tool = 0; + boolean drawLight = false; + + Cursor[] cursors = { + BTools.getCustomCursor(new ImageIcon("data/images/cursors/select.png")), + BTools.getCustomCursor(new ImageIcon("data/images/cursors/move.png")), + BTools.getCustomCursor(new ImageIcon("data/images/cursors/resize.png")), + }; + Point mouse = new Point(); // only used for better delta + + boolean dropDown = false; + int dropType = 0; + /* + * 0 = trident button + * 1 = add new object + * 2 = delete object + */ + Rectangle dropRect = null; + ImageIcon selectImg = new ImageIcon("data/images/dropdown/select.png"), moveImg = new ImageIcon("data/images/dropdown/move.png"), resizeImg = new ImageIcon("data/images/dropdown/resize.png"), resetImg = new ImageIcon("data/images/dropdown/reset.png"), quitImg = new ImageIcon("data/images/dropdown/quit.png"); + ImageIcon deleteImg = new ImageIcon("data/images/dropdown/delete.png"); + ImageIcon boxImg = new ImageIcon("data/images/dropdown/box.png"); + ImageIcon boxCollImg = new ImageIcon("data/images/dropdown/boxColl.png"); + ImageIcon collisionImg = new ImageIcon("data/images/dropdown/collision.png"); + ImageIcon plrStartImg = new ImageIcon("data/images/dropdown/plrStart.png"); + ImageIcon customImg = new ImageIcon("data/images/dropdown/customEnt.png"); + ImageIcon duplicateImg = new ImageIcon("data/images/dropdown/duplicate.png"); + ImageIcon editImg = new ImageIcon("data/images/dropdown/edit.png"); + ImageIcon triggerImg = new ImageIcon("data/images/dropdown/trigger.png"); + ImageIcon lightImg = new ImageIcon("data/images/dropdown/light.png"); + + ImageIcon crosshair = new ImageIcon("data/images/crosshair.png"); + boolean drawCross = true; + + long saveTime = 0; + + TridEntity selectedEntity = null; + + public MainPanel(Project proj){ + project = proj; + + BTools.resizeImgIcon(icon, 32, 32); + cam = new Camera(new Position(), this); + setBackground(Color.black); + frameManager.bgColor = Color.white; + cam.setDimension = new Dimension(frameManager.WIDTH, frameManager.HEIGHT); + + server = new Server(new ServerListener()); + } + + public void paintComponent(Graphics graphics){ + super.paintComponent(graphics); + Graphics g = frameManager.newFrame(); + + frameManager.bgColor = project.currentScene.bgColor; + + for(TridEntity e: project.currentScene.entities){ + Point p = cam.worldToScreen(e.position); + e.engineRender(g, this, p.x, p.y); + if(e.equals(selectedEntity)){ + g.setColor(new Color(0f, 0.2f, 1f, 0.5f)); + g.fillOval(p.x - 32, p.y - 32, 64, 64); + } + if(e instanceof CustomEntity){ + CustomEntity c = (CustomEntity)e; + String str = "["; + for(int i = 0; i < c.data.length; i++){ + str += c.data[i] + ""; + if(i == c.data.length - 1){ + str += "]"; + }else{ + str += ", "; + } + } + if(c.data.length == 0) str = "NO DATA"; + g.setColor(Color.white); + int width = Math.max(g.getFontMetrics().stringWidth(str), g.getFontMetrics().stringWidth(c.name)); + g.fillRect(p.x - width / 2, p.y + 32 - 5, width, 20); + g.setColor(Color.black); + g.setFont(new Font("Arial", Font.PLAIN, 10)); + TextBox.draw(c.name + "\n" + str, g, p.x, p.y + 32, TextBox.CENTER); + } + if(e instanceof Trigger){ + Trigger trig = (Trigger)e; + String str = "" + trig.id; + g.setColor(Color.white); + int width = g.getFontMetrics().stringWidth(str); + g.fillRect(p.x - width / 2, p.y + 32 - 5, width, 10); + g.setColor(Color.black); + g.setFont(new Font("Arial", Font.PLAIN, 10)); + TextBox.draw(str, g, p.x, p.y + 32, TextBox.CENTER); + } + } + + if(drawLight){ + int darkness = -project.currentScene.defaultLight + 255; + frameManager.fillScreen(new Color(0f, 0f, 0f, (darkness / 255f))); + } + + g.setColor(new Color(0f, 0f, 0f, 0.5f)); + g.fillRect(0, 0, frameManager.WIDTH, 40); + g.fillRect(0, frameManager.HEIGHT - 40, frameManager.WIDTH, 40); + g.setColor(Color.white); + g.setFont(new Font("Arial", Font.PLAIN, 20)); + TextBox.draw("Code Load Scene New Scene Save PlrDir: " + project.currentScene.getDir(), g, 40, 20); + icon.paintIcon(this, g, 4, 4); + TextBox.draw("[L] Show Darkness: " + drawLight + " Default light level: " + project.currentScene.defaultLight, g, frameManager.WIDTH - 10, frameManager.HEIGHT - 20, TextBox.RIGHT); + g.setColor(new Color(1f, 1f, 1f, (saveTime / 1000f))); + TextBox.draw("Saved!", g, 10, frameManager.HEIGHT - 20); + g.setColor(Color.white); + g.setFont(new Font("Arial", Font.PLAIN, 15)); + TextBox.draw("(" + cam.pos.toStringSimple() + ")", g, frameManager.WIDTH, 10, TextBox.RIGHT); + + if(dropDown){ + g.setColor(Color.lightGray); + g.fillRect(dropRect.x, dropRect.y, dropRect.width, dropRect.height); + g.setColor(Color.gray); + g.drawRect(dropRect.x, dropRect.y, dropRect.width, dropRect.height); + for(int i = 0; i < dropRect.height / 32; i++){ + g.drawLine(dropRect.x, dropRect.y + (i * 32), dropRect.x + dropRect.width, dropRect.y + (i * 32)); + } + + g.setColor(Color.black); + g.setFont(new Font("Arial", Font.PLAIN, 20)); + if(dropType == 0){ + selectImg.paintIcon(this, g, dropRect.x, dropRect.y); + TextBox.draw("Select", g, dropRect.x + 32, dropRect.y + 16); + moveImg.paintIcon(this, g, dropRect.x, dropRect.y + 32); + TextBox.draw("Move", g, dropRect.x + 32, dropRect.y + 16 + 32); + resizeImg.paintIcon(this, g, dropRect.x, dropRect.y + 64); + TextBox.draw("Resize", g, dropRect.x + 32, dropRect.y + 16 + 64); + resetImg.paintIcon(this, g, dropRect.x, dropRect.y + 64 + 32); + TextBox.draw("Return to (0, 0)", g, dropRect.x + 32, dropRect.y + 16 + 64 + 32); + editImg.paintIcon(this, g, dropRect.x, dropRect.y + 128); + TextBox.draw("Change bg color", g, dropRect.x + 32, dropRect.y + 16 + 128); + lightImg.paintIcon(this, g, dropRect.x, dropRect.y + 128 + 32); + TextBox.draw("Set Default Light", g, dropRect.x + 32, dropRect.y + 16 + 128 + 32); + quitImg.paintIcon(this, g, dropRect.x, dropRect.y + 128 + 64); + TextBox.draw("Save and Quit", g, dropRect.x + 32, dropRect.y + 16 + 128 + 64); + } + if(dropType == 1){ + deleteImg.paintIcon(this, g, dropRect.x, dropRect.y); + TextBox.draw("Delete", g, dropRect.x + 32, dropRect.y + 16); + duplicateImg.paintIcon(this, g, dropRect.x, dropRect.y + 32); + TextBox.draw("Duplicate", g, dropRect.x + 32, dropRect.y + 16 + 32); + editImg.paintIcon(this, g, dropRect.x, dropRect.y + 64); + TextBox.draw("Edit", g, dropRect.x + 32, dropRect.y + 16 + 64); + resetImg.paintIcon(this, g, dropRect.x, dropRect.y + 64 + 32); + TextBox.draw("Bring here", g, dropRect.x + 32, dropRect.y + 16 + 64 + 32); + } + if(dropType == 2){ + boxImg.paintIcon(this, g, dropRect.x, dropRect.y); + TextBox.draw("Add BoxNoColl", g, dropRect.x + 32, dropRect.y + 16); + boxCollImg.paintIcon(this, g, dropRect.x, dropRect.y + 32); + TextBox.draw("Add BoxColl", g, dropRect.x + 32, dropRect.y + 16 + 32); + collisionImg.paintIcon(this, g, dropRect.x, dropRect.y + 64); + TextBox.draw("Add InvisColl", g, dropRect.x + 32, dropRect.y + 16 + 64); + plrStartImg.paintIcon(this, g, dropRect.x, dropRect.y + 64 + 32); + TextBox.draw("Add PlrStart", g, dropRect.x + 32, dropRect.y + 16 + 64 + 32); + triggerImg.paintIcon(this, g, dropRect.x, dropRect.y + 128); + TextBox.draw("Add Trigger", g, dropRect.x + 32, dropRect.y + 16 + 128); + customImg.paintIcon(this, g, dropRect.x, dropRect.y + 128 + 32); + TextBox.draw("Add Custom Entity", g, dropRect.x + 32, dropRect.y + 16 + 128 + 32); + lightImg.paintIcon(this, g, dropRect.x, dropRect.y + 128 + 64); + TextBox.draw("Add Light", g, dropRect.x + 32, dropRect.y + 16 + 128 + 64); + } + } + + if(drawCross) crosshair.paintIcon(this, g, frameManager.WIDTH / 2 - 4, frameManager.HEIGHT / 2 - 4); + + frameManager.renderFrame(this, graphics); + } + + public int getDropSel(int y){ + return (y - dropRect.y) / 32; + } + + + private class InputListener extends InputAdapter{ + public InputListener(JPanel panel){ + super(panel); + } + + public void onKeyPressed(int key){ + if(key == KeyEvent.VK_R){ + cam.pos = new Position(); + } + if(key == KeyEvent.VK_1){ + tool = 0; + } + if(key == KeyEvent.VK_2){ + tool = 1; + } + if(key == KeyEvent.VK_3){ + tool = 2; + } + if(key == KeyEvent.VK_DELETE && selectedEntity != null){ + project.currentScene.entities.remove(selectedEntity); + selectedEntity = null; + } + if(key == KeyEvent.VK_M && km.getKeyDown(KeyEvent.VK_CONTROL)){ + project.currentScene.save("data/projects/" + project.name); + } + if(key == KeyEvent.VK_C && km.getKeyDown(KeyEvent.VK_CONTROL)){ + if(selectedEntity instanceof BoxColl){ + BoxColl box = (BoxColl)selectedEntity; + project.currentScene.entities.add(new BoxColl(box.position.copy(), new Dimension(box.collision.width, box.collision.height), box.color)); + selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1); + } + if(selectedEntity instanceof BoxNoColl){ + BoxNoColl box = (BoxNoColl)selectedEntity; + project.currentScene.entities.add(new BoxNoColl(box.position.copy(), box.color, box.width, box.height)); + selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1); + } + if(selectedEntity instanceof InvisColl){ + InvisColl box = (InvisColl)selectedEntity; + project.currentScene.entities.add(new InvisColl(box.position.copy(), new Dimension(box.collision.width, box.collision.height))); + selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1); + } + if(selectedEntity instanceof Trigger){ + Trigger box = (Trigger)selectedEntity; + project.currentScene.entities.add(new Trigger(box.position.copy(), new Dimension(box.box.width, box.box.height), box.id)); + selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1); + } + if(selectedEntity instanceof PlrStart){ + PlrStart box = (PlrStart)selectedEntity; + project.currentScene.entities.add(new PlrStart(box.position.copy())); + selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1); + } + if(selectedEntity instanceof Light){ + Light box = (Light)selectedEntity; + project.currentScene.entities.add(new Light(box.position.copy(), box.radius)); + selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1); + } + if(selectedEntity instanceof CustomEntity){ + CustomEntity box = (CustomEntity)selectedEntity; + int[] data = new int[box.data.length]; + for(int i = 0; i < data.length; i++){ + data[i] = box.data[i]; + } + Dimension collision = null; + if(box.collision != null) collision = new Dimension(box.collision.width, box.collision.height); + project.currentScene.entities.add(new CustomEntity(box.position.copy(), collision, data, box.name)); + selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1); + } + } + if(key == KeyEvent.VK_L){ + drawLight = !drawLight; + } + if(key == KeyEvent.VK_C && !km.getKeyDown(KeyEvent.VK_CONTROL)){ + drawCross = !drawCross; + } + } + + public void onMousePressed(int mb, Point mousePos){ + mousePos = frameManager.getMousePos(panel, mousePos); + if(mousePos.equals(new Point())) return; // likely outside of frame + + if(mb == 1){ + if(dropDown){ + if(dropRect.contains(mousePos)){ + int sel = getDropSel(mousePos.y); + if(dropType == 0){ + switch(sel){ + case 0: + case 1: + case 2: + tool = sel; + break; + case 3: + cam.pos = new Position(); + break; + case 4: + try{ + int r, g, b; + String input = JOptionPane.showInputDialog(panel, "Enter the red value.", "Trident", JOptionPane.QUESTION_MESSAGE); + r = Integer.parseInt(input); + input = JOptionPane.showInputDialog(panel, "Enter the green value.", "Trident", JOptionPane.QUESTION_MESSAGE); + g = Integer.parseInt(input); + input = JOptionPane.showInputDialog(panel, "Enter the blue value.", "Trident", JOptionPane.QUESTION_MESSAGE); + b = Integer.parseInt(input); + Color c = new Color(r, g, b); + project.currentScene.bgColor = c; + }catch(Exception e){} + break; + case 5: + try{ + int level; + String input = JOptionPane.showInputDialog(panel, "Enter the new default light level", "Trident", JOptionPane.QUESTION_MESSAGE); + level = Integer.parseInt(input); + level = BTools.clamp(level, 0, 255); + project.currentScene.defaultLight = level; + }catch(Exception e){} + break; + case 6: + project.currentScene.save("data/projects/" + project.name); + Main.window.dispose(); + Main.main(new String[0]); + return; + } + } + if(dropType == 1){ + switch(sel){ + case 0: + project.currentScene.entities.remove(selectedEntity); + selectedEntity = null; + break; + case 1: + if(selectedEntity instanceof BoxColl){ + BoxColl box = (BoxColl)selectedEntity; + project.currentScene.entities.add(new BoxColl(box.position.copy(), new Dimension(box.collision.width, box.collision.height), box.color)); + selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1); + } + if(selectedEntity instanceof BoxNoColl){ + BoxNoColl box = (BoxNoColl)selectedEntity; + project.currentScene.entities.add(new BoxNoColl(box.position.copy(), box.color, box.width, box.height)); + selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1); + } + if(selectedEntity instanceof InvisColl){ + InvisColl box = (InvisColl)selectedEntity; + project.currentScene.entities.add(new InvisColl(box.position.copy(), new Dimension(box.collision.width, box.collision.height))); + selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1); + } + if(selectedEntity instanceof Trigger){ + Trigger box = (Trigger)selectedEntity; + project.currentScene.entities.add(new Trigger(box.position.copy(), new Dimension(box.box.width, box.box.height), box.id)); + selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1); + } + if(selectedEntity instanceof PlrStart){ + PlrStart box = (PlrStart)selectedEntity; + project.currentScene.entities.add(new PlrStart(box.position.copy())); + selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1); + } + if(selectedEntity instanceof Light){ + Light box = (Light)selectedEntity; + project.currentScene.entities.add(new Light(box.position.copy(), box.radius)); + selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1); + } + if(selectedEntity instanceof CustomEntity){ + CustomEntity box = (CustomEntity)selectedEntity; + int[] data = new int[box.data.length]; + for(int i = 0; i < data.length; i++){ + data[i] = box.data[i]; + } + Dimension collision = null; + if(box.collision != null) collision = new Dimension(box.collision.width, box.collision.height); + project.currentScene.entities.add(new CustomEntity(box.position.copy(), collision, data, box.name)); + selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1); + } + break; + case 2: + if(selectedEntity instanceof BoxColl){ + try{ + int[] data = new int[3]; + for(int i = 0; i < 3; i++){ + String input = JOptionPane.showInputDialog(panel, "Enter data[" + i + "]", "Trident", JOptionPane.QUESTION_MESSAGE); + data[i] = Integer.parseInt(input); + } + BoxColl box = (BoxColl)selectedEntity; + box.color = new Color(data[0], data[1], data[2]); + }catch(Exception e){} + } + if(selectedEntity instanceof BoxNoColl){ + try{ + int[] data = new int[3]; + for(int i = 0; i < 3; i++){ + String input = JOptionPane.showInputDialog(panel, "Enter data[" + i + "]", "Trident", JOptionPane.QUESTION_MESSAGE); + data[i] = Integer.parseInt(input); + } + BoxNoColl box = (BoxNoColl)selectedEntity; + box.color = new Color(data[0], data[1], data[2]); + }catch(Exception e){} + } + if(selectedEntity instanceof CustomEntity){ + try{ + CustomEntity c = (CustomEntity)selectedEntity; + int[] data = new int[c.data.length]; + for(int i = 0; i < c.data.length; i++){ + String input = JOptionPane.showInputDialog(panel, "Enter data[" + i + "]", "Trident", JOptionPane.QUESTION_MESSAGE); + data[i] = Integer.parseInt(input); + } + c.data = data; + }catch(Exception e){} + } + if(selectedEntity instanceof Trigger){ + try{ + int[] data = new int[1]; + for(int i = 0; i < 1; i++){ + String input = JOptionPane.showInputDialog(panel, "Enter data[" + i + "]", "Trident", JOptionPane.QUESTION_MESSAGE); + data[i] = Integer.parseInt(input); + } + Trigger box = (Trigger)selectedEntity; + box.id = data[0]; + }catch(Exception e){} + } + break; + case 3: + Position worldPos = cam.mouseToPos(new Point(dropRect.x, dropRect.y)); + selectedEntity.position = worldPos; + break; + } + } + if(dropType == 2){ + Position worldPos = cam.mouseToPos(new Point(dropRect.x, dropRect.y)); + switch(sel){ + case 0: + project.currentScene.entities.add(new BoxNoColl(worldPos, Color.black, 100, 100)); + break; + case 1: + project.currentScene.entities.add(new BoxColl(worldPos, new Dimension(100, 100), Color.black)); + break; + case 2: + project.currentScene.entities.add(new InvisColl(worldPos, new Dimension(100, 100))); + break; + case 3: + project.currentScene.entities.add(new PlrStart(worldPos)); + break; + case 4: + try{ + String input = JOptionPane.showInputDialog(panel, "Enter the ID for the trigger", "Trident", JOptionPane.QUESTION_MESSAGE); + int id = Integer.parseInt(input); + project.currentScene.entities.add(new Trigger(worldPos, new Dimension(100, 100), id)); + }catch(Exception e){} + break; + case 5: + String name = JOptionPane.showInputDialog(panel, "Enter the object name", "Trident", JOptionPane.QUESTION_MESSAGE); + if(name != null){ + int coll = JOptionPane.showConfirmDialog(panel, "Does the object have collision?", "Trident", JOptionPane.YES_NO_CANCEL_OPTION); + if(coll == 2) break; + Dimension collider = null; + if(coll == 0) collider = new Dimension(100, 100); + + String input = JOptionPane.showInputDialog(panel, "Enter the amount of data you need", "Trident", JOptionPane.QUESTION_MESSAGE); + try{ + int numData = Integer.parseInt(input); + int[] data = new int[numData]; + for(int i = 0; i < numData; i++){ + String dataStr = JOptionPane.showInputDialog(panel, "Enter data[" + i + "]", "Trident", JOptionPane.QUESTION_MESSAGE); + data[i] = Integer.parseInt(dataStr); + } + project.currentScene.entities.add(new CustomEntity(worldPos, collider, data, name)); + System.out.println("created entity"); + }catch(Exception e){ + e.printStackTrace(); + dropDown = false; + return; + } + } + break; + case 6: + project.currentScene.entities.add(new project.ent.Light(worldPos, 50)); + break; + } + } + + dropDown = false; + return; + }else{ + dropDown = false; + return; + } + } + + if(mousePos.y < 40){ + System.out.println(mousePos.x); + // Toolbar + if(mousePos.x < 40){ + dropDown = true; + dropType = 0; + dropRect = new Rectangle(0, 40, 200, 32 * 7); + }else if(mousePos.x < 90){ + BTools.openHighlightFile(new File("data/projects/" + project.name).getAbsolutePath()); + }else if(mousePos.x < 212){ + String name = JOptionPane.showInputDialog(panel, "Enter the scene name", "Trident", JOptionPane.QUESTION_MESSAGE); + if(name != null){ + boolean loaded = project.loadScene(name); + if(!loaded){ + JOptionPane.showMessageDialog(panel, "Error: no scene with name '" + name + "' found.", "Trident", JOptionPane.ERROR_MESSAGE); + }else{ + cam.pos = new Position(); + } + } + }else if(mousePos.x < 327){ + String name = JOptionPane.showInputDialog(panel, "Enter the scene name", "Trident", JOptionPane.QUESTION_MESSAGE); + if(name != null){ + Scene scene = new Scene(name); + scene.save("data/projects/" + project.name); + project.setupScenes(); + project.loadScene(name); + cam.pos = new Position(); + } + }else if(mousePos.x < 391){ + project.currentScene.save("data/projects/" + project.name); + saveTime = 1000; + }else if(mousePos.x < 520){ + project.currentScene.plrDir++; + if(project.currentScene.plrDir > 3) project.currentScene.plrDir = 0; + }else{ + try{ + double x, y; + String inputX = JOptionPane.showInputDialog(panel, "Enter the x position", "Trident", JOptionPane.QUESTION_MESSAGE); + if(inputX != null){ + x = Double.parseDouble(inputX); + String inputY = JOptionPane.showInputDialog(panel, "Enter the y position", "Trident", JOptionPane.QUESTION_MESSAGE); + if(inputY != null){ + y = Double.parseDouble(inputY); + cam.pos = new Position(x, y); + } + } + }catch(Exception e){ + JOptionPane.showMessageDialog(panel, "Invalid input", "Trident", JOptionPane.ERROR_MESSAGE); + } + + + } + }else{ + if(tool == 0){ + if(selectedEntity != null){ + selectedEntity = null; + } + Position worldPos = cam.mouseToPos(mousePos); + for(TridEntity e: project.currentScene.entities){ + if(BTools.getDistance(e.position, worldPos) < 32){ + selectedEntity = e; + return; + } + } + } + } + } + + if(mb == 3){ + if(selectedEntity == null){ + dropDown = true; + dropType = 2; + dropRect = new Rectangle(mousePos.x, mousePos.y, 200, 32 * 7); + }else{ + dropDown = true; + dropType = 1; + dropRect = new Rectangle(mousePos.x, mousePos.y, 200, 32 * 4); + } + } + + } + } + + MainPanel parent = this; + private class ServerListener implements ActionListener{ + public void actionPerformed(ActionEvent event){ + + Point delta = new Point(-mouse.x + frameManager.getMousePos(parent, km.getMousePos()).x, -mouse.y + frameManager.getMousePos(parent, km.getMousePos()).y); + mouse = frameManager.getMousePos(parent, km.getMousePos()); + + // Movement + Point dir = new Point(); + if(km.getKeyDown(KeyEvent.VK_W)) dir.y--; + if(km.getKeyDown(KeyEvent.VK_S)) dir.y++; + if(km.getKeyDown(KeyEvent.VK_A)) dir.x--; + if(km.getKeyDown(KeyEvent.VK_D)) dir.x++; + double speed = 0.5; + if(km.getKeyDown(KeyEvent.VK_SHIFT)) speed *= 2; + if(km.getKeyDown(KeyEvent.VK_CONTROL)) speed /= 2; + cam.pos.x += dir.x * server.getElapsedTime() * speed; + cam.pos.y += dir.y * server.getElapsedTime() * speed; + + + + saveTime -= server.getElapsedTime(); + if(saveTime < 0) saveTime = 0; + + if(tool == 1 && selectedEntity != null && km.getMouseDown(1)){ + selectedEntity.position.x += delta.x; + selectedEntity.position.y += delta.y; + + + selectedEntity.position.x += dir.x * server.getElapsedTime() * speed; + selectedEntity.position.y += dir.y * server.getElapsedTime() * speed; + } + if(tool == 2 && selectedEntity != null && km.getMouseDown(1)){ + if(selectedEntity instanceof project.ent.Light){ + project.ent.Light light = (project.ent.Light)selectedEntity; + light.radius += delta.x; + if(light.radius < 0) light.radius = 0; + } + if(selectedEntity instanceof BoxNoColl){ + BoxNoColl box = (BoxNoColl)selectedEntity; + box.width += delta.x; + box.height -= delta.y; + if(box.width < 0) box.width = 0; + if(box.height < 0) box.height = 0; + } + if(selectedEntity instanceof Trigger){ + Trigger trig = (Trigger)selectedEntity; + trig.box.width += delta.x; + trig.box.height -= delta.y; + if(trig.box.width < 0) trig.box.width = 0; + if(trig.box.height < 0) trig.box.height = 0; + } + if(selectedEntity.HASCOLLISION){ + selectedEntity.collision.width += delta.x; + selectedEntity.collision.height -= delta.y; + if(selectedEntity.collision.width < 0) selectedEntity.collision.width = 0; + if(selectedEntity.collision.height < 0) selectedEntity.collision.height = 0; + } + } + + setCursor(cursors[tool]); + + repaint(); + } + } +} diff --git a/src/project/Project.java b/src/project/Project.java new file mode 100644 index 0000000..9880a57 --- /dev/null +++ b/src/project/Project.java @@ -0,0 +1,157 @@ +package project; + +import java.io.*; +import blib.util.*; +import java.util.ArrayList; + +import javax.swing.JOptionPane; + +import blib.bson.*; +public class Project { + + public static String[] projRegistry = null; + + public static final int BLANK2D = 1, BLANK3D = 2, CUSTOM = 3; + + public String name; + public ArrayList loadedScenes = new ArrayList(); + public Scene currentScene = new Scene("Empty Scene"); + + public Project(int proj){ // Load from file + name = projRegistry[proj]; + setupScenes(); + currentScene = loadedScenes.get(0); + } + public Project(String name, int t, String customTemp){ // New project + + this.name = name; + + String template = ""; + switch(t){ + case BLANK2D: + template = "blank2d"; + break; + case BLANK3D: + template = "blank3d"; + break; + case CUSTOM: + template = customTemp; + File f = new File("data/templates/" + template); + if(!f.exists()){ + JOptionPane.showMessageDialog(null, "Template '" + customTemp + "' not found. Falling back to blank2d.", "Trident", JOptionPane.ERROR_MESSAGE); + template = "blank2d"; + } + break; + } + + + try{ + // libraries + copyDirectory(new File("data/libraries/"), new File("data/projects/" + name + "/lib/")); + + // src + copyDirectory(new File("data/templates/" + template + "/src/"), new File("data/projects/" + name + "/src/")); + + // data + copyDirectory(new File("data/templates/" + template + "/data/"), new File("data/projects/" + name + "/data/")); + }catch(Exception e){ + System.out.println("ruh roh raggy"); + e.printStackTrace(); + System.exit(1); + } + + + + setupScenes(); + currentScene = loadedScenes.get(0); + } + + public static void loadRegistry(){ + ArrayList objects = BSonParser.readFile("data/projectRegistry.bson"); + BSonObject obj = BSonParser.getObject("projects", objects); + BSonList asList = (BSonList)obj; + projRegistry = new String[asList.list.size()]; + for(int i = 0; i < asList.list.size(); i++){ + projRegistry[i] = asList.list.get(i).getString(); + } + } + + public static void saveRegistry(){ + try{ + File file = new File("data/projectRegistry.bson"); + file.createNewFile(); + PrintWriter writer = new PrintWriter(file); + writer.println("{ projects"); + for(String s: projRegistry){ + writer.println("string " + s); + } + writer.println("}"); + writer.close(); + }catch(Exception e){e.printStackTrace();} + } + + public void setupScenes(){ + try{ + loadedScenes = new ArrayList(); + File dir = new File("data/projects/" + name + "/data/scenes"); + File[] files = dir.listFiles(); + ArrayList sceneFiles = new ArrayList(); + for(File f: files){ + if(BTools.hasExtension(f, "bson")) sceneFiles.add(f); + } + + for(File f: sceneFiles){ + loadedScenes.add(new Scene(f)); + } + }catch(Exception e){ + System.out.println("Error setting up scenes."); + e.printStackTrace(); + } + + } + + public boolean loadScene(String name){ + for(Scene s: loadedScenes){ + if(s.name.equals(name)){ + currentScene = s; + return true; + } + } + System.out.println("***********************************************************************************"); + System.out.println("Error loading scene: No scene with name '" + name + "' found."); + System.out.println("***********************************************************************************"); + return false; + } + + + + + + // you made this? i made this. + private static void copyDirectory(File sourceDirectory, File destinationDirectory) throws IOException { + if (!destinationDirectory.exists()) { + destinationDirectory.mkdirs(); + } + for (String f : sourceDirectory.list()) { + copyDirectoryCompatibityMode(new File(sourceDirectory, f), new File(destinationDirectory, f)); + } + } + public static void copyDirectoryCompatibityMode(File source, File destination) throws IOException { + if (source.isDirectory()) { + copyDirectory(source, destination); + } else { + copyFile(source, destination); + } + } + private static void copyFile(File sourceFile, File destinationFile) throws IOException { + try (InputStream in = new FileInputStream(sourceFile); + OutputStream out = new FileOutputStream(destinationFile)) { + byte[] buf = new byte[1024]; + int length; + while ((length = in.read(buf)) > 0) { + out.write(buf, 0, length); + } + } + } + +} diff --git a/src/project/Scene.java b/src/project/Scene.java new file mode 100644 index 0000000..969f5c5 --- /dev/null +++ b/src/project/Scene.java @@ -0,0 +1,181 @@ +package project; + +import java.util.ArrayList; +import java.awt.*; +import java.io.*; +import blib.bson.*; +import blib.util.*; +import blib.game.*; +import project.ent.*; +public class Scene { + + public final String name; + public ArrayList entities; + protected Position plrStart = new Position(); + public int plrDir = Player.SOUTH; + public Color bgColor = Color.white; + private TridEntity[] entRegistry = { + new BoxColl(), + new BoxNoColl(), + new InvisColl(), + new PlrStart(), + new Trigger(), + new project.ent.Light(), + }; + public int defaultLight = 255; + + public Scene(String n){ // Empty scene + name = n; + entities = new ArrayList(); + } + public Scene(File f) throws IOException{ + entities = new ArrayList(); + ArrayList objects = BSonParser.readFile(f.getAbsolutePath()); + BSonObject obj = BSonParser.getObject("name", objects); + name = obj.getString(); + obj = BSonParser.getObject("dir", objects); + if(obj != null){ + String str = obj.getString(); + if(str.equals("west")) plrDir = Player.WEST; + if(str.equals("north")) plrDir = Player.NORTH; + if(str.equals("east")) plrDir = Player.EAST; + } + obj = BSonParser.getObject("bgColor", objects); + BSonList asList = (BSonList)obj; + int r, g, b; + r = asList.list.get(0).getInt(); + g = asList.list.get(1).getInt(); + b = asList.list.get(2).getInt(); + bgColor = new Color(r, g, b); + obj = BSonParser.getObject("light", objects); + defaultLight = obj.getInt(); + obj = BSonParser.getObject("entities", objects); + asList = (BSonList)obj; + for(int i = 0; i < asList.list.size(); i++){ + String objName = asList.list.get(i).getString(); + i++; + boolean foundEnt = false; + for(TridEntity e: entRegistry){ + if(e.name.equals(objName)){ + double x, y; + x = asList.list.get(i).getDouble(); + i++; + y = asList.list.get(i).getDouble(); + i++; + int w = 0, h = 0; + i++; + if(e.HASCOLLISION){ + w = asList.list.get(i).getInt(); + i++; + h = asList.list.get(i).getInt(); + i++; + } + int[] data = new int[e.numData]; + for(int j = 0; j < e.numData; j++){ + data[j] = asList.list.get(i).getInt(); + i++; + } + i--; + entities.add(e.construct(new Position(x, y), (e.HASCOLLISION ? (new Dimension(w, h)) : null), data)); + foundEnt = true; + break; + } + } + if(!foundEnt){ + double x, y; + x = asList.list.get(i).getDouble(); + i++; + y = asList.list.get(i).getDouble(); + i++; + int w = 0, h = 0; + boolean hasColl = asList.list.get(i).getBoolean(); + i++; + if(hasColl){ + w = asList.list.get(i).getInt(); + i++; + h = asList.list.get(i).getInt(); + i++; + } + + int[] data = new int[0]; + while(i < asList.list.size() && asList.list.get(i).type == BSonObject.INT){ + int[] newData = new int[data.length + 1]; + for(int j = 0; j < data.length; j++) newData[j] = data[j]; + newData[data.length] = asList.list.get(i).getInt(); + data = newData; + i++; + } + entities.add(new CustomEntity(new Position(x, y), new Dimension(w, h), data, objName)); + i--; + } + } + } + + public String getDir(){ + if(plrDir == Player.SOUTH) return "south"; + if(plrDir == Player.EAST) return "east"; + if(plrDir == Player.WEST) return "west"; + if(plrDir == Player.NORTH) return "north"; + return "unknown direction"; + } + + public void save(String projDir){ + try{ + File file = new File(projDir + "/data/scenes/" + name + ".bson"); + file.createNewFile(); + PrintWriter writer = new PrintWriter(file); + writer.println("string name " + name); + writer.println("string dir " + getDir()); + writer.println("int light " + defaultLight); + writer.println("{ bgColor"); + writer.println("int " + bgColor.getRed()); + writer.println("int " + bgColor.getGreen()); + writer.println("int " + bgColor.getBlue()); + writer.println("}"); + writer.println("{ entities"); + for(TridEntity e: entities){ + writer.println("string " + e.name); + writer.println("double " + e.position.x); + writer.println("double " + e.position.y); + writer.println("boolean " + e.HASCOLLISION); + if(e.HASCOLLISION){ + writer.println("int " + e.getCollision().width); + writer.println("int " + e.getCollision().height); + } + if(e instanceof BoxNoColl){ + BoxNoColl box = (BoxNoColl)e; + writer.println("int " + box.width); + writer.println("int " + box.height); + writer.println("int " + box.color.getRed()); + writer.println("int " + box.color.getGreen()); + writer.println("int " + box.color.getBlue()); + } + if(e instanceof BoxColl){ + BoxColl box = (BoxColl)e; + writer.println("int " + box.color.getRed()); + writer.println("int " + box.color.getGreen()); + writer.println("int " + box.color.getBlue()); + } + if(e instanceof Trigger){ + Trigger trig = (Trigger)e; + writer.println("int " + trig.box.width); + writer.println("int " + trig.box.height); + writer.println("int " + trig.id); + } + if(e instanceof project.ent.Light){ + project.ent.Light light = (project.ent.Light)e; + writer.println("int " + light.radius); + } + if(e instanceof CustomEntity){ + CustomEntity custom = (CustomEntity)e; + for(int i: custom.data){ + writer.println("int " + i); + } + } + } + writer.println("}"); + writer.close(); + }catch(Exception e){} + } + +} diff --git a/src/project/TridEntity.java b/src/project/TridEntity.java new file mode 100644 index 0000000..fc5076d --- /dev/null +++ b/src/project/TridEntity.java @@ -0,0 +1,65 @@ +package project; + +import blib.game.*; +import blib.util.*; + +import javax.swing.*; +import java.awt.*; +public class TridEntity extends Entity { + + public final boolean HASCOLLISION; + public Dimension collision; + public String engineRenderData = ""; + private ImageIcon engineImg = new ImageIcon("data/images/trident/customEnt.png"); + public String name; + protected int numData; + + public TridEntity(Position pos){ + super(pos); + HASCOLLISION = false; + collision = null; + } + public TridEntity(Position pos, Dimension collision){ + super(pos); + if(collision == null || collision.equals(new Dimension(0, 0))) HASCOLLISION = false; + else HASCOLLISION = true; + this.collision = collision; + } + public TridEntity(String n, boolean hasColl, int numData){ + super(new Position()); + HASCOLLISION = hasColl; + collision = null; + name = n; + this.numData = numData; + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + System.out.println("Error: tried to create an empty entity"); + return null; + } + + public final Rectangle getCollision(){ + return new Rectangle((int)position.x - (collision.width / 2), (int)position.y - (collision.height / 2), collision.width, collision.height); + } + + public void gameStart(){ + + } + + public void render(Graphics g, JPanel panel, int x, int y){ + + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + if(HASCOLLISION){ + g.setColor(Color.red); + g.drawRect(x - getCollision().width / 2, y - getCollision().height / 2, getCollision().width, getCollision().height); + g.drawLine(x - getCollision().width / 2, y - getCollision().height / 2, x + getCollision().width / 2, y + getCollision().height / 2); + } + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } + + public void update(long elapsedTime){ + + } + +} diff --git a/src/project/ent/BoxColl.java b/src/project/ent/BoxColl.java new file mode 100644 index 0000000..8dff658 --- /dev/null +++ b/src/project/ent/BoxColl.java @@ -0,0 +1,39 @@ +package project.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import project.*; +public class BoxColl extends TridEntity{ + + public Color color = Color.white; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/boxColl.png"); + + public BoxColl(Position pos, Dimension size, Color c){ + super(pos, size); + color = c; + name = "boxcoll"; + } + public BoxColl(Position pos, Dimension size){ + super(pos, size); + name = "boxcoll"; + } + public BoxColl(){ + super("boxcoll", true, 3); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new BoxColl(pos, collision, new Color(data[0], data[1], data[2])); + } + + public void render(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.fillRect(x - getCollision().width / 2, y - getCollision().height / 2, getCollision().width, getCollision().height); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + render(g, panel, x, y); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/src/project/ent/BoxNoColl.java b/src/project/ent/BoxNoColl.java new file mode 100644 index 0000000..097a561 --- /dev/null +++ b/src/project/ent/BoxNoColl.java @@ -0,0 +1,47 @@ +package project.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; +import blib.game.*; + +import project.*; +public class BoxNoColl extends TridEntity{ + + public Color color = Color.white; + public int width, height; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/box.png"); + + public BoxNoColl(Position pos, Color c, int w, int h){ + super(pos); + color = c; + width = w; + height = h; + renderType = Entity.UNDER; + name = "boxnocoll"; + } + public BoxNoColl(Position pos, int w, int h){ + super(pos); + width = w; + height = h; + renderType = Entity.UNDER; + name = "boxnocoll"; + } + public BoxNoColl(){ + super("boxnocoll", false, 5); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new BoxNoColl(pos, new Color(data[2], data[3], data[4]), data[0], data[1]); + } + + public void render(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.fillRect(x - width / 2, y - height / 2, width, height); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + render(g, panel, x, y); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/src/project/ent/CustomEntity.java b/src/project/ent/CustomEntity.java new file mode 100644 index 0000000..cfb152a --- /dev/null +++ b/src/project/ent/CustomEntity.java @@ -0,0 +1,18 @@ +package project.ent; + +import blib.util.*; +import project.*; +import java.awt.*; +public class CustomEntity extends TridEntity{ + + public int[] data; + + public CustomEntity(Position pos, Dimension d, int[] dat, String n){ + super(pos, d); + data = dat; + name = n; + } + public CustomEntity(){ + super("custom", false, 0); + } +} diff --git a/src/project/ent/InvisColl.java b/src/project/ent/InvisColl.java new file mode 100644 index 0000000..db3c5f0 --- /dev/null +++ b/src/project/ent/InvisColl.java @@ -0,0 +1,31 @@ +package project.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import project.*; +public class InvisColl extends TridEntity{ + + public Color color = Color.red; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/collision.png"); + + public InvisColl(Position pos, Dimension size){ + super(pos, size); + name = "inviscoll"; + } + public InvisColl(){ + super("inviscoll", true, 0); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new InvisColl(pos, collision); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.drawRect(x - getCollision().width / 2, y - getCollision().height / 2, getCollision().width, getCollision().height); + g.drawLine(x - getCollision().width / 2, y - getCollision().height / 2, x + getCollision().width / 2, y + getCollision().height / 2); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/src/project/ent/Light.java b/src/project/ent/Light.java new file mode 100644 index 0000000..3420427 --- /dev/null +++ b/src/project/ent/Light.java @@ -0,0 +1,31 @@ +package project.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import project.*; +public class Light extends TridEntity{ + + public int radius; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/light.png"); + + public Light(Position pos, int r){ + super(pos); + name = "light"; + radius = r; + } + public Light(){ + super("light", false, 1); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new Light(pos, data[0]); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + g.setColor(Color.red); + g.drawOval(x - radius, y - radius, radius * 2, radius * 2); + } +} diff --git a/src/project/ent/PlrStart.java b/src/project/ent/PlrStart.java new file mode 100644 index 0000000..095a2a8 --- /dev/null +++ b/src/project/ent/PlrStart.java @@ -0,0 +1,27 @@ +package project.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import project.*; +public class PlrStart extends TridEntity{ + public Color color = Color.red; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/plrStart.png"); + + public PlrStart(Position pos){ + super(pos); + name = "plrstart"; + } + public PlrStart(){ + super("plrstart", false, 0); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new PlrStart(pos); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/src/project/ent/Trigger.java b/src/project/ent/Trigger.java new file mode 100644 index 0000000..38e775f --- /dev/null +++ b/src/project/ent/Trigger.java @@ -0,0 +1,35 @@ +package project.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import project.*; +public class Trigger extends TridEntity{ + + public Color color = Color.blue; + public Dimension box; + public int id; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/trigger.png"); + + public Trigger(Position pos, Dimension size, int i){ + super(pos); + name = "trigger"; + box = size; + id = i; + } + public Trigger(){ + super("trigger", false, 3); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new Trigger(pos, new Dimension(data[0], data[1]), data[2]); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.drawRect(x - box.width / 2, y - box.height / 2, box.width, box.height); + g.drawLine(x - box.width / 2, y - box.height / 2, x + box.width / 2, y + box.height / 2); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +}