This commit is contained in:
BlockManBlue 2023-12-03 20:38:26 -07:00 committed by GitHub
parent e2d0f8e5ec
commit fbef179069
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 191 additions and 22 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

View file

@ -62,6 +62,8 @@ public class MainPanel extends JPanel {
public void paintComponent(Graphics graphics){
super.paintComponent(graphics);
Graphics g = frameManager.newFrame();
frameManager.bgColor = project.currentScene.bgColor;
for(TridEntity e: project.currentScene.entities){
Point p = cam.worldToScreen(e.position);
@ -128,8 +130,10 @@ public class MainPanel extends JPanel {
TextBox.draw("Resize", g, dropRect.x + 32, dropRect.y + 16 + 64);
resetImg.paintIcon(this, g, dropRect.x, dropRect.y + 64 + 32);
TextBox.draw("Return to (0, 0)", g, dropRect.x + 32, dropRect.y + 16 + 64 + 32);
quitImg.paintIcon(this, g, dropRect.x, dropRect.y + 128);
TextBox.draw("Save and Quit", g, dropRect.x + 32, dropRect.y + 16 + 128);
editImg.paintIcon(this, g, dropRect.x, dropRect.y + 128);
TextBox.draw("Change bg color", g, dropRect.x + 32, dropRect.y + 16 + 128);
quitImg.paintIcon(this, g, dropRect.x, dropRect.y + 128 + 32);
TextBox.draw("Save and Quit", g, dropRect.x + 32, dropRect.y + 16 + 128 + 32);
}
if(dropType == 1){
deleteImg.paintIcon(this, g, dropRect.x, dropRect.y);
@ -243,6 +247,19 @@ public class MainPanel extends JPanel {
cam.pos = new Position();
break;
case 4:
try{
int r, g, b;
String input = JOptionPane.showInputDialog(panel, "Enter the red value.", "Trident", JOptionPane.QUESTION_MESSAGE);
r = Integer.parseInt(input);
input = JOptionPane.showInputDialog(panel, "Enter the green value.", "Trident", JOptionPane.QUESTION_MESSAGE);
g = Integer.parseInt(input);
input = JOptionPane.showInputDialog(panel, "Enter the blue value.", "Trident", JOptionPane.QUESTION_MESSAGE);
b = Integer.parseInt(input);
Color c = new Color(r, g, b);
project.currentScene.bgColor = c;
}catch(Exception e){}
break;
case 5:
project.currentScene.save("data/projects/" + project.name);
System.exit(0);
break;
@ -291,7 +308,7 @@ public class MainPanel extends JPanel {
try{
int[] data = new int[3];
for(int i = 0; i < 3; i++){
String input = JOptionPane.showInputDialog(null, "Enter data[" + i + "]", "Trident", JOptionPane.QUESTION_MESSAGE);
String input = JOptionPane.showInputDialog(panel, "Enter data[" + i + "]", "Trident", JOptionPane.QUESTION_MESSAGE);
data[i] = Integer.parseInt(input);
}
BoxColl box = (BoxColl)selectedEntity;
@ -302,7 +319,7 @@ public class MainPanel extends JPanel {
try{
int[] data = new int[3];
for(int i = 0; i < 3; i++){
String input = JOptionPane.showInputDialog(null, "Enter data[" + i + "]", "Trident", JOptionPane.QUESTION_MESSAGE);
String input = JOptionPane.showInputDialog(panel, "Enter data[" + i + "]", "Trident", JOptionPane.QUESTION_MESSAGE);
data[i] = Integer.parseInt(input);
}
BoxNoColl box = (BoxNoColl)selectedEntity;
@ -314,7 +331,7 @@ public class MainPanel extends JPanel {
CustomEntity c = (CustomEntity)selectedEntity;
int[] data = new int[c.data.length];
for(int i = 0; i < c.data.length; i++){
String input = JOptionPane.showInputDialog(null, "Enter data[" + i + "]", "Trident", JOptionPane.QUESTION_MESSAGE);
String input = JOptionPane.showInputDialog(panel, "Enter data[" + i + "]", "Trident", JOptionPane.QUESTION_MESSAGE);
data[i] = Integer.parseInt(input);
}
c.data = data;
@ -324,7 +341,7 @@ public class MainPanel extends JPanel {
try{
int[] data = new int[1];
for(int i = 0; i < 1; i++){
String input = JOptionPane.showInputDialog(null, "Enter data[" + i + "]", "Trident", JOptionPane.QUESTION_MESSAGE);
String input = JOptionPane.showInputDialog(panel, "Enter data[" + i + "]", "Trident", JOptionPane.QUESTION_MESSAGE);
data[i] = Integer.parseInt(input);
}
Trigger box = (Trigger)selectedEntity;
@ -355,25 +372,25 @@ public class MainPanel extends JPanel {
break;
case 4:
try{
String input = JOptionPane.showInputDialog(null, "Enter the ID for the trigger", "Trident", JOptionPane.QUESTION_MESSAGE);
String input = JOptionPane.showInputDialog(panel, "Enter the ID for the trigger", "Trident", JOptionPane.QUESTION_MESSAGE);
int id = Integer.parseInt(input);
project.currentScene.entities.add(new Trigger(worldPos, new Dimension(100, 100), id));
}catch(Exception e){}
break;
case 5:
String name = JOptionPane.showInputDialog(null, "Enter the object name", "Trident", JOptionPane.QUESTION_MESSAGE);
String name = JOptionPane.showInputDialog(panel, "Enter the object name", "Trident", JOptionPane.QUESTION_MESSAGE);
if(name != null){
int coll = JOptionPane.showConfirmDialog(null, "Does the object have collision?", "Trident", JOptionPane.YES_NO_CANCEL_OPTION);
int coll = JOptionPane.showConfirmDialog(panel, "Does the object have collision?", "Trident", JOptionPane.YES_NO_CANCEL_OPTION);
if(coll == 2) break;
Dimension collider = null;
if(coll == 0) collider = new Dimension(100, 100);
String input = JOptionPane.showInputDialog(null, "Enter the amount of data you need", "Trident", JOptionPane.QUESTION_MESSAGE);
String input = JOptionPane.showInputDialog(panel, "Enter the amount of data you need", "Trident", JOptionPane.QUESTION_MESSAGE);
try{
int numData = Integer.parseInt(input);
int[] data = new int[numData];
for(int i = 0; i < numData; i++){
String dataStr = JOptionPane.showInputDialog(null, "Enter data[" + i + "]", "Trident", JOptionPane.QUESTION_MESSAGE);
String dataStr = JOptionPane.showInputDialog(panel, "Enter data[" + i + "]", "Trident", JOptionPane.QUESTION_MESSAGE);
data[i] = Integer.parseInt(dataStr);
}
project.currentScene.entities.add(new CustomEntity(worldPos, collider, data, name));
@ -402,19 +419,19 @@ public class MainPanel extends JPanel {
if(mousePos.x < 40){
dropDown = true;
dropType = 0;
dropRect = new Rectangle(0, 40, 200, 32 * 5);
dropRect = new Rectangle(0, 40, 200, 32 * 6);
}else if(mousePos.x < 90){
BTools.openHighlightFile(new File("data/projects/" + project.name).getAbsolutePath());
}else if(mousePos.x < 212){
String name = JOptionPane.showInputDialog(null, "Enter the scene name", "Trident", JOptionPane.QUESTION_MESSAGE);
String name = JOptionPane.showInputDialog(panel, "Enter the scene name", "Trident", JOptionPane.QUESTION_MESSAGE);
if(name != null){
boolean loaded = project.loadScene(name);
if(!loaded){
JOptionPane.showMessageDialog(null, "Error: no scene with name '" + name + "' found.", "Trident", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(panel, "Error: no scene with name '" + name + "' found.", "Trident", JOptionPane.ERROR_MESSAGE);
}
}
}else if(mousePos.x < 327){
String name = JOptionPane.showInputDialog(null, "Enter the scene name", "Trident", JOptionPane.QUESTION_MESSAGE);
String name = JOptionPane.showInputDialog(panel, "Enter the scene name", "Trident", JOptionPane.QUESTION_MESSAGE);
if(name != null){
Scene scene = new Scene(name);
scene.save("data/projects/" + project.name);

View file

@ -38,6 +38,8 @@ public class Project {
dir.mkdirs();
dir = new File("data/projects/" + name + "/data/scenes");
dir.mkdirs();
dir = new File("data/projects/" + name + "/data/animations");
dir.mkdirs();
// Copy files (images and the such)
BTools.copyFile(new File("data/BLib.jar"), new File("data/projects/" + name + "/lib/BLib.jar"));
@ -47,6 +49,7 @@ public class Project {
BTools.copyFile(new File("data/images/trident/customEnt.png"), new File("data/projects/" + name + "/data/images/trident/customEnt.png"));
BTools.copyFile(new File("data/images/trident/plrStart.png"), new File("data/projects/" + name + "/data/images/trident/plrStart.png"));
BTools.copyFile(new File("data/images/trident/trigger.png"), new File("data/projects/" + name + "/data/images/trident/trigger.png"));
BTools.copyFile(new File("data/images/trident/splash.png"), new File("data/projects/" + name + "/data/images/trident/splash.png"));
BTools.copyFile(new File("data/icon.png"), new File("data/projects/" + name + "/data/icon.png"));
BTools.copyFile(new File("data/images/player/idleS.png"), new File("data/projects/" + name + "/data/images/player/idleS.png"));
BTools.copyFile(new File("data/images/player/idleN.png"), new File("data/projects/" + name + "/data/images/player/idleN.png"));
@ -97,6 +100,7 @@ public class Project {
writer.println("import java.awt.event.*;");
writer.println("import blib.input.*;");
writer.println("import java.util.ArrayList;");
writer.println("import blib.anim.*;");
writer.println("");
writer.println("import trident.ent.*;");
writer.println("import update.*;");
@ -105,6 +109,10 @@ public class Project {
writer.println(" protected FrameManager frameManager = new FrameManager();");
writer.println(" protected Server server;");
writer.println(" protected KeyManager km = new InputListener(this);");
writer.println(" private Animator introAnim;");
writer.println(" private Position introPos = new Position();");
writer.println(" private ImageIcon splash = new ImageIcon(\"data/images/trident/splash.png\");");
writer.println(" private boolean inIntro = false;");
writer.println(" ");
writer.println(" public MainPanel(){");
writer.println(" setBackground(Color.black);");
@ -126,12 +134,31 @@ public class Project {
writer.println("");
writer.println(" Trident.loadScene(Trident.defaultScene);");
writer.println("");
writer.println(" try{");
writer.println(" ArrayList<Animation> anims = new ArrayList<Animation>();");
writer.println(" anims.add(new Animation(\"data/animations/intro\"));");
writer.println("");
writer.println(" introAnim = new Animator(introPos, anims);");
writer.println(" }catch(Exception e){");
writer.println(" Trident.intro = false;");
writer.println(" }");
writer.println(" if(Trident.intro){");
writer.println(" introAnim.play(\"intro\");");
writer.println(" inIntro = true;");
writer.println(" }");
writer.println(" if(Trident.splash != null && BTools.hasImage(Trident.splash)){");
writer.println(" BTools.resizeImgIcon(Trident.splash, 160, 160);");
writer.println(" }");
writer.println("");
writer.println(" server = new Server(new ServerListener());");
writer.println(" }");
writer.println("");
writer.println(" public void paintComponent(Graphics graphics){");
writer.println(" super.paintComponent(graphics);");
writer.println(" Graphics g = frameManager.newFrame();");
writer.println(" int WIDTH = frameManager.WIDTH, HEIGHT = frameManager.HEIGHT;");
writer.println("");
writer.println(" frameManager.bgColor = Trident.currentScene.bgColor;");
writer.println("");
writer.println(" if(Trident.engineDraw){");
writer.println(" for(TridEntity e: Trident.currentScene.entities){");
@ -141,11 +168,13 @@ public class Project {
writer.println(" }");
writer.println("");
writer.println(" ArrayList<ArrayList<Entity>> splitEnt = Trident.player.camera.splitEntities(Trident.tridArrToEntArr(Trident.currentScene.entities), 16);");
writer.println(" if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(2));");
writer.println(" if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(0));");
writer.println(" if(Trident.drawPlayer){");
writer.println(" Trident.player.render(this, g, frameManager.WIDTH / 2 - 16, frameManager.HEIGHT / 2 - 16);");
writer.println(" }");
writer.println(" if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(1));");
writer.println(" if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(3));");
writer.println("");
writer.println(" if(Trident.drawCollision){");
writer.println(" g.setColor(Color.red);");
@ -164,10 +193,28 @@ public class Project {
writer.println(" TextBox.draw(Trident.player.getPos().toStringSimple(), g, 10, 30);");
writer.println(" }");
writer.println(" ");
writer.println(" if(inIntro){");
writer.println(" g.setColor(Color.black);");
writer.println(" g.fillRect(0, 0, 700, 500);");
writer.println("");
writer.println(" if(Trident.splash != null && BTools.hasImage(Trident.splash)){");
writer.println(" // Trident splash + custom splash");
writer.println(" splash.paintIcon(this, g, WIDTH / 2 - 80, 40);");
writer.println(" Trident.splash.paintIcon(this, g, WIDTH / 2 - 80, HEIGHT - 200);");
writer.println(" }else{");
writer.println(" // Trident splash only");
writer.println(" splash.paintIcon(this, g, WIDTH / 2 - 80, HEIGHT / 2 - 80);");
writer.println(" }");
writer.println("");
writer.println(" float alpha = (float)introPos.x;");
writer.println(" g.setColor(new Color(0f, 0f, 0f, alpha));");
writer.println(" g.fillRect(0, 0, 700, 500);");
writer.println(" }");
writer.println("");
writer.println(" frameManager.renderFrame(this, graphics);");
writer.println(" }");
writer.println("");
writer.println("");
writer.println(" public MainPanel panel = this;");
writer.println(" private class InputListener extends InputAdapter {");
writer.println(" public InputListener(JPanel panel){");
writer.println(" super(panel);");
@ -179,20 +226,33 @@ public class Project {
writer.println(" Main.window = BTools.getWindowFullscreen(Main.window, Trident.fullscreen, panel);");
writer.println(" return;");
writer.println(" }");
writer.println(" Inputs.keyPressed(key);");
writer.println(" if(!inIntro) Inputs.keyPressed(key);");
writer.println(" }");
writer.println("");
writer.println(" public void onMousePressed(int mb, Point mousePos){");
writer.println(" mousePos = frameManager.getMousePos(panel, mousePos);");
writer.println(" Position worldPos = Trident.player.camera.mouseToPos(mousePos);");
writer.println(" Inputs.mousePressed(mb, mousePos, worldPos);");
writer.println(" if(!inIntro) Inputs.mousePressed(mb, mousePos, worldPos);");
writer.println(" }");
writer.println("");
writer.println(" public void onScroll(int scroll){");
writer.println(" if(!inIntro) Inputs.onScroll(scroll);");
writer.println(" }");
writer.println(" }");
writer.println("");
writer.println(" private class ServerListener implements ActionListener {");
writer.println(" public void actionPerformed(ActionEvent event){");
writer.println(" Trident.mousePos = km.getMousePos();");
writer.println(" if(inIntro){");
writer.println(" introAnim.update(server.getElapsedTime());");
writer.println(" if(!introAnim.isPlaying()){");
writer.println(" inIntro = false;");
writer.println(" }");
writer.println(" repaint();");
writer.println(" return;");
writer.println(" }");
writer.println(" Trident.mousePos = frameManager.getMousePos(panel, km.getMousePos());");
writer.println(" Trident.mouseDelta = km.getMouseDelta();");
writer.println(" Trident.mouseWorldPos = Trident.player.camera.mouseToPos(Trident.mousePos);");
writer.println("");
writer.println(" frameManager.bgColor = Trident.bgColor;");
writer.println("");
@ -210,6 +270,15 @@ public class Project {
writer.println(" }");
writer.println(" }");
writer.println("");
writer.println(" for(int i = 0; i < 255; i++){");
writer.println(" Trident.keys[i] = km.getKeyDown(i);");
writer.println(" }");
writer.println(" Trident.m1 = km.getMouseDown(1);");
writer.println(" Trident.m2 = km.getMouseDown(2);");
writer.println(" Trident.m3 = km.getMouseDown(3);");
writer.println(" Trident.m4 = km.getMouseDown(4);");
writer.println(" Trident.m5 = km.getMouseDown(5);");
writer.println("");
writer.println(" Update.update(server.getElapsedTime());");
writer.println("");
writer.println(" repaint();");
@ -237,6 +306,7 @@ public class Project {
writer.println(" public ArrayList<TridEntity> entities;");
writer.println(" protected Position plrStart = new Position();");
writer.println(" protected int plrDir = Player.SOUTH;");
writer.println(" protected Color bgColor = Color.white;");
writer.println("");
writer.println(" public Scene(String n){ // Empty scene");
writer.println(" name = n;");
@ -254,8 +324,15 @@ public class Project {
writer.println(" if(str.equals(\"north\")) plrDir = Player.NORTH;");
writer.println(" if(str.equals(\"east\")) plrDir = Player.EAST;");
writer.println(" }");
writer.println(" obj = BSonParser.getObject(\"entities\", objects);");
writer.println(" obj = BSonParser.getObject(\"bgColor\", objects);");
writer.println(" BSonList asList = (BSonList)obj;");
writer.println(" int r, g, b;");
writer.println(" r = asList.list.get(0).getInt();");
writer.println(" g = asList.list.get(1).getInt();");
writer.println(" b = asList.list.get(2).getInt();");
writer.println(" bgColor = new Color(r, g, b);");
writer.println(" obj = BSonParser.getObject(\"entities\", objects);");
writer.println(" asList = (BSonList)obj;");
writer.println(" for(int i = 0; i < asList.list.size(); i++){");
writer.println(" String objName = asList.list.get(i).getString();");
writer.println(" i++;");
@ -326,6 +403,7 @@ public class Project {
writer.println("import blib.util.*;");
writer.println("import java.awt.*;");
writer.println("import java.util.ArrayList;");
writer.println("import javax.swing.*;");
writer.println("");
writer.println("import update.*;");
writer.println("import java.io.*;");
@ -337,11 +415,14 @@ public class Project {
writer.println(" public static boolean noclip = false;");
writer.println(" public static boolean engineDraw = false;");
writer.println(" public static Color debugColor = Color.red;");
writer.println(" public static boolean intro = true;");
writer.println(" public static ImageIcon splash = null;");
writer.println(" ");
writer.println(" // Public Variables");
writer.println(" public static Point mousePos;");
writer.println(" public static Point mouseDelta;");
writer.println(" public static boolean drawPlayer = true;");
writer.println(" public static Position mouseWorldPos = new Position();");
writer.println("");
writer.println("");
writer.println(" // Trident Variables");
@ -352,6 +433,8 @@ public class Project {
writer.println(" protected static ArrayList<Scene> loadedScenes = new ArrayList<Scene>();");
writer.println(" protected static ArrayList<TridEntity> entRegistry = new ArrayList<TridEntity>();");
writer.println(" protected static String defaultScene = \"default\";");
writer.println(" protected static boolean m1 = false, m2 = false, m3 = false, m4 = false, m5 = false;");
writer.println(" protected static boolean[] keys = new boolean[255];");
writer.println("");
writer.println("");
writer.println(" // Setting methods");
@ -449,6 +532,27 @@ public class Project {
writer.println(" public static ArrayList<Rectangle> getCollision(){");
writer.println(" return currentScene.getCollision();");
writer.println(" }");
writer.println(" public static boolean getMouseDown(int mb){");
writer.println(" if(mb == 1){");
writer.println(" return m1;");
writer.println(" }");
writer.println(" if(mb == 2){");
writer.println(" return m2;");
writer.println(" }");
writer.println(" if(mb == 3){");
writer.println(" return m3;");
writer.println(" }");
writer.println(" if(mb == 4){");
writer.println(" return m4;");
writer.println(" }");
writer.println(" if(mb == 5){");
writer.println(" return m5;");
writer.println(" }");
writer.println(" return false;");
writer.println(" }");
writer.println(" public static boolean getKeyDown(int key){");
writer.println(" return keys[key];");
writer.println(" }");
writer.println("");
writer.println("}");
writer.close();
@ -807,9 +911,13 @@ public class Project {
writer.println(" public static void mousePressed(int mb, Point mousePos, Position worldPos){");
writer.println("");
writer.println(" }");
writer.println("");
writer.println(" public static void onScroll(int scroll){");
writer.println(" ");
writer.println(" }");
writer.println("}");
writer.close();
}catch(Exception e){}
}catch(Exception e){}
try{
File file = new File("data/projects/" + name + "/src/update/Update.java");
file.createNewFile();
@ -852,6 +960,11 @@ public class Project {
PrintWriter writer = new PrintWriter(file);
writer.println("string name default");
writer.println("string dir east");
writer.println("{ bgColor");
writer.println("int 255");
writer.println("int 255");
writer.println("int 255");
writer.println("}");
writer.println("{ entities");
writer.println("string boxcoll");
writer.println("double -200");
@ -884,6 +997,32 @@ public class Project {
writer.println("}");
writer.close();
}catch(Exception e){}
// data/animations
try{
File file = new File("data/projects/" + name + "/data/animations/intro.anim");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.println("intro");
writer.println("false");
writer.println("1.0");
writer.println("0.0");
writer.println("0.0");
writer.println("0.0");
writer.println("1000");
writer.println("0.0");
writer.println("0.0");
writer.println("0.0");
writer.println("0.0");
writer.println("3000");
writer.println("0.0");
writer.println("0.0");
writer.println("1.0");
writer.println("0.0");
writer.println("1000");
writer.close();
}catch(Exception e){}
setupScenes();
currentScene = loadedScenes.get(0);

View file

@ -13,6 +13,7 @@ public class Scene {
public ArrayList<TridEntity> entities;
protected Position plrStart = new Position();
protected int plrDir = Player.SOUTH;
public Color bgColor = Color.white;
private TridEntity[] entRegistry = {
new BoxColl(),
new BoxNoColl(),
@ -37,8 +38,15 @@ public class Scene {
if(str.equals("north")) plrDir = Player.NORTH;
if(str.equals("east")) plrDir = Player.EAST;
}
obj = BSonParser.getObject("entities", objects);
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("entities", objects);
asList = (BSonList)obj;
for(int i = 0; i < asList.list.size(); i++){
System.out.println(i);
String objName = asList.list.get(i).getString();
@ -108,6 +116,11 @@ public class Scene {
PrintWriter writer = new PrintWriter(file);
writer.println("string name " + name);
writer.println("string dir south");
writer.println("{ bgColor");
writer.println("int " + bgColor.getRed());
writer.println("int " + bgColor.getGreen());
writer.println("int " + bgColor.getBlue());
writer.println("}");
writer.println("{ entities");
for(TridEntity e: entities){
writer.println("string " + e.name);