mirror of
https://github.com/Stefan-5422/School-Programming-Projekt-022022.git
synced 2026-09-04 00:46:01 +02:00
Accept items from all directions (Conveyor belt) add simple rotation on place
This commit is contained in:
@@ -26,7 +26,7 @@ public class ConveyorBehaviour extends Component {
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (count >= delay) {
|
||||
if (count > delay) {
|
||||
if (parent.getData(offerDataKey) != null) return;
|
||||
if (parent.getData(receiveDataKey) == null) return;
|
||||
|
||||
@@ -40,6 +40,7 @@ public class ConveyorBehaviour extends Component {
|
||||
if(isConveyed && parent.getData(offerDataKey) == null)
|
||||
{
|
||||
parent.setData(receiveDataKey, null);
|
||||
parent.trigger(receiveDataKey + "Changed", null);
|
||||
isConveyed = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,5 +43,6 @@ public class ItemBehaviour extends Component {
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
System.out.println("Destroyed:" + parent.getData("destroyed"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ public class ConveyorBelt extends Entity {
|
||||
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
|
||||
this.addBehaviour(new ItemBehaviour(this, blockContainer,"ReceivedItem"));
|
||||
this.addBehaviour(new RecieveBehaviour(this, blockContainer, Direction.DOWN, "ReceivedItem"));
|
||||
this.addBehaviour(new RecieveBehaviour(this, blockContainer, Direction.LEFT, "ReceivedItem"));
|
||||
this.addBehaviour(new RecieveBehaviour(this, blockContainer, Direction.RIGHT, "ReceivedItem"));
|
||||
this.addBehaviour(new OfferBehaviour(this, blockContainer, Direction.UP, "OfferItem"));
|
||||
this.addBehaviour(new ConveyorBehaviour(this,blockContainer, "ReceivedItem","OfferItem", 1));
|
||||
}
|
||||
|
||||
@@ -27,21 +27,19 @@ public class PlayerManager {
|
||||
|
||||
public void initialize() {
|
||||
Scene scene = world.getScene();
|
||||
scene.setOnKeyPressed(this::ProcessKeyPress);
|
||||
scene.setOnKeyPressed(this::processKeyPress);
|
||||
|
||||
scene.widthProperty().addListener((e) -> redrawChunks());
|
||||
scene.heightProperty().addListener((e) -> redrawChunks());
|
||||
|
||||
world.setOnMouseClicked(this::ProcessClick);
|
||||
world.setOnMouseClicked(this::processClick);
|
||||
world.setTranslateX(Integer.MAX_VALUE / -5000d);
|
||||
world.setTranslateY(Integer.MAX_VALUE / -5000d);
|
||||
|
||||
redrawChunks();
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
private void ProcessClick(MouseEvent mouse) {
|
||||
private void processClick(MouseEvent mouse) {
|
||||
Coordinate mouseCoordinate = new Coordinate((int) mouse.getX(), (int) mouse.getY());
|
||||
Coordinate chunkCoordinate = Coordinate.WorldToChunkCoordinate(mouseCoordinate);
|
||||
Coordinate blockCoordinate = Coordinate.WorldToChunkBlock(mouseCoordinate);
|
||||
@@ -57,15 +55,24 @@ public class PlayerManager {
|
||||
return;
|
||||
|
||||
Entity entity = (Entity) registryEntry.getEntity().getConstructor(types).newInstance(blockContainer);
|
||||
world.getChunk(chunkCoordinate).setEntity(entity, blockCoordinate);
|
||||
//entity.setRotation(random.nextInt(0,4));
|
||||
|
||||
Chunk chunk = world.getChunk(chunkCoordinate);
|
||||
Entity oldEntity = chunk.getEntity(blockCoordinate);
|
||||
|
||||
if(oldEntity != null && oldEntity.getClass().getSimpleName() == entity.getClass().getSimpleName()) {
|
||||
oldEntity.setData("destroyed", true);
|
||||
entity.setRotation(oldEntity.getRotation() + 1);
|
||||
}
|
||||
|
||||
chunk.setEntity(entity, blockCoordinate);
|
||||
|
||||
entity.initialize();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessKeyPress(KeyEvent key) {
|
||||
private void processKeyPress(KeyEvent key) {
|
||||
if (LEFT_KEY.match(key)) {
|
||||
world.setTranslateX(world.getTranslateX() + 45);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user