v10
BIN
data/images/trident/tilemap.png
Normal file
After Width: | Height: | Size: 372 B |
|
@ -1,4 +1,2 @@
|
|||
{ projects
|
||||
string new scene stuff makings
|
||||
string 3d
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
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
|
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 356 KiB |
Before Width: | Height: | Size: 363 KiB |
Before Width: | Height: | Size: 156 B |
Before Width: | Height: | Size: 173 B |
Before Width: | Height: | Size: 170 B |
Before Width: | Height: | Size: 163 B |
Before Width: | Height: | Size: 376 B |
Before Width: | Height: | Size: 403 B |
Before Width: | Height: | Size: 397 B |
Before Width: | Height: | Size: 361 B |
Before Width: | Height: | Size: 356 KiB |
Before Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 126 KiB |
Before Width: | Height: | Size: 113 KiB |
Before Width: | Height: | Size: 134 KiB |
Before Width: | Height: | Size: 432 B |
Before Width: | Height: | Size: 459 B |
Before Width: | Height: | Size: 333 B |
Before Width: | Height: | Size: 588 KiB |
Before Width: | Height: | Size: 486 B |
Before Width: | Height: | Size: 333 B |
Before Width: | Height: | Size: 444 B |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 333 B |
|
@ -1,13 +0,0 @@
|
|||
{ wallTextures
|
||||
string dirtymetal.jpg
|
||||
string panel.jpg
|
||||
string warning.jpg
|
||||
string door.jpg
|
||||
}
|
||||
{ npcTextures
|
||||
string station.png
|
||||
string puter.png
|
||||
}
|
||||
{ propTextures
|
||||
string puter.png
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
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
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
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<Dialog> dialogs = new ArrayList<Dialog>();
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package custom;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import blib.b3d.*;
|
||||
import blib.util.*;
|
||||
public class WallManager {
|
||||
|
||||
public static ArrayList<Wall> walls = null;
|
||||
public static Camera camera = new Camera(new Position(), 0);
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
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){
|
||||
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
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<BSonObject> 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;
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
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<BSonObject> 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;
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
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<BSonObject> 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;
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
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<BSonObject> 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;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package trident;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class Main{
|
||||
public static JFrame window = new JFrame("3D Trident Project");
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -1,229 +0,0 @@
|
|||
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;
|
||||
public 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(){
|
||||
|
||||
Trident.panel = this;
|
||||
|
||||
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<Animation> anims = new ArrayList<Animation>();
|
||||
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);
|
||||
Update.tridentEvent(Trident.EVENT_FULLSCREEN);
|
||||
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){}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,152 +0,0 @@
|
|||
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<ArrayList<Entity>> 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<Rectangle> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,120 +0,0 @@
|
|||
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 boolean loaded = false;
|
||||
public String filePath = null;
|
||||
public ArrayList<TridEntity> 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<TridEntity>();
|
||||
loaded = true;
|
||||
}
|
||||
public Scene(File f){
|
||||
filePath = f.getAbsolutePath();
|
||||
|
||||
ArrayList<BSonObject> objects = BSonParser.readFile(filePath);
|
||||
BSonObject obj = BSonParser.getObject("name", objects);
|
||||
name = obj.getString();
|
||||
}
|
||||
|
||||
public void preload(){
|
||||
entities = new ArrayList<TridEntity>();
|
||||
ArrayList<BSonObject> objects = BSonParser.readFile(filePath);
|
||||
BSonObject 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;
|
||||
}
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
public void unload(){
|
||||
entities = null;
|
||||
loaded = false;
|
||||
}
|
||||
|
||||
public static Scene loadScene(String path){ // stub method ::: Load a scene from a file
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArrayList<Rectangle> getCollision(){
|
||||
ArrayList<Rectangle> collision = new ArrayList<Rectangle>();
|
||||
for(int i = 0; i < entities.size(); i++){
|
||||
TridEntity e = entities.get(i);
|
||||
if(e.HASCOLLISION){
|
||||
collision.add(e.getCollision());
|
||||
}
|
||||
}
|
||||
|
||||
return collision;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,599 +0,0 @@
|
|||
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;
|
||||
public static boolean captureCursor = false;
|
||||
public static MainPanel panel = null;
|
||||
|
||||
|
||||
// Trident Variables
|
||||
protected static Player player;
|
||||
protected static Scene currentScene;
|
||||
protected static boolean fullscreen = false;
|
||||
protected static ArrayList<Scene> loadedScenes = new ArrayList<Scene>();
|
||||
protected static ArrayList<TridEntity> entRegistry = new ArrayList<TridEntity>();
|
||||
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<Entity> lights = new ArrayList<Entity>();
|
||||
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, EVENT_FULLSCREEN = 1;
|
||||
|
||||
|
||||
// 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<Scene>();
|
||||
File dir = new File("data/scenes");
|
||||
File[] files = dir.listFiles();
|
||||
ArrayList<File> sceneFiles = new ArrayList<File>();
|
||||
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){
|
||||
loadScene(name, false);
|
||||
}
|
||||
public static void loadScene(String name, boolean unload){
|
||||
lights = new ArrayList<Entity>();
|
||||
for(Scene s: loadedScenes){
|
||||
if(s.name.equals(name)){
|
||||
Scene oldScene = currentScene;
|
||||
|
||||
if(!s.loaded) s.preload();
|
||||
currentScene = s;
|
||||
if(unload) oldScene.unload();
|
||||
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 unloadScene(String name){
|
||||
for(Scene s: loadedScenes){
|
||||
if(s.name.equals(name)){
|
||||
if(s.equals(currentScene)){
|
||||
printError("ERROR: tried to unload current scene");
|
||||
return;
|
||||
}else{
|
||||
s.unload();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
printConsole("***********************************************************************************");
|
||||
printConsole("Error unloading scene: No scene with name '" + name + "' found.");
|
||||
printError("***********************************************************************************");
|
||||
}
|
||||
public static void preloadScene(String name){
|
||||
for(Scene s: loadedScenes){
|
||||
if(s.name.equals(name)){
|
||||
s.preload();
|
||||
return;
|
||||
}
|
||||
}
|
||||
printConsole("***********************************************************************************");
|
||||
printConsole("Error preloading 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<Entity> tridArrToEntArr(ArrayList<TridEntity> entities){
|
||||
ArrayList<Entity> newEntities = new ArrayList<Entity>();
|
||||
for(TridEntity e: entities){
|
||||
newEntities.add((Entity)e);
|
||||
}
|
||||
return newEntities;
|
||||
}
|
||||
public static ArrayList<TridEntity> entArrToTridArr(ArrayList<Entity> entities){
|
||||
ArrayList<TridEntity> newEntities = new ArrayList<TridEntity>();
|
||||
for(Entity e: entities){
|
||||
newEntities.add((TridEntity)e);
|
||||
}
|
||||
return newEntities;
|
||||
}
|
||||
public static ArrayList<TridEntity> getEntities(){
|
||||
return currentScene.entities;
|
||||
}
|
||||
public static ArrayList<Rectangle> 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<String> consoleLines = new ArrayList<String>();
|
||||
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<String> cmdParts = new ArrayList<String>();
|
||||
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<String>();
|
||||
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 <TYPE 'openItch' TO GO TO SITE>");
|
||||
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;
|
||||
case "trigger":
|
||||
int trig = Integer.parseInt(cmdParts.get(1));
|
||||
Update.trigger(trig);
|
||||
printConsole("ran trigger " + trig);
|
||||
break;
|
||||
case "mapList":
|
||||
page = 1;
|
||||
if(cmdParts.size() > 1) page = Integer.parseInt(cmdParts.get(1));
|
||||
printMaps(page);
|
||||
break;
|
||||
case "unloadMap":
|
||||
unloadScene(cmdParts.get(1));
|
||||
break;
|
||||
case "preloadMap":
|
||||
preloadScene(cmdParts.get(1));
|
||||
break;
|
||||
case "currentMap":
|
||||
printConsole("Current map: " + currentScene.name);
|
||||
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 <x> <y>",
|
||||
"loadMap <name>",
|
||||
"drawFrames [0/1, false/true]",
|
||||
"debugColor <r> <g> <b> [a]",
|
||||
"enableBloom [0/1, false/true]",
|
||||
"enableExposure [0/1, false/true]",
|
||||
"setBloom <amount>",
|
||||
"setExposure <amount>",
|
||||
"setLightBlur <amount>",
|
||||
"clear",
|
||||
"help [page]",
|
||||
"customHelp [page]",
|
||||
"errorTest",
|
||||
"roll",
|
||||
"trigger <trig>",
|
||||
"mapList [page]",
|
||||
"unloadMap <name>",
|
||||
"preloadMap <name>",
|
||||
"currentMap",
|
||||
};
|
||||
|
||||
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 printMaps(int page){
|
||||
int startIndex = (page - 1) * 10;
|
||||
if(startIndex > loadedScenes.size() - 1){
|
||||
printConsole("page beyond bounds: " + page);
|
||||
printConsole("number of pages: " + (loadedScenes.size() / 10 + ((loadedScenes.size() % 10 != 0) ? 1 : 0)));
|
||||
return;
|
||||
}
|
||||
|
||||
printConsole("-- MAPS --");
|
||||
printConsole("Page " + page + " of " + (loadedScenes.size() / 10 + ((loadedScenes.size() % 10 != 0) ? 1 : 0)));
|
||||
printConsole("");
|
||||
for(int i = startIndex; (i < loadedScenes.size() && i < startIndex + 10); i++){
|
||||
Scene s = loadedScenes.get(i);
|
||||
String str = "";
|
||||
if(!s.loaded) str += " [UNLOADED]";
|
||||
if(s.equals(currentScene)) str += " [CURRENT]";
|
||||
printConsole("} " + s.name + str);
|
||||
}
|
||||
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("");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
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_ESCAPE){
|
||||
Trident.captureCursor = false;
|
||||
}
|
||||
// if(key == KeyEvent.VK_DOWN) Rend3D.offset++;
|
||||
// if(key == KeyEvent.VK_UP) Rend3D.offset--;
|
||||
}
|
||||
}
|
||||
|
||||
public static void mousePressed(int mb, Point mousePos, Position worldPos){
|
||||
Trident.captureCursor = true;
|
||||
}
|
||||
|
||||
public static void onScroll(int scroll){
|
||||
|
||||
}
|
||||
}
|
|
@ -1,205 +0,0 @@
|
|||
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<Wall>();
|
||||
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){
|
||||
int mouseDelta = 0;
|
||||
if(Trident.captureCursor){
|
||||
int startX = Trident.panel.km.getMousePos().x;
|
||||
Point p = new Point(Main.window.getWidth() / 2 + Main.window.getX(), Main.window.getHeight() / 2 + Main.window.getY());
|
||||
mouseDelta = startX - Main.window.getWidth() / 2;
|
||||
if(!Trident.getFullscreen()) mouseDelta += 8;
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice[] gs = ge.getScreenDevices();
|
||||
|
||||
// Search the devices for the one that draws the specified point.
|
||||
for (GraphicsDevice device: gs) {
|
||||
GraphicsConfiguration[] configurations =
|
||||
device.getConfigurations();
|
||||
|
||||
|
||||
boolean gtfo = false;
|
||||
for (GraphicsConfiguration config: configurations) {
|
||||
Rectangle bounds = config.getBounds();
|
||||
if(bounds.contains(p)) {
|
||||
// Set point to screen coordinates.
|
||||
|
||||
try {
|
||||
Robot r = new Robot(device);
|
||||
r.mouseMove(p.x, p.y);
|
||||
} catch (AWTException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
gtfo = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(gtfo) break;
|
||||
}
|
||||
|
||||
Trident.panel.setCursor(BTools.getBlankCursor());
|
||||
}else{
|
||||
Trident.panel.setCursor(Cursor.getDefaultCursor());
|
||||
}
|
||||
|
||||
Trident.setPlrSpeed(0);
|
||||
if(HUD.currentDialog == null){ // only move when there's no dialog
|
||||
|
||||
if(Trident.captureCursor) WallManager.camera.direction += Math.toRadians(mouseDelta * 0.007) * 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<String> 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",
|
||||
};
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
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
|
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 156 B |
Before Width: | Height: | Size: 173 B |
Before Width: | Height: | Size: 170 B |
Before Width: | Height: | Size: 163 B |
Before Width: | Height: | Size: 376 B |
Before Width: | Height: | Size: 403 B |
Before Width: | Height: | Size: 397 B |
Before Width: | Height: | Size: 361 B |
Before Width: | Height: | Size: 432 B |
Before Width: | Height: | Size: 459 B |
Before Width: | Height: | Size: 333 B |
Before Width: | Height: | Size: 588 KiB |
Before Width: | Height: | Size: 486 B |
Before Width: | Height: | Size: 333 B |
Before Width: | Height: | Size: 444 B |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 333 B |
|
@ -1,43 +0,0 @@
|
|||
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
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
string name scene2
|
||||
string dir south
|
||||
int light 255
|
||||
{ bgColor
|
||||
int 255
|
||||
int 255
|
||||
int 255
|
||||
}
|
||||
{ entities
|
||||
string boxcoll
|
||||
double 4.0
|
||||
double -98.0
|
||||
boolean true
|
||||
int 240
|
||||
int 45
|
||||
int 255
|
||||
int 0
|
||||
int 0
|
||||
string boxnocoll
|
||||
double 5.0
|
||||
double 16.0
|
||||
boolean false
|
||||
int 311
|
||||
int 186
|
||||
int 0
|
||||
int 0
|
||||
int 0
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
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){
|
||||
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package trident;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class Main{
|
||||
protected static JFrame window = new JFrame("2D Trident Project");
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -1,227 +0,0 @@
|
|||
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<Animation> anims = new ArrayList<Animation>();
|
||||
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);
|
||||
Update.tridentEvent(Trident.EVENT_FULLSCREEN);
|
||||
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){}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
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<ArrayList<Entity>> 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<Rectangle> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,120 +0,0 @@
|
|||
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 boolean loaded = false;
|
||||
public String filePath = null;
|
||||
public ArrayList<TridEntity> 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<TridEntity>();
|
||||
loaded = true;
|
||||
}
|
||||
public Scene(File f){
|
||||
filePath = f.getAbsolutePath();
|
||||
|
||||
ArrayList<BSonObject> objects = BSonParser.readFile(filePath);
|
||||
BSonObject obj = BSonParser.getObject("name", objects);
|
||||
name = obj.getString();
|
||||
}
|
||||
|
||||
public void preload(){
|
||||
entities = new ArrayList<TridEntity>();
|
||||
ArrayList<BSonObject> objects = BSonParser.readFile(filePath);
|
||||
BSonObject 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;
|
||||
}
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
public void unload(){
|
||||
entities = null;
|
||||
loaded = false;
|
||||
}
|
||||
|
||||
public static Scene loadScene(String path){ // stub method ::: Load a scene from a file
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArrayList<Rectangle> getCollision(){
|
||||
ArrayList<Rectangle> collision = new ArrayList<Rectangle>();
|
||||
for(int i = 0; i < entities.size(); i++){
|
||||
TridEntity e = entities.get(i);
|
||||
if(e.HASCOLLISION){
|
||||
collision.add(e.getCollision());
|
||||
}
|
||||
}
|
||||
|
||||
return collision;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,595 +0,0 @@
|
|||
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<Scene> loadedScenes = new ArrayList<Scene>();
|
||||
protected static ArrayList<TridEntity> entRegistry = new ArrayList<TridEntity>();
|
||||
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<Entity> lights = new ArrayList<Entity>();
|
||||
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, EVENT_FULLSCREEN = 1;
|
||||
|
||||
|
||||
// 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<Scene>();
|
||||
File dir = new File("data/scenes");
|
||||
File[] files = dir.listFiles();
|
||||
ArrayList<File> sceneFiles = new ArrayList<File>();
|
||||
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){
|
||||
loadScene(name, false);
|
||||
}
|
||||
public static void loadScene(String name, boolean unload){
|
||||
lights = new ArrayList<Entity>();
|
||||
for(Scene s: loadedScenes){
|
||||
if(s.name.equals(name)){
|
||||
Scene oldScene = currentScene;
|
||||
|
||||
if(!s.loaded) s.preload();
|
||||
currentScene = s;
|
||||
if(unload) oldScene.unload();
|
||||
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 unloadScene(String name){
|
||||
for(Scene s: loadedScenes){
|
||||
if(s.name.equals(name)){
|
||||
if(s.equals(currentScene)){
|
||||
printError("ERROR: tried to unload current scene");
|
||||
return;
|
||||
}else{
|
||||
s.unload();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
printConsole("***********************************************************************************");
|
||||
printConsole("Error unloading scene: No scene with name '" + name + "' found.");
|
||||
printError("***********************************************************************************");
|
||||
}
|
||||
public static void preloadScene(String name){
|
||||
for(Scene s: loadedScenes){
|
||||
if(s.name.equals(name)){
|
||||
s.preload();
|
||||
return;
|
||||
}
|
||||
}
|
||||
printConsole("***********************************************************************************");
|
||||
printConsole("Error preloading 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<Entity> tridArrToEntArr(ArrayList<TridEntity> entities){
|
||||
ArrayList<Entity> newEntities = new ArrayList<Entity>();
|
||||
for(TridEntity e: entities){
|
||||
newEntities.add((Entity)e);
|
||||
}
|
||||
return newEntities;
|
||||
}
|
||||
public static ArrayList<TridEntity> entArrToTridArr(ArrayList<Entity> entities){
|
||||
ArrayList<TridEntity> newEntities = new ArrayList<TridEntity>();
|
||||
for(Entity e: entities){
|
||||
newEntities.add((TridEntity)e);
|
||||
}
|
||||
return newEntities;
|
||||
}
|
||||
public static ArrayList<TridEntity> getEntities(){
|
||||
return currentScene.entities;
|
||||
}
|
||||
public static ArrayList<Rectangle> 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<String> consoleLines = new ArrayList<String>();
|
||||
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<String> cmdParts = new ArrayList<String>();
|
||||
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<String>();
|
||||
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 <TYPE 'openItch' TO GO TO SITE>");
|
||||
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;
|
||||
case "trigger":
|
||||
int trig = Integer.parseInt(cmdParts.get(1));
|
||||
Update.trigger(trig);
|
||||
printConsole("ran trigger " + trig);
|
||||
break;
|
||||
case "mapList":
|
||||
page = 1;
|
||||
if(cmdParts.size() > 1) page = Integer.parseInt(cmdParts.get(1));
|
||||
printMaps(page);
|
||||
break;
|
||||
case "unloadMap":
|
||||
unloadScene(cmdParts.get(1));
|
||||
break;
|
||||
case "preloadMap":
|
||||
preloadScene(cmdParts.get(1));
|
||||
break;
|
||||
case "currentMap":
|
||||
printConsole("Current map: " + currentScene.name);
|
||||
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 <x> <y>",
|
||||
"loadMap <name>",
|
||||
"drawFrames [0/1, false/true]",
|
||||
"debugColor <r> <g> <b> [a]",
|
||||
"enableBloom [0/1, false/true]",
|
||||
"enableExposure [0/1, false/true]",
|
||||
"setBloom <amount>",
|
||||
"setExposure <amount>",
|
||||
"setLightBlur <amount>",
|
||||
"clear",
|
||||
"help [page]",
|
||||
"customHelp [page]",
|
||||
"errorTest",
|
||||
"roll",
|
||||
"trigger <trig>",
|
||||
"mapList [page]",
|
||||
"unloadMap <name>",
|
||||
"preloadMap <name>",
|
||||
"currentMap",
|
||||
};
|
||||
|
||||
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 printMaps(int page){
|
||||
int startIndex = (page - 1) * 10;
|
||||
if(startIndex > loadedScenes.size() - 1){
|
||||
printConsole("page beyond bounds: " + page);
|
||||
printConsole("number of pages: " + (loadedScenes.size() / 10 + ((loadedScenes.size() % 10 != 0) ? 1 : 0)));
|
||||
return;
|
||||
}
|
||||
|
||||
printConsole("-- MAPS --");
|
||||
printConsole("Page " + page + " of " + (loadedScenes.size() / 10 + ((loadedScenes.size() % 10 != 0) ? 1 : 0)));
|
||||
printConsole("");
|
||||
for(int i = startIndex; (i < loadedScenes.size() && i < startIndex + 10); i++){
|
||||
Scene s = loadedScenes.get(i);
|
||||
String str = "";
|
||||
if(!s.loaded) str += " [UNLOADED]";
|
||||
if(s.equals(currentScene)) str += " [CURRENT]";
|
||||
printConsole("} " + s.name + str);
|
||||
}
|
||||
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("");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
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){
|
||||
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
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<String> 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",
|
||||
};
|
||||
}
|
BIN
data/templates/blank2d/data/images/trident/tilemap.png
Normal file
After Width: | Height: | Size: 372 B |
BIN
data/templates/blank3d/data/images/trident/tilemap.png
Normal file
After Width: | Height: | Size: 372 B |