Add Hub; Fix Conveyor;

This commit is contained in:
Stefan-5422
2022-05-12 12:49:37 +02:00
parent 30d4d70ae8
commit 5bb37573eb
13 changed files with 1047 additions and 19 deletions
@@ -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);
}
@@ -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++;
@@ -24,7 +24,6 @@ public class GeneratorBehaviour extends Component {
@Override
public void update() {
this.parent.setData(dataKey, item.clone());
System.out.println("generate");
}
@Override
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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"));
}
}
@@ -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"));
}
}
@@ -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!");
@@ -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();
+2
View File
@@ -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;
}