Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/chest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/diamond.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/key.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/knight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/zombie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"tag": "location-1",
"objects": [
{ "tag": "object-1", "position": { "row": 1, "col": 8 }, "type": "collectible", "assetPath": "assets/diamond.png" },
{ "tag": "object-2", "position": { "row": 6, "col": 3 }, "type": "collectible", "assetPath": "assets/key.png" },
{ "tag": "object-3", "position": { "row": 1, "col": 1 }, "type": "dialog", "assetPath": "assets/zombie.png" },
{ "tag": "object-4", "position": { "row": 3, "col": 2 }, "type": "dialog", "assetPath": "assets/zombie.png" },
{ "tag": "object-5", "position": { "row": 8, "col": 8 }, "type": "dialog", "assetPath": "assets/chest.png" }
],
"backgroundPath": "assets/map.png"
}
14 changes: 14 additions & 0 deletions configurations/demo-config-1/root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"tag": "GameByConfig1",
"locationTags": [
"location-1"
],
"rootLocation": "location-1",
"player": {
"tag": "player",
"position": { "row": 4, "col": 5 },
"type": "player",
"assetPath": "assets/knight.png",
"location": "location-1"
}
}
2 changes: 1 addition & 1 deletion src/main/java/io/rpg/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void start(Stage stage) throws IOException {
Configurator.setRootLevel(Level.DEBUG);
Logger logger = LogManager.getLogger(Main.class);

Initializer worldInitializer = new Initializer("configurations/config-1", stage);
Initializer worldInitializer = new Initializer("configurations/demo-config-1", stage);
Result<Game, Exception> initializationResult = worldInitializer.initialize();

if (initializationResult.isError()) {
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/io/rpg/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.rpg.model.data.MouseClickedEvent;
import io.rpg.model.data.Vector;
import io.rpg.model.location.LocationModel;
import io.rpg.model.object.CollectibleGameObject;
import io.rpg.model.object.GameObject;
import io.rpg.model.object.InteractiveGameObject;
import io.rpg.model.object.Player;
Expand Down Expand Up @@ -117,13 +118,19 @@ private int getWindowCenterY() {

@Override
public void onMouseClickedEvent(MouseClickedEvent event) {
int SCALE = 64;
Vector playerPos = currentModel.getPlayer().getPixelPosition();
GameObjectView objectView = event.source();
GameObject object = currentModel.getObject((int) objectView.getY() / 32, (int) objectView.getX() / 32);
if (Math.abs(playerPos.x - objectView.getX()) / 32 <= 1.5 && Math.abs(playerPos.y - objectView.getY()) / 32 <= 1.5) {
GameObject object = currentModel.getObject((int) objectView.getY() / SCALE, (int) objectView.getX() / SCALE);
if (Math.abs(playerPos.x - objectView.getX()) / SCALE <= 1.5 && Math.abs(playerPos.y - objectView.getY()) / SCALE <= 1.5) {
if (object instanceof InteractiveGameObject) {
((InteractiveGameObject) object).onAction();
}

if (object instanceof CollectibleGameObject) {
popupController.openPointsPopup(5, getWindowCenterX(), getWindowCenterY());
objectView.setVisible(false);
}
}
logger.info("Controller notified on click from " + event.source());
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/rpg/model/data/Vector.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public Vector(float x, float y) {

public Vector(Position position) {
// TODO THIS MOTHT
this.x = position.col * 32;
this.y = position.row * 32;
int SCALE = 64;
this.x = position.col * SCALE;
this.y = position.row * SCALE;
}

}
7 changes: 6 additions & 1 deletion src/main/java/io/rpg/view/GameObjectView.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class GameObjectView extends ImageView
private Path path;
private final Set<MouseClickedEvent.Observer> onClickedObservers;

private final int SCALE = 32;
private final int SCALE = 64;

public GameObjectView(@NotNull Path assetPath, @NotNull Position position) {
this.path = assetPath;
Expand All @@ -25,6 +25,11 @@ public GameObjectView(@NotNull Path assetPath, @NotNull Position position) {
// todo: better position class
this.setX(position.col * SCALE);
this.setY(position.row * SCALE);

this.setPreserveRatio(true);
this.setSmooth(false);
this.setFitHeight(SCALE);

this.onClickedObservers = new HashSet<>();
this.setOnMouseClicked(event -> emitOnMouseClickedEvent(new MouseClickedEvent(this, event)));
}
Expand Down