diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
new file mode 100644
index 0000000..797acea
--- /dev/null
+++ b/.idea/runConfigurations.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src.uml b/src.uml
new file mode 100644
index 0000000..48a0433
--- /dev/null
+++ b/src.uml
@@ -0,0 +1,943 @@
+
+
+ JAVA
+ C:/Users/Stefan/Documents/code/School-Programming-Projekt-022022/src
+
+ com.yes.yes.ui.BuildBox
+ com.yes.yes.behaviours.TestRecieveBeahaviour
+ com.yes.yes.utils.GlobalEventHandler
+ com.yes.yes.entities.machines.TestMachine2
+ com.yes.yes.utils.EventHandler
+ com.yes.yes.utils.Component
+ com.yes.yes.behaviours.TestOffererBehaviour
+ com.yes.yes.entities.parts.Square
+ com.yes.yes.behaviours.TestBehaviour
+ com.yes.yes.utils.RegistryEntry
+ com.yes.yes.world.Chunk
+ com.yes.yes.entities.machines.TestMachine
+ com.yes.yes.utils.BlockContainer
+ com.yes.yes.MainController
+ com.yes.yes.world.World
+ com.yes.yes.utils.Direction
+ com.yes.yes.ui.BuildItem
+ com.yes.yes.behaviours.OfferBehaviour
+ com.yes.yes.YesApplication
+ com.yes.yes.utils.EntityRegistry
+ com.yes.yes.utils.Part
+ com.yes.yes.behaviours.PlaceBehaviour
+ com.yes.yes.behaviours.ItemBehaviour
+ com.yes.yes.utils.Coordinate
+ com.yes.yes.utils.Entity
+ com.yes.yes.utils.exceptions.AlreadyExistsException
+ com.yes.yes.managers.PlayerManager
+ com.yes.yes.utils.Item
+ com.yes.yes.managers.GameManager
+ com.yes.yes.utils.Size
+ com.yes.yes.managers.UiManager
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ All
+ private
+
+
diff --git a/src/main/java/com/yes/yes/YesApplication.java b/src/main/java/com/yes/yes/YesApplication.java
index f5f59ff..c756c58 100644
--- a/src/main/java/com/yes/yes/YesApplication.java
+++ b/src/main/java/com/yes/yes/YesApplication.java
@@ -16,7 +16,7 @@ public class YesApplication extends javafx.application.Application {
@Override
public void stop() {
- System.out.println("closing bro");
+ System.out.println("Closing!");
GlobalEventHandler.trigger("closing",null);
}
diff --git a/src/main/java/com/yes/yes/behaviours/ConveyorBehaviour.java b/src/main/java/com/yes/yes/behaviours/ConveyorBehaviour.java
index aa1e525..7b77709 100644
--- a/src/main/java/com/yes/yes/behaviours/ConveyorBehaviour.java
+++ b/src/main/java/com/yes/yes/behaviours/ConveyorBehaviour.java
@@ -27,10 +27,11 @@ public class ConveyorBehaviour extends Component {
@Override
public void update() {
if (count > delay) {
+ count = 0;
+
if (parent.getData(offerDataKey) != null) return;
parent.setData(offerDataKey, parent.getData(receiveDataKey));
- count = 0;
isConveyed = true;
} else if (parent.getData(receiveDataKey) != null && !isConveyed) {
count++;
diff --git a/src/main/java/com/yes/yes/behaviours/GeneratorBehaviour.java b/src/main/java/com/yes/yes/behaviours/GeneratorBehaviour.java
index fdf00cb..8faa4b8 100644
--- a/src/main/java/com/yes/yes/behaviours/GeneratorBehaviour.java
+++ b/src/main/java/com/yes/yes/behaviours/GeneratorBehaviour.java
@@ -24,7 +24,6 @@ public class GeneratorBehaviour extends Component {
@Override
public void update() {
this.parent.setData(dataKey, item.clone());
- System.out.println("generate");
}
@Override
diff --git a/src/main/java/com/yes/yes/behaviours/OfferBehaviour.java b/src/main/java/com/yes/yes/behaviours/OfferBehaviour.java
index 6459f02..43fa2c8 100644
--- a/src/main/java/com/yes/yes/behaviours/OfferBehaviour.java
+++ b/src/main/java/com/yes/yes/behaviours/OfferBehaviour.java
@@ -7,6 +7,7 @@ public class OfferBehaviour extends Component {
private Coordinate direction;
private String dataKey;
+
private Entity receiver;
@@ -21,7 +22,6 @@ public class OfferBehaviour extends Component {
//System.out.println("Entity placed in range");
try {
if (blockContainer.getBlockRelative(direction, parent.getRotation()) == entity) {
- //System.out.println("Success");
this.receiver = entity;
}
} catch (IllegalAccessException e) {
diff --git a/src/main/java/com/yes/yes/behaviours/RecieveBehaviour.java b/src/main/java/com/yes/yes/behaviours/RecieveBehaviour.java
index 13bb4db..c373273 100644
--- a/src/main/java/com/yes/yes/behaviours/RecieveBehaviour.java
+++ b/src/main/java/com/yes/yes/behaviours/RecieveBehaviour.java
@@ -20,7 +20,6 @@ public class RecieveBehaviour extends Component {
System.out.println("Entity placed in range");
try {
if (blockContainer.getBlockRelative(direction, parent.getRotation()) == entity) {
- System.out.println("Success");
this.offerer = entity;
}
} catch (IllegalAccessException e) {
diff --git a/src/main/java/com/yes/yes/entities/machines/GeneratorMachine.java b/src/main/java/com/yes/yes/entities/machines/GeneratorMachine.java
index 2452664..3b7cffc 100644
--- a/src/main/java/com/yes/yes/entities/machines/GeneratorMachine.java
+++ b/src/main/java/com/yes/yes/entities/machines/GeneratorMachine.java
@@ -17,17 +17,17 @@ import javafx.scene.shape.TriangleMesh;
public class GeneratorMachine extends Entity {
public GeneratorMachine() {
super();
- Rectangle c = new Rectangle(50, 50);
- c.setFill(Color.RED);
+ Rectangle r = new Rectangle(50, 50);
+ r.setFill(Color.RED);
- Polygon t = new Polygon();
- t.getPoints().addAll(
+ Polygon p = new Polygon();
+ p.getPoints().addAll(
25.0,0.0,
0.0,50.0,
50.0,50.0);
- t.setFill(new Color(0,0,0,0.5));
+ p.setFill(new Color(0,0,0,0.5));
- this.getChildren().addAll(c,t);
+ this.getChildren().addAll(r,p);
}
public GeneratorMachine(BlockContainer blockContainer) {
diff --git a/src/main/java/com/yes/yes/entities/machines/HubAcceptor.java b/src/main/java/com/yes/yes/entities/machines/HubAcceptor.java
new file mode 100644
index 0000000..fc82d45
--- /dev/null
+++ b/src/main/java/com/yes/yes/entities/machines/HubAcceptor.java
@@ -0,0 +1,25 @@
+package com.yes.yes.entities.machines;
+
+import com.yes.yes.behaviours.ItemBehaviour;
+import com.yes.yes.behaviours.PlaceBehaviour;
+import com.yes.yes.behaviours.RecieveBehaviour;
+import com.yes.yes.utils.BlockContainer;
+import com.yes.yes.utils.Direction;
+import com.yes.yes.utils.Entity;
+import javafx.scene.paint.Color;
+import javafx.scene.shape.Rectangle;
+
+public class HubAcceptor extends Entity {
+ public HubAcceptor() {
+ Rectangle r = new Rectangle(50, 50);
+ r.setFill(Color.PINK);
+
+ this.getChildren().add(r);
+ }
+
+ public HubAcceptor(BlockContainer blockContainer) {
+ this();
+ this.addBehaviour(new PlaceBehaviour(this, blockContainer));
+ this.addBehaviour(new RecieveBehaviour(this, blockContainer, Direction.LEFT, "Input"));
+ }
+}
diff --git a/src/main/java/com/yes/yes/entities/machines/HubDisplay.java b/src/main/java/com/yes/yes/entities/machines/HubDisplay.java
new file mode 100644
index 0000000..fa9f667
--- /dev/null
+++ b/src/main/java/com/yes/yes/entities/machines/HubDisplay.java
@@ -0,0 +1,29 @@
+package com.yes.yes.entities.machines;
+
+import com.yes.yes.behaviours.ItemBehaviour;
+import com.yes.yes.behaviours.PlaceBehaviour;
+import com.yes.yes.behaviours.RecieveBehaviour;
+import com.yes.yes.utils.BlockContainer;
+import com.yes.yes.utils.Direction;
+import com.yes.yes.utils.Entity;
+import javafx.scene.paint.Color;
+import javafx.scene.shape.Rectangle;
+import javafx.scene.text.Text;
+
+public class HubDisplay extends Entity {
+
+ public HubDisplay() {
+ Rectangle r = new Rectangle(50, 50);
+ r.setFill(Color.PINK);
+
+ Text text = new Text("yes");
+
+ this.getChildren().addAll(r, text);
+ }
+
+ public HubDisplay(BlockContainer blockContainer) {
+ this();
+ this.addBehaviour(new PlaceBehaviour(this, blockContainer));
+ this.addBehaviour(new ItemBehaviour(this, blockContainer, "objective"));
+ }
+}
diff --git a/src/main/java/com/yes/yes/managers/GameManager.java b/src/main/java/com/yes/yes/managers/GameManager.java
index 9b4e21d..cd33fcc 100644
--- a/src/main/java/com/yes/yes/managers/GameManager.java
+++ b/src/main/java/com/yes/yes/managers/GameManager.java
@@ -1,9 +1,6 @@
package com.yes.yes.managers;
-import com.yes.yes.entities.machines.ConveyorBelt;
-import com.yes.yes.entities.machines.GeneratorMachine;
-import com.yes.yes.entities.machines.TestMachine;
-import com.yes.yes.entities.machines.TestMachine2;
+import com.yes.yes.entities.machines.*;
import com.yes.yes.utils.EntityRegistry;
import com.yes.yes.utils.GlobalEventHandler;
import com.yes.yes.utils.RegistryEntry;
@@ -36,8 +33,10 @@ public class GameManager {
try {
EntityRegistry.register(new RegistryEntry("test", "test receive machine", TestMachine.class));
EntityRegistry.register(new RegistryEntry("test2", "test offer machine", TestMachine2.class));
- EntityRegistry.register(new RegistryEntry("generator", "generator", GeneratorMachine.class));
+ EntityRegistry.register(new RegistryEntry("generator", "Generator", GeneratorMachine.class));
EntityRegistry.register(new RegistryEntry("conveyorBelt", "Conveyor Belt", ConveyorBelt.class));
+ EntityRegistry.register(new RegistryEntry("hub","Central Hub", HubDisplay.class));
+ EntityRegistry.register(new RegistryEntry("hubAcceptor","Central Hub Acceptor", HubAcceptor.class));
} catch (AlreadyExistsException e) {
e.printStackTrace();
}
@@ -53,7 +52,7 @@ public class GameManager {
ex.printStackTrace();
}
//System.out.println("Finished tick!");
- }, 0, 1, TimeUnit.SECONDS);
+ }, 0, 100, TimeUnit.MILLISECONDS);
GlobalEventHandler.addListener("timerTick", this, (__) -> {
//System.out.println("Tick!");
diff --git a/src/main/java/com/yes/yes/managers/PlayerManager.java b/src/main/java/com/yes/yes/managers/PlayerManager.java
index 82bb961..3dcbc9f 100644
--- a/src/main/java/com/yes/yes/managers/PlayerManager.java
+++ b/src/main/java/com/yes/yes/managers/PlayerManager.java
@@ -7,17 +7,24 @@ import com.yes.yes.world.World;
import javafx.scene.Scene;
import javafx.scene.input.*;
+import java.security.Key;
+
public class PlayerManager {
private static final KeyCombination LEFT_KEY = new KeyCodeCombination(KeyCode.A);
private static final KeyCombination RIGHT_KEY = new KeyCodeCombination(KeyCode.D);
private static final KeyCombination UP_KEY = new KeyCodeCombination(KeyCode.W);
private static final KeyCombination DOWN_KEY = new KeyCodeCombination(KeyCode.S);
+ private static final KeyCombination DELETE_KEY = new KeyCodeCombination(KeyCode.X);
+ private static final KeyCombination HOME_KEY = new KeyCodeCombination(KeyCode.INSERT);
private final World world;
private final BuildBox buildBox;
+ private static final Coordinate START_POSITION = new Coordinate(Integer.MAX_VALUE / -5000,Integer.MAX_VALUE / -5000);
+
private Coordinate chunkPos = new Coordinate(0, 0);
private int currentRotation = 0;
+ private Coordinate currentMousePosition;
public PlayerManager(World world, BuildBox buildBox) {
this.world = world;
@@ -32,8 +39,9 @@ public class PlayerManager {
scene.heightProperty().addListener((e) -> redrawChunks());
world.setOnMouseClicked(this::processClick);
- world.setTranslateX(Integer.MAX_VALUE / -5000d);
- world.setTranslateY(Integer.MAX_VALUE / -5000d);
+ world.setTranslateX(START_POSITION.x);
+ world.setTranslateY(START_POSITION.y);
+ world.setOnMouseMoved((mouse)-> currentMousePosition = new Coordinate((int) mouse.getX(), (int) mouse.getY()));
redrawChunks();
}
@@ -89,6 +97,19 @@ public class PlayerManager {
if (DOWN_KEY.match(key)) {
world.setTranslateY(world.getTranslateY() - 45);
}
+ if(DELETE_KEY.match(key)) {
+ Coordinate chunkCoordinate = Coordinate.WorldToChunkCoordinate(currentMousePosition);
+ Coordinate blockCoordinate = Coordinate.WorldToChunkBlock(currentMousePosition);
+
+ Chunk chunk = world.getChunk(chunkCoordinate);
+ chunk.removeEntity(blockCoordinate);
+ }
+ if(HOME_KEY.match(key))
+ {
+ world.setTranslateX(START_POSITION.x);
+ world.setTranslateY(START_POSITION.y);
+ redrawChunks();
+ }
Size preferredAmountOfChunks = getPreferredAmountOfChunks();
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index c4aa20f..940bdb1 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -5,4 +5,6 @@ module com.yes.yes {
opens com.yes.yes to javafx.fxml;
exports com.yes.yes;
+ exports com.yes.yes.utils;
+ opens com.yes.yes.utils to javafx.fxml;
}
\ No newline at end of file