mirror of
https://github.com/Stefan-5422/School-Programming-Projekt-022022.git
synced 2026-09-04 00:46:01 +02:00
Add Incinerator (DestroyMachine) and remove test mashine
This commit is contained in:
@@ -15,7 +15,7 @@ public class YesApplication extends javafx.application.Application {
|
||||
@Override
|
||||
public void stop() {
|
||||
System.out.println("Closing!");
|
||||
GlobalEventHandler.trigger("closing", null);
|
||||
GlobalEventHandler.trigger("app:closing", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.yes.yes.entities.machines;
|
||||
|
||||
import com.yes.yes.behaviours.ItemBehaviour;
|
||||
import com.yes.yes.behaviours.OfferBehaviour;
|
||||
import com.yes.yes.behaviours.PlaceBehaviour;
|
||||
import com.yes.yes.behaviours.TestBehaviour;
|
||||
import com.yes.yes.utils.BlockContainer;
|
||||
import com.yes.yes.utils.Direction;
|
||||
import com.yes.yes.utils.Entity;
|
||||
import com.yes.yes.world.Chunk;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
|
||||
public class TestMachine2 extends Entity {
|
||||
public TestMachine2() {
|
||||
super();
|
||||
this.getChildren().add(new Rectangle(Chunk.ENTITY_SIZE, Chunk.ENTITY_SIZE));
|
||||
}
|
||||
|
||||
public TestMachine2(BlockContainer blockContainer) {
|
||||
this();
|
||||
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
|
||||
this.addBehaviour(new TestBehaviour(this, blockContainer));
|
||||
this.addBehaviour(new ItemBehaviour(this, blockContainer, "Item"));
|
||||
this.addBehaviour(new OfferBehaviour(this, blockContainer, Direction.RIGHT, "Item"));
|
||||
}
|
||||
}
|
||||
@@ -31,8 +31,7 @@ public class GameManager {
|
||||
world.toBack();
|
||||
|
||||
try {
|
||||
EntityRegistry.register(new RegistryEntry("test", "test receive machine", DestroyMachine.class));
|
||||
EntityRegistry.register(new RegistryEntry("test2", "test offer machine", TestMachine2.class));
|
||||
EntityRegistry.register(new RegistryEntry("destroyer", "Incinerator", DestroyMachine.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));
|
||||
@@ -45,16 +44,16 @@ public class GameManager {
|
||||
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
|
||||
executor.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
GlobalEventHandler.trigger("timerTick", null);
|
||||
GlobalEventHandler.trigger("global:timerTick", null);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
//System.out.println("Finished tick!");
|
||||
}, 0, 100, TimeUnit.MILLISECONDS);
|
||||
|
||||
GlobalEventHandler.addListener("timerTick", this, (__) -> {
|
||||
GlobalEventHandler.addListener("global:timerTick", this, (__) -> {
|
||||
//System.out.println("Tick!");
|
||||
});
|
||||
GlobalEventHandler.addListener("closing", this, (__) -> executor.shutdown());
|
||||
GlobalEventHandler.addListener("app:closing", this, (__) -> executor.shutdown());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,13 +83,6 @@ public class PlayerManager {
|
||||
}
|
||||
|
||||
private void processKeyRelease(KeyEvent key) {
|
||||
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);
|
||||
@@ -110,6 +103,13 @@ 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);
|
||||
}
|
||||
|
||||
Size preferredAmountOfChunks = getPreferredAmountOfChunks();
|
||||
Coordinate chunkPosition = getCurrentChunkPosition();
|
||||
|
||||
@@ -11,7 +11,7 @@ public abstract class Entity extends javafx.scene.Group {
|
||||
private int rotation;
|
||||
|
||||
public Entity() {
|
||||
GlobalEventHandler.addListener("timerTick", this, (__) -> update());
|
||||
GlobalEventHandler.addListener("global:timerTick", this, (__) -> update());
|
||||
}
|
||||
|
||||
public final void addBehaviour(Component behaviour) {
|
||||
@@ -43,7 +43,7 @@ public abstract class Entity extends javafx.scene.Group {
|
||||
}
|
||||
|
||||
public final void destroy() {
|
||||
GlobalEventHandler.removeListener("timerTick", this, (__) -> update());
|
||||
GlobalEventHandler.removeListener("global:timerTick", this);
|
||||
for (Component component : behaviours) {
|
||||
component.destroy();
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.yes.yes.utils;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class GlobalEventHandler {
|
||||
private static final EventHandler handler = new EventHandler();
|
||||
public final class GlobalEventHandler {
|
||||
private static EventHandler handler = new EventHandler();
|
||||
|
||||
private GlobalEventHandler() {
|
||||
}
|
||||
@@ -12,7 +12,7 @@ public class GlobalEventHandler {
|
||||
handler.addListener(eventName, object, function);
|
||||
}
|
||||
|
||||
public static <T> void removeListener(String eventName, Object object, Consumer<T> function) {
|
||||
public static void removeListener(String eventName, Object object) {
|
||||
handler.removeListener(eventName, object);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user