This commit is contained in:
Blocky 2024-05-06 15:31:45 -06:00 committed by GitHub
parent ba894d7e91
commit 5507b3b074
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 60 additions and 2 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: 111 B

Binary file not shown.

View file

@ -9,6 +9,7 @@ import java.awt.*;
import blib.game.*; import blib.game.*;
import java.io.*; import java.io.*;
import project.ent.*; import project.ent.*;
import project.ent.Light;
public class MainPanel extends JPanel { public class MainPanel extends JPanel {
Project project; Project project;
@ -47,6 +48,9 @@ public class MainPanel extends JPanel {
ImageIcon triggerImg = new ImageIcon("data/images/dropdown/trigger.png"); ImageIcon triggerImg = new ImageIcon("data/images/dropdown/trigger.png");
ImageIcon lightImg = new ImageIcon("data/images/dropdown/light.png"); ImageIcon lightImg = new ImageIcon("data/images/dropdown/light.png");
ImageIcon crosshair = new ImageIcon("data/images/crosshair.png");
boolean drawCross = true;
long saveTime = 0; long saveTime = 0;
TridEntity selectedEntity = null; TridEntity selectedEntity = null;
@ -122,6 +126,9 @@ public class MainPanel extends JPanel {
TextBox.draw("[L] Show Darkness: " + drawLight + " Default light level: " + project.currentScene.defaultLight, g, frameManager.WIDTH - 10, frameManager.HEIGHT - 20, TextBox.RIGHT); 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))); g.setColor(new Color(1f, 1f, 1f, (saveTime / 1000f)));
TextBox.draw("Saved!", g, 10, frameManager.HEIGHT - 20); TextBox.draw("Saved!", g, 10, frameManager.HEIGHT - 20);
g.setColor(Color.white);
g.setFont(new Font("Arial", Font.PLAIN, 15));
TextBox.draw("(" + cam.pos.toStringSimple() + ")", g, frameManager.WIDTH, 10, TextBox.RIGHT);
if(dropDown){ if(dropDown){
g.setColor(Color.lightGray); g.setColor(Color.lightGray);
@ -178,6 +185,8 @@ public class MainPanel extends JPanel {
} }
} }
if(drawCross) crosshair.paintIcon(this, g, frameManager.WIDTH / 2 - 4, frameManager.HEIGHT / 2 - 4);
frameManager.renderFrame(this, graphics); frameManager.renderFrame(this, graphics);
} }
@ -215,22 +224,32 @@ public class MainPanel extends JPanel {
if(selectedEntity instanceof BoxColl){ if(selectedEntity instanceof BoxColl){
BoxColl box = (BoxColl)selectedEntity; BoxColl box = (BoxColl)selectedEntity;
project.currentScene.entities.add(new BoxColl(box.position.copy(), new Dimension(box.collision.width, box.collision.height), box.color)); project.currentScene.entities.add(new BoxColl(box.position.copy(), new Dimension(box.collision.width, box.collision.height), box.color));
selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1);
} }
if(selectedEntity instanceof BoxNoColl){ if(selectedEntity instanceof BoxNoColl){
BoxNoColl box = (BoxNoColl)selectedEntity; BoxNoColl box = (BoxNoColl)selectedEntity;
project.currentScene.entities.add(new BoxNoColl(box.position.copy(), box.color, box.width, box.height)); project.currentScene.entities.add(new BoxNoColl(box.position.copy(), box.color, box.width, box.height));
selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1);
} }
if(selectedEntity instanceof InvisColl){ if(selectedEntity instanceof InvisColl){
InvisColl box = (InvisColl)selectedEntity; InvisColl box = (InvisColl)selectedEntity;
project.currentScene.entities.add(new InvisColl(box.position.copy(), new Dimension(box.collision.width, box.collision.height))); project.currentScene.entities.add(new InvisColl(box.position.copy(), new Dimension(box.collision.width, box.collision.height)));
selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1);
} }
if(selectedEntity instanceof Trigger){ if(selectedEntity instanceof Trigger){
Trigger box = (Trigger)selectedEntity; Trigger box = (Trigger)selectedEntity;
project.currentScene.entities.add(new Trigger(box.position.copy(), new Dimension(box.box.width, box.box.height), box.id)); project.currentScene.entities.add(new Trigger(box.position.copy(), new Dimension(box.box.width, box.box.height), box.id));
selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1);
} }
if(selectedEntity instanceof PlrStart){ if(selectedEntity instanceof PlrStart){
PlrStart box = (PlrStart)selectedEntity; PlrStart box = (PlrStart)selectedEntity;
project.currentScene.entities.add(new PlrStart(box.position.copy())); project.currentScene.entities.add(new PlrStart(box.position.copy()));
selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1);
}
if(selectedEntity instanceof Light){
Light box = (Light)selectedEntity;
project.currentScene.entities.add(new Light(box.position.copy(), box.radius));
selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1);
} }
if(selectedEntity instanceof CustomEntity){ if(selectedEntity instanceof CustomEntity){
CustomEntity box = (CustomEntity)selectedEntity; CustomEntity box = (CustomEntity)selectedEntity;
@ -241,11 +260,15 @@ public class MainPanel extends JPanel {
Dimension collision = null; Dimension collision = null;
if(box.collision != null) collision = new Dimension(box.collision.width, box.collision.height); if(box.collision != null) collision = new Dimension(box.collision.width, box.collision.height);
project.currentScene.entities.add(new CustomEntity(box.position.copy(), collision, data, box.name)); project.currentScene.entities.add(new CustomEntity(box.position.copy(), collision, data, box.name));
selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1);
} }
} }
if(key == KeyEvent.VK_L){ if(key == KeyEvent.VK_L){
drawLight = !drawLight; drawLight = !drawLight;
} }
if(key == KeyEvent.VK_C && !km.getKeyDown(KeyEvent.VK_CONTROL)){
drawCross = !drawCross;
}
} }
public void onMousePressed(int mb, Point mousePos){ public void onMousePressed(int mb, Point mousePos){
@ -305,22 +328,32 @@ public class MainPanel extends JPanel {
if(selectedEntity instanceof BoxColl){ if(selectedEntity instanceof BoxColl){
BoxColl box = (BoxColl)selectedEntity; BoxColl box = (BoxColl)selectedEntity;
project.currentScene.entities.add(new BoxColl(box.position.copy(), new Dimension(box.collision.width, box.collision.height), box.color)); project.currentScene.entities.add(new BoxColl(box.position.copy(), new Dimension(box.collision.width, box.collision.height), box.color));
selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1);
} }
if(selectedEntity instanceof BoxNoColl){ if(selectedEntity instanceof BoxNoColl){
BoxNoColl box = (BoxNoColl)selectedEntity; BoxNoColl box = (BoxNoColl)selectedEntity;
project.currentScene.entities.add(new BoxNoColl(box.position.copy(), box.color, box.width, box.height)); project.currentScene.entities.add(new BoxNoColl(box.position.copy(), box.color, box.width, box.height));
selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1);
} }
if(selectedEntity instanceof InvisColl){ if(selectedEntity instanceof InvisColl){
InvisColl box = (InvisColl)selectedEntity; InvisColl box = (InvisColl)selectedEntity;
project.currentScene.entities.add(new InvisColl(box.position.copy(), new Dimension(box.collision.width, box.collision.height))); project.currentScene.entities.add(new InvisColl(box.position.copy(), new Dimension(box.collision.width, box.collision.height)));
selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1);
} }
if(selectedEntity instanceof Trigger){ if(selectedEntity instanceof Trigger){
Trigger box = (Trigger)selectedEntity; Trigger box = (Trigger)selectedEntity;
project.currentScene.entities.add(new Trigger(box.position.copy(), new Dimension(box.box.width, box.box.height), box.id)); project.currentScene.entities.add(new Trigger(box.position.copy(), new Dimension(box.box.width, box.box.height), box.id));
selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1);
} }
if(selectedEntity instanceof PlrStart){ if(selectedEntity instanceof PlrStart){
PlrStart box = (PlrStart)selectedEntity; PlrStart box = (PlrStart)selectedEntity;
project.currentScene.entities.add(new PlrStart(box.position.copy())); project.currentScene.entities.add(new PlrStart(box.position.copy()));
selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1);
}
if(selectedEntity instanceof Light){
Light box = (Light)selectedEntity;
project.currentScene.entities.add(new Light(box.position.copy(), box.radius));
selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1);
} }
if(selectedEntity instanceof CustomEntity){ if(selectedEntity instanceof CustomEntity){
CustomEntity box = (CustomEntity)selectedEntity; CustomEntity box = (CustomEntity)selectedEntity;
@ -331,6 +364,7 @@ public class MainPanel extends JPanel {
Dimension collision = null; Dimension collision = null;
if(box.collision != null) collision = new Dimension(box.collision.width, box.collision.height); if(box.collision != null) collision = new Dimension(box.collision.width, box.collision.height);
project.currentScene.entities.add(new CustomEntity(box.position.copy(), collision, data, box.name)); project.currentScene.entities.add(new CustomEntity(box.position.copy(), collision, data, box.name));
selectedEntity = project.currentScene.entities.get(project.currentScene.entities.size() - 1);
} }
break; break;
case 2: case 2:
@ -461,6 +495,8 @@ public class MainPanel extends JPanel {
boolean loaded = project.loadScene(name); boolean loaded = project.loadScene(name);
if(!loaded){ if(!loaded){
JOptionPane.showMessageDialog(panel, "Error: no scene with name '" + name + "' found.", "Trident", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(panel, "Error: no scene with name '" + name + "' found.", "Trident", JOptionPane.ERROR_MESSAGE);
}else{
cam.pos = new Position();
} }
} }
}else if(mousePos.x < 327){ }else if(mousePos.x < 327){
@ -470,6 +506,7 @@ public class MainPanel extends JPanel {
scene.save("data/projects/" + project.name); scene.save("data/projects/" + project.name);
project.setupScenes(); project.setupScenes();
project.loadScene(name); project.loadScene(name);
cam.pos = new Position();
} }
}else if(mousePos.x < 391){ }else if(mousePos.x < 391){
project.currentScene.save("data/projects/" + project.name); project.currentScene.save("data/projects/" + project.name);
@ -477,6 +514,23 @@ public class MainPanel extends JPanel {
}else if(mousePos.x < 520){ }else if(mousePos.x < 520){
project.currentScene.plrDir++; project.currentScene.plrDir++;
if(project.currentScene.plrDir > 3) project.currentScene.plrDir = 0; if(project.currentScene.plrDir > 3) project.currentScene.plrDir = 0;
}else{
try{
double x, y;
String inputX = JOptionPane.showInputDialog(panel, "Enter the x position", "Trident", JOptionPane.QUESTION_MESSAGE);
if(inputX != null){
x = Double.parseDouble(inputX);
String inputY = JOptionPane.showInputDialog(panel, "Enter the y position", "Trident", JOptionPane.QUESTION_MESSAGE);
if(inputY != null){
y = Double.parseDouble(inputY);
cam.pos = new Position(x, y);
}
}
}catch(Exception e){
JOptionPane.showMessageDialog(panel, "Invalid input", "Trident", JOptionPane.ERROR_MESSAGE);
}
} }
}else{ }else{
if(tool == 0){ if(tool == 0){
@ -528,12 +582,18 @@ public class MainPanel extends JPanel {
cam.pos.x += dir.x * server.getElapsedTime() * speed; cam.pos.x += dir.x * server.getElapsedTime() * speed;
cam.pos.y += dir.y * server.getElapsedTime() * speed; cam.pos.y += dir.y * server.getElapsedTime() * speed;
saveTime -= server.getElapsedTime(); saveTime -= server.getElapsedTime();
if(saveTime < 0) saveTime = 0; if(saveTime < 0) saveTime = 0;
if(tool == 1 && selectedEntity != null && km.getMouseDown(1)){ if(tool == 1 && selectedEntity != null && km.getMouseDown(1)){
selectedEntity.position.x += delta.x; selectedEntity.position.x += delta.x;
selectedEntity.position.y += delta.y; selectedEntity.position.y += delta.y;
selectedEntity.position.x += dir.x * server.getElapsedTime() * speed;
selectedEntity.position.y += dir.y * server.getElapsedTime() * speed;
} }
if(tool == 2 && selectedEntity != null && km.getMouseDown(1)){ if(tool == 2 && selectedEntity != null && km.getMouseDown(1)){
if(selectedEntity instanceof project.ent.Light){ if(selectedEntity instanceof project.ent.Light){

View file

@ -52,13 +52,11 @@ public class Scene {
obj = BSonParser.getObject("entities", objects); obj = BSonParser.getObject("entities", objects);
asList = (BSonList)obj; asList = (BSonList)obj;
for(int i = 0; i < asList.list.size(); i++){ for(int i = 0; i < asList.list.size(); i++){
System.out.println(i);
String objName = asList.list.get(i).getString(); String objName = asList.list.get(i).getString();
i++; i++;
boolean foundEnt = false; boolean foundEnt = false;
for(TridEntity e: entRegistry){ for(TridEntity e: entRegistry){
if(e.name.equals(objName)){ if(e.name.equals(objName)){
System.out.println("load " + objName);
double x, y; double x, y;
x = asList.list.get(i).getDouble(); x = asList.list.get(i).getDouble();
i++; i++;