mirror of
https://github.com/Stefan-5422/School-Programming-Projekt-022022.git
synced 2026-09-04 00:46:01 +02:00
- Add cutter machine base
- Add color system - Improve some variable names -
This commit is contained in:
@@ -14,15 +14,14 @@ public class YesApplication extends javafx.application.Application {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
System.out.println("Closing!");
|
|
||||||
GlobalEventHandler.trigger("app:closing", null);
|
GlobalEventHandler.trigger("app:closing", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) throws IOException {
|
public void start(Stage stage) throws IOException {
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(YesApplication.class.getResource("main-view.fxml"));
|
FXMLLoader fxmlLoader = new FXMLLoader(YesApplication.class.getResource("main-view.fxml"));
|
||||||
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
|
Scene scene = new Scene(fxmlLoader.load(), 1280 , 720 );
|
||||||
stage.setTitle("Hello!");
|
stage.setTitle("Yes!");
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
|
|
||||||
stage.setMaximized(true);
|
stage.setMaximized(true);
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ public class ItemBehaviour extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void itemChanged(Item item) {
|
private void itemChanged(Item item) {
|
||||||
//System.out.println("Running item update");
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
this.itemGroup.getChildren().clear();
|
this.itemGroup.getChildren().clear();
|
||||||
if (item != null)
|
if (item != null)
|
||||||
@@ -35,7 +34,6 @@ public class ItemBehaviour extends Component {
|
|||||||
this.itemGroup.getChildren().add(alignmentRectangle);
|
this.itemGroup.getChildren().add(alignmentRectangle);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//System.out.println("Finished item update");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ import javafx.scene.shape.Polygon;
|
|||||||
public class ConveyorBelt extends Entity {
|
public class ConveyorBelt extends Entity {
|
||||||
public ConveyorBelt() {
|
public ConveyorBelt() {
|
||||||
super();
|
super();
|
||||||
Polygon t = new Polygon();
|
Polygon p = new Polygon();
|
||||||
t.getPoints().addAll(
|
p.getPoints().addAll(
|
||||||
Chunk.ENTITY_SIZE / 2d, 0.0,
|
Chunk.ENTITY_SIZE / 2d, 0.0,
|
||||||
0.0, (double) Chunk.ENTITY_SIZE,
|
0.0, (double) Chunk.ENTITY_SIZE,
|
||||||
(double) Chunk.ENTITY_SIZE, (double) Chunk.ENTITY_SIZE);
|
(double) Chunk.ENTITY_SIZE, (double) Chunk.ENTITY_SIZE);
|
||||||
t.setFill(new Color(0, 0, 0, 1));
|
p.setFill(new Color(0, 0, 0, 1));
|
||||||
|
|
||||||
this.getChildren().addAll(t);
|
this.getChildren().addAll(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused") // Called dynamically
|
@SuppressWarnings("unused") // Called dynamically
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.yes.yes.entities.machines;
|
||||||
|
|
||||||
|
import com.yes.yes.behaviours.DestroyBehaviour;
|
||||||
|
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.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);
|
||||||
|
c.setFill(Color.BLACK);
|
||||||
|
c.setCenterX(Chunk.ENTITY_SIZE / 2);
|
||||||
|
c.setCenterY(Chunk.ENTITY_SIZE / 2);
|
||||||
|
|
||||||
|
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);
|
||||||
|
p.setFill(new Color(1, 1, 1, 0.5));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
this.getChildren().addAll(c,p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused") // Called dynamically
|
||||||
|
public Cutter(BlockContainer blockContainer) {
|
||||||
|
this();
|
||||||
|
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
|
||||||
|
this.addBehaviour(new ReceiveBehaviour(this, blockContainer, Direction.DOWN, "Item"));
|
||||||
|
//TODO: Add split/modify behaviour
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,22 +10,21 @@ import com.yes.yes.world.Chunk;
|
|||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Circle;
|
import javafx.scene.shape.Circle;
|
||||||
import javafx.scene.shape.Polygon;
|
import javafx.scene.shape.Polygon;
|
||||||
|
import javafx.scene.shape.Rectangle;
|
||||||
|
|
||||||
public class DestroyMachine extends Entity {
|
public class DestroyMachine extends Entity {
|
||||||
public DestroyMachine() {
|
public DestroyMachine() {
|
||||||
super();
|
super();
|
||||||
Circle c = new Circle(Chunk.ENTITY_SIZE / 2);
|
Rectangle r = new Rectangle(Chunk.ENTITY_SIZE,Chunk.ENTITY_SIZE);
|
||||||
c.setCenterX(Chunk.ENTITY_SIZE / 2);
|
|
||||||
c.setCenterY(Chunk.ENTITY_SIZE / 2);
|
|
||||||
|
|
||||||
Polygon t = new Polygon();
|
Polygon p = new Polygon();
|
||||||
t.getPoints().addAll(
|
p.getPoints().addAll(
|
||||||
Chunk.ENTITY_SIZE / 2d, 0.0,
|
Chunk.ENTITY_SIZE / 2d, 0.0,
|
||||||
0.0, (double) Chunk.ENTITY_SIZE,
|
0.0, (double) Chunk.ENTITY_SIZE,
|
||||||
(double) Chunk.ENTITY_SIZE, (double) Chunk.ENTITY_SIZE);
|
(double) Chunk.ENTITY_SIZE, (double) Chunk.ENTITY_SIZE);
|
||||||
t.setFill(new Color(1, 1, 1, 0.5));
|
p.setFill(new Color(1, 1, 1, 0.5));
|
||||||
|
|
||||||
this.getChildren().addAll(c, t);
|
this.getChildren().addAll(r, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused") // Called dynamically
|
@SuppressWarnings("unused") // Called dynamically
|
||||||
|
|||||||
@@ -5,47 +5,50 @@ import com.yes.yes.behaviours.ItemBehaviour;
|
|||||||
import com.yes.yes.behaviours.OfferBehaviour;
|
import com.yes.yes.behaviours.OfferBehaviour;
|
||||||
import com.yes.yes.behaviours.PlaceBehaviour;
|
import com.yes.yes.behaviours.PlaceBehaviour;
|
||||||
import com.yes.yes.entities.parts.Square;
|
import com.yes.yes.entities.parts.Square;
|
||||||
import com.yes.yes.utils.BlockContainer;
|
import com.yes.yes.utils.*;
|
||||||
import com.yes.yes.utils.Direction;
|
|
||||||
import com.yes.yes.utils.Entity;
|
|
||||||
import com.yes.yes.utils.Item;
|
|
||||||
import com.yes.yes.world.Chunk;
|
import com.yes.yes.world.Chunk;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Polygon;
|
import javafx.scene.shape.Polygon;
|
||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.shape.Rectangle;
|
||||||
|
|
||||||
public class GeneratorMachine extends Entity {
|
public class GeneratorMachine extends Entity {
|
||||||
|
Rectangle rectangle;
|
||||||
|
|
||||||
public GeneratorMachine() {
|
public GeneratorMachine() {
|
||||||
super();
|
super();
|
||||||
Rectangle r = new Rectangle(Chunk.ENTITY_SIZE, Chunk.ENTITY_SIZE);
|
rectangle = new Rectangle(Chunk.ENTITY_SIZE, Chunk.ENTITY_SIZE);
|
||||||
r.setFill(Color.RED);
|
rectangle.setFill(Color.RED);
|
||||||
|
|
||||||
Polygon p = new Polygon();
|
Polygon p = new Polygon();
|
||||||
p.getPoints().addAll(
|
p.getPoints().addAll(
|
||||||
Chunk.ENTITY_SIZE/2d, 0.0,
|
Chunk.ENTITY_SIZE / 2d, 0.0,
|
||||||
0.0, (double) Chunk.ENTITY_SIZE,
|
0.0, (double) Chunk.ENTITY_SIZE,
|
||||||
(double) Chunk.ENTITY_SIZE, (double) Chunk.ENTITY_SIZE);
|
(double) Chunk.ENTITY_SIZE, (double) Chunk.ENTITY_SIZE);
|
||||||
p.setFill(new Color(0, 0, 0, 0.5));
|
p.setFill(new Color(0, 0, 0, 0.5));
|
||||||
|
|
||||||
this.getChildren().addAll(r, p);
|
this.getChildren().addAll(rectangle, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused") // Called dynamically
|
@SuppressWarnings("unused") // Called dynamically
|
||||||
public GeneratorMachine(BlockContainer blockContainer) {
|
public GeneratorMachine(BlockContainer blockContainer) {
|
||||||
this();
|
this();
|
||||||
|
|
||||||
|
rectangle.setFill(blockContainer.chunkColor());
|
||||||
|
|
||||||
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
|
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
|
||||||
this.addBehaviour(new ItemBehaviour(this, blockContainer, "Item"));
|
this.addBehaviour(new ItemBehaviour(this, blockContainer, "Item"));
|
||||||
this.addBehaviour(new OfferBehaviour(this, blockContainer, Direction.UP, "Item"));
|
this.addBehaviour(new OfferBehaviour(this, blockContainer, Direction.UP, "Item"));
|
||||||
this.addBehaviour(new GeneratorBehaviour(this, blockContainer, generateItem(), "Item"));
|
this.addBehaviour(new GeneratorBehaviour(this, blockContainer, generateItem(blockContainer.chunkColor()), "Item"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Item generateItem() {
|
private Item generateItem(Color color) {
|
||||||
Item it = new Item();
|
Item item = new Item();
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int j = 0; j < 4; j++) {
|
||||||
it.setPart(i, j, new Square());
|
Square square = new Square(color);
|
||||||
|
item.setPart(i, j, square);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return it;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import javafx.scene.shape.Polygon;
|
|||||||
public class Splitter extends Entity {
|
public class Splitter extends Entity {
|
||||||
public Splitter() {
|
public Splitter() {
|
||||||
super();
|
super();
|
||||||
Polygon p1 = new Polygon();
|
Polygon p = new Polygon();
|
||||||
p1.getPoints().addAll(
|
p.getPoints().addAll(
|
||||||
0.0, Chunk.ENTITY_SIZE / 2d,
|
0.0, Chunk.ENTITY_SIZE / 2d,
|
||||||
Chunk.ENTITY_SIZE / 2d, 0.0,
|
Chunk.ENTITY_SIZE / 2d, 0.0,
|
||||||
(double) Chunk.ENTITY_SIZE, Chunk.ENTITY_SIZE / 2d,
|
(double) Chunk.ENTITY_SIZE, Chunk.ENTITY_SIZE / 2d,
|
||||||
@@ -23,9 +23,9 @@ public class Splitter extends Entity {
|
|||||||
Chunk.ENTITY_SIZE / 2d, Chunk.ENTITY_SIZE / 2d,
|
Chunk.ENTITY_SIZE / 2d, Chunk.ENTITY_SIZE / 2d,
|
||||||
Chunk.ENTITY_SIZE / 4d, (double) Chunk.ENTITY_SIZE
|
Chunk.ENTITY_SIZE / 4d, (double) Chunk.ENTITY_SIZE
|
||||||
);
|
);
|
||||||
p1.setFill(new Color(0, 0, 0, 1));
|
p.setFill(new Color(0, 0, 0, 1));
|
||||||
|
|
||||||
this.getChildren().addAll(p1);
|
this.getChildren().addAll(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused") // Called dynamically
|
@SuppressWarnings("unused") // Called dynamically
|
||||||
|
|||||||
@@ -6,17 +6,24 @@ import javafx.scene.shape.Rectangle;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class Square extends com.yes.yes.utils.Part {
|
public class Square extends com.yes.yes.utils.Part {
|
||||||
final Random rand = new Random();
|
|
||||||
|
|
||||||
|
Rectangle rect = new Rectangle(23, 23);
|
||||||
|
|
||||||
|
public Square(Color color)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
setColor(color);
|
||||||
|
}
|
||||||
public Square() {
|
public Square() {
|
||||||
int r = rand.nextInt(255);
|
rect = new Rectangle(23, 23);
|
||||||
int g = rand.nextInt(255);
|
rect.setStroke(Color.BLACK);
|
||||||
int b = rand.nextInt(255);
|
|
||||||
|
|
||||||
var rect = new Rectangle(23, 23);
|
|
||||||
rect.setFill(Color.rgb(r, g, b));
|
|
||||||
rect.setStroke(Color.BLUE);
|
|
||||||
rect.setStrokeWidth(1);
|
rect.setStrokeWidth(1);
|
||||||
this.getChildren().add(rect);
|
this.getChildren().add(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onColorChanged(Color color)
|
||||||
|
{
|
||||||
|
rect.setFill(color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ public class GameManager {
|
|||||||
EntityRegistry.register(new RegistryEntry("hub", "Central Hub", HubDisplay.class));
|
EntityRegistry.register(new RegistryEntry("hub", "Central Hub", HubDisplay.class));
|
||||||
EntityRegistry.register(new RegistryEntry("hubAcceptor", "Central Hub Acceptor", HubAcceptor.class));
|
EntityRegistry.register(new RegistryEntry("hubAcceptor", "Central Hub Acceptor", HubAcceptor.class));
|
||||||
EntityRegistry.register(new RegistryEntry("splitter", "Splitter", Splitter.class));
|
EntityRegistry.register(new RegistryEntry("splitter", "Splitter", Splitter.class));
|
||||||
|
EntityRegistry.register(new RegistryEntry("cutter","Cutter", Cutter.class));
|
||||||
} catch (AlreadyExistsException e) {
|
} catch (AlreadyExistsException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,10 @@ public class PlayerManager {
|
|||||||
Class<?>[] types = new Class<?>[1];
|
Class<?>[] types = new Class<?>[1];
|
||||||
types[0] = BlockContainer.class;
|
types[0] = BlockContainer.class;
|
||||||
|
|
||||||
BlockContainer blockContainer = new BlockContainer(world, blockCoordinate, chunkCoordinate);
|
Chunk chunk = world.getChunk(chunkCoordinate);
|
||||||
|
Entity oldEntity = chunk.getEntity(blockCoordinate);
|
||||||
|
|
||||||
|
BlockContainer blockContainer = new BlockContainer(world, chunk.getChunkColor(), blockCoordinate, chunkCoordinate);
|
||||||
RegistryEntry registryEntry = EntityRegistry.getEntry(buildBox.getSelectedEntity());
|
RegistryEntry registryEntry = EntityRegistry.getEntry(buildBox.getSelectedEntity());
|
||||||
|
|
||||||
if (registryEntry == null)
|
if (registryEntry == null)
|
||||||
@@ -62,9 +65,6 @@ public class PlayerManager {
|
|||||||
|
|
||||||
Entity entity = (Entity) registryEntry.getEntity().getConstructor(types).newInstance(blockContainer);
|
Entity entity = (Entity) registryEntry.getEntity().getConstructor(types).newInstance(blockContainer);
|
||||||
|
|
||||||
Chunk chunk = world.getChunk(chunkCoordinate);
|
|
||||||
Entity oldEntity = chunk.getEntity(blockCoordinate);
|
|
||||||
|
|
||||||
if (oldEntity != null && oldEntity.getClass().getSimpleName().equals(entity.getClass().getSimpleName())) {
|
if (oldEntity != null && oldEntity.getClass().getSimpleName().equals(entity.getClass().getSimpleName())) {
|
||||||
if (mouse.getButton() == MouseButton.PRIMARY)
|
if (mouse.getButton() == MouseButton.PRIMARY)
|
||||||
currentRotation = oldEntity.getRotation() + 1;
|
currentRotation = oldEntity.getRotation() + 1;
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ package com.yes.yes.utils;
|
|||||||
|
|
||||||
import com.yes.yes.world.Chunk;
|
import com.yes.yes.world.Chunk;
|
||||||
import com.yes.yes.world.World;
|
import com.yes.yes.world.World;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
public record BlockContainer(World world, Coordinate blockCoordinate, Coordinate chunkCoordinate) {
|
public record BlockContainer(World world, Color chunkColor, Coordinate blockCoordinate, Coordinate chunkCoordinate) {
|
||||||
final static int MAX_RADIUS = 2;
|
final static int MAX_RADIUS = 2;
|
||||||
|
|
||||||
public Entity getBlockAbsolute(Coordinate offset) throws IllegalArgumentException {
|
public Entity getBlockAbsolute(Coordinate offset) throws IllegalArgumentException {
|
||||||
|
|||||||
@@ -31,9 +31,7 @@ public abstract class Entity extends javafx.scene.Group {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final void update() {
|
public final void update() {
|
||||||
//System.out.println("Updating: " + getClass().getSimpleName());
|
|
||||||
for (Component behaviour : behaviours) {
|
for (Component behaviour : behaviours) {
|
||||||
//System.out.println("Updating " + behaviour.getClass().getSimpleName());
|
|
||||||
behaviour.update();
|
behaviour.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,10 @@ public class Item extends javafx.scene.Group implements Cloneable {
|
|||||||
Class<?>[] types = new Class<?>[0];
|
Class<?>[] types = new Class<?>[0];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
clone.setPart(i, j, this.getPart(i, j).getClass().getConstructor(types).newInstance());
|
Part part = this.getPart(i, j);
|
||||||
|
Part clonePart = part.getClass().getConstructor(types).newInstance();
|
||||||
|
clonePart.setColor(part.getColor());
|
||||||
|
clone.setPart(i, j, clonePart);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.yes.yes.utils;
|
||||||
|
|
||||||
|
public class NoiseGenerator {
|
||||||
|
private NoiseGenerator(){}
|
||||||
|
|
||||||
|
public static double calculate(int value)
|
||||||
|
{
|
||||||
|
return Math.abs(Math.sin(Math.tan(value) + Math.pow(value,2)) * Math.cos(Math.pow(value,2)) * Integer.MAX_VALUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,9 @@
|
|||||||
package com.yes.yes.utils;
|
package com.yes.yes.utils;
|
||||||
|
|
||||||
import javafx.scene.Node;
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
public abstract class Part extends javafx.scene.Group {
|
public abstract class Part extends javafx.scene.Group {
|
||||||
public void addChild(Node element) {
|
Color color;
|
||||||
this.getChildren().add(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeChild(Node element) {
|
|
||||||
this.getChildren().remove(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void rotate(int quarters) {
|
public void rotate(int quarters) {
|
||||||
|
|
||||||
@@ -17,4 +11,14 @@ public abstract class Part extends javafx.scene.Group {
|
|||||||
this.getTransforms().add(new javafx.scene.transform.Rotate(quarters % 4 * 90, 0, 0));
|
this.getTransforms().add(new javafx.scene.transform.Rotate(quarters % 4 * 90, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void onColorChanged(Color color);
|
||||||
|
|
||||||
|
public void setColor(Color color) {
|
||||||
|
this.color = color;
|
||||||
|
onColorChanged(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package com.yes.yes.world;
|
|||||||
|
|
||||||
import com.yes.yes.utils.Coordinate;
|
import com.yes.yes.utils.Coordinate;
|
||||||
import com.yes.yes.utils.Entity;
|
import com.yes.yes.utils.Entity;
|
||||||
|
import com.yes.yes.utils.NoiseGenerator;
|
||||||
import javafx.geometry.HPos;
|
import javafx.geometry.HPos;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.VPos;
|
import javafx.geometry.VPos;
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.*;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
@@ -12,12 +14,24 @@ public class Chunk extends GridPane {
|
|||||||
public static final int CHUNK_SIZE = 8;
|
public static final int CHUNK_SIZE = 8;
|
||||||
public static final int ENTITY_SIZE = 50;
|
public static final int ENTITY_SIZE = 50;
|
||||||
private final Entity[] data = new Entity[CHUNK_SIZE * CHUNK_SIZE];
|
private final Entity[] data = new Entity[CHUNK_SIZE * CHUNK_SIZE];
|
||||||
|
private final Color chunkColor;
|
||||||
|
|
||||||
public Chunk() {
|
public Chunk(Coordinate pos) {
|
||||||
super();
|
super();
|
||||||
this.setMaxSize(CHUNK_SIZE * ENTITY_SIZE, CHUNK_SIZE * ENTITY_SIZE);
|
this.setMaxSize(CHUNK_SIZE * ENTITY_SIZE, CHUNK_SIZE * ENTITY_SIZE);
|
||||||
this.setMinSize(CHUNK_SIZE * ENTITY_SIZE, CHUNK_SIZE * ENTITY_SIZE);
|
this.setMinSize(CHUNK_SIZE * ENTITY_SIZE, CHUNK_SIZE * ENTITY_SIZE);
|
||||||
|
|
||||||
|
chunkColor = switch (((int) NoiseGenerator.calculate(pos.x * pos.y)) % 3) {
|
||||||
|
case 0 -> Color.RED;
|
||||||
|
case 1 -> Color.GREEN;
|
||||||
|
case 2 -> Color.BLUE;
|
||||||
|
default -> throw new IllegalStateException();
|
||||||
|
};
|
||||||
|
|
||||||
|
Color fillColor = new Color(chunkColor.getRed(),chunkColor.getGreen(), chunkColor.getBlue(), 0.1);
|
||||||
|
|
||||||
|
this.setBackground(new Background(new BackgroundFill(fillColor, CornerRadii.EMPTY, Insets.EMPTY)));
|
||||||
|
|
||||||
for (int i = 0; i < CHUNK_SIZE; i++) {
|
for (int i = 0; i < CHUNK_SIZE; i++) {
|
||||||
for (int j = 0; j < CHUNK_SIZE; j++) {
|
for (int j = 0; j < CHUNK_SIZE; j++) {
|
||||||
this.getColumnConstraints().add(new ColumnConstraints(ENTITY_SIZE));
|
this.getColumnConstraints().add(new ColumnConstraints(ENTITY_SIZE));
|
||||||
@@ -53,6 +67,10 @@ public class Chunk extends GridPane {
|
|||||||
data[pos.x + pos.y * CHUNK_SIZE] = null;
|
data[pos.x + pos.y * CHUNK_SIZE] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Color getChunkColor() {
|
||||||
|
return chunkColor;
|
||||||
|
}
|
||||||
|
|
||||||
public Entity getEntity(Coordinate pos) {
|
public Entity getEntity(Coordinate pos) {
|
||||||
return data[pos.x + pos.y * CHUNK_SIZE];
|
return data[pos.x + pos.y * CHUNK_SIZE];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class World extends GridPane {
|
|||||||
|
|
||||||
public void addChunk(Coordinate pos) throws AlreadyExistsException {
|
public void addChunk(Coordinate pos) throws AlreadyExistsException {
|
||||||
if (chunks.get(pos) == null) {
|
if (chunks.get(pos) == null) {
|
||||||
chunks.put(pos, new Chunk());
|
chunks.put(pos, new Chunk(pos));
|
||||||
} else {
|
} else {
|
||||||
throw new AlreadyExistsException("Chunk already exists");
|
throw new AlreadyExistsException("Chunk already exists");
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ public class World extends GridPane {
|
|||||||
public Chunk getChunk(Coordinate pos) {
|
public Chunk getChunk(Coordinate pos) {
|
||||||
Chunk c = chunks.get(pos);
|
Chunk c = chunks.get(pos);
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
c = new Chunk();
|
c = new Chunk(pos);
|
||||||
chunks.put(pos, c);
|
chunks.put(pos, c);
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<?import javafx.scene.layout.VBox?>
|
|
||||||
<VBox spacing="20.0" xmlns:fx="http://javafx.com/fxml"
|
|
||||||
fx:controller="com.yes.yes.MainController" fx:id="root">
|
|
||||||
</VBox>
|
|
||||||
Reference in New Issue
Block a user