-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTitleScreen.java
executable file
·90 lines (77 loc) · 2.31 KB
/
TitleScreen.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
import greenfoot.*;
/**
* Title Screen for the game
* Players can create a new game
* Or load their previous game if they have a save file
*
* @author Jimmy
* @version June 13 2024
*/
public class TitleScreen extends World {
private static final GreenfootSound bgm = new GreenfootSound("bgm.mp3");
private final Button startNew = new Button();
private final Button loadGame = new Button();
/**
* Constructor for objects of class TitleScreen.
*/
public TitleScreen() {
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1280, 720, 1);
// Background
setBackground("WorldBackground.jpg");
// Title
Font font = new Font("Arial", 64);
SuperDisplayLabel titleLabel = new SuperDisplayLabel(Color.WHITE, Color.BLACK, font);
addObject(titleLabel, 600, 200);
GreenfootImage titleImage = new GreenfootImage("ArcaneOdysseyLogo.png");
titleLabel.setImage(titleImage);
titleLabel.setLocation(640, 150);
// Start Button
GreenfootImage startImage = new GreenfootImage("startNewImage.png");
startNew.setImage(startImage);
addObject(startNew, 640, 300);
// Load Button
GreenfootImage loadImage = new GreenfootImage("loadGameImage.png");
loadGame.setImage(loadImage);
addObject(loadGame, 640, 450);
// Background Music
bgm.setVolume(30);
}
/**
* Method to stop background music from any world
*/
public static void stopBGM() {
bgm.pause();
}
/**
* Method to play background music from any world
*/
public static void playBGM() {
bgm.playLoop();
}
public void act() {
checkPressed();
}
public void checkPressed() {
if (Greenfoot.mouseClicked(startNew)) {
Level0 world = new Level0();
Greenfoot.setWorld(world);
}
if (Greenfoot.mouseClicked(loadGame)) {
LoadSettings world = new LoadSettings();
Greenfoot.setWorld(world);
}
}
/**
* Play background music if world has started
*/
public void started() {
bgm.playLoop();
}
/**
* Pause background music if world has stopped
*/
public void stopped() {
bgm.pause();
}
}