-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColoris.java
More file actions
116 lines (95 loc) · 3.84 KB
/
Coloris.java
File metadata and controls
116 lines (95 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package coloris;
import javafx.animation.AnimationTimer;
import javafx.animation.FadeTransition;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Coloris extends Application //remove all magic numbers!!!!!!!!!!!!!
{
private static final double INITIAL_SCENE_WIDTH = 1260;
private static final double INITIAL_SCENE_HEIGHT = 988.8;
private Group root;
private Scene scene;
private Rectangle titleContainer;
private Rectangle gameContainer;
private Board board;
private AnimationTimer timer;
private MediaPlayer titlePlayer;
private MediaPlayer gamePlayer;
@Override
public void start(Stage stage)
{
root = new Group();
Image titleBackground = new Image(getClass().getResource("/coloris/sprites/title_background.png").toString(), INITIAL_SCENE_WIDTH, INITIAL_SCENE_HEIGHT, false, false);
titleContainer = new Rectangle(INITIAL_SCENE_WIDTH, INITIAL_SCENE_HEIGHT);
titleContainer.setFill(new ImagePattern(titleBackground, 0, 0, 1, 1, true));
Image gameBackground = new Image(getClass().getResource("/coloris/sprites/game_background.png").toString(), INITIAL_SCENE_WIDTH, INITIAL_SCENE_HEIGHT, false, false);
gameContainer = new Rectangle(INITIAL_SCENE_WIDTH, INITIAL_SCENE_HEIGHT);
gameContainer.setFill(new ImagePattern(gameBackground, 0, 0, 1, 1, true));
scene = new Scene(root, INITIAL_SCENE_WIDTH, INITIAL_SCENE_HEIGHT);
root.getChildren().addAll(gameContainer, titleContainer);
stage.setScene(scene);
stage.sizeToScene();
stage.setTitle("Coloris");
stage.setResizable(false);
stage.getIcons().add(new Image(getClass().getResource("/coloris/sprites/icon.png").toString()));
stage.show();
setTitleScene();
}
public void setTitleScene()
{
Media sound = new Media(getClass().getResource("/coloris/music/avesoft.mp3").toString());
titlePlayer = new MediaPlayer(sound);
titlePlayer.setStartTime(Duration.seconds(5)); //magic number
titlePlayer.setStopTime(Duration.seconds(11)); //magic number
titlePlayer.setOnEndOfMedia(() -> {
FadeTransition ft = new FadeTransition(Duration.seconds(1), titleContainer);
ft.setFromValue(1.0);
ft.setToValue(0.0);
ft.setOnFinished((e) -> {
root.getChildren().remove(titleContainer);
setGameScene();
});
ft.play();
});
titlePlayer.play();
}
public void setGameScene()
{
scene.setOnKeyPressed(k -> {
board.keyPressed(k.getCode());
});
GameInfo gameInfo = new GameInfo(scene);
board = new Board(gameInfo);
root.getChildren().add(board);
//start playing audio here
Media sound = new Media(getClass().getResource("/coloris/music/in_gamebgm.mp3").toString());
gamePlayer = new MediaPlayer(sound);
gamePlayer.setStopTime(Duration.seconds(176)); //magic number
gamePlayer.setCycleCount(MediaPlayer.INDEFINITE);
gamePlayer.play();
timer = new AnimationTimer() {
@Override
public void handle(long now) {
update();
}
};
timer.start();
}
public void update()
{
if (board.isGameover() == false)
board.update();
}
public static void main(String[] args)
{
launch(args);
}
}