forked from RyoleBg/PE-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharSelectState.hx
107 lines (100 loc) · 3.67 KB
/
CharSelectState.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
package;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.tweens.FlxTween;
import flixel.text.FlxText;
import flixel.util.FlxTimer;
import flixel.util.FlxColor;
import flixel.effects.FlxFlicker;
import flixel.group.FlxGroup.FlxTypedGroup;
class CharSelectState extends MusicBeatState{
var charsArray:Array<String> = ['BOYFRIEND', 'BF-CAR'];
var leBG:FlxSprite;
var bf:FlxSprite;
var bfcar:FlxSprite;
var selectedText:FlxText;
var charSelect:FlxSprite;
public static var curSelected:Int = 0;
override function create(){
FlxG.sound.playMusic(Paths.music('tea-time'));
leBG = new FlxSprite().loadGraphic(Paths.image('menuBG'));
leBG.color = FlxColor.BLUE;
leBG.screenCenter();
add(leBG);
bf = new FlxSprite(450, 300).loadGraphic(Paths.image('characters/BOYFRIEND'));
bf.frames = Paths.getSparrowAtlas('characters/BOYFRIEND');
bf.animation.addByPrefix('idle', 'BF idle dance', 24, true);
bf.animation.addByPrefix('hey', 'BF HEY!!', 24, true);
bf.animation.play('idle');
add(bf);
bfcar = new FlxSprite(450, 300).loadGraphic(Paths.image('characters/bfCar'));
bfcar.frames = Paths.getSparrowAtlas('characters/bfCar');
bfcar.animation.addByPrefix('idle', 'BF idle dance', 24, true);
bfcar.animation.addByPrefix('hey', 'BF HEY!!', 24, true);
bfcar.animation.addByPrefix('singUP', 'BF NOTE UP', 24, true);
bfcar.animation.play('idle');
add(bfcar);
selectedText = new FlxText(0, 10, charsArray[0], 24);
selectedText.alpha = 0.5;
selectedText.x = (FlxG.width) - (selectedText.width) - 25;
add(selectedText);
charSelect = new Alphabet(0, 50, "Select Your Character", true, false);
charSelect.offset.x -= 150;
add(charSelect);
changeSelection();
super.create();
}
function changeSelection(change:Int = 0){
curSelected += change;
if (curSelected < 0)
curSelected = charsArray.length - 1;
if (curSelected >= charsArray.length)
curSelected = 0;
selectedText.text = charsArray[curSelected];
switch(curSelected){
case 0:
bf.visible = true;
bfcar.visible = false;
FlxTween.color(leBG, 2, leBG.color, FlxColor.BLUE, {onComplete:function(twn:FlxTween){
FlxTween.cancelTweensOf(leBG);
}});
case 1:
bf.visible = false;
bfcar.visible = true;
FlxTween.color(leBG, 2, leBG.color, FlxColor.RED, {onComplete:function(twn:FlxTween){
FlxTween.cancelTweensOf(leBG);
}});
}
}
override function update(elapsed:Float){
if (controls.UI_LEFT_P){
changeSelection(-1);
FlxG.sound.play(Paths.sound('scrollMenu'));
}
if (controls.UI_RIGHT_P){
changeSelection(1);
FlxG.sound.play(Paths.sound('scrollMenu'));
}
if (controls.ACCEPT){
FlxG.sound.play(Paths.sound('confirmMenu'));
switch(curSelected){
case 1:
FlxFlicker.flicker(bfcar, 1.5, 0.15, false);
bfcar.animation.play('singUP');
case 0:
FlxFlicker.flicker(bf, 1.5, 0.15, false);
bf.animation.play('hey');
}
new FlxTimer().start(1.5, function(tmr:FlxTimer)
{
MusicBeatState.switchState(new PlayState());
});
}
if (controls.BACK){
FlxG.sound.play(Paths.sound('cancelMenu'));
MusicBeatState.switchState(new FreeplayState());
}
super.update(elapsed);
}
}