This commit is contained in:
BlockManBlue 2024-01-20 13:34:55 -07:00 committed by GitHub
parent c1c54779ad
commit 2ae0d180e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 467 additions and 40 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

View file

@ -5,6 +5,7 @@ import javax.swing.*;
import project.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Main {
public static Image icon = new ImageIcon("data/icon.png").getImage();
public static void main(String[] args){

View file

@ -18,6 +18,7 @@ public class MainPanel extends JPanel {
Camera cam;
ImageIcon icon = new ImageIcon("data/icon.png");
int tool = 0;
boolean drawLight = false;
Cursor[] cursors = {
BTools.getCustomCursor(new ImageIcon("data/images/cursors/select.png")),
@ -44,6 +45,9 @@ public class MainPanel extends JPanel {
ImageIcon duplicateImg = new ImageIcon("data/images/dropdown/duplicate.png");
ImageIcon editImg = new ImageIcon("data/images/dropdown/edit.png");
ImageIcon triggerImg = new ImageIcon("data/images/dropdown/trigger.png");
ImageIcon lightImg = new ImageIcon("data/images/dropdown/light.png");
long saveTime = 0;
TridEntity selectedEntity = null;
@ -103,12 +107,21 @@ public class MainPanel extends JPanel {
}
}
if(drawLight){
int darkness = -project.currentScene.defaultLight + 255;
frameManager.fillScreen(new Color(0f, 0f, 0f, (darkness / 255f)));
}
g.setColor(new Color(0f, 0f, 0f, 0.5f));
g.fillRect(0, 0, frameManager.WIDTH, 40);
g.fillRect(0, frameManager.HEIGHT - 40, frameManager.WIDTH, 40);
g.setColor(Color.white);
g.setFont(new Font("Arial", Font.PLAIN, 20));
TextBox.draw("Code Load Scene New Scene Save", g, 40, 20);
TextBox.draw("Code Load Scene New Scene Save PlrDir: " + project.currentScene.getDir(), g, 40, 20);
icon.paintIcon(this, g, 4, 4);
TextBox.draw("[L] Show Darkness: " + drawLight + " Default light level: " + project.currentScene.defaultLight, g, frameManager.WIDTH - 10, frameManager.HEIGHT - 20, TextBox.RIGHT);
g.setColor(new Color(1f, 1f, 1f, (saveTime / 1000f)));
TextBox.draw("Saved!", g, 10, frameManager.HEIGHT - 20);
if(dropDown){
g.setColor(Color.lightGray);
@ -132,8 +145,10 @@ public class MainPanel extends JPanel {
TextBox.draw("Return to (0, 0)", g, dropRect.x + 32, dropRect.y + 16 + 64 + 32);
editImg.paintIcon(this, g, dropRect.x, dropRect.y + 128);
TextBox.draw("Change bg color", g, dropRect.x + 32, dropRect.y + 16 + 128);
quitImg.paintIcon(this, g, dropRect.x, dropRect.y + 128 + 32);
TextBox.draw("Save and Quit", g, dropRect.x + 32, dropRect.y + 16 + 128 + 32);
lightImg.paintIcon(this, g, dropRect.x, dropRect.y + 128 + 32);
TextBox.draw("Set Default Light", g, dropRect.x + 32, dropRect.y + 16 + 128 + 32);
quitImg.paintIcon(this, g, dropRect.x, dropRect.y + 128 + 64);
TextBox.draw("Save and Quit", g, dropRect.x + 32, dropRect.y + 16 + 128 + 64);
}
if(dropType == 1){
deleteImg.paintIcon(this, g, dropRect.x, dropRect.y);
@ -158,6 +173,8 @@ public class MainPanel extends JPanel {
TextBox.draw("Add Trigger", g, dropRect.x + 32, dropRect.y + 16 + 128);
customImg.paintIcon(this, g, dropRect.x, dropRect.y + 128 + 32);
TextBox.draw("Add Custom Entity", g, dropRect.x + 32, dropRect.y + 16 + 128 + 32);
lightImg.paintIcon(this, g, dropRect.x, dropRect.y + 128 + 64);
TextBox.draw("Add Light", g, dropRect.x + 32, dropRect.y + 16 + 128 + 64);
}
}
@ -226,6 +243,9 @@ public class MainPanel extends JPanel {
project.currentScene.entities.add(new CustomEntity(box.position.copy(), collision, data, box.name));
}
}
if(key == KeyEvent.VK_L){
drawLight = !drawLight;
}
}
public void onMousePressed(int mb, Point mousePos){
@ -260,6 +280,15 @@ public class MainPanel extends JPanel {
}catch(Exception e){}
break;
case 5:
try{
int level;
String input = JOptionPane.showInputDialog(panel, "Enter the new default light level", "Trident", JOptionPane.QUESTION_MESSAGE);
level = Integer.parseInt(input);
level = BTools.clamp(level, 0, 255);
project.currentScene.defaultLight = level;
}catch(Exception e){}
break;
case 6:
project.currentScene.save("data/projects/" + project.name);
System.exit(0);
break;
@ -402,6 +431,9 @@ public class MainPanel extends JPanel {
}
}
break;
case 6:
project.currentScene.entities.add(new project.ent.Light(worldPos, 50));
break;
}
}
@ -414,12 +446,12 @@ public class MainPanel extends JPanel {
}
if(mousePos.y < 40){
// System.out.println(mousePos.x);
System.out.println(mousePos.x);
// Toolbar
if(mousePos.x < 40){
dropDown = true;
dropType = 0;
dropRect = new Rectangle(0, 40, 200, 32 * 6);
dropRect = new Rectangle(0, 40, 200, 32 * 7);
}else if(mousePos.x < 90){
BTools.openHighlightFile(new File("data/projects/" + project.name).getAbsolutePath());
}else if(mousePos.x < 212){
@ -440,6 +472,10 @@ public class MainPanel extends JPanel {
}
}else if(mousePos.x < 391){
project.currentScene.save("data/projects/" + project.name);
saveTime = 1000;
}else if(mousePos.x < 520){
project.currentScene.plrDir++;
if(project.currentScene.plrDir > 3) project.currentScene.plrDir = 0;
}
}else{
if(tool == 0){
@ -461,7 +497,7 @@ public class MainPanel extends JPanel {
if(selectedEntity == null){
dropDown = true;
dropType = 2;
dropRect = new Rectangle(mousePos.x, mousePos.y, 200, 32 * 6);
dropRect = new Rectangle(mousePos.x, mousePos.y, 200, 32 * 7);
}else{
dropDown = true;
dropType = 1;
@ -491,11 +527,19 @@ public class MainPanel extends JPanel {
cam.pos.x += dir.x * server.getElapsedTime() * speed;
cam.pos.y += dir.y * server.getElapsedTime() * speed;
saveTime -= server.getElapsedTime();
if(saveTime < 0) saveTime = 0;
if(tool == 1 && selectedEntity != null && km.getMouseDown(1)){
selectedEntity.position.x += delta.x;
selectedEntity.position.y += delta.y;
}
if(tool == 2 && selectedEntity != null && km.getMouseDown(1)){
if(selectedEntity instanceof project.ent.Light){
project.ent.Light light = (project.ent.Light)selectedEntity;
light.radius += delta.x;
if(light.radius < 0) light.radius = 0;
}
if(selectedEntity instanceof BoxNoColl){
BoxNoColl box = (BoxNoColl)selectedEntity;
box.width += delta.x;

View file

@ -43,12 +43,14 @@ public class Project {
// Copy files (images and the such)
BTools.copyFile(new File("data/BLib.jar"), new File("data/projects/" + name + "/lib/BLib.jar"));
BTools.copyFile(new File("data/JHLabs Filters.jar"), new File("data/projects/" + name + "/lib/JHLabs Filters.jar"));
BTools.copyFile(new File("data/images/trident/box.png"), new File("data/projects/" + name + "/data/images/trident/box.png"));
BTools.copyFile(new File("data/images/trident/boxColl.png"), new File("data/projects/" + name + "/data/images/trident/boxColl.png"));
BTools.copyFile(new File("data/images/trident/collision.png"), new File("data/projects/" + name + "/data/images/trident/collision.png"));
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/light.png"), new File("data/projects/" + name + "/data/images/trident/light.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"));
@ -72,7 +74,7 @@ public class Project {
writer.println("import javax.swing.*;");
writer.println("import java.awt.*;");
writer.println("public class Main{");
writer.println(" protected static JFrame window = new JFrame(\"Trident Game\");");
writer.println(" protected static JFrame window = new JFrame(\"" + name + "\");");
writer.println(" public static void main(String[] args){");
writer.println(" window.setSize(700, 500);");
writer.println(" window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);");
@ -98,8 +100,13 @@ public class Project {
writer.println("import blib.game.*;");
writer.println("import blib.util.*;");
writer.println("import java.awt.event.*;");
writer.println("import java.io.File;");
writer.println("import java.io.PrintWriter;");
writer.println("");
writer.println("import blib.input.*;");
writer.println("import java.util.ArrayList;");
writer.println("import java.util.Scanner;");
writer.println("");
writer.println("import blib.anim.*;");
writer.println("");
writer.println("import trident.ent.*;");
@ -121,12 +128,15 @@ public class Project {
writer.println(" Trident.player.camera.setDimension = new Dimension(frameManager.WIDTH, frameManager.HEIGHT);");
writer.println(" Trident.player.resizeImages(32, 32);");
writer.println(" Trident.currentScene = new Scene(\"Test Scene\");");
writer.println(" Trident.camShake = new CamShake(Trident.player.camera);");
writer.println(" Trident.lightManager.blur.setRadius(100);");
writer.println("");
writer.println(" Trident.addCustomEntity(new BoxColl());");
writer.println(" Trident.addCustomEntity(new BoxNoColl());");
writer.println(" Trident.addCustomEntity(new InvisColl());");
writer.println(" Trident.addCustomEntity(new PlrStart());");
writer.println(" Trident.addCustomEntity(new Trigger());");
writer.println(" Trident.addCustomEntity(new TridLight());");
writer.println("");
writer.println(" Update.setup();");
writer.println("");
@ -157,6 +167,9 @@ public class Project {
writer.println(" super.paintComponent(graphics);");
writer.println(" Graphics g = frameManager.newFrame();");
writer.println(" int WIDTH = frameManager.WIDTH, HEIGHT = frameManager.HEIGHT;");
writer.println(" int offX, offY;");
writer.println(" offX = Trident.camShake.offX;");
writer.println(" offY = Trident.camShake.offY;");
writer.println("");
writer.println(" frameManager.bgColor = Trident.currentScene.bgColor;");
writer.println("");
@ -168,13 +181,16 @@ 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.engineDraw) Trident.player.camera.render(g, splitEnt.get(2), offX, offY);");
writer.println(" if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(0), offX, offY);");
writer.println(" if(Trident.drawPlayer){");
writer.println(" Trident.player.render(this, g, frameManager.WIDTH / 2 - 16, frameManager.HEIGHT / 2 - 16);");
writer.println(" Trident.player.render(this, g, frameManager.WIDTH / 2 - 16 - offX, frameManager.HEIGHT / 2 - 16 - offY);");
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(" if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(1), offX, offY);");
writer.println(" if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(3), offX, offY);");
writer.println("");
writer.println("");
writer.println(" Trident.lightManager.render(Trident.player.camera, Trident.lights, g, offX, offY);");
writer.println("");
writer.println(" if(Trident.drawCollision){");
writer.println(" g.setColor(Color.red);");
@ -192,6 +208,20 @@ public class Project {
writer.println(" g.setFont(new Font(\"Arial\", Font.ITALIC, 10));");
writer.println(" TextBox.draw(Trident.player.getPos().toStringSimple(), g, 10, 30);");
writer.println(" }");
writer.println(" if(Trident.drawFrames){");
writer.println(" g.setColor(Trident.debugColor);");
writer.println(" g.setFont(new Font(\"Arial\", Font.ITALIC, 10));");
writer.println(" TextBox.draw(\"delay: \" + server.getElapsedTime() + \" ms\", g, 10, 30);");
writer.println(" TextBox.draw(\"FPS: \" + (1000 / server.getElapsedTime()), g, 10, 40);");
writer.println(" }");
writer.println(" ");
writer.println(" // Apply Post Processing");
writer.println(" if(Trident.enableExposure){");
writer.println(" Trident.exposure.filter(frameManager.getFrame(), frameManager.getFrame());");
writer.println(" }");
writer.println(" if(Trident.enableBloom){");
writer.println(" Trident.bloom.filter(frameManager.getFrame(), frameManager.getFrame());");
writer.println(" }");
writer.println(" ");
writer.println(" if(inIntro){");
writer.println(" g.setColor(Color.black);");
@ -226,7 +256,174 @@ public class Project {
writer.println(" Main.window = BTools.getWindowFullscreen(Main.window, Trident.fullscreen, panel);");
writer.println(" return;");
writer.println(" }");
writer.println(" if(!inIntro) Inputs.keyPressed(key);");
writer.println(" if(!inIntro){");
writer.println(" if(key == 192 && Trident.consoleEnabled){");
writer.println(" // dev console");
writer.println(" String command = JOptionPane.showInputDialog(null, \"Enter Console Command\", \"Dev Console\", JOptionPane.QUESTION_MESSAGE);");
writer.println(" if(command != null && command.length() > 0){");
writer.println(" ArrayList<String> cmdParts = new ArrayList<String>();");
writer.println(" Scanner scanner = new Scanner(command);");
writer.println(" while(scanner.hasNext()){");
writer.println(" cmdParts.add(scanner.next());");
writer.println(" }");
writer.println(" scanner.close();");
writer.println("");
writer.println(" if(cmdParts.size() == 0) return;");
writer.println(" try{");
writer.println(" switch(cmdParts.get(0)){");
writer.println(" case \"drawCollision\":");
writer.println(" if(cmdParts.size() == 1){");
writer.println(" JOptionPane.showMessageDialog(null, \"drawCollision is \" + Trident.drawCollision, \"Dev Console\", JOptionPane.INFORMATION_MESSAGE);");
writer.println(" break;");
writer.println(" }");
writer.println(" if(cmdParts.get(1).equals(\"1\") || cmdParts.get(1).equals(\"true\")){");
writer.println(" Trident.drawCollision = true;");
writer.println(" }");
writer.println(" if(cmdParts.get(1).equals(\"0\") || cmdParts.get(1).equals(\"false\")){");
writer.println(" Trident.drawCollision = false;");
writer.println(" }");
writer.println(" break;");
writer.println(" case \"engineDraw\":");
writer.println(" if(cmdParts.size() == 1){");
writer.println(" JOptionPane.showMessageDialog(null, \"engineDraw is \" + Trident.engineDraw, \"Dev Console\", JOptionPane.INFORMATION_MESSAGE);");
writer.println(" break;");
writer.println(" }");
writer.println(" if(cmdParts.get(1).equals(\"1\") || cmdParts.get(1).equals(\"true\")){");
writer.println(" Trident.engineDraw = true;");
writer.println(" }");
writer.println(" if(cmdParts.get(1).equals(\"0\") || cmdParts.get(1).equals(\"false\")){");
writer.println(" Trident.engineDraw = false;");
writer.println(" }");
writer.println(" break;");
writer.println(" case \"drawPos\":");
writer.println(" if(cmdParts.size() == 1){");
writer.println(" JOptionPane.showMessageDialog(null, \"drawPos is \" + Trident.drawPos, \"Dev Console\", JOptionPane.INFORMATION_MESSAGE);");
writer.println(" break;");
writer.println(" }");
writer.println(" if(cmdParts.get(1).equals(\"1\") || cmdParts.get(1).equals(\"true\")){");
writer.println(" Trident.drawPos = true;");
writer.println(" }");
writer.println(" if(cmdParts.get(1).equals(\"0\") || cmdParts.get(1).equals(\"false\")){");
writer.println(" Trident.drawPos = false;");
writer.println(" }");
writer.println(" break;");
writer.println(" case \"noclip\":");
writer.println(" if(cmdParts.size() == 1){");
writer.println(" JOptionPane.showMessageDialog(null, \"noclip is \" + Trident.noclip, \"Dev Console\", JOptionPane.INFORMATION_MESSAGE);");
writer.println(" break;");
writer.println(" }");
writer.println(" if(cmdParts.get(1).equals(\"1\") || cmdParts.get(1).equals(\"true\")){");
writer.println(" Trident.noclip = true;");
writer.println(" }");
writer.println(" if(cmdParts.get(1).equals(\"0\") || cmdParts.get(1).equals(\"false\")){");
writer.println(" Trident.noclip = false;");
writer.println(" }");
writer.println(" break;");
writer.println(" case \"tp\":");
writer.println(" int x = Integer.parseInt(cmdParts.get(1));");
writer.println(" int y = Integer.parseInt(cmdParts.get(2));");
writer.println(" Trident.setPlrPos(new Position(x, y));");
writer.println(" break;");
writer.println(" case \"loadMap\":");
writer.println(" String map = \"\";");
writer.println(" for(int i = 1; i < cmdParts.size(); i++){");
writer.println(" map += cmdParts.get(i);");
writer.println(" if(i != cmdParts.size() - 1) map += \" \";");
writer.println(" }");
writer.println(" Trident.loadScene(map);");
writer.println(" break;");
writer.println(" case \"drawFrames\":");
writer.println(" if(cmdParts.size() == 1){");
writer.println(" JOptionPane.showMessageDialog(null, \"drawFrames is \" + Trident.drawFrames, \"Dev Console\", JOptionPane.INFORMATION_MESSAGE);");
writer.println(" break;");
writer.println(" }");
writer.println(" if(cmdParts.get(1).equals(\"1\") || cmdParts.get(1).equals(\"true\")){");
writer.println(" Trident.drawFrames = true;");
writer.println(" }");
writer.println(" if(cmdParts.get(1).equals(\"0\") || cmdParts.get(1).equals(\"false\")){");
writer.println(" Trident.drawFrames = false;");
writer.println(" }");
writer.println(" break;");
writer.println(" case \"debugColor\":");
writer.println(" int r, g, b;");
writer.println(" float alpha = -1;");
writer.println(" r = Integer.parseInt(cmdParts.get(1));");
writer.println(" g = Integer.parseInt(cmdParts.get(2));");
writer.println(" b = Integer.parseInt(cmdParts.get(3));");
writer.println(" if(cmdParts.size() == 5){");
writer.println(" alpha = Float.parseFloat(cmdParts.get(4));");
writer.println(" }");
writer.println(" if(alpha != -1){");
writer.println(" Trident.debugColor = new Color(r / 255f, g / 255f, b / 255f, alpha);");
writer.println(" }else{");
writer.println(" Trident.debugColor = new Color(r, g, b);");
writer.println(" }");
writer.println(" break;");
writer.println(" case \"enableBloom\":");
writer.println(" if(cmdParts.size() == 1){");
writer.println(" JOptionPane.showMessageDialog(null, \"enableBloom is \" + Trident.enableBloom, \"Dev Console\", JOptionPane.INFORMATION_MESSAGE);");
writer.println(" break;");
writer.println(" }");
writer.println(" if(cmdParts.get(1).equals(\"1\") || cmdParts.get(1).equals(\"true\")){");
writer.println(" Trident.enableBloom = true;");
writer.println(" }");
writer.println(" if(cmdParts.get(1).equals(\"0\") || cmdParts.get(1).equals(\"false\")){");
writer.println(" Trident.enableBloom = false;");
writer.println(" }");
writer.println(" break;");
writer.println(" case \"enableExposure\":");
writer.println(" if(cmdParts.size() == 1){");
writer.println(" JOptionPane.showMessageDialog(null, \"enableExposure is \" + Trident.enableExposure, \"Dev Console\", JOptionPane.INFORMATION_MESSAGE);");
writer.println(" break;");
writer.println(" }");
writer.println(" if(cmdParts.get(1).equals(\"1\") || cmdParts.get(1).equals(\"true\")){");
writer.println(" Trident.enableExposure = true;");
writer.println(" }");
writer.println(" if(cmdParts.get(1).equals(\"0\") || cmdParts.get(1).equals(\"false\")){");
writer.println(" Trident.enableExposure = false;");
writer.println(" }");
writer.println(" break;");
writer.println(" case \"setBloom\":");
writer.println(" double amount = Double.parseDouble(cmdParts.get(1));");
writer.println(" Trident.setBloom(amount);");
writer.println(" break;");
writer.println(" case \"setExposure\":");
writer.println(" double expo = Double.parseDouble(cmdParts.get(1));");
writer.println(" Trident.setExposure(expo);");
writer.println(" break;");
writer.println(" case \"setLightBlur\":");
writer.println(" int blurLevel = Integer.parseInt(cmdParts.get(1)); ");
writer.println(" Trident.setLightBlur(blurLevel);");
writer.println(" break;");
writer.println(" default:");
writer.println(" int cmd = Update.command(cmdParts);");
writer.println(" if(cmd != 0){");
writer.println(" JOptionPane.showMessageDialog(null, \"Unknown command: \" + cmdParts.get(0), \"Dev Console\", JOptionPane.INFORMATION_MESSAGE);");
writer.println(" }");
writer.println(" break;");
writer.println(" }");
writer.println(" }catch(Exception e){");
writer.println(" int sel = JOptionPane.showConfirmDialog(null, \"Something went wrong while running your command. Save error log?\", \"Dev Console\", JOptionPane.YES_NO_OPTION);");
writer.println(" if(sel == 0){");
writer.println(" try{");
writer.println(" File file = new File(\"errorLog.txt\");");
writer.println(" file.createNewFile();");
writer.println(" PrintWriter writer = new PrintWriter(file);");
writer.println(" e.printStackTrace(writer);");
writer.println(" writer.close();");
writer.println(" }catch(Exception ex){");
writer.println(" JOptionPane.showMessageDialog(null, \"Somehow, something also went wrong while saving the error logs. Printing into the default console...\", \"Dev Console\", JOptionPane.INFORMATION_MESSAGE);");
writer.println(" System.out.println(\" ********* What went wrong while printing:\");");
writer.println(" ex.printStackTrace();");
writer.println(" System.out.println(\" ********* What went wrong with the command:\");");
writer.println(" e.printStackTrace();");
writer.println(" }");
writer.println(" }");
writer.println(" }");
writer.println(" }");
writer.println(" }");
writer.println(" Inputs.keyPressed(key);");
writer.println(" }");
writer.println(" }");
writer.println("");
writer.println(" public void onMousePressed(int mb, Point mousePos){");
@ -254,7 +451,7 @@ public class Project {
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(" Trident.camShake.update(server.getElapsedTime());");
writer.println("");
writer.println(" if(!Trident.noclip) Trident.player.updateWithCollision(server.getElapsedTime(), Trident.currentScene.getCollision());");
writer.println(" else Trident.player.update(server.getElapsedTime());");
@ -281,6 +478,8 @@ public class Project {
writer.println("");
writer.println(" Update.update(server.getElapsedTime());");
writer.println("");
writer.println(" Trident.getEntities().sort((o1, o2) -> o2.compareSort(o1));");
writer.println("");
writer.println(" repaint();");
writer.println(" }");
writer.println(" }");
@ -307,6 +506,7 @@ public class Project {
writer.println(" protected Position plrStart = new Position();");
writer.println(" protected int plrDir = Player.SOUTH;");
writer.println(" protected Color bgColor = Color.white;");
writer.println(" protected int defaultLight = 255;");
writer.println("");
writer.println(" public Scene(String n){ // Empty scene");
writer.println(" name = n;");
@ -331,6 +531,8 @@ public class Project {
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(\"light\", objects);");
writer.println(" defaultLight = obj.getInt();");
writer.println(" obj = BSonParser.getObject(\"entities\", objects);");
writer.println(" asList = (BSonList)obj;");
writer.println(" for(int i = 0; i < asList.list.size(); i++){");
@ -404,9 +606,11 @@ public class Project {
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.*;");
writer.println("import trident.ent.*;");
writer.println("import com.jhlabs.image.GlowFilter;");
writer.println("import com.jhlabs.image.ExposureFilter;");
writer.println("public class Trident {");
writer.println("");
writer.println(" // Debug Settings");
@ -417,17 +621,19 @@ public class Project {
writer.println(" public static Color debugColor = Color.red;");
writer.println(" public static boolean intro = true;");
writer.println(" public static ImageIcon splash = null;");
writer.println(" public static boolean drawFrames = false;");
writer.println(" public static boolean consoleEnabled = true;");
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(" public static boolean enableBloom = true, enableExposure = true;");
writer.println("");
writer.println("");
writer.println(" // Trident Variables");
writer.println(" protected static Player player;");
writer.println(" protected static Color bgColor;");
writer.println(" protected static Scene currentScene;");
writer.println(" protected static boolean fullscreen = false;");
writer.println(" protected static ArrayList<Scene> loadedScenes = new ArrayList<Scene>();");
@ -435,15 +641,17 @@ public class Project {
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(" protected static CamShake camShake;");
writer.println(" protected static ArrayList<Entity> lights = new ArrayList<Entity>();");
writer.println(" protected static LightManager lightManager = new LightManager(255);");
writer.println(" protected static GlowFilter bloom = new GlowFilter();");
writer.println(" protected static ExposureFilter exposure = new ExposureFilter();");
writer.println("");
writer.println("");
writer.println(" // Setting methods");
writer.println(" public static void setPlrSpeed(double speed){");
writer.println(" player.speed = speed;");
writer.println(" }");
writer.println(" public static void setBackground(Color color){");
writer.println(" bgColor = color;");
writer.println(" }");
writer.println(" public static void setPlrPos(Position pos){");
writer.println(" player.goToPos(pos);");
writer.println(" }");
@ -473,11 +681,20 @@ public class Project {
writer.println(" ");
writer.println(" }");
writer.println(" public static void loadScene(String name){");
writer.println(" lights = new ArrayList<Entity>();");
writer.println(" for(Scene s: loadedScenes){");
writer.println(" if(s.name.equals(name)){");
writer.println(" currentScene = s;");
writer.println(" player.goToPos(s.plrStart);");
writer.println(" player.setDirection(s.plrDir);");
writer.println(" for(TridEntity e: s.entities){");
writer.println(" if(e instanceof TridLight){");
writer.println(" TridLight asLight = (TridLight)e;");
writer.println(" lights.add(new Light(asLight.position, asLight.radius));");
writer.println(" }");
writer.println(" e.sceneStart(s.name);");
writer.println(" }");
writer.println(" lightManager.defaultLight = s.defaultLight;");
writer.println(" Update.sceneStart(name);");
writer.println(" return;");
writer.println(" }");
@ -498,6 +715,30 @@ public class Project {
writer.println(" public static void destroy(TridEntity object){");
writer.println(" getEntities().remove(object);");
writer.println(" }");
writer.println(" public static void shakeCam(double intensity){");
writer.println(" camShake.addTrauma(intensity);");
writer.println(" }");
writer.println(" public static void removeShake(){");
writer.println(" camShake.trauma = 0;");
writer.println(" }");
writer.println(" public static void setShakeStrength(int str){");
writer.println(" camShake.strength = str;");
writer.println(" }");
writer.println(" public static void setShakeLoss(double loss){");
writer.println(" camShake.traumaLoss = loss;");
writer.println(" }");
writer.println(" public static void setBloom(double amount){");
writer.println(" bloom.setAmount((float)amount);");
writer.println(" }");
writer.println(" public static void setExposure(double exp){");
writer.println(" exposure.setExposure((float)exp);");
writer.println(" }");
writer.println(" public static void setLightBlur(int level){");
writer.println(" lightManager.blur.setIterations(level);");
writer.println(" }");
writer.println(" public static void addLight(Light l){");
writer.println(" lights.add(l);");
writer.println(" }");
writer.println("");
writer.println(" // Getting methods");
writer.println(" public static double getPlrSpeed(){");
@ -553,6 +794,9 @@ public class Project {
writer.println(" public static boolean getKeyDown(int key){");
writer.println(" return keys[key];");
writer.println(" }");
writer.println(" public static Player getPlr(){");
writer.println(" return player;");
writer.println(" }");
writer.println("");
writer.println("}");
writer.close();
@ -600,7 +844,7 @@ public class Project {
writer.println(" return null;");
writer.println(" }");
writer.println("");
writer.println(" public final Rectangle getCollision(){");
writer.println(" public Rectangle getCollision(){");
writer.println(" return new Rectangle((int)position.x - (collision.width / 2), (int)position.y - (collision.height / 2), collision.width, collision.height);");
writer.println(" }");
writer.println(" ");
@ -621,6 +865,46 @@ public class Project {
writer.println("");
writer.println(" }");
writer.println("");
writer.println(" public void sceneStart(String scene){");
writer.println(" ");
writer.println(" }");
writer.println("");
writer.println(" public int getRendDatSort(){");
writer.println(" if(renderType == Entity.TALL){");
writer.println(" return 2;");
writer.println(" }");
writer.println(" if(renderType == Entity.UNDER){");
writer.println(" return 1;");
writer.println(" }");
writer.println(" if(renderType == Entity.ABOVE){");
writer.println(" return 3;");
writer.println(" }");
writer.println(" if(renderType == Entity.BOTTOMPRIORITY){");
writer.println(" return 0;");
writer.println(" }");
writer.println(" if(renderType == Entity.TOPPRIORITY){");
writer.println(" return 4;");
writer.println(" }");
writer.println(" return 2;");
writer.println(" }");
writer.println("");
writer.println(" public int compareSort(TridEntity e){");
writer.println(" if(e.getRendDatSort() > getRendDatSort()){");
writer.println(" // e should be above");
writer.println(" return 1;");
writer.println(" }else if(e.getRendDatSort() < getRendDatSort()){");
writer.println(" return -1;");
writer.println(" }");
writer.println("");
writer.println(" if(e.position.y > position.y){");
writer.println(" return 1;");
writer.println(" }else if(e.position.y < position.y){");
writer.println(" return -1;");
writer.println(" }");
writer.println("");
writer.println(" return 0;");
writer.println(" }");
writer.println("");
writer.println("}");
writer.close();
}catch(Exception e){}
@ -836,7 +1120,40 @@ public class Project {
writer.println("}");
writer.close();
}catch(Exception e){}
try{
File file = new File("data/projects/" + name + "/src/trident/ent/TridLight.java");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.println("package trident.ent;");
writer.println("");
writer.println("import blib.util.*;");
writer.println("import java.awt.*;");
writer.println("import javax.swing.*;");
writer.println("");
writer.println("import trident.*;");
writer.println("public class TridLight extends TridEntity{");
writer.println(" ");
writer.println(" public int radius;");
writer.println("");
writer.println(" private ImageIcon engineImg = new ImageIcon(\"data/images/trident/light.png\");");
writer.println(" ");
writer.println(" public TridLight(Position pos, int r){");
writer.println(" super(pos);");
writer.println(" radius = r;");
writer.println(" } ");
writer.println(" public TridLight(){");
writer.println(" super(\"light\", false, 1);");
writer.println(" }");
writer.println(" public TridEntity construct(Position pos, Dimension collision, int[] data){");
writer.println(" return new TridLight(pos, data[0]);");
writer.println(" }");
writer.println("");
writer.println(" public void engineRender(Graphics g, JPanel panel, int x, int y){");
writer.println(" engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2);");
writer.println(" }");
writer.println("}");
writer.close();
}catch(Exception e){}
// src/ent
@ -874,6 +1191,11 @@ public class Project {
writer.println(" public void update(long elapsedTime){");
writer.println(" ");
writer.println(" }");
writer.println("");
writer.println(" // Runs at the beginning of the scene");
writer.println(" public void sceneStart(String scene){");
writer.println("");
writer.println(" }");
writer.println("}");
writer.close();
}catch(Exception e){}
@ -888,24 +1210,10 @@ public class Project {
writer.println("import java.awt.*;");
writer.println("import java.awt.event.*;");
writer.println("import blib.util.*;");
writer.println("");
writer.println("import trident.*;");
writer.println("public class Inputs {");
writer.println(" ");
writer.println(" public static void keyPressed(int key){");
writer.println(" // Basic debug keys");
writer.println(" if(key == KeyEvent.VK_F1){");
writer.println(" Trident.drawCollision = !Trident.drawCollision;");
writer.println(" }");
writer.println(" if(key == KeyEvent.VK_F2){");
writer.println(" Trident.engineDraw = !Trident.engineDraw;");
writer.println(" }");
writer.println(" if(key == KeyEvent.VK_F3){");
writer.println(" Trident.drawPos = !Trident.drawPos;");
writer.println(" }");
writer.println(" if(key == KeyEvent.VK_F4){");
writer.println(" Trident.noclip = !Trident.noclip;");
writer.println(" }");
writer.println(" ");
writer.println(" }");
writer.println("");
writer.println(" public static void mousePressed(int mb, Point mousePos, Position worldPos){");
@ -926,6 +1234,7 @@ public class Project {
writer.println("");
writer.println("import trident.*;");
writer.println("import ent.*;");
writer.println("import java.util.ArrayList;");
writer.println("public class Update {");
writer.println("");
writer.println(" public static void setup(){");
@ -935,19 +1244,38 @@ public class Project {
writer.println(" // Set settings");
writer.println(" Trident.setPlrSpeed(0.2);");
writer.println(" Trident.setShortCollision(true);");
writer.println("");
writer.println(" // Post Processing");
writer.println(" Trident.setBloom(0.2);");
writer.println(" Trident.setExposure(1);");
writer.println(" Trident.enableBloom = false;");
writer.println(" Trident.enableExposure = false;");
writer.println(" Trident.setLightBlur(1);");
writer.println(" }");
writer.println("");
writer.println(" public static void sceneStart(String scene){");
writer.println("");
writer.println(" }");
writer.println(" ");
writer.println(" public static void update(long elapsedTimes){");
writer.println(" public static void update(long elapsedTime){");
writer.println("");
writer.println(" }");
writer.println("");
writer.println(" public static void trigger(int id){");
writer.println(" ");
writer.println(" }");
writer.println("");
writer.println(" public static int command(ArrayList<String> cmdParts){ // cmdParts.get(0) is the command, while the rest are arguments for the command.");
writer.println(" switch(cmdParts.get(0)){");
writer.println(" case \"helloWorld\":");
writer.println(" System.out.println(\"Hello, World!\");");
writer.println(" return 0;");
writer.println(" case \"ping\":");
writer.println(" System.out.println(\"pong\");");
writer.println(" return 0;");
writer.println(" }");
writer.println(" return 1; // return 1 if command is not recognized");
writer.println(" }");
writer.println("}");
writer.close();
}catch(Exception e){}
@ -960,6 +1288,7 @@ public class Project {
PrintWriter writer = new PrintWriter(file);
writer.println("string name default");
writer.println("string dir east");
writer.println("int light 25");
writer.println("{ bgColor");
writer.println("int 255");
writer.println("int 255");
@ -994,6 +1323,11 @@ public class Project {
writer.println("int 255");
writer.println("int 0");
writer.println("int 0");
writer.println("string light");
writer.println("double -200");
writer.println("double 200");
writer.println("boolean false");
writer.println("int 100");
writer.println("}");
writer.close();
}catch(Exception e){}

View file

@ -12,7 +12,7 @@ public class Scene {
public final String name;
public ArrayList<TridEntity> entities;
protected Position plrStart = new Position();
protected int plrDir = Player.SOUTH;
public int plrDir = Player.SOUTH;
public Color bgColor = Color.white;
private TridEntity[] entRegistry = {
new BoxColl(),
@ -20,7 +20,9 @@ public class Scene {
new InvisColl(),
new PlrStart(),
new Trigger(),
new project.ent.Light(),
};
public int defaultLight = 255;
public Scene(String n){ // Empty scene
name = n;
@ -45,6 +47,8 @@ public class Scene {
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++){
@ -109,13 +113,22 @@ public class Scene {
}
}
public String getDir(){
if(plrDir == Player.SOUTH) return "south";
if(plrDir == Player.EAST) return "east";
if(plrDir == Player.WEST) return "west";
if(plrDir == Player.NORTH) return "north";
return "unknown direction";
}
public void save(String projDir){
try{
File file = new File(projDir + "/data/scenes/" + name + ".bson");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.println("string name " + name);
writer.println("string dir south");
writer.println("string dir " + getDir());
writer.println("int light " + defaultLight);
writer.println("{ bgColor");
writer.println("int " + bgColor.getRed());
writer.println("int " + bgColor.getGreen());
@ -151,6 +164,10 @@ public class Scene {
writer.println("int " + trig.box.height);
writer.println("int " + trig.id);
}
if(e instanceof project.ent.Light){
project.ent.Light light = (project.ent.Light)e;
writer.println("int " + light.radius);
}
if(e instanceof CustomEntity){
CustomEntity custom = (CustomEntity)e;
for(int i: custom.data){

View file

@ -0,0 +1,31 @@
package project.ent;
import blib.util.*;
import java.awt.*;
import javax.swing.*;
import project.*;
public class Light extends TridEntity{
public int radius;
private ImageIcon engineImg = new ImageIcon("data/images/trident/light.png");
public Light(Position pos, int r){
super(pos);
name = "light";
radius = r;
}
public Light(){
super("light", false, 1);
}
public TridEntity construct(Position pos, Dimension collision, int[] data){
return new Light(pos, data[0]);
}
public void engineRender(Graphics g, JPanel panel, int x, int y){
engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2);
g.setColor(Color.red);
g.drawOval(x - radius, y - radius, radius * 2, radius * 2);
}
}