-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainMenu.as
194 lines (132 loc) · 4.33 KB
/
MainMenu.as
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package
{
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import com.lorentz.processing.*;
import com.lorentz.SVG.display.*;
import com.lorentz.SVG.events.*;
import com.greensock.*;
public class MainMenu extends Screen
{
private var demoGame: Game;
namespace svg = "http://www.w3.org/2000/svg";
[Embed(source="images/continents.svg", mimeType="application/octet-stream")]
public static const CONTINENTS:Class;
public var loading:MyTextField;
public var earth:Sprite;
public static var instance:MainMenu;
public function MainMenu ()
{
instance = this;
demoGame = new Game(true);
demoGame.alpha = 0.5;
addChild(demoGame);
addChild(new MyTextField(320, 30, "Pongtinental", "center", 104));
//addChild(new MyTextField(320, 300, "Press any key to begin", "center", 27));
initContinents();
}
public function addButtons ():void
{
var playButton: Button = new Button("Single player", 56);
playButton.x = 320 - playButton.width / 2;
playButton.y = 200;
playButton.addEventListener(MouseEvent.CLICK, function (param:*=null):void {
Settings.player1Controller = "AI";
Main.screen = new Game(false);
});
addChild(playButton);
var play2Button: Button = new Button("Multiplayer", 56);
play2Button.x = 320 - play2Button.width / 2;
play2Button.y = 300;
play2Button.addEventListener(MouseEvent.CLICK, function (param:*=null):void {
Settings.player1Controller = "Keyboard";
Main.screen = new Game(false);
});
addChild(play2Button);
var settingsButton: Button = new Button("Settings", 56);
settingsButton.x = 320 - settingsButton.width / 2;
settingsButton.y = 275;
settingsButton.addEventListener(MouseEvent.CLICK, function (param:*=null):void {Main.screen = new SettingsMenu();});
//addChild(settingsButton);
}
public function initContinents (): void
{
if (Main.continents) return;
Audio.init(Main.instance);
Main.continents = {};
Main.continentNames = [];
Main.continentsSmall = {};
ProcessExecutor.instance.initialize(Main.instance.stage);
earth = new Sprite;
earth.y = 200;
addChild(earth);
addChild(loading = new MyTextField(320, 420, "Loading...", "center", 32));
initNextContinent(earth);
}
public function initNextContinent (earth:Sprite): void
{
use namespace svg;
var xml:XML = getXML(CONTINENTS);
var id:String;
var bitmap:BitmapData;
for each (var continent:XML in xml.g) {
if (Main.continents[continent.@id] || id) {
continent.@style += "; display:none;";
} else {
id = continent.@id;
Main.continentNames.push(id);
Main.continents[id] = bitmap = new BitmapData(640, 480, true, 0x0);
}
}
if (! id) {
// Done loading!
loading.parent.removeChild(loading);
TweenLite.to(earth, 1.0, {alpha: 0.5});
addButtons();
return;
}
function complete ():void
{
bitmap.draw(svg);
var scale:Number = 5;
var small:BitmapData = new BitmapData(640/scale, 480/scale, true, 0x0);
svg.scaleX = svg.scaleY = 1.0 / scale;
small.draw(svg, svg.transform.matrix);
Main.continentsSmall[id] = small;
var image:Bitmap = new Bitmap(bitmap);
earth.addChild(image);
earth.removeChild(svg);
demoGame._collisionList.addItem(image);
initNextContinent(earth);
}
var svg:SVGDocument = new SVGDocument();
svg.parse(xml);
earth.addChild(svg);
svg.addEventListener(SVGEvent.RENDERED, complete);
}
/**
* Loads the file as an XML object.
* @param file The embedded file to load.
* @return An XML object representing the file.
*/
public static function getXML(file:Class):XML
{
var bytes:ByteArray = new file;
return XML(bytes.readUTFBytes(bytes.length));
}
public override function init (): void
{
//stage.addEventListener(KeyboardEvent.KEY_DOWN, startGamekeyDownListener, false, 0, true);
}
public override function update (): void
{
demoGame.update();
}
private function startGamekeyDownListener (ev: KeyboardEvent): void
{
stage.removeEventListener(KeyboardEvent.KEY_DOWN, startGamekeyDownListener);
Main.screen = new SettingsMenu();//Game(false);
}
}
}