diff --git a/bin/main/MainPanel$InputListener.class b/bin/main/MainPanel$InputListener.class index f7f523c..7ab9894 100644 Binary files a/bin/main/MainPanel$InputListener.class and b/bin/main/MainPanel$InputListener.class differ diff --git a/bin/main/MainPanel$ServerListener.class b/bin/main/MainPanel$ServerListener.class index 0c600da..4ba4693 100644 Binary files a/bin/main/MainPanel$ServerListener.class and b/bin/main/MainPanel$ServerListener.class differ diff --git a/bin/main/MainPanel.class b/bin/main/MainPanel.class index 644480e..85f113d 100644 Binary files a/bin/main/MainPanel.class and b/bin/main/MainPanel.class differ diff --git a/bin/project/TridEntity.class b/bin/project/TridEntity.class index f83f2ae..2a98fb7 100644 Binary files a/bin/project/TridEntity.class and b/bin/project/TridEntity.class differ diff --git a/bin/project/ent/BoxColl.class b/bin/project/ent/BoxColl.class index a0437ca..02782f0 100644 Binary files a/bin/project/ent/BoxColl.class and b/bin/project/ent/BoxColl.class differ diff --git a/bin/project/ent/BoxNoColl.class b/bin/project/ent/BoxNoColl.class index 5e4895b..d426e57 100644 Binary files a/bin/project/ent/BoxNoColl.class and b/bin/project/ent/BoxNoColl.class differ diff --git a/bin/project/ent/CustomEntity.class b/bin/project/ent/CustomEntity.class index f86a1ee..9d948e3 100644 Binary files a/bin/project/ent/CustomEntity.class and b/bin/project/ent/CustomEntity.class differ diff --git a/bin/project/ent/Trigger.class b/bin/project/ent/Trigger.class index b4a3645..aab767d 100644 Binary files a/bin/project/ent/Trigger.class and b/bin/project/ent/Trigger.class differ diff --git a/data/libraries/BLib.jar b/data/libraries/BLib.jar index 99e9d99..558b0ae 100644 Binary files a/data/libraries/BLib.jar and b/data/libraries/BLib.jar differ diff --git a/data/projectRegistry.bson b/data/projectRegistry.bson index 2777d63..3e5eb59 100644 --- a/data/projectRegistry.bson +++ b/data/projectRegistry.bson @@ -1,2 +1,3 @@ { projects +string test } diff --git a/data/projects/test/data/animations/intro.anim b/data/projects/test/data/animations/intro.anim new file mode 100644 index 0000000..e93c287 --- /dev/null +++ b/data/projects/test/data/animations/intro.anim @@ -0,0 +1,17 @@ +intro +false +1.0 +0.0 +0.0 +0.0 +1000 +0.0 +0.0 +0.0 +0.0 +3000 +0.0 +0.0 +1.0 +0.0 +1000 diff --git a/data/projects/test/data/icon.png b/data/projects/test/data/icon.png new file mode 100644 index 0000000..75679b4 Binary files /dev/null and b/data/projects/test/data/icon.png differ diff --git a/data/projects/test/data/images/player/idleE.png b/data/projects/test/data/images/player/idleE.png new file mode 100644 index 0000000..fc1896b Binary files /dev/null and b/data/projects/test/data/images/player/idleE.png differ diff --git a/data/projects/test/data/images/player/idleN.png b/data/projects/test/data/images/player/idleN.png new file mode 100644 index 0000000..e86f6cc Binary files /dev/null and b/data/projects/test/data/images/player/idleN.png differ diff --git a/data/projects/test/data/images/player/idleS.png b/data/projects/test/data/images/player/idleS.png new file mode 100644 index 0000000..cb923cc Binary files /dev/null and b/data/projects/test/data/images/player/idleS.png differ diff --git a/data/projects/test/data/images/player/idleW.png b/data/projects/test/data/images/player/idleW.png new file mode 100644 index 0000000..e706b7d Binary files /dev/null and b/data/projects/test/data/images/player/idleW.png differ diff --git a/data/projects/test/data/images/player/walkE.png b/data/projects/test/data/images/player/walkE.png new file mode 100644 index 0000000..b9e2df3 Binary files /dev/null and b/data/projects/test/data/images/player/walkE.png differ diff --git a/data/projects/test/data/images/player/walkN.png b/data/projects/test/data/images/player/walkN.png new file mode 100644 index 0000000..63aef9b Binary files /dev/null and b/data/projects/test/data/images/player/walkN.png differ diff --git a/data/projects/test/data/images/player/walkS.png b/data/projects/test/data/images/player/walkS.png new file mode 100644 index 0000000..ff3366a Binary files /dev/null and b/data/projects/test/data/images/player/walkS.png differ diff --git a/data/projects/test/data/images/player/walkW.png b/data/projects/test/data/images/player/walkW.png new file mode 100644 index 0000000..3ab625d Binary files /dev/null and b/data/projects/test/data/images/player/walkW.png differ diff --git a/data/projects/test/data/images/trident/box.png b/data/projects/test/data/images/trident/box.png new file mode 100644 index 0000000..2095f6a Binary files /dev/null and b/data/projects/test/data/images/trident/box.png differ diff --git a/data/projects/test/data/images/trident/boxColl.png b/data/projects/test/data/images/trident/boxColl.png new file mode 100644 index 0000000..e63707b Binary files /dev/null and b/data/projects/test/data/images/trident/boxColl.png differ diff --git a/data/projects/test/data/images/trident/collision.png b/data/projects/test/data/images/trident/collision.png new file mode 100644 index 0000000..77597a8 Binary files /dev/null and b/data/projects/test/data/images/trident/collision.png differ diff --git a/data/projects/test/data/images/trident/consolebg.png b/data/projects/test/data/images/trident/consolebg.png new file mode 100644 index 0000000..fc0a33e Binary files /dev/null and b/data/projects/test/data/images/trident/consolebg.png differ diff --git a/data/projects/test/data/images/trident/customEnt.png b/data/projects/test/data/images/trident/customEnt.png new file mode 100644 index 0000000..bb10f72 Binary files /dev/null and b/data/projects/test/data/images/trident/customEnt.png differ diff --git a/data/projects/test/data/images/trident/light.png b/data/projects/test/data/images/trident/light.png new file mode 100644 index 0000000..6f7887c Binary files /dev/null and b/data/projects/test/data/images/trident/light.png differ diff --git a/data/projects/test/data/images/trident/plrStart.png b/data/projects/test/data/images/trident/plrStart.png new file mode 100644 index 0000000..58d0ff2 Binary files /dev/null and b/data/projects/test/data/images/trident/plrStart.png differ diff --git a/data/projects/test/data/images/trident/splash.png b/data/projects/test/data/images/trident/splash.png new file mode 100644 index 0000000..0d40d89 Binary files /dev/null and b/data/projects/test/data/images/trident/splash.png differ diff --git a/data/projects/test/data/images/trident/trigger.png b/data/projects/test/data/images/trident/trigger.png new file mode 100644 index 0000000..fcb46cd Binary files /dev/null and b/data/projects/test/data/images/trident/trigger.png differ diff --git a/data/projects/test/data/scenes/default.bson b/data/projects/test/data/scenes/default.bson new file mode 100644 index 0000000..db16038 --- /dev/null +++ b/data/projects/test/data/scenes/default.bson @@ -0,0 +1,43 @@ +string name default +string dir east +int light 25 +{ bgColor +int 255 +int 255 +int 255 +} +{ entities +string boxcoll +double -200.0 +double 0.0 +boolean true +int 100 +int 100 +int 0 +int 255 +int 0 +string plrstart +double -300.0 +double 0.0 +boolean false +string inviscoll +double -200.0 +double 100.0 +boolean true +int 100 +int 100 +string boxnocoll +double -200.0 +double -100.0 +boolean false +int 100 +int 100 +int 255 +int 0 +int 0 +string light +double -200.0 +double 200.0 +boolean false +int 100 +} diff --git a/data/projects/test/lib/BLib.jar b/data/projects/test/lib/BLib.jar new file mode 100644 index 0000000..99e9d99 Binary files /dev/null and b/data/projects/test/lib/BLib.jar differ diff --git a/data/projects/test/lib/JHLabs Filters.jar b/data/projects/test/lib/JHLabs Filters.jar new file mode 100644 index 0000000..2ce3ec6 Binary files /dev/null and b/data/projects/test/lib/JHLabs Filters.jar differ diff --git a/data/projects/test/src/ent/ExampleEntity.java b/data/projects/test/src/ent/ExampleEntity.java new file mode 100644 index 0000000..98fabb0 --- /dev/null +++ b/data/projects/test/src/ent/ExampleEntity.java @@ -0,0 +1,36 @@ +package ent; + +import blib.util.*; +import trident.*; +import javax.swing.*; +import java.awt.*; +public class ExampleEntity extends TridEntity { + + // Constructor, runs when the entity is created + public ExampleEntity(Position pos){ + super(pos); + } + // Registry constructor, used only for adding to the registry + public ExampleEntity(){ + super("example", false, 0); + } + // Custom constructor, used by the engine when building a scene + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new ExampleEntity(pos); + } + + // Render while in game + public void render(Graphics g, JPanel panel, int x, int y){ + + } + + // Runs every tick while the game is running + public void update(long elapsedTime){ + + } + + // Runs at the beginning of the scene + public void sceneStart(String scene){ + + } +} diff --git a/data/projects/test/src/trident/Main.java b/data/projects/test/src/trident/Main.java new file mode 100644 index 0000000..339cb42 --- /dev/null +++ b/data/projects/test/src/trident/Main.java @@ -0,0 +1,18 @@ +package trident; + +import javax.swing.*; +import java.awt.*; +public class Main{ + protected static JFrame window = new JFrame("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); + } +} diff --git a/data/projects/test/src/trident/MainPanel.java b/data/projects/test/src/trident/MainPanel.java new file mode 100644 index 0000000..20afddf --- /dev/null +++ b/data/projects/test/src/trident/MainPanel.java @@ -0,0 +1,226 @@ +package trident; + +import javax.swing.*; +import java.awt.*; +import blib.game.*; +import blib.util.*; +import java.awt.event.*; +import blib.input.*; +import java.util.ArrayList; +import blib.anim.*; +import trident.ent.*; +import update.*; +public class MainPanel extends JPanel { + + protected FrameManager frameManager = new FrameManager(); + public static Server server; + protected KeyManager km = new InputListener(this); + private Animator introAnim; + public static Position introPos = new Position(); + public static ImageIcon splash = new ImageIcon("data/images/trident/splash.png"); + public static boolean inIntro = false; + private RenderingThread rendThread = new RenderingThread(); + + public MainPanel(){ + + System.setProperty("sun.java2d.opengl", "true"); // hardware acceleration? + + setBackground(Color.black); + + Trident.player = new Player(new Position(), km, 0.1, this, "data/images/player", 16, 16); + Trident.player.camera.setDimension = new Dimension(frameManager.WIDTH, frameManager.HEIGHT); + Trident.player.resizeImages(32, 32); + Trident.currentScene = new Scene("Test Scene"); + Trident.camShake = new CamShake(Trident.player.camera); + Trident.lightManager.blur.setRadius(100); + + Trident.addCustomEntity(new BoxColl()); + Trident.addCustomEntity(new BoxNoColl()); + Trident.addCustomEntity(new InvisColl()); + Trident.addCustomEntity(new PlrStart()); + Trident.addCustomEntity(new Trigger()); + Trident.addCustomEntity(new TridLight()); + + setFocusTraversalKeysEnabled(false); + + Update.setup(); + + Trident.setupScenes(); + + Trident.loadScene(Trident.defaultScene); + + for(String s: Update.fonts){ + BTools.addFont(s, this); + } + + try{ + ArrayList anims = new ArrayList(); + anims.add(new Animation("data/animations/intro")); + + introAnim = new Animator(introPos, anims); + }catch(Exception e){ + Trident.intro = false; + } + if(Trident.intro){ + introAnim.play("intro"); + inIntro = true; + } + if(Trident.splash != null && BTools.hasImage(Trident.splash)){ + BTools.resizeImgIcon(Trident.splash, 160, 160); + } + + Trident.consoleError = false; + rendThread.start(); + + server = new Server(new ServerListener(), this); + } + + public void paintComponent(Graphics graphics){ + super.paintComponent(graphics); + Graphics g = frameManager.newFrame(); + + frameManager.bgColor = Trident.currentScene.bgColor; + + if(rendThread.lastFrame != null){ + g.drawImage(rendThread.lastFrame, 0, 0, null); + } + + frameManager.renderFrame(this, graphics); + } + + public MainPanel panel = this; + private class InputListener extends InputAdapter { + public InputListener(JPanel panel){ + super(panel); + } + + public void onKeyPressed(int key){ + if(key == KeyEvent.VK_F12){ + frameManager.saveScreenshot("data/screenshots"); + Update.tridentEvent(Trident.EVENT_SCREENSHOT); + } + if(key == KeyEvent.VK_F11){ + Trident.fullscreen = !Trident.fullscreen; + Main.window = BTools.getWindowFullscreen(Main.window, Trident.fullscreen, panel); + return; + } + if(!inIntro){ + if(key == 192 && Trident.consoleEnabled){ + Trident.consoleOpen = !Trident.consoleOpen; + Trident.consoleType = ""; + Trident.consoleError = false; + } + if(Trident.consoleOpen){ + if(key >= KeyEvent.VK_A && key <= KeyEvent.VK_Z){ + char c = KeyEvent.getKeyText(key).charAt(0); + if(!km.getKeyDown(KeyEvent.VK_SHIFT)){ + c = Character.toLowerCase(c); + } + Trident.consoleType += c; + } + if(key >= KeyEvent.VK_0 && key <= KeyEvent.VK_9){ + char c = KeyEvent.getKeyText(key).charAt(0); + Trident.consoleType += c; + } + if(key == KeyEvent.VK_SPACE){ + Trident.consoleType += " "; + } + if(key == KeyEvent.VK_MINUS){ + Trident.consoleType += "-"; + } + if(key == KeyEvent.VK_PERIOD){ + Trident.consoleType += "."; + } + if(key == KeyEvent.VK_BACK_SPACE){ + if(Trident.consoleType.length() > 0) Trident.consoleType = Trident.consoleType.substring(0, Trident.consoleType.length() - 1); + } + if(key == KeyEvent.VK_UP){ + Trident.consoleType = Trident.lastCommand; + } + + if(key == KeyEvent.VK_ENTER){ + Trident.runCommand(Trident.consoleType); + Trident.consoleType = ""; + } + return; + } + Inputs.keyPressed(key); + } + } + + public void onMousePressed(int mb, Point mousePos){ + mousePos = frameManager.getMousePos(panel, mousePos); + Position worldPos = Trident.player.camera.mouseToPos(mousePos); + if(!inIntro) Inputs.mousePressed(mb, mousePos, worldPos); + } + + public void onScroll(int scroll){ + if(!inIntro) Inputs.onScroll(scroll); + } + } + + private class ServerListener implements ActionListener { + public void actionPerformed(ActionEvent event){ + if(inIntro){ + introAnim.update(server.getElapsedTime()); + if(!introAnim.isPlaying()){ + inIntro = false; + } + repaint(); + return; + } + + if(!hasFocus()) km.reset(); + + if(!Trident.consoleOpen){ + Trident.mousePos = frameManager.getMousePos(panel, km.getMousePos()); + Trident.mouseDelta = km.getMouseDelta(); + Trident.mouseWorldPos = Trident.player.camera.mouseToPos(Trident.mousePos); + + Trident.camShake.update(server.getElapsedTime()); + + if(!Trident.noclip) Trident.player.updateWithCollision(server.getElapsedTime(), Trident.currentScene.getCollision()); + else Trident.player.update(server.getElapsedTime()); + + for(int i = 0; i < Trident.getEntities().size(); i++){ + TridEntity e = Trident.getEntities().get(i); + e.update(server.getElapsedTime()); + if(e instanceof Trigger){ + Trigger trig = (Trigger)e; + if(trig.containsPos(Trident.player.getPos())){ + Update.trigger(trig.id); + } + } + } + + if(Trident.reset){ + km.reset(); + Trident.reset = false; + } + for(int i = 0; i < 255; i++){ + Trident.keys[i] = km.getKeyDown(i); + } + Trident.m1 = km.getMouseDown(1); + Trident.m2 = km.getMouseDown(2); + Trident.m3 = km.getMouseDown(3); + Trident.m4 = km.getMouseDown(4); + Trident.m5 = km.getMouseDown(5); + + if(Trident.newSprite != null){ + Trident.player = new Player(Trident.player.getPos(), km, 0.2, panel, Trident.newSprite, 16, 16); + Trident.newSprite = null; + Trident.player.resizeImages(32, 32); + Trident.player.camera.setDimension = new Dimension(frameManager.WIDTH, frameManager.HEIGHT); + Trident.camShake = new CamShake(Trident.player.camera); + Trident.player.shortCollision = true; + } + + Update.update(server.getElapsedTime()); + } + + + + try {Trident.getEntities().sort((o1, o2) -> o2.compareSort(o1));} catch(Exception e){} + } + } +} diff --git a/data/projects/test/src/trident/RenderingThread.java b/data/projects/test/src/trident/RenderingThread.java new file mode 100644 index 0000000..65220e3 --- /dev/null +++ b/data/projects/test/src/trident/RenderingThread.java @@ -0,0 +1,148 @@ +package trident; + +import java.awt.image.*; +import java.util.ArrayList; +import java.util.ConcurrentModificationException; +import blib.util.*; +import java.awt.*; +import blib.game.*; +import javax.swing.*; +public class RenderingThread extends Thread { + + public BufferedImage lastFrame = null; + private long elapsedTime, previousStartTime = -1; + + private ImageIcon consoleBg = new ImageIcon("data/images/trident/consolebg.png"); + private long errorFlashTime = 0; + + public RenderingThread(){ + BTools.resizeImgIcon(consoleBg, Trident.getFrameWidth(), 483); + } + + public void run(){ + while(true){ + try{ + + long now = System.currentTimeMillis(); + elapsedTime = previousStartTime != -1 ? now - previousStartTime : 0; + previousStartTime = now; + int WIDTH = Trident.getFrameWidth(), HEIGHT = Trident.getFrameHeight(); + int offX, offY; + offX = Trident.camShake.offX; + offY = Trident.camShake.offY; + BufferedImage newFrame = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB); + Graphics g = newFrame.getGraphics(); + + if(Trident.engineDraw){ + for(TridEntity e: Trident.currentScene.entities){ + Point p = Trident.player.camera.worldToScreen(e.position); + e.engineRender(g, null, p.x, p.y); + } + } + + ArrayList> splitEnt = Trident.player.camera.splitEntities(Trident.tridArrToEntArr(Trident.currentScene.entities), 16); + if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(2), offX, offY); + if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(0), offX, offY); + if(Trident.drawPlayer){ + Trident.player.render(null, g, WIDTH / 2 - offX, HEIGHT / 2 - offY); + } + if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(1), offX, offY); + + Trident.lightManager.render(Trident.player.camera, Trident.lights, g, offX, offY); + + if(!Trident.engineDraw) Trident.player.camera.render(g, splitEnt.get(3), offX, offY); + + + + + if(Trident.drawCollision){ + g.setColor(Color.red); + ArrayList collision = Trident.currentScene.getCollision(); + collision.add(Trident.player.getCollision()); + for(Rectangle r: collision){ + Point p = Trident.player.camera.worldToScreen(new Position(r.x, r.y)); + g.drawRect(p.x, p.y, r.width, r.height); + g.drawLine(p.x, p.y, p.x + r.width, p.y + r.height); + } + } + + if(Trident.drawPos){ + g.setColor(Trident.debugColor); + g.setFont(new Font("Arial", Font.ITALIC, 10)); + TextBox.draw(Trident.player.getPos().toStringSimple(), g, 10, 20); + } + if(Trident.drawFrames){ + g.setColor(Trident.debugColor); + g.setFont(new Font("Arial", Font.ITALIC, 10)); + TextBox.draw("TPS: " + (1000 / Math.max(MainPanel.server.getElapsedTime(), 1)) + " (" + MainPanel.server.getElapsedTime() + " ms)", g, 10, 30); + TextBox.draw("FPS: " + (1000 / Math.max(elapsedTime, 1)) + " (" + elapsedTime + " ms)", g, 10, 40); + } + + // Apply Post Processing + if(Trident.enableExposure){ + Trident.exposure.filter(newFrame, newFrame); + } + if(Trident.enableBloom){ + Trident.bloom.filter(newFrame, newFrame); + } + + if(MainPanel.inIntro){ + g.setColor(Color.black); + g.fillRect(0, 0, 700, 500); + + if(Trident.splash != null && BTools.hasImage(Trident.splash)){ + // Trident splash + custom splash + MainPanel.splash.paintIcon(null, g, WIDTH / 2 - 80, 40); + Trident.splash.paintIcon(null, g, WIDTH / 2 - 80, HEIGHT - 200); + }else{ + // Trident splash only + MainPanel.splash.paintIcon(null, g, WIDTH / 2 - 80, HEIGHT / 2 - 80); + } + + float alpha = (float)MainPanel.introPos.x; + g.setColor(new Color(0f, 0f, 0f, alpha)); + g.fillRect(0, 0, 700, 500); + } + + if(Trident.consoleOpen){ + // bg + consoleBg.paintIcon(null, g, 0, -252); + g.setColor(new Color(0f, 0f, 0f, 0.7f)); + g.fillRect(0, 0, Trident.getFrameWidth(), Trident.getFrameHeight() / 2); + + // text + g.setColor(Color.white); + g.setFont(new Font("Arial", Font.PLAIN, 10)); + for(int i = 0; i < Trident.consoleLines.size(); i++){ + int index = BTools.flip(i, Trident.consoleLines.size() - 1); + TextBox.draw(Trident.consoleLines.get(index), g, 5, Trident.getFrameHeight() / 2 - 25 - (i * 10)); + } + + // borders + g.setColor(new Color(32, 12, 121)); + g.drawRect(0, 0, Trident.getFrameWidth() - 1, Trident.getFrameHeight() / 2); + g.drawLine(0, Trident.getFrameHeight() / 2 - 10, Trident.getFrameWidth(), Trident.getFrameHeight() / 2 - 10); + + // text entry box + g.setColor(Color.white); + g.setFont(new Font("Arial", Font.PLAIN, 10)); + TextBox.draw("> " + Trident.consoleType + "_", g, 3, Trident.getFrameHeight() / 2 - 5); + } + if(Trident.consoleError){ + errorFlashTime += elapsedTime; + g.setColor(new Color(1f, (float)(Math.min(1, Math.sin(errorFlashTime / 500.0) / 2 + 0.5)), (float)(Math.min(1, Math.sin(errorFlashTime / 500.0) / 2 + 0.5)))); + g.setFont(new Font("Arial", Font.BOLD, 20)); + TextBox.draw("ERROR\nOpen console with [~](tilde)", g, Trident.getFrameWidth() / 2, 10, TextBox.CENTER); + } + + lastFrame = newFrame; + }catch(Exception e){ + if(!(e instanceof ConcurrentModificationException)){ + e.printStackTrace(); + } + } + + + } + } +} diff --git a/data/projects/test/src/trident/Scene.java b/data/projects/test/src/trident/Scene.java new file mode 100644 index 0000000..e456f8f --- /dev/null +++ b/data/projects/test/src/trident/Scene.java @@ -0,0 +1,104 @@ +package trident; + +import java.util.ArrayList; +import java.awt.*; +import java.io.*; +import blib.bson.*; +import blib.util.*; +import trident.ent.*; +import blib.game.*; +public class Scene { + + public final String name; + public ArrayList entities; + protected Position plrStart = new Position(); + protected int plrDir = Player.SOUTH; + protected Color bgColor = Color.white; + protected int defaultLight = 255; + + public Scene(String n){ // Empty scene + name = n; + entities = new ArrayList(); + } + public Scene(File f) throws IOException{ + entities = new ArrayList(); + ArrayList objects = BSonParser.readFile(f.getAbsolutePath()); + BSonObject obj = BSonParser.getObject("name", objects); + name = obj.getString(); + obj = BSonParser.getObject("dir", objects); + if(obj != null){ + String str = obj.getString(); + if(str.equals("west")) plrDir = Player.WEST; + if(str.equals("north")) plrDir = Player.NORTH; + if(str.equals("east")) plrDir = Player.EAST; + } + obj = BSonParser.getObject("bgColor", objects); + BSonList asList = (BSonList)obj; + int r, g, b; + r = asList.list.get(0).getInt(); + g = asList.list.get(1).getInt(); + b = asList.list.get(2).getInt(); + bgColor = new Color(r, g, b); + obj = BSonParser.getObject("light", objects); + defaultLight = obj.getInt(); + obj = BSonParser.getObject("entities", objects); + asList = (BSonList)obj; + for(int i = 0; i < asList.list.size(); i++){ + String objName = asList.list.get(i).getString(); + i++; + boolean foundEnt = false; + for(TridEntity e: Trident.entRegistry){ + if(e.name.equals(objName)){ + double x, y; + x = asList.list.get(i).getDouble(); + i++; + y = asList.list.get(i).getDouble(); + i++; + int w = 0, h = 0; + i++; + if(e.HASCOLLISION){ + w = asList.list.get(i).getInt(); + i++; + h = asList.list.get(i).getInt(); + i++; + } + int[] data = new int[e.numData]; + for(int j = 0; j < e.numData; j++){ + data[j] = asList.list.get(i).getInt(); + i++; + } + i--; + entities.add(e.construct(new Position(x, y), (e.HASCOLLISION ? (new Dimension(w, h)) : null), data)); + foundEnt = true; + break; + } + } + if(!foundEnt) Trident.printConsole("ERROR: no entity type '" + objName + "' found"); + } + + // Check for plrstart + for(TridEntity e: entities){ + if(e instanceof PlrStart){ + plrStart = e.position.copy(); + break; + } + } + } + + public static Scene loadScene(String path){ // stub method ::: Load a scene from a file + return null; + } + + public ArrayList getCollision(){ + ArrayList collision = new ArrayList(); + for(int i = 0; i < entities.size(); i++){ + TridEntity e = entities.get(i); + if(e.HASCOLLISION){ + collision.add(e.getCollision()); + } + } + + return collision; + } + +} diff --git a/data/projects/test/src/trident/TridEntity.java b/data/projects/test/src/trident/TridEntity.java new file mode 100644 index 0000000..9e172c4 --- /dev/null +++ b/data/projects/test/src/trident/TridEntity.java @@ -0,0 +1,101 @@ +package trident; + +import blib.game.*; +import blib.util.*; + +import javax.swing.*; +import java.awt.*; +public class TridEntity extends Entity { + + public final boolean HASCOLLISION; + private final Dimension collision; + public String engineRenderData = ""; + private ImageIcon engineImg = new ImageIcon("data/images/trident/customEnt.png"); + protected String name; + protected int numData; + + public TridEntity(Position pos){ + super(pos); + HASCOLLISION = false; + collision = null; + } + public TridEntity(Position pos, Dimension collision){ + super(pos); + if(collision.equals(new Dimension(0, 0))) HASCOLLISION = false; + else HASCOLLISION = true; + this.collision = collision; + } + public TridEntity(String n, boolean hasColl, int numData){ + super(new Position()); + HASCOLLISION = hasColl; + collision = null; + name = n; + this.numData = numData; + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + System.out.println("Error: tried to create an empty entity"); + return null; + } + + public Rectangle getCollision(){ + return new Rectangle((int)position.x - (collision.width / 2), (int)position.y - (collision.height / 2), collision.width, collision.height); + } + + public void render(Graphics g, JPanel panel, int x, int y){ + + } + + protected void engineRender(Graphics g, JPanel panel, int x, int y){ + if(HASCOLLISION){ + g.setColor(Color.red); + g.drawRect(x - getCollision().width / 2, y - getCollision().height / 2, getCollision().width, getCollision().height); + g.drawLine(x - getCollision().width / 2, y - getCollision().height / 2, x + getCollision().width / 2, y + getCollision().height / 2); + } + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } + + public void update(long elapsedTime){ + + } + + public void sceneStart(String scene){ + + } + + public int getRendDatSort(){ + if(renderType == Entity.TALL){ + return 2; + } + if(renderType == Entity.UNDER){ + return 1; + } + if(renderType == Entity.ABOVE){ + return 3; + } + if(renderType == Entity.BOTTOMPRIORITY){ + return 0; + } + if(renderType == Entity.TOPPRIORITY){ + return 4; + } + return 2; + } + + public int compareSort(TridEntity e){ + if(e.getRendDatSort() > getRendDatSort()){ + // e should be above + return 1; + }else if(e.getRendDatSort() < getRendDatSort()){ + return -1; + } + + if(e.position.y > position.y){ + return 1; + }else if(e.position.y < position.y){ + return -1; + } + + return 0; + } + +} diff --git a/data/projects/test/src/trident/Trident.java b/data/projects/test/src/trident/Trident.java new file mode 100644 index 0000000..695f873 --- /dev/null +++ b/data/projects/test/src/trident/Trident.java @@ -0,0 +1,516 @@ +package trident; + +import blib.game.*; +import blib.util.*; +import java.awt.*; +import java.util.ArrayList; +import java.util.Scanner; + +import javax.swing.*; +import update.*; +import java.io.*; +import trident.ent.*; +import com.jhlabs.image.GlowFilter; +import com.jhlabs.image.ExposureFilter; +public class Trident { + + // Debug Settings + public static boolean drawPos = false; + public static boolean drawCollision = false; + public static boolean noclip = false; + public static boolean engineDraw = false; + public static Color debugColor = Color.red; + public static boolean intro = true; + public static ImageIcon splash = null; + public static boolean drawFrames = false; + public static boolean consoleEnabled = true; + public static boolean consoleOpen = false; + public static boolean consoleError = false; + public static String lastCommand = ""; + + // Public Variables + public static Point mousePos; + public static Point mouseDelta; + public static boolean drawPlayer = true; + public static Position mouseWorldPos = new Position(); + public static boolean enableBloom = true, enableExposure = true; + + + // Trident Variables + protected static Player player; + protected static Scene currentScene; + protected static boolean fullscreen = false; + protected static ArrayList loadedScenes = new ArrayList(); + protected static ArrayList entRegistry = new ArrayList(); + protected static String defaultScene = "default"; + protected static boolean m1 = false, m2 = false, m3 = false, m4 = false, m5 = false; + protected static boolean[] keys = new boolean[255]; + protected static CamShake camShake; + protected static ArrayList lights = new ArrayList(); + protected static LightManager lightManager = new LightManager(255); + protected static GlowFilter bloom = new GlowFilter(); + protected static ExposureFilter exposure = new ExposureFilter(); + protected static boolean reset = false; + protected static String newSprite = null; + + // Trident events + public static final int EVENT_SCREENSHOT = 0; + + + // Setting methods + public static void setPlrSpeed(double speed){ + player.speed = speed; + } + public static void setPlrPos(Position pos){ + player.goToPos(pos); + } + public static void setShortCollision(boolean b){ + player.shortCollision = b; + } + public static void setWindowTitle(String title){ + Main.window.setTitle(title); + } + public static void setupScenes(){ + try{ + loadedScenes = new ArrayList(); + File dir = new File("data/scenes"); + File[] files = dir.listFiles(); + ArrayList sceneFiles = new ArrayList(); + for(File f: files){ + if(BTools.hasExtension(f, "bson")) sceneFiles.add(f); + } + + for(File f: sceneFiles){ + loadedScenes.add(new Scene(f)); + } + }catch(Exception e){ + printException("Error setting up scenes", e); + } + + } + public static void loadScene(String name){ + lights = new ArrayList(); + for(Scene s: loadedScenes){ + if(s.name.equals(name)){ + currentScene = s; + player.goToPos(s.plrStart); + player.setDirection(s.plrDir); + for(TridEntity e: s.entities){ + if(e instanceof TridLight){ + TridLight asLight = (TridLight)e; + lights.add(new Light(asLight.position, asLight.radius)); + } + e.sceneStart(s.name); + } + lightManager.defaultLight = s.defaultLight; + Update.sceneStart(name); + return; + } + } + printConsole("***********************************************************************************"); + printConsole("Error loading scene: No scene with name '" + name + "' found."); + printError("***********************************************************************************"); + } + public static void addCustomEntity(TridEntity e){ // Add a cutsom entity to the registry + entRegistry.add(e); + } + public static void spawnEntity(TridEntity e){ + currentScene.entities.add(e); + } + public static void setDefaultScene(String s){ + defaultScene = s; + } + public static void destroy(TridEntity object){ + getEntities().remove(object); + } + public static void shakeCam(double intensity){ + camShake.addTrauma(intensity); + } + public static void removeShake(){ + camShake.trauma = 0; + } + public static void setShakeStrength(int str){ + camShake.strength = str; + } + public static void setShakeLoss(double loss){ + camShake.traumaLoss = loss; + } + public static void setBloom(double amount){ + bloom.setAmount((float)amount); + } + public static void setExposure(double exp){ + exposure.setExposure((float)exp); + } + public static void setLightBlur(int level){ + lightManager.blur.setIterations(level); + } + public static void addLight(Light l){ + lights.add(l); + } + public static void resetKeys(){ + reset = true; + } + public static void setPlrSprite(String path){ + newSprite = path; + } + public static void removeLight(Light l){ + lights.remove(l); + } + public static void setDefaultLight(int level){ + lightManager.defaultLight = level; + } + public static void stopShake(){ + camShake.trauma = 0; + } + + // Getting methods + public static double getPlrSpeed(){ + return player.speed; + } + public static Position getPlrPos(){ + return player.getPos().copy(); + } + public static Scene getCurrentScene(){ + return currentScene; + } + public static boolean getFullscreen(){ + return fullscreen; + } + public static ArrayList tridArrToEntArr(ArrayList entities){ + ArrayList newEntities = new ArrayList(); + for(TridEntity e: entities){ + newEntities.add((Entity)e); + } + return newEntities; + } + public static ArrayList entArrToTridArr(ArrayList entities){ + ArrayList newEntities = new ArrayList(); + for(Entity e: entities){ + newEntities.add((TridEntity)e); + } + return newEntities; + } + public static ArrayList getEntities(){ + return currentScene.entities; + } + public static ArrayList getCollision(){ + return currentScene.getCollision(); + } + public static boolean getMouseDown(int mb){ + if(mb == 1){ + return m1; + } + if(mb == 2){ + return m2; + } + if(mb == 3){ + return m3; + } + if(mb == 4){ + return m4; + } + if(mb == 5){ + return m5; + } + return false; + } + public static boolean getKeyDown(int key){ + return keys[key]; + } + public static Player getPlr(){ + return player; + } + public static int getFrameWidth(){ + return 684; + } + public static int getFrameHeight(){ + return 462; + } + public static Point getShakeOffset(){ + return new Point(camShake.offX, camShake.offY); + } + + + // Commands + public static ArrayList consoleLines = new ArrayList(); + public static String consoleType = ""; // What the user is typing + + public static void runCommand(String command){ + if(command != null && command.length() > 0){ + lastCommand = command; + printConsole(" > " + command); + + ArrayList cmdParts = new ArrayList(); + Scanner scanner = new Scanner(command); + while(scanner.hasNext()){ + cmdParts.add(scanner.next()); + } + scanner.close(); + + if(cmdParts.size() == 0) return; + try{ + switch(cmdParts.get(0)){ + case "drawCollision": + if(cmdParts.size() == 1){ + printConsole("drawCollision is " + Trident.drawCollision); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.drawCollision = true; + printConsole("set drawCollision to " + Trident.drawCollision); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.drawCollision = false; + printConsole("set drawCollision to " + Trident.drawCollision); + } + break; + case "engineDraw": + if(cmdParts.size() == 1){ + printConsole("engineDraw is " + Trident.engineDraw); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.engineDraw = true; + printConsole("set engineDraw to " + Trident.engineDraw); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.engineDraw = false; + printConsole("set engineDraw to " + Trident.engineDraw); + } + break; + case "drawPos": + if(cmdParts.size() == 1){ + printConsole("drawPos is " + Trident.drawPos); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.drawPos = true; + printConsole("set drawPos to " + Trident.drawPos); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.drawPos = false; + printConsole("set drawPos to " + Trident.drawPos); + } + break; + case "noclip": + if(cmdParts.size() == 1){ + printConsole("noclip is " + Trident.noclip); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.noclip = true; + printConsole("set noclip to " + Trident.noclip); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.noclip = false; + printConsole("set noclip to " + Trident.noclip); + } + break; + case "tp": + int x = Integer.parseInt(cmdParts.get(1)); + int y = Integer.parseInt(cmdParts.get(2)); + Trident.setPlrPos(new Position(x, y)); + printConsole("teleported player to (" + x + ", " + y + ")"); + break; + case "loadMap": + String map = ""; + for(int i = 1; i < cmdParts.size(); i++){ + map += cmdParts.get(i); + if(i != cmdParts.size() - 1) map += " "; + } + Trident.loadScene(map); + break; + case "drawFrames": + if(cmdParts.size() == 1){ + printConsole("drawFrames is " + Trident.drawFrames); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.drawFrames = true; + printConsole("set drawFrames to " + Trident.drawFrames); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.drawFrames = false; + printConsole("set drawFrames to " + Trident.drawFrames); + } + break; + case "debugColor": + int r, g, b; + float alpha = -1; + r = Integer.parseInt(cmdParts.get(1)); + g = Integer.parseInt(cmdParts.get(2)); + b = Integer.parseInt(cmdParts.get(3)); + if(cmdParts.size() == 5){ + alpha = Float.parseFloat(cmdParts.get(4)); + } + if(alpha != -1){ + Trident.debugColor = new Color(r / 255f, g / 255f, b / 255f, alpha); + printConsole("set debugColor to (" + r + ", " + g + ", " + b + ", " + alpha + ")"); + }else{ + Trident.debugColor = new Color(r, g, b); + printConsole("set debugColor to (" + r + ", " + g + ", " + b + ")"); + } + break; + case "enableBloom": + if(cmdParts.size() == 1){ + printConsole("enableBloom is " + Trident.enableBloom); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.enableBloom = true; + printConsole("set enableBloom to " + Trident.enableBloom); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.enableBloom = false; + printConsole("set enableBloom to " + Trident.enableBloom); + } + break; + case "enableExposure": + if(cmdParts.size() == 1){ + printConsole("enableExposure is " + Trident.enableExposure); + break; + } + if(cmdParts.get(1).equals("1") || cmdParts.get(1).equals("true")){ + Trident.enableExposure = true; + printConsole("set enableExposure to " + Trident.enableExposure); + } + if(cmdParts.get(1).equals("0") || cmdParts.get(1).equals("false")){ + Trident.enableExposure = false; + printConsole("set enableExposure to " + Trident.enableExposure); + } + break; + case "setBloom": + double amount = Double.parseDouble(cmdParts.get(1)); + Trident.setBloom(amount); + printConsole("set bloom to " + amount); + break; + case "setExposure": + double expo = Double.parseDouble(cmdParts.get(1)); + Trident.setExposure(expo); + printConsole("set exposure to " + expo); + break; + case "setLightBlur": + int blurLevel = Integer.parseInt(cmdParts.get(1)); + Trident.setLightBlur(blurLevel); + printConsole("set lightBlur to " + blurLevel + " (recommended: 1)"); + break; + case "clear": + consoleLines = new ArrayList(); + break; + case "help": + int page = 1; + if(cmdParts.size() > 1) page = Integer.parseInt(cmdParts.get(1)); + printHelp(page); + break; + case "customHelp": + int p = 1; + if(cmdParts.size() > 1) p = Integer.parseInt(cmdParts.get(1)); + printCustomHelp(p); + break; + case "credits": + runCommand("clear"); + printConsole("Trident Engine built in Java by Blocky"); + printConsole("---"); + printConsole("Github: @HeyIts-Blocky"); + printConsole("Insta: @heyits_blocky"); + printConsole("Itch.io: blockmanblue.itch.io "); + printConsole("---"); + printConsole(""); + break; + case "openItch": + BTools.openWebsite("https://blockmanblue.itch.io/"); + break; + case "errorTest": + consoleOpen = false; + printError("Error test"); + break; + case "roll": + printConsole("You got " + BTools.randInt(0, 101) + " points"); + break; + default: + int cmd = Update.command(cmdParts); + if(cmd != 0){ + printConsole("Unknown command: " + cmdParts.get(0)); + } + break; + } + }catch(Exception e){ + printConsole("Something went wrong while running your command."); + printException("", e); + } + } + } + public static void printConsole(String text){ + consoleLines.add(text); + if(consoleLines.size() > 30) consoleLines.remove(0); + } + public static void printError(String text){ + consoleError = true; + printConsole(text); + } + public static void printException(String text, Exception e){ + consoleError = true; + printConsole(text); + printConsole("Error type: " + e.getClass().getName()); + } + public static void printExceptionSilent(String text, Exception e){ + printConsole(text); + printConsole("Error type: " + e.getClass().getName()); + } + private static String[] cmds = { + "credits", + "drawCollision [0/1, false/true]", + "engineDraw [0/1, false/true]", + "drawPos [0/1, false/true]", + "noclip [0/1, false/true]", + "tp ", + "loadMap ", + "drawFrames [0/1, false/true]", + "debugColor [a]", + "enableBloom [0/1, false/true]", + "enableExposure [0/1, false/true]", + "setBloom ", + "setExposure ", + "setLightBlur ", + "clear", + "help [page]", + "customHelp [page]", + "errorTest", + "roll", + }; + + public static void printHelp(int page){ + int startIndex = (page - 1) * 10; + if(startIndex > cmds.length - 1){ + printConsole("page beyond bounds: " + page); + printConsole("number of pages: " + (cmds.length / 10 + ((cmds.length % 10 != 0) ? 1 : 0))); + return; + } + + printConsole("-- BUILT-IN COMMANDS --"); + printConsole("Page " + page + " of " + (cmds.length / 10 + ((cmds.length % 10 != 0) ? 1 : 0))); + printConsole(""); + for(int i = startIndex; (i < cmds.length && i < startIndex + 10); i++){ + printConsole("} " + cmds[i]); + } + printConsole(""); + } + + public static void printCustomHelp(int page){ + int startIndex = (page - 1) * 10; + if(startIndex > Update.commands.length - 1){ + printConsole("page beyond bounds: " + page); + printConsole("number of pages: " + (Update.commands.length / 10 + ((Update.commands.length % 10 != 0) ? 1 : 0))); + return; + } + + printConsole("-- GAME-SPECIFIC COMMANDS --"); + printConsole("Page " + page + " of " + (Update.commands.length / 10 + ((Update.commands.length % 10 != 0) ? 1 : 0))); + printConsole(""); + for(int i = startIndex; (i < Update.commands.length && i < startIndex + 10); i++){ + printConsole("} " + Update.commands[i]); + } + printConsole(""); + } + +} diff --git a/data/projects/test/src/trident/ent/BoxColl.java b/data/projects/test/src/trident/ent/BoxColl.java new file mode 100644 index 0000000..8201a9d --- /dev/null +++ b/data/projects/test/src/trident/ent/BoxColl.java @@ -0,0 +1,37 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import trident.*; +public class BoxColl extends TridEntity{ + + public Color color = Color.white; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/boxColl.png"); + + public BoxColl(Position pos, Dimension size, Color c){ + super(pos, size); + color = c; + } + public BoxColl(Position pos, Dimension size){ + super(pos, size); + } + public BoxColl(){ + super("boxcoll", true, 3); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new BoxColl(pos, collision, new Color(data[0], data[1], data[2])); + } + + public void render(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.fillRect(x - getCollision().width / 2, y - getCollision().height / 2, getCollision().width, getCollision().height); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + render(g, panel, x, y); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/projects/test/src/trident/ent/BoxNoColl.java b/data/projects/test/src/trident/ent/BoxNoColl.java new file mode 100644 index 0000000..e12beb7 --- /dev/null +++ b/data/projects/test/src/trident/ent/BoxNoColl.java @@ -0,0 +1,45 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; +import blib.game.*; + +import trident.*; +public class BoxNoColl extends TridEntity{ + + public Color color = Color.white; + public int width, height; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/box.png"); + + public BoxNoColl(Position pos, Color c, int w, int h){ + super(pos); + color = c; + width = w; + height = h; + renderType = Entity.UNDER; + } + public BoxNoColl(Position pos, int w, int h){ + super(pos); + width = w; + height = h; + renderType = Entity.UNDER; + } + public BoxNoColl(){ + super("boxnocoll", false, 5); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new BoxNoColl(pos, new Color(data[2], data[3], data[4]), data[0], data[1]); + } + + public void render(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.fillRect(x - width / 2, y - height / 2, width, height); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + render(g, panel, x, y); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/projects/test/src/trident/ent/InvisColl.java b/data/projects/test/src/trident/ent/InvisColl.java new file mode 100644 index 0000000..7736536 --- /dev/null +++ b/data/projects/test/src/trident/ent/InvisColl.java @@ -0,0 +1,30 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import trident.*; +public class InvisColl extends TridEntity{ + + public Color color = Color.red; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/collision.png"); + + public InvisColl(Position pos, Dimension size){ + super(pos, size); + } + public InvisColl(){ + super("inviscoll", true, 0); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new InvisColl(pos, collision); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.drawRect(x - getCollision().width / 2, y - getCollision().height / 2, getCollision().width, getCollision().height); + g.drawLine(x - getCollision().width / 2, y - getCollision().height / 2, x + getCollision().width / 2, y + getCollision().height / 2); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/projects/test/src/trident/ent/PlrStart.java b/data/projects/test/src/trident/ent/PlrStart.java new file mode 100644 index 0000000..26fe13d --- /dev/null +++ b/data/projects/test/src/trident/ent/PlrStart.java @@ -0,0 +1,26 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import trident.*; +public class PlrStart extends TridEntity{ + public Color color = Color.red; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/plrStart.png"); + + public PlrStart(Position pos){ + super(pos); + } + public PlrStart(){ + super("plrstart", false, 0); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new PlrStart(pos); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/projects/test/src/trident/ent/TridLight.java b/data/projects/test/src/trident/ent/TridLight.java new file mode 100644 index 0000000..888bf49 --- /dev/null +++ b/data/projects/test/src/trident/ent/TridLight.java @@ -0,0 +1,28 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import trident.*; +public class TridLight extends TridEntity{ + + public int radius; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/light.png"); + + public TridLight(Position pos, int r){ + super(pos); + radius = r; + } + public TridLight(){ + super("light", false, 1); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new TridLight(pos, data[0]); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/projects/test/src/trident/ent/Trigger.java b/data/projects/test/src/trident/ent/Trigger.java new file mode 100644 index 0000000..d52126d --- /dev/null +++ b/data/projects/test/src/trident/ent/Trigger.java @@ -0,0 +1,41 @@ +package trident.ent; + +import blib.util.*; +import java.awt.*; +import javax.swing.*; + +import trident.*; +public class Trigger extends TridEntity{ + + public Color color = Color.blue; + public Dimension box; + public int id; + + private ImageIcon engineImg = new ImageIcon("data/images/trident/trigger.png"); + + public Trigger(Position pos, Dimension size, int i){ + super(pos); + name = "trigger"; + box = size; + id = i; + } + public Trigger(){ + super("trigger", false, 3); + } + public TridEntity construct(Position pos, Dimension collision, int[] data){ + return new Trigger(pos, new Dimension(data[0], data[1]), data[2]); + } + + public boolean containsPos(Position pos){ + Point p = new Point((int)pos.x, (int)pos.y); + Rectangle rect = new Rectangle((int)position.x - box.width / 2, (int)position.y - box.height / 2, box.width, box.height); + return rect.contains(p); + } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + g.setColor(color); + g.drawRect(x - box.width / 2, y - box.height / 2, box.width, box.height); + g.drawLine(x - box.width / 2, y - box.height / 2, x + box.width / 2, y + box.height / 2); + engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); + } +} diff --git a/data/projects/test/src/update/Inputs.java b/data/projects/test/src/update/Inputs.java new file mode 100644 index 0000000..0fc6ecc --- /dev/null +++ b/data/projects/test/src/update/Inputs.java @@ -0,0 +1,19 @@ +package update; + +import java.awt.*; +import java.awt.event.*; +import blib.util.*; +public class Inputs { + + public static void keyPressed(int key){ + + } + + public static void mousePressed(int mb, Point mousePos, Position worldPos){ + + } + + public static void onScroll(int scroll){ + + } +} diff --git a/data/projects/test/src/update/Update.java b/data/projects/test/src/update/Update.java new file mode 100644 index 0000000..57a2e9b --- /dev/null +++ b/data/projects/test/src/update/Update.java @@ -0,0 +1,59 @@ +package update; + +import trident.*; +import ent.*; +import java.util.ArrayList; +public class Update { + + public static final String[] fonts = {}; // add fonts here + + public static void setup(){ + // Add custom entities to the registry here. Required in order to load them properly + Trident.addCustomEntity(new ExampleEntity()); // Use the empty constructor + + // Set settings + Trident.setPlrSpeed(0.2); + Trident.setShortCollision(true); + + // Post Processing + Trident.setBloom(0.2); + Trident.setExposure(1); + Trident.enableBloom = false; + Trident.enableExposure = false; + Trident.setLightBlur(1); + } + + public static void sceneStart(String scene){ + + } + + public static void update(long elapsedTime){ + + } + + public static void trigger(int id){ + + } + + public static void tridentEvent(int id){ + if(id == Trident.EVENT_SCREENSHOT){ + Trident.printConsole("Took a screenshot!"); + } + } + + public static int command(ArrayList cmdParts){ // cmdParts.get(0) is the command, while the rest are arguments for the command. + switch(cmdParts.get(0)){ + case "helloWorld": + Trident.printConsole("Hello, World!"); + return 0; + case "ping": + Trident.printConsole("pong"); + return 0; + } + return 1; // return 1 if command is not recognized + } + public static String[] commands = { // Fill this with the format for all custom commands + "helloWorld", + "ping", + }; +} diff --git a/lib/BLib.jar b/lib/BLib.jar index 99e9d99..558b0ae 100644 Binary files a/lib/BLib.jar and b/lib/BLib.jar differ diff --git a/src/main/MainPanel.java b/src/main/MainPanel.java index 7c67975..4757334 100644 --- a/src/main/MainPanel.java +++ b/src/main/MainPanel.java @@ -10,6 +10,7 @@ import blib.game.*; import java.io.*; import project.ent.*; import project.ent.Light; +import java.util.ArrayList; public class MainPanel extends JPanel { Project project; @@ -73,41 +74,14 @@ public class MainPanel extends JPanel { frameManager.bgColor = project.currentScene.bgColor; + ArrayList ents = new ArrayList(); + for(TridEntity e: project.currentScene.entities) ents.add((Entity)e); + cam.render(g, ents); for(TridEntity e: project.currentScene.entities){ Point p = cam.worldToScreen(e.position); - e.engineRender(g, this, p.x, p.y); if(e.equals(selectedEntity)){ g.setColor(new Color(0f, 0.2f, 1f, 0.5f)); - g.fillOval(p.x - 32, p.y - 32, 64, 64); - } - if(e instanceof CustomEntity){ - CustomEntity c = (CustomEntity)e; - String str = "["; - for(int i = 0; i < c.data.length; i++){ - str += c.data[i] + ""; - if(i == c.data.length - 1){ - str += "]"; - }else{ - str += ", "; - } - } - if(c.data.length == 0) str = "NO DATA"; - g.setColor(Color.white); - int width = Math.max(g.getFontMetrics().stringWidth(str), g.getFontMetrics().stringWidth(c.name)); - g.fillRect(p.x - width / 2, p.y + 32 - 5, width, 20); - g.setColor(Color.black); - g.setFont(new Font("Arial", Font.PLAIN, 10)); - TextBox.draw(c.name + "\n" + str, g, p.x, p.y + 32, TextBox.CENTER); - } - if(e instanceof Trigger){ - Trigger trig = (Trigger)e; - String str = "" + trig.id; - g.setColor(Color.white); - int width = g.getFontMetrics().stringWidth(str); - g.fillRect(p.x - width / 2, p.y + 32 - 5, width, 10); - g.setColor(Color.black); - g.setFont(new Font("Arial", Font.PLAIN, 10)); - TextBox.draw(str, g, p.x, p.y + 32, TextBox.CENTER); + g.fillOval((int)((p.x / cam.getZoom()) - 32), (int)((p.y / cam.getZoom()) - 32), 64, 64); } } @@ -128,7 +102,7 @@ public class MainPanel extends JPanel { TextBox.draw("Saved!", g, 10, frameManager.HEIGHT - 20); g.setColor(Color.white); g.setFont(new Font("Arial", Font.PLAIN, 15)); - TextBox.draw("(" + cam.pos.toStringSimple() + ")", g, frameManager.WIDTH, 10, TextBox.RIGHT); + TextBox.draw("(" + cam.pos.toStringSimple() + ")\nx" + BTools.simplifyDouble(cam.getZoom()), g, frameManager.WIDTH, 10, TextBox.RIGHT); if(dropDown){ g.setColor(Color.lightGray); @@ -547,7 +521,7 @@ public class MainPanel extends JPanel { } } } - + if(mb == 2) cam.setZoom(1); if(mb == 3){ if(selectedEntity == null){ dropDown = true; @@ -561,6 +535,13 @@ public class MainPanel extends JPanel { } } + + public void onScroll(int scroll){ + double zDelta = scroll * 0.1; + if(km.getKeyDown(KeyEvent.VK_SHIFT)) zDelta *= 2; + if(km.getKeyDown(KeyEvent.VK_CONTROL)) zDelta /= 2; + cam.setZoom(BTools.clamp(cam.getZoom() + zDelta, 0.1, 15)); + } } MainPanel parent = this; @@ -579,8 +560,8 @@ public class MainPanel extends JPanel { double speed = 0.5; if(km.getKeyDown(KeyEvent.VK_SHIFT)) speed *= 2; if(km.getKeyDown(KeyEvent.VK_CONTROL)) speed /= 2; - cam.pos.x += dir.x * server.getElapsedTime() * speed; - cam.pos.y += dir.y * server.getElapsedTime() * speed; + cam.pos.x += dir.x * server.getElapsedTime() * speed * cam.getZoom(); + cam.pos.y += dir.y * server.getElapsedTime() * speed * cam.getZoom(); diff --git a/src/project/TridEntity.java b/src/project/TridEntity.java index fc5076d..4414a82 100644 --- a/src/project/TridEntity.java +++ b/src/project/TridEntity.java @@ -46,7 +46,7 @@ public class TridEntity extends Entity { } public void render(Graphics g, JPanel panel, int x, int y){ - + engineRender(g, panel, x, y); } public void engineRender(Graphics g, JPanel panel, int x, int y){ diff --git a/src/project/ent/BoxColl.java b/src/project/ent/BoxColl.java index 8dff658..e1e3e64 100644 --- a/src/project/ent/BoxColl.java +++ b/src/project/ent/BoxColl.java @@ -28,12 +28,12 @@ public class BoxColl extends TridEntity{ } 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); + engineRender(g, panel, x, y); } public void engineRender(Graphics g, JPanel panel, int x, int y){ - render(g, panel, x, y); + g.setColor(color); + g.fillRect(x - getCollision().width / 2, y - getCollision().height / 2, getCollision().width, getCollision().height); engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); } } diff --git a/src/project/ent/BoxNoColl.java b/src/project/ent/BoxNoColl.java index 097a561..8138431 100644 --- a/src/project/ent/BoxNoColl.java +++ b/src/project/ent/BoxNoColl.java @@ -36,12 +36,12 @@ public class BoxNoColl extends TridEntity{ } public void render(Graphics g, JPanel panel, int x, int y){ - g.setColor(color); - g.fillRect(x - width / 2, y - height / 2, width, height); + engineRender(g, panel, x, y); } public void engineRender(Graphics g, JPanel panel, int x, int y){ - render(g, panel, x, y); + g.setColor(color); + g.fillRect(x - width / 2, y - height / 2, width, height); engineImg.paintIcon(panel, g, x - engineImg.getIconWidth() / 2, y - engineImg.getIconHeight() / 2); } } diff --git a/src/project/ent/CustomEntity.java b/src/project/ent/CustomEntity.java index cfb152a..eb0a498 100644 --- a/src/project/ent/CustomEntity.java +++ b/src/project/ent/CustomEntity.java @@ -3,6 +3,8 @@ package project.ent; import blib.util.*; import project.*; import java.awt.*; + +import javax.swing.JPanel; public class CustomEntity extends TridEntity{ public int[] data; @@ -15,4 +17,24 @@ public class CustomEntity extends TridEntity{ public CustomEntity(){ super("custom", false, 0); } + + public void engineRender(Graphics g, JPanel panel, int x, int y){ + super.engineRender(g, panel, x, y);String str = "["; + for(int i = 0; i < data.length; i++){ + str += data[i] + ""; + if(i == data.length - 1){ + str += "]"; + }else{ + str += ", "; + } + } + if(data.length == 0) str = "NO DATA"; + g.setColor(Color.white); + int width = Math.max(g.getFontMetrics().stringWidth(str), g.getFontMetrics().stringWidth(name)); + g.fillRect(x - width / 2, y + 32 - 5, width, 20); + g.setColor(Color.black); + g.setFont(new Font("Arial", Font.PLAIN, 10)); + TextBox.draw(name + "\n" + str, g, x, y + 32, TextBox.CENTER); + + } } diff --git a/src/project/ent/Trigger.java b/src/project/ent/Trigger.java index 38e775f..bbd2e82 100644 --- a/src/project/ent/Trigger.java +++ b/src/project/ent/Trigger.java @@ -31,5 +31,13 @@ public class Trigger extends TridEntity{ 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); + + String str = "" + id; + g.setColor(Color.white); + int width = g.getFontMetrics().stringWidth(str); + g.fillRect(x - width / 2, y + 32 - 5, width, 10); + g.setColor(Color.black); + g.setFont(new Font("Arial", Font.PLAIN, 10)); + TextBox.draw(str, g, x, y + 32, TextBox.CENTER); } }