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

Commit

Permalink
Sprint 1: Merge pull request #2 from NaulaN/develop
Browse files Browse the repository at this point in the history
Sprint 1
  • Loading branch information
naulan-chrzaszcz authored May 13, 2022
2 parents 9019e9e + 53630d6 commit 459f250
Show file tree
Hide file tree
Showing 49 changed files with 784 additions and 126 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.gradle/
/.idea/
/build/
/out/
Binary file removed .gradle/7.3.3/checksums/checksums.lock
Binary file not shown.
Binary file removed .gradle/7.3.3/fileHashes/fileHashes.lock
Binary file not shown.
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/compiler.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/discord.xml

This file was deleted.

17 changes: 0 additions & 17 deletions .idea/gradle.xml

This file was deleted.

20 changes: 0 additions & 20 deletions .idea/jarRepositories.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/misc.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repositories {
}

ext {
junitVersion = '5.8.1'
junitVersion = '5.8.2'
}

sourceCompatibility = '11'
Expand All @@ -25,7 +25,7 @@ tasks.withType(JavaCompile) {

application {
mainModule = 'fr.sae.terraria'
mainClass = 'fr.sae.terraria.HelloApplication'
mainClass = 'fr.sae.terraria.Terraria'
}

javafx {
Expand All @@ -34,9 +34,10 @@ javafx {
}

dependencies {

testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")

implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.7'
}

test {
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/fr/sae/terraria/Controller.java

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/java/fr/sae/terraria/Environment.java

This file was deleted.

32 changes: 23 additions & 9 deletions src/main/java/fr/sae/terraria/Terraria.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
package fr.sae.terraria;

import fr.sae.terraria.controller.Controller;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.File;
import java.io.IOException;

import java.net.URL;

public class Terraria extends javafx.application.Application

public class Terraria extends Application
{
private String titleWindow = "Terraria-Like!";
// TODO: effet de profondeur dans la terre
private String titleWindow = "Terraria-Like";
private int widthWindow = 1280;
private int heightWindow = 720;


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

public void start(Stage stage) throws IOException
{
FXMLLoader fxmlLoader = new FXMLLoader(Terraria.class.getResource("hello-view.fxml"));
/* TODO: Commencer par le menu */

URL pathFxml = Terraria.class.getResource("vue/game.fxml");
if (pathFxml == null)
pathFxml = new File("src/main/resources/fr/sae/terraria/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);

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

public static void main(String[] args) {
launch();
stage.show();
}
}
162 changes: 162 additions & 0 deletions src/main/java/fr/sae/terraria/controller/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package fr.sae.terraria.controller;

import fr.sae.terraria.modele.blocks.Dirt;
import fr.sae.terraria.modele.blocks.Stone;
import fr.sae.terraria.modele.entities.entity.Entity;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import java.util.ResourceBundle;

import java.net.URL;

import fr.sae.terraria.Terraria;
import fr.sae.terraria.modele.Environment;
import fr.sae.terraria.modele.TileMaps;


public class Controller implements Initializable
{
@FXML
private BorderPane root;
@FXML
private HBox title;
@FXML
private Pane display;

private IntegerProperty tileWidth = new SimpleIntegerProperty();
private IntegerProperty tileHeight = new SimpleIntegerProperty();

private Environment environment;
private TileMaps tiles;

private int ticks = 0;


public Controller(Stage primaryStage)
{
environment = new Environment();
tiles = new TileMaps();

primaryStage.addEventFilter(KeyEvent.KEY_PRESSED, key -> {
environment.getKeysInput().put(key.getCode(), true);
key.consume();
});

primaryStage.addEventFilter(KeyEvent.KEY_RELEASED, key -> {
environment.getKeysInput().put(key.getCode(), false);
key.consume();
});

primaryStage.heightProperty().addListener((obs, oldV, newV) -> tileHeight.setValue((int) (TileMaps.tileDefaultSize*((newV.intValue()-title.getPrefHeight()) / 256))));
primaryStage.widthProperty().addListener((obs, oldV, newV) -> tileWidth.setValue((int) (TileMaps.tileDefaultSize*((newV.intValue() / 465)))));
}

@Override
public void initialize(URL location, ResourceBundle resources)
{
tiles.load("src/main/resources/fr/sae/terraria/maps/map_0.json");

tileHeight.setValue((int) (TileMaps.tileDefaultSize*((root.getPrefHeight()-title.getPrefHeight()) / 256)));
tileWidth.setValue((int) (TileMaps.tileDefaultSize*((root.getPrefWidth() / 465))));

InputStream floorTopPath = Terraria.class.getResourceAsStream("tiles/floor-top.png");
if (floorTopPath == null) try {
floorTopPath = new FileInputStream("src/main/resources/fr/sae/terraria/tiles/floor-top.png");
} catch (FileNotFoundException e) { throw new RuntimeException(e); }
Image floorTopImg = new Image(floorTopPath, tileWidth.get(), tileHeight.get(), false, false);

InputStream floorLeftPath = Terraria.class.getResourceAsStream("tiles/floor-left.png");
if (floorLeftPath == null) try {
floorLeftPath = new FileInputStream("src/main/resources/fr/sae/terraria/tiles/floor-left.png");
} catch (FileNotFoundException e) { throw new RuntimeException(e); }
Image floorLeftImg = new Image(floorLeftPath, tileWidth.get(), tileHeight.get(), false, false);

InputStream floorRightPath = Terraria.class.getResourceAsStream("tiles/floor-right.png");
if (floorRightPath == null) try {
floorRightPath = new FileInputStream("src/main/resources/fr/sae/terraria/tiles/floor-right.png");
} catch (FileNotFoundException e) { throw new RuntimeException(e); }
Image floorRightImg = new Image(floorRightPath, tileWidth.get(), tileHeight.get(), false, false);

InputStream stonePath = Terraria.class.getResourceAsStream("tiles/rock-fill.png");
if (stonePath == null) try {
stonePath = new FileInputStream("src/main/resources/fr/sae/terraria/tiles/rock-fill.png");
} catch (FileNotFoundException e) { throw new RuntimeException(e); }
Image stoneImg = new Image(stonePath, tileWidth.get(), tileHeight.get(), false, false);

InputStream dirtPath = Terraria.class.getResourceAsStream("tiles/dirt-top.png");
if (dirtPath == null) try {
dirtPath = new FileInputStream("src/main/resources/fr/sae/terraria/tiles/dirt-top.png");
} catch (FileNotFoundException e) { throw new RuntimeException(e); }
Image dirtImg = new Image(dirtPath, tileWidth.get(), tileHeight.get(), false, false);

InputStream playerPath = Terraria.class.getResourceAsStream("sprites/player/player_idle.png");
if (playerPath == null) try {
playerPath = new FileInputStream("src/main/resources/fr/sae/terraria/sprites/player/player_idle.png");
} catch (FileNotFoundException e) { throw new RuntimeException(e); }

for (int y = 0; y < tiles.getHeight() ; y++)
for (int x = 0 ; x < tiles.getWidth() ; x++)
switch (tiles.getTile(y,x))
{
case TileMaps.STONE:
Stone stoneSprite = new Stone(x*tileWidth.get(), y*tileHeight.get());
stoneSprite.setRect((int) stoneImg.getWidth(), (int) stoneImg.getHeight());
display.getChildren().add(createImageView(stoneSprite, stoneImg));
environment.getEntities().add(stoneSprite);
break;
case TileMaps.DIRT:
Dirt dirtSprite = new Dirt(x*tileWidth.get(), y*tileHeight.get());
dirtSprite.setRect((int) dirtImg.getWidth(), (int) dirtImg.getHeight());
display.getChildren().add(createImageView(dirtSprite, dirtImg));
environment.getEntities().add(dirtSprite);
break;
case TileMaps.FLOOR_TOP:
Dirt floorTopSprite = new Dirt(x*tileWidth.get(), y*tileHeight.get());
floorTopSprite.setRect((int) floorTopImg.getWidth(), (int) floorTopImg.getHeight());
display.getChildren().add(createImageView(floorTopSprite, floorTopImg));
environment.getEntities().add(floorTopSprite);
break;
case TileMaps.FLOOR_LEFT:
Dirt floorLeftSprite = new Dirt(x*tileWidth.get(), y*tileHeight.get());
floorLeftSprite.setRect((int) floorLeftImg.getWidth(), (int) floorLeftImg.getHeight());
display.getChildren().add(createImageView(floorLeftSprite, floorLeftImg));
environment.getEntities().add(floorLeftSprite);
break;
case TileMaps.FLOOR_RIGHT:
Dirt floorRightSprite = new Dirt(x*tileWidth.get(), y*tileHeight.get());
floorRightSprite.setRect((int) floorRightImg.getWidth(), (int) floorRightImg.getHeight());
display.getChildren().add(createImageView(floorRightSprite, floorRightImg));
environment.getEntities().add(floorRightSprite);
break;
}

ImageView playerImgView = new ImageView(new Image(playerPath, tileWidth.get(), tileHeight.get()*2, false, false));
environment.getPlayer().setRect((int) playerImgView.getFitWidth(), (int) playerImgView.getFitHeight());
playerImgView.translateYProperty().bind(environment.getPlayer().getYProperty());
playerImgView.translateXProperty().bind(environment.getPlayer().getXProperty());
display.getChildren().add(playerImgView);
}

private ImageView createImageView(Entity entity, Image img)
{
ImageView imageView = new ImageView(img);
imageView.translateXProperty().bind(entity.getXProperty());
imageView.translateYProperty().bind(entity.getYProperty());

return imageView;
}
}
Loading

0 comments on commit 459f250

Please sign in to comment.