mirror of
https://github.com/Stefan-5422/School-Programming-Projekt-022022.git
synced 2026-09-04 00:46:01 +02:00
Implement horizontal cutter
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package com.yes.yes.behaviours;
|
||||
|
||||
import com.yes.yes.utils.*;
|
||||
|
||||
public class CutItemBehaviour extends Component {
|
||||
private final Orientation orientation;
|
||||
private final String receiveDataKey;
|
||||
private final String offerDataKey1;
|
||||
private final String offerDataKey2;
|
||||
private final int processingDuration;
|
||||
private int progress = 0;
|
||||
|
||||
public CutItemBehaviour(Entity entity, BlockContainer blockContainer, Orientation orientation, String receiveDataKey, String offerDataKey1, String offerDataKey2, int processingDuration) {
|
||||
super(entity, blockContainer);
|
||||
this.orientation = orientation;
|
||||
this.receiveDataKey = receiveDataKey;
|
||||
this.offerDataKey1 = offerDataKey1;
|
||||
this.offerDataKey2 = offerDataKey2;
|
||||
this.processingDuration = processingDuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (progress > processingDuration) {
|
||||
if (parent.getData(offerDataKey1) != null || parent.getData(offerDataKey2) != null) return;
|
||||
|
||||
|
||||
Item half1 = new Item();
|
||||
Item half2 = new Item();
|
||||
|
||||
Item item = parent.getData(receiveDataKey);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (orientation == Orientation.Horizontal) {
|
||||
half1.setPart(i, 0, item.getPart(i, 0));
|
||||
half1.setPart(i, 1, item.getPart(i, 1));
|
||||
half2.setPart(i, 2, item.getPart(i, 2));
|
||||
half2.setPart(i, 3, item.getPart(i, 3));
|
||||
} else {
|
||||
half1.setPart(i, 0, item.getPart(i, 0));
|
||||
half1.setPart(i, 2, item.getPart(i, 2));
|
||||
half2.setPart(i, 1, item.getPart(i, 1));
|
||||
half2.setPart(i, 3, item.getPart(i, 3));
|
||||
}
|
||||
}
|
||||
|
||||
parent.setData(offerDataKey1, half1);
|
||||
parent.setData(offerDataKey2, half2);
|
||||
parent.setData(receiveDataKey, null);
|
||||
|
||||
progress = 0;
|
||||
} else if (parent.getData(receiveDataKey) != null) {
|
||||
progress++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,23 @@
|
||||
package com.yes.yes.entities.machines;
|
||||
|
||||
import com.yes.yes.behaviours.DestroyBehaviour;
|
||||
import com.yes.yes.behaviours.CutItemBehaviour;
|
||||
import com.yes.yes.behaviours.OfferBehaviour;
|
||||
import com.yes.yes.behaviours.PlaceBehaviour;
|
||||
import com.yes.yes.behaviours.ReceiveBehaviour;
|
||||
import com.yes.yes.utils.BlockContainer;
|
||||
import com.yes.yes.utils.Direction;
|
||||
import com.yes.yes.utils.Entity;
|
||||
import com.yes.yes.utils.Orientation;
|
||||
import com.yes.yes.world.Chunk;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Circle;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
|
||||
public class Cutter extends Entity {
|
||||
public Cutter() {
|
||||
super();
|
||||
|
||||
Circle c = new Circle(Chunk.ENTITY_SIZE/2);
|
||||
Circle c = new Circle(Chunk.ENTITY_SIZE / 2);
|
||||
c.setFill(Color.BLACK);
|
||||
c.setCenterX(Chunk.ENTITY_SIZE / 2);
|
||||
c.setCenterY(Chunk.ENTITY_SIZE / 2);
|
||||
@@ -24,13 +25,12 @@ public class Cutter extends Entity {
|
||||
Polygon p = new Polygon();
|
||||
p.getPoints().addAll(
|
||||
Chunk.ENTITY_SIZE / 2d, 0.0,
|
||||
Chunk.ENTITY_SIZE/4d, (double) Chunk.ENTITY_SIZE,
|
||||
(double) Chunk.ENTITY_SIZE/4d*3, (double) Chunk.ENTITY_SIZE);
|
||||
Chunk.ENTITY_SIZE / 4d, (double) Chunk.ENTITY_SIZE,
|
||||
(double) Chunk.ENTITY_SIZE / 4d * 3, (double) Chunk.ENTITY_SIZE);
|
||||
p.setFill(new Color(1, 1, 1, 0.5));
|
||||
|
||||
|
||||
|
||||
this.getChildren().addAll(c,p);
|
||||
this.getChildren().addAll(c, p);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused") // Called dynamically
|
||||
@@ -38,6 +38,9 @@ public class Cutter extends Entity {
|
||||
this();
|
||||
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
|
||||
this.addBehaviour(new ReceiveBehaviour(this, blockContainer, Direction.DOWN, "Item"));
|
||||
//TODO: Add split/modify behaviour
|
||||
this.addBehaviour(new CutItemBehaviour(this, blockContainer, Orientation.Horizontal, "ReceivedItem", "OfferItemLeft", "OfferItemRight", 5));
|
||||
this.addBehaviour(new ReceiveBehaviour(this, blockContainer, Direction.DOWN, "ReceivedItem"));
|
||||
this.addBehaviour(new OfferBehaviour(this, blockContainer, Direction.LEFT, "OfferItemLeft"));
|
||||
this.addBehaviour(new OfferBehaviour(this, blockContainer, Direction.RIGHT, "OfferItemRight"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,14 @@ public class Item extends javafx.scene.Group implements Cloneable {
|
||||
this.getChildren().remove(parts[layer][section]);
|
||||
}
|
||||
|
||||
part.rotate(section);
|
||||
parts[layer][section] = part;
|
||||
|
||||
if (part == null) return;
|
||||
|
||||
part.rotate(section);
|
||||
part.getTransforms().add(new Scale(-layer * 0.25f + 1f, -layer * 0.25f + 1f));
|
||||
|
||||
parts[layer][section] = part;
|
||||
|
||||
this.getChildren().add(part);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.yes.yes.utils;
|
||||
|
||||
public enum Orientation {
|
||||
Horizontal,
|
||||
Vertical
|
||||
}
|
||||
Reference in New Issue
Block a user