Création d'une boucle de jeu

main
ZIRTR0X 3 years ago
parent 5a7cdfd3da
commit f8a86c508d

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXToggleButton?>
<?import com.jfoenix.controls.JFXButton?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.MenuItem?>
@ -11,10 +12,9 @@
<?import javafx.scene.shape.Line?>
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.ToggleGroup?>
<AnchorPane fx:id="levelRoot" xmlns:fx="http://javafx.com/fxml/1" id="pane" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity"
minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"
@ -39,17 +39,17 @@
</Label>
<Line endX="181.0" endY="-3.0517578125E-5" layoutX="107.0" layoutY="160.0" startX="1.0889129638671875"
startY="-1.52587890625E-5" stroke="#535252"/>
<RadioButton fx:id="radioButton1" layoutX="85" layoutY="200" prefHeight="33.0" prefWidth="75.0" selected="true" textFill="WHITE">
<RadioButton fx:id="radioButton1" layoutX="85" layoutY="200" prefHeight="33.0" prefWidth="75.0" textFill="WHITE" onMouseClicked="#setDifficulty1">
<toggleGroup>
<ToggleGroup fx:id="group"/>
</toggleGroup>
</RadioButton>
<RadioButton fx:id="radioButton2" layoutX="160" layoutY="200" prefHeight="33.0" prefWidth="75.0" textFill="WHITE">
<RadioButton fx:id="radioButton2" layoutX="160" layoutY="200" prefHeight="33.0" prefWidth="75.0" textFill="WHITE" onMouseClicked="#setDifficulty2">
<toggleGroup>
<fx:reference source="group"/>
</toggleGroup>
</RadioButton>
<RadioButton fx:id="radioButton3" layoutX="238" layoutY="200" prefHeight="33.0" prefWidth="75.0" textFill="WHITE">
<RadioButton fx:id="radioButton3" layoutX="238" layoutY="200" prefHeight="33.0" prefWidth="75.0" textFill="WHITE" onMouseClicked="#setDifficulty3">
<toggleGroup>
<fx:reference source="group"/>
</toggleGroup>
@ -88,13 +88,33 @@
<SplitMenuButton alignment="CENTER" contentDisplay="CENTER" layoutX="152.0" layoutY="351.0"
mnemonicParsing="false" text="Choix Personnage">
<items>
<MenuItem onAction="#changeSkin" fx:id="choice1" mnemonicParsing="false" text="Personnage 1"/>
<MenuItem onAction="#changeSkin" fx:id="choice2" mnemonicParsing="false" text="Personnage 2"/>
<MenuItem onAction="#changeSkin" fx:id="choice3" mnemonicParsing="false" text="Personnage 3"/>
<MenuItem onAction="#changeSkin1" fx:id="choice1" mnemonicParsing="false" text="Personnage 1"/>
<MenuItem onAction="#changeSkin2" fx:id="choice2" mnemonicParsing="false" text="Personnage 2"/>
<MenuItem onAction="#changeSkin3" fx:id="choice3" mnemonicParsing="false" text="Personnage 3"/>
</items>
<font>
<Font name="Segoe UI Black" size="12.0"/>
</font>
</SplitMenuButton>
</children>
<Rectangle arcHeight="5.0" arcWidth="5.0" height="50.0" layoutX="775.0" layoutY="525.0" opacity="0.6"
stroke="BLACK" strokeLineCap="ROUND" strokeLineJoin="ROUND" strokeMiterLimit="0.0" strokeWidth="5.0"
width="100.0">
<cursor>
<Cursor fx:constant="DEFAULT"/>
</cursor>
</Rectangle>
<Rectangle arcHeight="5.0" arcWidth="5.0" height="50.0" layoutX="775.0" layoutY="525.0" opacity="0.6"
stroke="BLACK" strokeLineCap="ROUND" strokeLineJoin="ROUND" strokeMiterLimit="0.0" strokeWidth="5.0"
width="100.0">
<cursor>
<Cursor fx:constant="DEFAULT"/>
</cursor>
</Rectangle>
<JFXButton layoutX="788" layoutY="535" prefHeight="30.0" prefWidth="75.0"
style="-fx-background-color: #EB9C0A;" text="START" textFill="WHITE" onMouseClicked="#launchGame" fx:id="button">
<font>
<Font name="Segoe UI Black" size="13.0"/>
</font>
</JFXButton>
</AnchorPane>

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.effect.Shadow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.shape.Line?>
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.control.Button?>
<AnchorPane fx:id="levelRoot" id="1" fx:controller="controller.GamePlayController" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1300.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/11" xmlns:fx="http://javafx.com/fxml/1" >
<children>
<AnchorPane minHeight="400.0" minWidth="400.0" prefHeight="608.0" prefWidth="348.0" layoutX="960.0">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#323436" height="900.0" layoutY="0.0" stroke="BLACK" strokeType="INSIDE" width="340" />
<ImageView fitHeight="128.0" fitWidth="93.0" layoutX="50.0" layoutY="33.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../image/personnage/Perso1.2.png" />
</image>
</ImageView>
<Label layoutX="144.0" layoutY="59.0" prefHeight="41.0" prefWidth="124.0" text="Pseudonyme" textFill="WHITE">
<font>
<Font name="Segoe UI Black" size="16.0" />
</font>
</Label>
<Rectangle arcHeight="5.0" arcWidth="5.0" height="331.0" layoutX="50.0" layoutY="166.0" opacity="0.3" stroke="BLACK" strokeDashOffset="10.0" strokeLineCap="ROUND" strokeLineJoin="ROUND" strokeMiterLimit="100.0" strokeType="INSIDE" strokeWidth="5.0" width="201.0" />
<Line endX="100.0" layoutX="139.0" layoutY="222.0" startX="-77.0" stroke="#f2f0f0" />
<Label alignment="CENTER" layoutX="88.0" layoutY="173.0" prefHeight="41.0" prefWidth="124.0" text="Action" textFill="WHITE">
<font>
<Font name="Segoe UI" size="16.0" />
</font>
</Label>
<JFXButton fx:id="buttonDe" onAction="#lancerDe" layoutX="95.0" layoutY="530.0" prefHeight="30.0" prefWidth="119.0" ripplerFill="#e1e1e1" style="-fx-background-color: #EB9C0A;" text="Lancer le dé" textAlignment="CENTER" textFill="WHITE">
<font>
<Font name="Segoe UI" size="15.0" />
</font>
<effect>
<Shadow />
</effect>
</JFXButton>
<ImageView fx:id="de" fitWidth="75" fitHeight="75" layoutX="100" layoutY="580.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../image/dé/icon.png"/>
</image>
</ImageView>
</children>
</AnchorPane>
</children>
</AnchorPane>

@ -30,7 +30,9 @@ public class Main extends Application {
primaryStage.setScene(new Scene(root, 900, 600));
primaryStage.setResizable(false);
primaryStage.show();
//boucle de lecture
GameLoop loop = new GameLoop();
loop.start();
//début musique
ArrayList<Musique> musiqueListe = new ArrayList<Musique>();

@ -0,0 +1,36 @@
package model;
public class GameLoop {
private Thread timer;
public void start() {
timer = new Thread("timer") {
public void run() {
final double FPS = 60;
final double DELAY = 1000000000 / FPS;
long lastTime = System.nanoTime();
long timer = 0;
double delta = 0;
long currentTime;
int frames = 0;
while (true) {
currentTime = System.nanoTime();
delta += (currentTime - lastTime) / DELAY;
timer += currentTime - lastTime;
lastTime = currentTime;
if (delta >= 1) {
//update(); // fonction qui sera update
frames++;
delta--;
}
if (timer >= 1000000000) {
timer = 0;
System.out.println("FPS: " + frames);
frames = 0;
}
}
}
};
}
}

@ -0,0 +1,36 @@
package model;
public class Time {
private Thread timer;
public void start() {
timer = new Thread("timer") {
public void run() {
final double FPS = 60;
final double DELAY = 1000000000 / FPS;
long lastTime = System.nanoTime();
long timer = 0;
double delta = 0;
long currentTime;
int frames = 0;
while (true) {
currentTime = System.nanoTime();
delta += (currentTime - lastTime) / DELAY;
timer += currentTime - lastTime;
lastTime = currentTime;
if (delta >= 1) {
//update(); // fonction qui sera update
frames++;
delta--;
}
if (timer >= 1000000000) {
timer = 0;
System.out.println("FPS: " + frames);
frames = 0;
}
}
}
};
}
}
Loading…
Cancel
Save