-
Notifications
You must be signed in to change notification settings - Fork 0
/
SceneController.java
185 lines (140 loc) · 5.95 KB
/
SceneController.java
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package application;
import application.main.Plyr;
import application.main.Stick;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.animation.AnimationTimer;
import java.io.IOException;
public class SceneController {
@FXML
private Stage stage1;
private Stage stage2;
@FXML
private static Pane easy_gamepane ;
private Stage stage_easy;
@FXML
private Stage stage_end;
// @FXML
// private ImageView plyr;
private Scene scene;
private Parent root;
public static Pane geteasy_gamepane()
{
return easy_gamepane;
}
public void switchTofirst_scrn(ActionEvent event) throws IOException
{
root = FXMLLoader.load(getClass().getResource("first_scrn.fxml"));
stage1 = (Stage)((Node)event.getSource()).getScene().getWindow();
scene = new Scene(root);
String css = this.getClass().getResource("application.css").toExternalForm();
scene.getStylesheets().add(css);
stage1.setScene(scene);
stage1.show();
}
public void switchTosecond_scrn(ActionEvent event) throws IOException
{
Parent root = FXMLLoader.load(getClass().getResource("second_scrn.fxml"));
stage2 = (Stage)((Node)event.getSource()).getScene().getWindow();
scene = new Scene(root);
stage2.setScene(scene);
stage2.show();
}
//before error :
// public void switchToeasy_gameplay(ActionEvent event) throws IOException {
// Parent root = FXMLLoader.load(getClass().getResource("easy_gameplay.fxml"));
// Scene scene = new Scene(root);
//
// easy_gamepane = (Pane) scene.lookup("#easy_gamepane");
// EasyPlatform easyPlatform = new EasyPlatform(easy_gamepane);
//
//
//
// stage_easy = (Stage)((Node)event.getSource()).getScene().getWindow();
// scene = new Scene(root);
// stage_easy.setScene(scene);
// stage_easy.show();
//
// }
public void switchToeasy_gameplay(ActionEvent event) throws IOException
{
FXMLLoader loader = new FXMLLoader(getClass().getResource("easy_gameplay.fxml"));
Pane easy_gamepane = (Pane) loader.load();
main main_obj = new main();
Stick stick = main_obj.new Stick() ; // Create the stick
//String imageUrl = getClass().getResource("player3.png").toExternalForm();
//Image playerImage = new Image(imageUrl);
Image playerImage = new Image(getClass().getResourceAsStream("player5.png"));
Plyr plyr = main_obj.new Plyr(playerImage);
EasyPlatform easyPlatform = new EasyPlatform(easy_gamepane, stick , plyr); // Initialize EasyPlatform with the stick
AnimationTimer animationTimer = new AnimationTimer() {
private long lastUpdate = 0;
@Override
public void handle(long now) {
if (now - lastUpdate >= 1000000) {
// Update player's position here
plyr.move(easyPlatform.width -30); // Assuming you have a move() method in the Plyr class
lastUpdate = now;
}
}
};
Scene scene = new Scene(easy_gamepane);
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
stage.setScene(scene);
stage.show();
animationTimer.start();
easyPlatform.start_animation();
}
public void switchTomed_gameplay(ActionEvent event) throws IOException
{
FXMLLoader loader = new FXMLLoader(getClass().getResource("med_gameplay.fxml"));
Pane med_gamepane = (Pane) loader.load();
main main_obj = new main();
Stick stick = main_obj.new Stick() ; // Create the stick
//String imageUrl = getClass().getResource("player3.png").toExternalForm();
//Image playerImage = new Image(imageUrl);
Image playerImage = new Image(getClass().getResourceAsStream("player5.png"));
Plyr plyr = main_obj.new Plyr(playerImage);
MediumPlatform medPlatform = new MediumPlatform(med_gamepane, stick , 100 , plyr); // Initialize EasyPlatform with the stick
Scene scene = new Scene(med_gamepane);
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
stage.setScene(scene);
stage.show();
medPlatform.initializeAnimationTimer();
medPlatform.setCollision(true);
//easyPlatform.initializePlatforms();
}
public void switchTohard_gameplay(ActionEvent event) throws IOException
{
FXMLLoader loader = new FXMLLoader(getClass().getResource("hard_gameplay.fxml"));
Pane hard_gamepane = (Pane) loader.load();
main main_obj = new main();
Stick stick = main_obj.new Stick() ; // Create the stick
//String imageUrl = getClass().getResource("player3.png").toExternalForm();
//Image playerImage = new Image(imageUrl);
Image playerImage = new Image(getClass().getResourceAsStream("player5.png"));
Plyr plyr = main_obj.new Plyr(playerImage);
HardPlatform hardPlatform = new HardPlatform(hard_gamepane, stick , 100 , plyr); // Initialize EasyPlatform with the stick
Scene scene = new Scene(hard_gamepane);
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
stage.setScene(scene);
stage.show();
hardPlatform.initializeAnimationTimer();
hardPlatform.setCollision(true);
//easyPlatform.initializePlatforms();
}
public void switchToEndgame(ActionEvent event) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("gameplay.fxml"));
stage_end= (Stage)((Node)event.getSource()).getScene().getWindow();
scene = new Scene(root);
stage_end.setScene(scene);
stage_end.show();
}
}