mirror of
https://github.com/Stefan-5422/School-Programming-Projekt-022022.git
synced 2026-09-04 00:46:01 +02:00
Add start of working items;
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.yes.yes.behaviours;
|
||||
|
||||
import com.yes.yes.utils.BlockContainer;
|
||||
import com.yes.yes.utils.Component;
|
||||
import com.yes.yes.utils.Entity;
|
||||
import com.yes.yes.utils.Item;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.transform.Scale;
|
||||
|
||||
public class ItemBehaviour extends Component {
|
||||
|
||||
private VBox itemGroup;
|
||||
private Item item;
|
||||
|
||||
public ItemBehaviour(Entity entity, BlockContainer blockContainer) {
|
||||
super(entity, blockContainer);
|
||||
}
|
||||
|
||||
private void itemChanged(Item item) {
|
||||
if(this.item != null) {
|
||||
this.itemGroup.getChildren().clear();
|
||||
}
|
||||
this.item = item;
|
||||
|
||||
this.itemGroup.getChildren().add(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
parent.addListener("itemChanged", this::itemChanged);
|
||||
|
||||
itemGroup = new VBox();
|
||||
itemGroup.setAlignment(Pos.CENTER);
|
||||
|
||||
this.parent.getChildren().add(itemGroup);
|
||||
|
||||
Scale s = new Scale(0.7, 0.7);
|
||||
itemGroup.getTransforms().add(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,6 @@ public class PlaceBehaviour extends Component {
|
||||
}
|
||||
}
|
||||
}
|
||||
Item item = new Item();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int i1 = 0; i1 < 4; i1++) {
|
||||
item.setPart(i, i1, new Square());
|
||||
}
|
||||
}
|
||||
// parent.getChildren().add(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.yes.yes.behaviours;
|
||||
|
||||
import com.yes.yes.utils.BlockContainer;
|
||||
import com.yes.yes.utils.Component;
|
||||
import com.yes.yes.utils.Coordinate;
|
||||
import com.yes.yes.utils.Entity;
|
||||
|
||||
public class TestOffererBehaviour extends Component {
|
||||
|
||||
private Entity reciever;
|
||||
|
||||
public TestOffererBehaviour(Entity entity, BlockContainer blockContainer) {
|
||||
super(entity, blockContainer);
|
||||
}
|
||||
|
||||
private void placed(Entity entity) {
|
||||
try {
|
||||
if (blockContainer.getBlock(new Coordinate(1, 0)) == entity) {
|
||||
this.reciever = entity;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
try {
|
||||
this.reciever = blockContainer.getBlock(new Coordinate(1, 0));
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.parent.addListener("placed", this::placed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if(reciever == null) return;
|
||||
|
||||
reciever.trigger("offerItem", someItem);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.yes.yes.entities.machines;
|
||||
|
||||
import com.yes.yes.behaviours.ItemBehaviour;
|
||||
import com.yes.yes.behaviours.PlaceBehaviour;
|
||||
import com.yes.yes.behaviours.TestBehaviour;
|
||||
import com.yes.yes.utils.BlockContainer;
|
||||
@@ -9,12 +10,16 @@ import javafx.scene.shape.Circle;
|
||||
public class TestMachine extends Entity {
|
||||
public TestMachine() {
|
||||
super();
|
||||
this.getChildren().add(new Circle(25));
|
||||
Circle c = new Circle(25);
|
||||
c.setCenterX(25);
|
||||
c.setCenterY(25);
|
||||
this.getChildren().add(c);
|
||||
}
|
||||
|
||||
public TestMachine(BlockContainer blockContainer) {
|
||||
this();
|
||||
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
|
||||
this.addBehaviour(new TestBehaviour(this, blockContainer));
|
||||
this.addBehaviour(new ItemBehaviour(this, blockContainer));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.yes.yes.entities.machines;
|
||||
|
||||
import com.yes.yes.behaviours.ItemBehaviour;
|
||||
import com.yes.yes.behaviours.PlaceBehaviour;
|
||||
import com.yes.yes.behaviours.TestBehaviour;
|
||||
import com.yes.yes.utils.BlockContainer;
|
||||
@@ -16,5 +17,6 @@ public class TestMachine2 extends Entity {
|
||||
this();
|
||||
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
|
||||
this.addBehaviour(new TestBehaviour(this, blockContainer));
|
||||
this.addBehaviour(new ItemBehaviour(this, blockContainer));
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@ import javafx.scene.shape.Rectangle;
|
||||
|
||||
public class Square extends com.yes.yes.utils.Part {
|
||||
public Square() {
|
||||
var rect = new Rectangle(25, 25);
|
||||
var rect = new Rectangle(23, 23);
|
||||
rect.setFill(Color.RED);
|
||||
rect.setStroke(Color.BLACK);
|
||||
rect.setStroke(Color.BLUE);
|
||||
rect.setStrokeWidth(1);
|
||||
this.getChildren().add(rect);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.yes.yes.utils;
|
||||
|
||||
import javafx.scene.transform.Scale;
|
||||
|
||||
public class Item extends javafx.scene.Group {
|
||||
final Part[][] parts = new Part[4][4];
|
||||
|
||||
@@ -12,6 +14,9 @@ public class Item extends javafx.scene.Group {
|
||||
this.getChildren().remove(parts[layer][section]);
|
||||
}
|
||||
|
||||
part.rotate(section);
|
||||
|
||||
part.getTransforms().add(new Scale(-layer*0.25f+1f, -layer*0.25f+1f));
|
||||
|
||||
parts[layer][section] = part;
|
||||
this.getChildren().add(part);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.yes.yes.utils;
|
||||
|
||||
import com.yes.yes.world.Chunk;
|
||||
import javafx.scene.Node;
|
||||
|
||||
public abstract class Part extends javafx.scene.Group {
|
||||
@@ -14,6 +15,7 @@ public abstract class Part extends javafx.scene.Group {
|
||||
public void rotate(int quarters) {
|
||||
|
||||
this.getTransforms().clear();
|
||||
this.getTransforms().add(new javafx.scene.transform.Rotate(quarters % 4 * 90, 1, 1));
|
||||
this.getTransforms().add(new javafx.scene.transform.Rotate(quarters % 4 * 90, 0, 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user