1- package starcore .menus ;
1+ package starcore .menus . main ;
22
3- import flixel .FlxG ;
4- import flixel .FlxSprite ;
5- import flixel .addons .transition .FlxTransitionableState ;
6- import flixel .group .FlxGroup .FlxTypedGroup ;
7- import flixel .text .FlxText ;
3+ import flixel .group .FlxSpriteGroup ;
84import flixel .util .FlxColor ;
95import flixel .util .FlxSpriteUtil ;
10- import flixel .util .FlxTimer ;
116import starcore .backend .Controls ;
127import starcore .backend .util .PathUtil ;
13- import starcore .backend .util .WorldUtil ;
14- import starcore .background .BackgroundPlanet ;
15- import starcore .background .BackgroundStar ;
16- import starcore .play .PlayState ;
8+ import starcore .graphics .states .MenuDisplay ;
179import starcore .ui .UIClickableSprite ;
1810
1911/**
20- * State that represents the main menu of the game.
21- * This is where the player can start a new game, load a game, or quit the game.
12+ * The menu for displaying the title of the game.
2213 */
23- class MainMenuState extends FlxTransitionableState
14+ class TitleMenuDisplay extends MenuDisplay
2415{
2516 var logo : FlxText ;
2617
2718 var buttons : Array <String > = [' play' , ' quit' ];
28- var buttonsGroup : FlxTypedGroup < FlxSprite > ;
19+ var buttonsGroup : FlxSpriteGroup ;
2920 var buttonClickFunctions : Map <String , Void -> Void >;
3021 var buttonWasClicked : Bool = false ;
3122
32- var stars : FlxTypedGroup <BackgroundStar >;
33- var planets : FlxTypedGroup <BackgroundPlanet >;
34- var starChangeAlphaTimer : FlxTimer ;
35-
36- override function create (): Void
23+ override function update (elapsed : Float ): Void
3724 {
38- super .create ();
39-
40- // Play menu music
41- StarcoreG .playMenuMusic ();
42-
43- // Add the planets in the background
44- planets = WorldUtil .generatePlanets ();
45- add (planets );
25+ super .update (elapsed );
4626
47- // Add the stars in the background
48- stars = WorldUtil .generateStars ();
49- add (stars );
27+ if (Controls .getBinds ().UI_BACK_JUST_PRESSED )
28+ {
29+ StarcoreG .closeGame ();
30+ }
31+ }
5032
51- // Setup the logo
33+ function create (): Void
34+ {
35+ // Setup the logo that says "STARCORE".
36+ // TODO: Replace with a better logo.
5237 logo = new FlxText ();
5338 logo .text = ' STARCORE' ;
5439 logo .size = 165 ;
@@ -58,14 +43,14 @@ class MainMenuState extends FlxTransitionableState
5843 logo .setPosition ((FlxG .width / 2 ) - (logo .width / 2 ), 0 );
5944 add (logo );
6045
61- // Setup the main menu buttons
62- buttonsGroup = new FlxTypedGroup < FlxSprite > ();
46+ // Setup the main menu buttons.
47+ buttonsGroup = new FlxSpriteGroup ();
6348 add (buttonsGroup );
6449
6550 buttonClickFunctions = [
6651 ' play' => () ->
6752 {
68- FlxG . switchState (() -> new PlayState ( ));
53+ parentState . switchMenu ( new SavesMenuDisplay ( parentState ));
6954 },
7055 ' quit' => () ->
7156 {
@@ -80,12 +65,7 @@ class MainMenuState extends FlxTransitionableState
8065 coolSwaggerButton .loadGraphic (PathUtil .ofSharedImage (' menus/main/ $btn -button' ));
8166 coolSwaggerButton .scale .set (4 , 4 );
8267 coolSwaggerButton .updateHitbox ();
83- coolSwaggerButton .behavior .updateHoverBounds (
84- coolSwaggerButton .x ,
85- coolSwaggerButton .y ,
86- coolSwaggerButton .width ,
87- coolSwaggerButton .height
88- );
68+ coolSwaggerButton .behavior .updateHoverBounds (coolSwaggerButton .x , coolSwaggerButton .y , coolSwaggerButton .width , coolSwaggerButton .height );
8969 coolSwaggerButton .setPosition (0 , newY );
9070 coolSwaggerButton .behavior .onClick = buttonClickFunctions .get (btn );
9171 coolSwaggerButton .behavior .onHover = () ->
@@ -105,13 +85,5 @@ class MainMenuState extends FlxTransitionableState
10585 }
10686 }
10787
108- override function update (elapsed : Float ): Void
109- {
110- super .update (elapsed );
111-
112- if (Controls .getBinds ().UI_BACK_JUST_PRESSED )
113- {
114- StarcoreG .closeGame ();
115- }
116- }
88+ function close (): Void {}
11789}
0 commit comments