Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #14 from NaulaN/develop
Browse files Browse the repository at this point in the history
Sprint n°3
  • Loading branch information
naulan-chrzaszcz authored Jun 8, 2022
2 parents 5574f53 + 903958a commit 0621d12
Show file tree
Hide file tree
Showing 114 changed files with 3,339 additions and 1,397 deletions.
Binary file added UML.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 72 additions & 12 deletions src/main/java/fr/sae/terraria/Terraria.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package fr.sae.terraria;

import fr.sae.terraria.controller.Controller;
import fr.sae.terraria.controller.GameController;
import fr.sae.terraria.controller.MenuController;
import javafx.application.Application;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.fxml.FXMLLoader;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.stage.Stage;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Objects;


public class Terraria extends Application
{
// Constants
public static final String srcPath = "src/main/resources/fr/sae/terraria/";
public static final String SRC_PATH = "src/main/resources/fr/sae/terraria/";
public static final double TARGET_FPS = .017;
public static final int DISPLAY_RENDERING_WIDTH = 465;
public static final int DISPLAY_RENDERING_HEIGHT = 256;
Expand All @@ -26,22 +34,74 @@ public class Terraria extends Application

public static void main(String[] args) { launch(); }

private FXMLLoader loadFXML(String path)
{
URL pathGameFxml = Terraria.class.getResource(path);
if (Objects.isNull(pathGameFxml)) try {
pathGameFxml = new File(Terraria.SRC_PATH + path).toURI().toURL();
} catch (MalformedURLException e) { throw new RuntimeException(e); }

return new FXMLLoader(pathGameFxml);
}

public void start(Stage stage) throws IOException
{
URL pathFxml = Terraria.class.getResource("vue/game.fxml");
if (pathFxml == null)
pathFxml = new File(srcPath + "vue/game.fxml").toURI().toURL();

FXMLLoader fxmlLoader = new FXMLLoader(pathFxml);
Controller ctrl = new Controller(stage);
fxmlLoader.setController(ctrl);
Scene scene = new Scene(fxmlLoader.load(), this.widthWindow, this.heightWindow);

GameController gameController = new GameController(stage);
MenuController menuController = new MenuController(stage);

FXMLLoader fxmlLoader = this.loadFXML("vue/game.fxml");
fxmlLoader.setController(gameController);
Scene game = new Scene(fxmlLoader.load(), this.widthWindow, this.heightWindow);
game.setCursor(Cursor.NONE);

fxmlLoader = this.loadFXML("vue/menu.fxml");
fxmlLoader.setController(menuController);
Scene menu = new Scene(fxmlLoader.load(), this.widthWindow, this.heightWindow);

stage.setTitle(this.titleWindow);
stage.setResizable(false);
stage.setScene(scene);

BooleanProperty switchScene = new SimpleBooleanProperty();
// Change de scènes suivant les valeurs boolean
switchScene.addListener((obs, oldB, newB) -> stage.setScene(newB.equals(Boolean.TRUE) ? game : menu));

stage.setScene(game);
int[] timePressedKey = new int[1]; // Permet que le menu ne clignote pas et reste afficher même si le bouton 'M' est encore enfoncer.
stage.addEventFilter(KeyEvent.KEY_PRESSED, key -> {
if (key.getCode() == KeyCode.M && timePressedKey[0] <= 1)
switchScene.set(!switchScene.get());

timePressedKey[0]++;
key.consume();
});
stage.addEventFilter(KeyEvent.KEY_RELEASED, key -> timePressedKey[0] = 1);
stage.sizeToScene();

// Sync les changements du joueur entre les contrôleurs.
stage.sceneProperty().addListener(((obs, oldScene, newScene) -> {
if (switchScene.get()) {
if (!Objects.isNull(menuController.player)) {
gameController.player = menuController.player;
menuController.loop.stop();
gameController.environment.getLoop().play();
}
} else {
if (!Objects.isNull(gameController.player)) {
menuController.player = gameController.player;
menuController.loop.play();
gameController.environment.getLoop().stop();
}
}
}));
stage.widthProperty().addListener((obs, oldV, newV) -> {
gameController.scaleMultiplicatorWidth = (newV.intValue() / Terraria.DISPLAY_RENDERING_WIDTH);
menuController.scaleMultiplicatorWidth = (newV.intValue() / Terraria.DISPLAY_RENDERING_WIDTH);
});
stage.heightProperty().addListener((obs, oldV, newV) -> {
gameController.scaleMultiplicatorHeight = ((newV.intValue()-gameController.title.getPrefHeight()) / Terraria.DISPLAY_RENDERING_HEIGHT);
menuController.scaleMultiplicatorHeight = ((newV.intValue()-gameController.title.getPrefHeight()) / Terraria.DISPLAY_RENDERING_HEIGHT);
});

stage.show();
}
}
190 changes: 0 additions & 190 deletions src/main/java/fr/sae/terraria/controller/Controller.java

This file was deleted.

Loading

0 comments on commit 0621d12

Please sign in to comment.