-
Notifications
You must be signed in to change notification settings - Fork 292
/
MenuState.hx
111 lines (95 loc) · 2.8 KB
/
MenuState.hx
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
package states;
import ui.OptionsSubState;
import ui.LargeText;
import flixel.FlxG;
import flixel.FlxState;
import flixel.text.FlxBitmapText;
import flixel.text.FlxText;
import flixel.ui.FlxButton;
import flixel.util.FlxColor;
import flixel.addons.editors.ogmo.FlxOgmo3Loader;
class MenuState extends FlxState
{
override public function create()
{
// NOTE: differs from tutorial!
var map = new FlxOgmo3Loader(AssetPaths.turnBasedRPG__ogmo, AssetPaths.room_001__json);
var walls = map.loadTilemap(AssetPaths.tiles__png, "walls");
walls.x -= 123;
walls.y -= 10;
add(walls);
// Use FlxBitmapText for crisper edges on large text
var titleText = new LargeText(0, 16, "DUNGEON\nCRAWLER");
titleText.alignment = CENTER;
titleText.setBorderStyle(OUTLINE, 0xFF3f2631);
titleText.screenCenter(X);
add(titleText);
// TUTORIAL VERSION:
// var titleText = new FlxText(0, 16, 0, "DUNGEON\nCRAWLER", 32);
// titleText.alignment = CENTER;
// titleText.screenCenter(X);
// add(titleText);
var playButton = new FlxButton(0, 0, "Play", clickPlay);
playButton.loadGraphic(AssetPaths.button__png, true, 80, 20);
playButton.onUp.sound = FlxG.sound.load(AssetPaths.select__wav);
playButton.x = (FlxG.width / 2) - 10 - playButton.width;
playButton.y = FlxG.height - playButton.height - 10;
add(playButton);
var optionsButton = new FlxButton(0, 0, "Options", clickOptions);
optionsButton.loadGraphic(AssetPaths.button__png, true, 80, 20);
optionsButton.x = (FlxG.width / 2) + 10;
optionsButton.y = FlxG.height - optionsButton.height - 10;
add(optionsButton);
#if desktop
var exitButton = new FlxButton(FlxG.width - 28, 8, "X", clickExit);
exitButton.loadGraphic(AssetPaths.small_button__png, true, 20, 20);
add(exitButton);
#end
if (FlxG.sound.music == null) // don't restart the music if it's already playing
{
initSound();
}
FlxG.camera.fade(FlxColor.BLACK, 0.33, true);
super.create();
}
function initSound()
{
var volumes:{ music:Float, sound:Float } = null;
if (FlxG.save.data.volumes != null)
{
volumes = FlxG.save.data.volumes;
}
else
{
volumes = { music:0.5, sound:1.0 };
}
FlxG.sound.defaultMusicGroup.volume = volumes.music;
FlxG.sound.defaultSoundGroup.volume = volumes.sound;
#if flash
FlxG.sound.playMusic(AssetPaths.HaxeFlixel_Tutorial_Game__mp3, 1.0, true);
#else
FlxG.sound.playMusic(AssetPaths.HaxeFlixel_Tutorial_Game__ogg, 1.0, true);
#end
}
function clickPlay()
{
FlxG.camera.fade(FlxColor.BLACK, 0.33, false, function()
{
FlxG.switchState(PlayState.new);
});
}
function clickOptions()
{
openSubState(new OptionsSubState());
// FlxG.camera.fade(FlxColor.BLACK, 0.33, false, function()
// {
// FlxG.switchState(OptionsState.new);
// });
}
#if desktop
function clickExit()
{
Sys.exit(0);
}
#end
}