mirror of
https://github.com/Stefan-5422/School-Programming-Projekt-022022.git
synced 2026-09-10 07:36:05 +02:00
More code cleanup and fix receive behavior
This commit is contained in:
@@ -1,2 +1,30 @@
|
|||||||
package com.yes.yes.behaviours;public class DestroyBehaviour {
|
package com.yes.yes.behaviours;
|
||||||
|
|
||||||
|
import com.yes.yes.utils.BlockContainer;
|
||||||
|
import com.yes.yes.utils.Component;
|
||||||
|
import com.yes.yes.utils.Entity;
|
||||||
|
|
||||||
|
public class DestroyBehaviour extends Component {
|
||||||
|
private String dataKey;
|
||||||
|
|
||||||
|
public DestroyBehaviour(Entity entity, BlockContainer blockContainer, String dataKey) {
|
||||||
|
super(entity, blockContainer);
|
||||||
|
this.dataKey = dataKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
this.parent.setData(dataKey, null);
|
||||||
|
this.parent.trigger(dataKey + "Changed", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import javafx.scene.transform.Scale;
|
|||||||
|
|
||||||
public class ItemBehaviour extends Component {
|
public class ItemBehaviour extends Component {
|
||||||
|
|
||||||
private final String dataKey;
|
|
||||||
private VBox itemGroup;
|
private VBox itemGroup;
|
||||||
|
private String dataKey;
|
||||||
|
|
||||||
public ItemBehaviour(Entity entity, BlockContainer blockContainer, String dataKey) {
|
public ItemBehaviour(Entity entity, BlockContainer blockContainer, String dataKey) {
|
||||||
super(entity, blockContainer);
|
super(entity, blockContainer);
|
||||||
@@ -35,6 +35,7 @@ public class ItemBehaviour extends Component {
|
|||||||
|
|
||||||
itemGroup = new VBox();
|
itemGroup = new VBox();
|
||||||
itemGroup.setAlignment(Pos.CENTER);
|
itemGroup.setAlignment(Pos.CENTER);
|
||||||
|
//itemGroup.setRotate(-this.parent.getRotate());
|
||||||
|
|
||||||
this.parent.getChildren().add(itemGroup);
|
this.parent.getChildren().add(itemGroup);
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public class ReceiveBehaviour extends Component {
|
|||||||
|
|
||||||
this.parent.setData(dataKey, item);
|
this.parent.setData(dataKey, item);
|
||||||
this.parent.trigger(dataKey + "Changed", item);
|
this.parent.trigger(dataKey + "Changed", item);
|
||||||
|
this.offerer.trigger("itemAccepted", this.parent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.yes.yes.behaviours.*;
|
|||||||
import com.yes.yes.utils.BlockContainer;
|
import com.yes.yes.utils.BlockContainer;
|
||||||
import com.yes.yes.utils.Direction;
|
import com.yes.yes.utils.Direction;
|
||||||
import com.yes.yes.utils.Entity;
|
import com.yes.yes.utils.Entity;
|
||||||
|
import com.yes.yes.world.Chunk;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Polygon;
|
import javafx.scene.shape.Polygon;
|
||||||
|
|
||||||
@@ -12,9 +13,9 @@ public class ConveyorBelt extends Entity {
|
|||||||
super();
|
super();
|
||||||
Polygon t = new Polygon();
|
Polygon t = new Polygon();
|
||||||
t.getPoints().addAll(
|
t.getPoints().addAll(
|
||||||
25.0, 0.0,
|
Chunk.ENTITY_SIZE / 2d, 0.0,
|
||||||
0.0, 50.0,
|
0.0, (double) Chunk.ENTITY_SIZE,
|
||||||
50.0, 50.0);
|
(double) Chunk.ENTITY_SIZE, (double) Chunk.ENTITY_SIZE);
|
||||||
t.setFill(new Color(0, 0, 0, 1));
|
t.setFill(new Color(0, 0, 0, 1));
|
||||||
|
|
||||||
this.getChildren().addAll(t);
|
this.getChildren().addAll(t);
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package com.yes.yes.entities.machines;
|
package com.yes.yes.entities.machines;
|
||||||
|
|
||||||
import com.yes.yes.behaviours.ItemBehaviour;
|
import com.yes.yes.behaviours.*;
|
||||||
import com.yes.yes.behaviours.PlaceBehaviour;
|
|
||||||
import com.yes.yes.behaviours.ReceiveBehaviour;
|
|
||||||
import com.yes.yes.behaviours.TestBehaviour;
|
|
||||||
import com.yes.yes.utils.BlockContainer;
|
import com.yes.yes.utils.BlockContainer;
|
||||||
import com.yes.yes.utils.Direction;
|
import com.yes.yes.utils.Direction;
|
||||||
import com.yes.yes.utils.Entity;
|
import com.yes.yes.utils.Entity;
|
||||||
@@ -11,9 +8,10 @@ import com.yes.yes.world.Chunk;
|
|||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Circle;
|
import javafx.scene.shape.Circle;
|
||||||
import javafx.scene.shape.Polygon;
|
import javafx.scene.shape.Polygon;
|
||||||
|
import javafx.scene.shape.Rectangle;
|
||||||
|
|
||||||
public class TestMachine extends Entity {
|
public class DestroyMachine extends Entity {
|
||||||
public TestMachine() {
|
public DestroyMachine() {
|
||||||
super();
|
super();
|
||||||
Circle c = new Circle(Chunk.ENTITY_SIZE / 2);
|
Circle c = new Circle(Chunk.ENTITY_SIZE / 2);
|
||||||
c.setCenterX(Chunk.ENTITY_SIZE / 2);
|
c.setCenterX(Chunk.ENTITY_SIZE / 2);
|
||||||
@@ -29,11 +27,10 @@ public class TestMachine extends Entity {
|
|||||||
this.getChildren().addAll(c, t);
|
this.getChildren().addAll(c, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestMachine(BlockContainer blockContainer) {
|
public DestroyMachine(BlockContainer blockContainer) {
|
||||||
this();
|
this();
|
||||||
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
|
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
|
||||||
this.addBehaviour(new TestBehaviour(this, blockContainer));
|
|
||||||
this.addBehaviour(new ItemBehaviour(this, blockContainer, "Item"));
|
|
||||||
this.addBehaviour(new ReceiveBehaviour(this, blockContainer, Direction.DOWN, "Item"));
|
this.addBehaviour(new ReceiveBehaviour(this, blockContainer, Direction.DOWN, "Item"));
|
||||||
|
this.addBehaviour(new DestroyBehaviour(this, blockContainer, "Item"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.yes.yes.utils.BlockContainer;
|
|||||||
import com.yes.yes.utils.Direction;
|
import com.yes.yes.utils.Direction;
|
||||||
import com.yes.yes.utils.Entity;
|
import com.yes.yes.utils.Entity;
|
||||||
import com.yes.yes.utils.Item;
|
import com.yes.yes.utils.Item;
|
||||||
|
import com.yes.yes.world.Chunk;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Polygon;
|
import javafx.scene.shape.Polygon;
|
||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.shape.Rectangle;
|
||||||
@@ -16,14 +17,14 @@ import javafx.scene.shape.Rectangle;
|
|||||||
public class GeneratorMachine extends Entity {
|
public class GeneratorMachine extends Entity {
|
||||||
public GeneratorMachine() {
|
public GeneratorMachine() {
|
||||||
super();
|
super();
|
||||||
Rectangle r = new Rectangle(50, 50);
|
Rectangle r = new Rectangle(Chunk.ENTITY_SIZE, Chunk.ENTITY_SIZE);
|
||||||
r.setFill(Color.RED);
|
r.setFill(Color.RED);
|
||||||
|
|
||||||
Polygon p = new Polygon();
|
Polygon p = new Polygon();
|
||||||
p.getPoints().addAll(
|
p.getPoints().addAll(
|
||||||
25.0, 0.0,
|
Chunk.ENTITY_SIZE/2d, 0.0,
|
||||||
0.0, 50.0,
|
0.0, (double) Chunk.ENTITY_SIZE,
|
||||||
50.0, 50.0);
|
(double) Chunk.ENTITY_SIZE, (double) Chunk.ENTITY_SIZE);
|
||||||
p.setFill(new Color(0, 0, 0, 0.5));
|
p.setFill(new Color(0, 0, 0, 0.5));
|
||||||
|
|
||||||
this.getChildren().addAll(r, p);
|
this.getChildren().addAll(r, p);
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ import com.yes.yes.behaviours.ReceiveBehaviour;
|
|||||||
import com.yes.yes.utils.BlockContainer;
|
import com.yes.yes.utils.BlockContainer;
|
||||||
import com.yes.yes.utils.Direction;
|
import com.yes.yes.utils.Direction;
|
||||||
import com.yes.yes.utils.Entity;
|
import com.yes.yes.utils.Entity;
|
||||||
|
import com.yes.yes.world.Chunk;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.shape.Rectangle;
|
||||||
|
|
||||||
public class HubAcceptor extends Entity {
|
public class HubAcceptor extends Entity {
|
||||||
public HubAcceptor() {
|
public HubAcceptor() {
|
||||||
Rectangle r = new Rectangle(50, 50);
|
Rectangle r = new Rectangle(Chunk.ENTITY_SIZE, Chunk.ENTITY_SIZE);
|
||||||
r.setFill(Color.PINK);
|
r.setFill(Color.PINK);
|
||||||
|
|
||||||
this.getChildren().add(r);
|
this.getChildren().add(r);
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import com.yes.yes.behaviours.ItemBehaviour;
|
|||||||
import com.yes.yes.behaviours.PlaceBehaviour;
|
import com.yes.yes.behaviours.PlaceBehaviour;
|
||||||
import com.yes.yes.utils.BlockContainer;
|
import com.yes.yes.utils.BlockContainer;
|
||||||
import com.yes.yes.utils.Entity;
|
import com.yes.yes.utils.Entity;
|
||||||
|
import com.yes.yes.world.Chunk;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.shape.Rectangle;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
@@ -11,12 +14,17 @@ import javafx.scene.text.Text;
|
|||||||
public class HubDisplay extends Entity {
|
public class HubDisplay extends Entity {
|
||||||
|
|
||||||
public HubDisplay() {
|
public HubDisplay() {
|
||||||
Rectangle r = new Rectangle(50, 50);
|
Rectangle r = new Rectangle(Chunk.ENTITY_SIZE, Chunk.ENTITY_SIZE);
|
||||||
r.setFill(Color.PINK);
|
r.setFill(Color.PINK);
|
||||||
|
|
||||||
Text text = new Text("yes");
|
Text text = new Text("yes\nthis is a test sentence");
|
||||||
|
text.setWrappingWidth(Chunk.ENTITY_SIZE);
|
||||||
|
|
||||||
this.getChildren().addAll(r, text);
|
StackPane stackPane = new StackPane();
|
||||||
|
stackPane.getChildren().addAll(r, text);
|
||||||
|
stackPane.setAlignment(Pos.CENTER);
|
||||||
|
|
||||||
|
this.getChildren().addAll(stackPane);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HubDisplay(BlockContainer blockContainer) {
|
public HubDisplay(BlockContainer blockContainer) {
|
||||||
|
|||||||
@@ -7,12 +7,13 @@ import com.yes.yes.behaviours.TestBehaviour;
|
|||||||
import com.yes.yes.utils.BlockContainer;
|
import com.yes.yes.utils.BlockContainer;
|
||||||
import com.yes.yes.utils.Direction;
|
import com.yes.yes.utils.Direction;
|
||||||
import com.yes.yes.utils.Entity;
|
import com.yes.yes.utils.Entity;
|
||||||
|
import com.yes.yes.world.Chunk;
|
||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.shape.Rectangle;
|
||||||
|
|
||||||
public class TestMachine2 extends Entity {
|
public class TestMachine2 extends Entity {
|
||||||
public TestMachine2() {
|
public TestMachine2() {
|
||||||
super();
|
super();
|
||||||
this.getChildren().add(new Rectangle(50, 50));
|
this.getChildren().add(new Rectangle(Chunk.ENTITY_SIZE, Chunk.ENTITY_SIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestMachine2(BlockContainer blockContainer) {
|
public TestMachine2(BlockContainer blockContainer) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import javafx.scene.shape.Rectangle;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class Square extends com.yes.yes.utils.Part {
|
public class Square extends com.yes.yes.utils.Part {
|
||||||
Random rand = new Random();
|
final Random rand = new Random();
|
||||||
|
|
||||||
public Square() {
|
public Square() {
|
||||||
int r = rand.nextInt(255);
|
int r = rand.nextInt(255);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class GameManager {
|
|||||||
world.toBack();
|
world.toBack();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
EntityRegistry.register(new RegistryEntry("test", "test receive machine", TestMachine.class));
|
EntityRegistry.register(new RegistryEntry("test", "test receive machine", DestroyMachine.class));
|
||||||
EntityRegistry.register(new RegistryEntry("test2", "test offer machine", TestMachine2.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("conveyorBelt", "Conveyor Belt", ConveyorBelt.class));
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class PlayerManager {
|
|||||||
Chunk chunk = world.getChunk(chunkCoordinate);
|
Chunk chunk = world.getChunk(chunkCoordinate);
|
||||||
Entity oldEntity = chunk.getEntity(blockCoordinate);
|
Entity oldEntity = chunk.getEntity(blockCoordinate);
|
||||||
|
|
||||||
if (oldEntity != null && oldEntity.getClass().getSimpleName() == entity.getClass().getSimpleName()) {
|
if (oldEntity != null && oldEntity.getClass().getSimpleName().equals(entity.getClass().getSimpleName())) {
|
||||||
if (mouse.getButton() == MouseButton.PRIMARY)
|
if (mouse.getButton() == MouseButton.PRIMARY)
|
||||||
currentRotation = oldEntity.getRotation() + 1;
|
currentRotation = oldEntity.getRotation() + 1;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public record BlockContainer(World world, Coordinate blockCoordinate, Coordinate
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only works with a valid direction
|
// Only works with a valid direction
|
||||||
public final Entity getBlockRelative(Coordinate direction, int rotation) throws IllegalAccessException {
|
public Entity getBlockRelative(Coordinate direction, int rotation) throws IllegalAccessException {
|
||||||
for (int i = 0; i < rotation % 4; i++) {
|
for (int i = 0; i < rotation % 4; i++) {
|
||||||
direction = Direction.rotateRight(direction);
|
direction = Direction.rotateRight(direction);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class Direction {
|
|||||||
private Direction() {
|
private Direction() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Coordinate rotateRight(Coordinate direction) {
|
public static Coordinate rotateRight(Coordinate direction) {
|
||||||
if (direction == Direction.LEFT) return Direction.UP;
|
if (direction == Direction.LEFT) return Direction.UP;
|
||||||
if (direction == Direction.UP) return Direction.RIGHT;
|
if (direction == Direction.UP) return Direction.RIGHT;
|
||||||
if (direction == Direction.RIGHT) return Direction.DOWN;
|
if (direction == Direction.RIGHT) return Direction.DOWN;
|
||||||
@@ -20,7 +20,7 @@ public class Direction {
|
|||||||
throw new InvalidParameterException("Coordinate is not a direction");
|
throw new InvalidParameterException("Coordinate is not a direction");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Coordinate rotateLeft(Coordinate direction) {
|
public static Coordinate rotateLeft(Coordinate direction) {
|
||||||
if (direction == Direction.LEFT) return Direction.DOWN;
|
if (direction == Direction.LEFT) return Direction.DOWN;
|
||||||
if (direction == Direction.DOWN) return Direction.RIGHT;
|
if (direction == Direction.DOWN) return Direction.RIGHT;
|
||||||
if (direction == Direction.RIGHT) return Direction.UP;
|
if (direction == Direction.RIGHT) return Direction.UP;
|
||||||
|
|||||||
Reference in New Issue
Block a user