PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 0ms

/src/MenuState.as

http://github.com/schonstal/shadowmonk
ActionScript | 89 lines | 74 code | 15 blank | 0 comment | 16 complexity | 0d4870c6d7eb2a19766d7cdfef5ec7dc MD5 | raw file
 1package
 2{
 3	import org.flixel.*;
 4
 5	public class MenuState extends FlxState
 6	{
 7        private var f:Boolean = true;
 8        
 9        private var items:Array;
10        private var _current:Number = 1;
11        private var _t:FlxText;
12        private var _selected:Boolean = false;
13
14        private var _light:Number = 0xfff6e5fa;
15        private var _dark:Number = 0xff682777;
16
17		public function MenuState()
18		{
19            items = new Array();
20
21            var m:Title;
22            m = new Title();
23            add(m);
24            FlxG.level = 1;
25			
26			var t:FlxText;
27			t = new FlxText(0,0,200,"Version: 0.4-ALPHA");
28			t.alignment = "left";
29			add(t);
30
31            addItem(1, "Start Game");
32            addItem(2, "Credits");
33            SoundBank.music("menu");
34		}
35
36        override public function update():void
37		{
38			super.update();
39
40            if(!_selected) {
41                if(FlxG.keys.justPressed("UP")) {
42                    SoundBank.play("up");
43                    if(_current > 1) {
44                        moveCursor(_current - 1);
45                    } else {
46                        moveCursor(items.length);
47                    }
48                } else if(FlxG.keys.justPressed("DOWN")) {
49                    SoundBank.play("down");
50                    if(_current < items.length) {
51                        moveCursor(_current + 1);
52                    } else {
53                        moveCursor(1);
54                    }
55                } else if(FlxG.keys.justPressed("X") || FlxG.keys.justPressed("ENTER")) {
56                    _selected = true;
57                    SoundBank.play("select");
58                    FlxG.music.fadeOut(0.5);
59
60                    if(_current == 1)
61                        Starter.levelSelect();
62                    else if(_current == 2)
63                        FlxG.fade.start(0xff000000,0.5,function():void { FlxG.state = new Credits() });
64                }
65            }
66            
67		}
68        
69        private function addItem(item:Number, title:String):void {
70			var t:FlxText;
71			t = new FlxText(92,80+(item*12),200, title);
72			t.alignment = "right";
73            t.setFormat("SNES");
74            t.color = (_current==item?_light:_dark);
75            items[item-1] = t;
76			add(t);
77        }
78        
79        private function moveCursor(newItem:int):void {
80            var selected:FlxText = items[_current-1] as FlxText;
81            selected.color = _dark;
82            
83            _current = newItem;
84
85            selected = items[_current-1] as FlxText;
86            selected.color = _light;
87        }
88	}
89}