Mobile Asteroid Game - ActionScript
This is a mobile game for android created in Adobe Flash meant to be published on Air 20.0. The objective of the game is to dodge asteroids while collecting gems to gain a higher score. Tilt your phone to move your ship while tapping your screen to shoot the asteroids, but be careful because your gun needs to cool down.
This was created in Adobe Flash, all the graphical assets made with the tools provided in the software. All the ActionScript code was written in the Actions functionality of Flash and the final product is published into an APK for android.
A video demonstrating the output and the code is shown below:
Source Code
1 //Note: This code is embeded as actions in a Flash file and is not meant to be run as actionsScript files
2 //Some code was provided by the instructor, mostly symbol definitions, this is indicated by the box comments
3
4 //initial logo, scene "gameLogo", frame 1
5 transition.addEventListener(MouseEvent.CLICK, skipTransition1);
6
7 function skipTransition1 (eventInfo) {
8 gotoAndPlay(1, "gameMenu")
9 }
10
11
12 //initial menu, scene "gameMenu", frame 1
13 transitionin.addEventListener(MouseEvent.CLICK, skipTransition2);
14
15 function skipTransition2 (eventInfo) {
16 gotoAndPlay("loop", "gameMenu")
17 }
18
19 //scene "gameMenu", frame 95 loop
20 stop();
21 playInitial.addEventListener(MouseEvent.CLICK, playGame);
22
23 function playGame (eventInfo) {
24 gotoAndPlay("transitionOut")
25 }
26
27 import flash.display.StageScaleMode;
28 import flash.display.StageAlign;
29
30 stage.addEventListener(Event.RESIZE, handleResize);
31
32 stage.scaleMode = StageScaleMode.NO_SCALE;
33 stage.align = StageAlign.TOP_LEFT;
34 handleResize(null);
35
36 function handleResize(eventInfo) {
37 if (stage.stageWidth >= 620, stage.stageHeight >= 860) {
38 logo.x = (stage.stageWidth / 2) | 0;
39 logo.y = 190;
40
41 playInitial.x = (stage.stageWidth / 2) | 0;
42 playInitial.y = (stage.stageHeight / 2) | 0;
43
44 info.x = (stage.stageWidth / 2) - 275 | 0;
45 info.y = stage.stageHeight - 360;
46
47 dark.x = (stage.stageWidth / 2) | 0;
48 dark.y = (stage.stageHeight / 2) | 0;
49 dark.width = stage.stageWidth;
50 dark.height = stage.stageHeight;
51
52 stars.x = (stage.stageWidth / 2) | 0;
53 stars.y = (stage.stageHeight / 2) | 0;
54 stars.width = stage.stageWidth;
55 stars.height = stage.stageHeight;
56
57 bg.x = (stage.stageWidth / 2) | 0;
58 bg.y = (stage.stageHeight / 2) | 0;
59 bg.width = stage.stageWidth;
60 bg.height = stage.stageHeight;
61
62 } else {
63 logo.width = ((stage.stageWidth / 16) * 15) | 0;
64 logo.height = (stage.stageHeight / 5) | 0;
65 logo.x = (stage.stageWidth / 2) | 0;
66 logo.y = (stage.stageHeight / 6) | 0;
67
68 playInitial.width = (stage.stageWidth / 3) | 0;
69 playInitial.height = (stage.stageHeight / 9) | 0;
70 playInitial.x = (stage.stageWidth / 2) | 0;
71 playInitial.y = (stage.stageHeight / 2) | 0;
72
73 info.width = ((stage.stageWidth / 16) * 14) | 0;
74 info.height = (stage.stageHeight / 3) | 0;
75 info.x = (stage.stageWidth / 2) - (info.width / 2) | 0;
76 info.y = stage.stageHeight - (info.height + (stage.stageHeight / 16));
77
78 dark.x = (stage.stageWidth / 2) | 0;
79 dark.y = (stage.stageHeight / 2) | 0;
80 dark.width = stage.stageWidth;
81 dark.height = stage.stageHeight;
82
83 stars.x = (stage.stageWidth / 2) | 0;
84 stars.y = (stage.stageHeight / 2) | 0;
85 stars.width = stage.stageWidth;
86 stars.height = stage.stageHeight;
87
88 bg.x = (stage.stageWidth / 2) | 0;
89 bg.y = (stage.stageHeight / 2) | 0;
90 bg.width = stage.stageWidth;
91 bg.height = stage.stageHeight;
92 }
93 }
94
95 //transition out of menu, scene "gameMenu" frame 96
96 transitionout.addEventListener(MouseEvent.CLICK, skipTransition3);
97
98 function skipTransition3 (eventInfo) {
99 gotoAndPlay(1, "gamePlay")
100 }
1 //scene "gamePlay" frame 1, transitiong to gameplay
2 transitionin.addEventListener(MouseEvent.CLICK, skipTransition2);
3
4 function skipTransition2 (eventInfo) {
5 gotoAndPlay("loop", "gameMenu")
6 }
7
8 //scene "gamePlay" frame 96, actual gameplay
9 import flash.sensors.Accelerometer;
10 import flash.events.AccelerometerEvent;
11 var accel:Accelerometer = new Accelerometer();
12
13 stop();
14
15 stage.addEventListener(Event.ENTER_FRAME, handleTick);
16 stage.addEventListener(MouseEvent.MOUSE_MOVE, handleMove);
17
18 stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
19 stage.addEventListener(KeyboardEvent.KEY_UP, handleKeyUp);
20 stage.addEventListener(MouseEvent.CLICK, shoot);
21
22 accel.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate);
23
24 //set a speed and acceleration
25 var maxSpeed = 17;
26 var v = 6;
27 var a = 0.1;
28 if (v >= 10){
29 v = 10
30 }
31
32 //dealing with movement
33 var mouseMove = true;
34
35 var shouldMoveLeft = false;
36 var shouldMoveRight = false;
37
38
39 // track how long we've been playing
40 var tickCount = 0;
41
42 //movement with Accelerometer
43 function onAccUpdate(e:AccelerometerEvent):void{
44 player.x -= (e.accelerationX*10);
45 }
46
47
48 function handleTick(eventInfo) {
49 tickCount++;
50
51 // lets move the player to where the mouse is
52 var distance = stage.mouseX - player.x;
53
54 // only when we're paying attention the mouse do we examine its position
55 if(mouseMove) {
56 if(distance > maxSpeed) { // if we're to the right, go right
57 shouldMoveLeft = false;
58 shouldMoveRight = true;
59 } else if(distance < -maxSpeed) { // if we're to the left, go left
60 shouldMoveRight = false;
61 shouldMoveLeft = true;
62 } else { // if we're on target, don't move
63 shouldMoveLeft = false;
64 shouldMoveRight = false;
65 }
66 }
67
68 // actually perform the movement
69 if(shouldMoveLeft) {
70 player.x -= maxSpeed;
71 }
72 if(shouldMoveRight) {
73 player.x += maxSpeed;
74 }
75
76 //lets stop the players movement from leaving the screen
77 if(player.x < 60) {
78 player.x = 60;
79 }
80 if(player.x > 580) {
81 player.x = 580;
82 }
83
84 if(tickCount%30 == 0){
85 v += a;
86 }
87
88 var i=0
89 // lets go over every falling object 1
90 for(i=0; i < spawnBox1.activeObjects.length; i++){
91 var object = spawnBox1.activeObjects[i];
92
93 // make the object fall down
94 object.y += v;
95
96
97 // if our position is lower than the screen
98 if(object.y > stage.stageHeight + 80){
99 // then remove it
100 spawnBox1.deleteObject(object);
101 stage.removeChild(object);
102 // move back now the array is smaller
103 i--;
104 }
105
106 // if the player hits the object
107 if(player.checkCollision(object)){
108 // do something
109 player.gotoAndPlay("hit");
110 object.gotoAndPlay("hit");
111 // then remove it
112 spawnBox1.deleteObject(object);
113 //ending the game
114 gameOver();
115 return;
116 }
117
118 }
119
120 // lets go over every falling object 2
121 for(i=0; i < spawnBox2.activeObjects.length; i++){
122 object = spawnBox2.activeObjects[i];
123
124
125 // make the object fall down
126 object.y += v;
127
128
129 // if our position is lower than the screen
130 if(object.y > stage.stageHeight + 80){
131 // then remove it
132 spawnBox2.deleteObject(object);
133 stage.removeChild(object);
134 // move back now the array is smaller
135 i--;
136 }
137
138 // if the player hits the object
139 if(player.checkCollision(object)){
140 // do something
141 player.gotoAndPlay("hit");
142 object.gotoAndPlay("hit");
143 // then remove it
144 spawnBox2.deleteObject(object);
145 //ending the game
146 gameOver();
147 return;
148 }
149
150 }
151
152 // lets go over every falling object 3
153 for(i=0; i < spawnBox3.activeObjects.length; i++){
154 object = spawnBox3.activeObjects[i];
155
156
157 // make the object fall down
158 object.y += v;
159
160
161 // if our position is lower than the screen
162 if(object.y > stage.stageHeight + 80){
163 // then remove it
164 spawnBox3.deleteObject(object);
165 stage.removeChild(object);
166 // move back now the array is smaller
167 i--;
168 }
169
170 // if the player hits the object
171 if(player.checkCollision(object)){
172 // do something
173 player.gotoAndPlay("hit");
174 object.gotoAndPlay("hit");
175 // then remove it
176 spawnBox3.deleteObject(object);
177 //ending the game
178 gameOver();
179 return;
180 }
181 }
182
183 // lets go over every falling object gem 1
184 for(i=0; i < spawnGem1.activeObjects.length; i++){
185 object = spawnGem1.activeObjects[i];
186
187
188 // make the object fall down
189 object.y += (v + 1);
190
191
192 // if our position is lower than the screen
193 if(object.y > stage.stageHeight + 80){
194 // then remove it
195 spawnGem1.deleteObject(object);
196 stage.removeChild(object);
197 // move back now the array is smaller
198 i--;
199 }
200
201 // if the player hits the object
202 if(player.checkCollision(object)){
203 // do something
204 count.addPoints(5);
205 object.gotoAndPlay("hit");
206 // then remove it
207 spawnGem1.deleteObject(object);
208 }
209
210 }
211
212 // lets go over every falling object gem 2
213 for(i=0; i < spawnGem2.activeObjects.length; i++){
214 object = spawnGem2.activeObjects[i];
215
216
217 // make the object fall down
218 object.y += (v + 2);
219
220
221 // if our position is lower than the screen
222 if(object.y > stage.stageHeight + 80){
223 // then remove it
224 spawnGem2.deleteObject(object);
225 stage.removeChild(object);
226 // move back now the array is smaller
227 i--;
228 }
229
230 // if the player hits the object
231 if(player.checkCollision(object)){
232 // do something
233 count.addPoints(5);
234 object.gotoAndPlay("hit");
235 // then remove it
236 spawnGem2.deleteObject(object);
237 }
238
239 }
240
241
242
243 // lets go over the shooters
244 for(i=0; i < player.spawnShoot.activeObjects.length; i++){
245 object = player.spawnShoot.activeObjects[i];
246
247
248 // make the object shoot up
249 object.y -= (20);
250
251
252 // if the bullet is higher than the screen
253 if(object.y < -80){
254 // then remove it
255 player.spawnShoot.deleteObject(object);
256 stage.removeChild(object);
257 // move back now the array is smaller
258 i--;
259 }
260
261 for(i=0; i < spawnGem2.activeObjects.length; i++){
262 var fallingObject = spawnGem2.activeObjects[i];
263 // if the bullet hits the object
264 if(object.checkCollision(fallingObject)){
265 // do something
266 fallingObject.gotoAndPlay("hit");
267 // then remove it
268 player.spawnShoot.deleteObject(object);
269 spawnBox1.deleteObject(fallingObject);
270 spawnBox2.deleteObject(fallingObject);
271 spawnBox3.deleteObject(fallingObject);
272 stage.removeChild(object);
273 }
274 }
275
276 for(i=0; i < spawnGem1.activeObjects.length; i++){
277 fallingObject = spawnGem1.activeObjects[i];
278 // if the bullet hits the object
279 if(object.checkCollision(fallingObject)){
280 // do something
281 fallingObject.gotoAndPlay("hit");
282 // then remove it
283 player.spawnShoot.deleteObject(object);
284 spawnBox1.deleteObject(fallingObject);
285 spawnBox2.deleteObject(fallingObject);
286 spawnBox3.deleteObject(fallingObject);
287 stage.removeChild(object);
288 }
289 }
290
291 for(i=0; i < spawnBox1.activeObjects.length; i++){
292 fallingObject = spawnBox1.activeObjects[i];
293 // if the bullet hits the object
294 if(object.checkCollision(fallingObject)){
295 // do something
296 fallingObject.gotoAndPlay("hit");
297 // then remove it
298 player.spawnShoot.deleteObject(object);
299 spawnBox1.deleteObject(fallingObject);
300 spawnBox2.deleteObject(fallingObject);
301 spawnBox3.deleteObject(fallingObject);
302 stage.removeChild(object);
303 }
304 }
305
306 for(i=0; i < spawnBox2.activeObjects.length; i++){
307 fallingObject = spawnBox2.activeObjects[i];
308 // if the bullet hits the object
309 if(object.checkCollision(fallingObject)){
310 // do something
311 fallingObject.gotoAndPlay("hit");
312 // then remove it
313 player.spawnShoot.deleteObject(object);
314 spawnBox1.deleteObject(fallingObject);
315 spawnBox2.deleteObject(fallingObject);
316 spawnBox3.deleteObject(fallingObject);
317 stage.removeChild(object);
318 }
319 }
320
321 for(i=0; i < spawnBox3.activeObjects.length; i++){
322 fallingObject = spawnBox3.activeObjects[i];
323 // if the bullet hits the object
324 if(object.checkCollision(fallingObject)){
325 // do something
326 fallingObject.gotoAndPlay("hit");
327 // then remove it
328 player.spawnShoot.deleteObject(object);
329 spawnBox1.deleteObject(fallingObject);
330 spawnBox2.deleteObject(fallingObject);
331 spawnBox3.deleteObject(fallingObject);
332 stage.removeChild(object);
333 }
334 }
335
336 }
337
338
339
340 // every 30 ticks lets add a point
341 if(tickCount%30 == 0){
342 count.addPoints(1);
343 }
344
345 // every 40 ticks lets add a new object for spawn box 1
346 if(tickCount%40 == 0){
347 var newObject;
348 newObject = spawnBox1.createNewObject()
349 stage.addChild(newObject);
350 }
351
352 // every 30 ticks lets add a new object for spawn box 2
353 if(tickCount%30 == 0){
354 newObject = spawnBox2.createNewObject()
355 stage.addChild(newObject);
356 }
357
358 // every 40 ticks lets add a new object for spawn box 3
359 if(tickCount%40 == 0){
360 newObject = spawnBox3.createNewObject()
361 stage.addChild(newObject);
362 }
363
364 // every 150 ticks lets add a new gem for gem 1
365 if(tickCount%150 == 0){
366 newObject = spawnGem1.createNewObject()
367 stage.addChild(newObject);
368 }
369
370 // every 250 ticks lets add a new object for spawn box 3
371 if(tickCount%250 == 0){
372 newObject = spawnGem2.createNewObject()
373 stage.addChild(newObject);
374 }
375
376
377 }
378
379 function shoot(eventInfo) {
380 var newObject;
381 newObject = player.spawnShoot.createNewObject()
382 stage.addChild(newObject);
383 }
384
385
386 //saving the score
387 import flash.net.SharedObject;
388
389 var score:SharedObject = SharedObject.getLocal("score")
390 var hiScore:SharedObject = SharedObject.getLocal("hiScore")
391
392 score.data.score = count.counterTextField.text;
393 score.flush();
394
395
396
397 // keys are almost as simple as the buttons
398 // but there's only one key listener so we need figure out which key it was
399 // it's also a good idea to turn the mouse off so it doesn't fight
400 function handleKeyDown(eventInfo) {
401 if(eventInfo.keyCode == 37){ // left
402 shouldMoveLeft = true;
403 }
404 if(eventInfo.keyCode == 39){ // right
405 shouldMoveRight = true;
406 }
407 mouseMove = false;
408 }
409 function handleKeyUp(eventInfo) {
410 if(eventInfo.keyCode == 37){ // left
411 shouldMoveLeft = false;
412 }
413 if(eventInfo.keyCode == 39){ // right
414 shouldMoveRight = false;
415 }
416 }
417
418 // the key presses could turn our mouse off with no way to turn it on
419 // so lets allow moving the mouse to turn it on so it can re-enable
420 function handleMove(eventInfo) {
421 mouseMove = true;
422 }
423
424 //cleaning up the game
425 function gameOver() {
426 stage.removeEventListener(Event.ENTER_FRAME, handleTick);
427 stage.removeEventListener(MouseEvent.MOUSE_MOVE, handleMove);
428 stage.removeEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
429 stage.removeEventListener(KeyboardEvent.KEY_UP, handleKeyUp);
430 stage.removeEventListener(MouseEvent.CLICK, shoot);
431 gotoAndPlay("transitionOver");
432 }
433
434 //scene "gamePlay" frame 97, game over
435 transitionOut.addEventListener(MouseEvent.CLICK, skipTransition5);
436
437 function skipTransition5 (eventInfo) {
438 gotoAndPlay(1, "gameOver")
439 }
440
441 for(var i=0; i < spawnBox1.activeObjects.length; i++){
442
443 var object = spawnBox1.activeObjects[i];
444
445 spawnBox1.deleteObject(object);
446 stage.removeChild(object);
447
448 i--;
449 }
450
451 for(i=0; i < spawnBox2.activeObjects.length; i++){
452
453 object = spawnBox2.activeObjects[i];
454
455 spawnBox2.deleteObject(object);
456 stage.removeChild(object);
457
458 i--;
459 }
460
461 for(i=0; i < spawnBox3.activeObjects.length; i++){
462
463 object = spawnBox3.activeObjects[i];
464
465 spawnBox3.deleteObject(object);
466 stage.removeChild(object);
467
468 i--;
469 }
470
471 for(i=0; i < spawnGem1.activeObjects.length; i++){
472
473 object = spawnGem1.activeObjects[i];
474
475 spawnGem1.deleteObject(object);
476 stage.removeChild(object);
477
478 i--;
479 }
480
481 for(i=0; i < spawnGem2.activeObjects.length; i++){
482
483 object = spawnGem2.activeObjects[i];
484
485 spawnGem2.deleteObject(object);
486 stage.removeChild(object);
487
488 i--;
489 }
490
491 for(i=0; i < player.spawnShoot.activeObjects.length; i++){
492
493 object = player.spawnShoot.activeObjects[i];
494
495 player.spawnShoot.deleteObject(object);
496 stage.removeChild(object);
497
498 i--;
499 }
500
1 //scene "gameOver" frame 99
2 stop();
3 playAgain.addEventListener(MouseEvent.CLICK, transitionToGame);
4 menu.addEventListener(MouseEvent.CLICK, transitionToMenu);
5
6 function transitionToGame (eventInfo) {
7 gotoAndPlay("transitionGame")
8 }
9
10 function transitionToMenu (eventInfo) {
11 gotoAndPlay("transitionMenu")
12 }
13
14
15 //scene "gameOver" frame 130
16 gotoAndPlay(1,"gamePlay");
17
18 //scene "gameOver" frame 161
19 gotoAndPlay(1,"gameMenu");
1 //Symbol definitions
2 //variables refer to symbol names and parameters are animated actions
3
4
5 //Instructions frame 50
6 meteor.gotoAndPlay("hit")
7 ship.gotoAndPlay("hit")
8 //Instructions frame 91
9 meteor.gotoAndPlay("rush")
10 ship.gotoAndPlay("rush")
11 //Instructions frame 230
12 gem.gotoAndPlay("hit")
13
14
15 //[Red, Green] Rush frame 1
16 gotoAndPlay("rush")
17 //[Red, Green] Rush frame 30
18 gotoAndPlay("rush")
19 //[Red, Green] Rush frame 40
20 stop()
21 this.parent.removeChild(this);
22
23
24 //Meteor Rush [1 - 6] frame 40
25 gotoAndPlay("rush")
26 //Meteor Rush [1 - 6] frame 63
27 stop();
28 this.parent.removeChild(this);
29
30
31 //Rocket ship rushing frame 1 Actions
32 import flash.display.DisplayObject;
33 import flash.geom.Rectangle;
34 import flash.display.Bitmap;
35 import flash.display.BitmapData;
36
37 /////////////////////////////////////////////////////
38 //
39 //
40 // ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING :)
41 // you won't have to change this to pass
42 //
43 //
44 /////////////////////////////////////////////////////
45 // README:
46 //
47 //
48 // When you want to find out if things overlap call "checkCollision".
49 // Pass in the object you want me to check if I hit, I will return
50 // whether the objects overlap as a true/false
51 // Should things run slowly just use hitTestObject instead, it's a
52 // built in function that will be less accurate but faster to run.
53 //
54 //
55 ////////////////////////////////////////////////////
56 function checkCollision(object:DisplayObject, simple:Boolean = false):Boolean {
57 // there's nothing to collide
58 if(!object || (object as Object).dead) { return false; }
59
60 // rule out anything that we know can't collide
61 if(hitTestObject(object)) {
62 if(simple) { return true; }
63 } else {
64 return false;
65 }
66
67 // get overlap
68 var self:Rectangle = this.getBounds(this);
69 var bounds:Rectangle = object.getBounds(this);
70
71 // set up the image to use
72 var img:BitmapData = new BitmapData(stage.stageWidth|0, stage.stageHeight|0, false);
73 var mtx:Matrix;
74
75 // draw in the first image
76 var rootOffset = root.transform.concatenatedMatrix.clone();
77 rootOffset.invert();
78
79 mtx = transform.concatenatedMatrix.clone();
80 mtx.concat(rootOffset);
81 img.draw(this, mtx, new ColorTransform(1,1,1,1, 255,-255,-255, 255));
82
83 mtx = object.transform.concatenatedMatrix.clone();
84 mtx.concat(rootOffset);
85 img.draw(object, mtx, new ColorTransform(1,1,1,1, 255,255,255, 255), "difference");
86
87 // find the intersection
88 var intersection:Rectangle = img.getColorBoundsRect(0xFFFFFFFF, 0xFF00FFFF);
89
90 // if there is no intersection, return false
91 return intersection.width != 0;
92 }
93 //Rocket ship rushing frame 55 Actions
94 stop();
95 this.parent.removeChild(this);
96 //Rocket ship rushing frame 1 Labels
97 gotoAndPlay("rush")
98 //Rocket ship rushing frame 55 Labels
99 stop()
100
101
102 //Shooter frame 1
103 import flash.display.DisplayObject;
104
105 /////////////////////////////////////////////////////////////////
106 // README:
107 //
108 // All the objects you add to this movie clip will be made into a "list" of objects, using the
109 // provided function you can ask for one and I will manage creating one of them at random for you.
110 //
111 // YOU MUST "EXPORT FOR ACTIONSCRIPT" THE SMYBOL AS WE USE IT IN CODE OTHERWISE THINGS WONT WORK
112 //
113 // You can add the same thing twice, but that just means it will be twice as likely to show up
114 // I've hidden all the code you don't need to see or care about on srcBox so look there or don't. :)
115 //
116 /////////////////////////////////////////////////////////////////
117
118 var activeObjects = [bullet]; // I'm an array of all the objects that have been made, loop over me with a "for loop" to do things to all my objects
119
120 // call this function when you want to make a new random object ( you'll need to *add* me to the display tree as a *child* )
121 function createNewObject():DisplayObject {
122 return srcBox.createNewObject();
123 }
124
125 // call this function when you want to remove an object from your "active" objects ( don't forget to remove me from the display! )
126 function deleteObject(object) {
127 srcBox.deleteObject(object);
128 }
129
130
131 //Bullet Frame 1
132 import flash.display.DisplayObject;
133 import flash.geom.Rectangle;
134 import flash.display.Bitmap;
135 import flash.display.BitmapData;
136
137 stop();
138 /////////////////////////////////////////////////////
139 //
140 //
141 // ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING :)
142 // you won't have to change this to pass
143 //
144 //
145 /////////////////////////////////////////////////////
146 // README:
147 //
148 //
149 // When you want to find out if things overlap call "checkCollision".
150 // Pass in the object you want me to check if I hit, I will return
151 // whether the objects overlap as a true/false
152 // Should things run slowly just use hitTestObject instead, it's a
153 // built in function that will be less accurate but faster to run.
154 //
155 //
156 ////////////////////////////////////////////////////
157 function checkCollision(object:DisplayObject, simple:Boolean = false):Boolean {
158 // there's nothing to collide
159 if(!object || (object as Object).dead) { return false; }
160
161 // rule out anything that we know can't collide
162 if(hitTestObject(object)) {
163 if(simple) { return true; }
164 } else {
165 return false;
166 }
167
168 // get overlap
169 var self:Rectangle = this.getBounds(this);
170 var bounds:Rectangle = object.getBounds(this);
171
172 // set up the image to use
173 var img:BitmapData = new BitmapData(stage.stageWidth|0, stage.stageHeight|0, false);
174 var mtx:Matrix;
175
176 // draw in the first image
177 var rootOffset = root.transform.concatenatedMatrix.clone();
178 rootOffset.invert();
179
180 mtx = transform.concatenatedMatrix.clone();
181 mtx.concat(rootOffset);
182 img.draw(this, mtx, new ColorTransform(1,1,1,1, 255,-255,-255, 255));
183
184 mtx = object.transform.concatenatedMatrix.clone();
185 mtx.concat(rootOffset);
186 img.draw(object, mtx, new ColorTransform(1,1,1,1, 255,255,255, 255), "difference");
187
188 // find the intersection
189 var intersection:Rectangle = img.getColorBoundsRect(0xFFFFFFFF, 0xFF00FFFF);
190
191 // if there is no intersection, return false
192 return intersection.width != 0;
193 }
194 //Bullet Frame 2
195 stop();
196
197 //srcBox shooter frame 1
198 /////////////////////////////////////////////////////
199 //
200 //
201 // ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING :)
202 // you won't have to change this to pass
203 //
204 //
205 /////////////////////////////////////////////////////
206 import flash.display.DisplayObject;
207 import flash.geom.Point;
208
209 // keep an easy reference to my parent as that's where the other clips are
210 var target:MovieClip = this.parent as MovieClip;
211
212 // create a place to store all the data sources I have
213 var sources:Array = [];
214 target.activeObjects = new Vector.<DisplayObject>();
215
216 // while it has children
217 while(target.numChildren){
218 // remove them
219 var o = target.removeChildAt(0);
220
221 // if they're me, I don't want to store them
222 if(this === o){ continue; }
223
224 // otherwise add what type of thing it is (constructor) to the list of things I can make (push)
225 sources.push({
226 trns: o.alpha,
227 ctor: o.constructor,
228 mtx: o.transform.matrix
229 });
230 }
231
232 // add myself back to the stage, and hide myself
233 target.addChild(this);
234 visible = false;
235
236 // store this off for easy math
237 var itemCount = sources.length;
238
239 // allow an easy way to make a new source inside the hitbox
240 function createNewObject():DisplayObject {
241 // nothing to make!
242 if(itemCount == 0){ return null; }
243
244 // get the info randomly from the list
245 var randIndex = Math.floor(Math.random() * itemCount);
246 var srcData = sources[randIndex];
247
248 // make a new object and its properties
249 var newObj = new srcData.ctor();
250 newObj.transform.matrix = srcData.mtx;
251 newObj.alpha = srcData.trns;
252
253 // get a random position
254 var position:Point = new Point(
255 width * Math.random(),
256 height * Math.random()
257 );
258
259 // get the starting position
260 var origin = localToGlobal(new Point(0,0));
261
262 // use the point's position information
263 newObj.x = position.x + origin.x;
264 newObj.y = position.y + origin.y;
265
266 // add to active list
267 target.activeObjects.push(newObj);
268
269 // send the new object back
270 return newObj;
271 }
272
273 // allow an easy way to get rid of things
274 function deleteObject(oldObj:DisplayObject) {
275 // do nothing if there isn't anything to do something with
276 if(!oldObj) { return; }
277 (oldObj as Object).dead = true;
278
279 // find where what we want to remove is
280 var pos = target.activeObjects.indexOf(oldObj);
281
282 // remove only it
283 target.activeObjects.splice(pos, 1);
284 }
285
286
287 //Spawn Box frame 1
288 import flash.display.DisplayObject;
289
290 /////////////////////////////////////////////////////////////////
291 // README:
292 //
293 // All the objects you add to this movie clip will be made into a "list" of objects, using the
294 // provided function you can ask for one and I will manage creating one of them at random for you.
295 //
296 // YOU MUST "EXPORT FOR ACTIONSCRIPT" THE SMYBOL AS WE USE IT IN CODE OTHERWISE THINGS WONT WORK
297 //
298 // You can add the same thing twice, but that just means it will be twice as likely to show up
299 // I've hidden all the code you don't need to see or care about on srcBox so look there or don't. :)
300 //
301 /////////////////////////////////////////////////////////////////
302
303 var activeObjects = [rock1, rock2, rock3, rock4, rock5, rock6]; // I'm an array of all the objects that have been made, loop over me with a "for loop" to do things to all my objects
304
305 // call this function when you want to make a new random object ( you'll need to *add* me to the display tree as a *child* )
306 function createNewObject():DisplayObject {
307 return srcBox.createNewObject();
308 }
309
310 // call this function when you want to remove an object from your "active" objects ( don't forget to remove me from the display! )
311 function deleteObject(object) {
312 srcBox.deleteObject(object);
313 }
314
315 //srcBox frame 1
316 /////////////////////////////////////////////////////
317 //
318 //
319 // ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING :)
320 // you won't have to change this to pass
321 //
322 //
323 /////////////////////////////////////////////////////
324 import flash.display.DisplayObject;
325 import flash.geom.Point;
326
327 // keep an easy reference to my parent as that's where the other clips are
328 var target:MovieClip = this.parent as MovieClip;
329
330 // create a place to store all the data sources I have
331 var sources:Array = [];
332 target.activeObjects = new Vector.<DisplayObject>();
333
334 // while it has children
335 while(target.numChildren){
336 // remove them
337 var o = target.removeChildAt(0);
338
339 // if they're me, I don't want to store them
340 if(this === o){ continue; }
341
342 // otherwise add what type of thing it is (constructor) to the list of things I can make (push)
343 sources.push({
344 trns: o.alpha,
345 ctor: o.constructor,
346 mtx: o.transform.matrix
347 });
348 }
349
350 // add myself back to the stage, and hide myself
351 target.addChild(this);
352 visible = false;
353
354 // store this off for easy math
355 var itemCount = sources.length;
356
357 // allow an easy way to make a new source inside the hitbox
358 function createNewObject():DisplayObject {
359 // nothing to make!
360 if(itemCount == 0){ return null; }
361
362 // get the info randomly from the list
363 var randIndex = Math.floor(Math.random() * itemCount);
364 var srcData = sources[randIndex];
365
366 // make a new object and its properties
367 var newObj = new srcData.ctor();
368 newObj.transform.matrix = srcData.mtx;
369 newObj.alpha = srcData.trns;
370
371 // get a random position
372 var position:Point = new Point(
373 width * Math.random(),
374 height * Math.random()
375 );
376
377 // get the starting position
378 var origin = localToGlobal(new Point(0,0));
379
380 // use the point's position information
381 newObj.x = position.x + origin.x;
382 newObj.y = position.y + origin.y;
383
384 // add to active list
385 target.activeObjects.push(newObj);
386
387 // send the new object back
388 return newObj;
389 }
390
391 // allow an easy way to get rid of things
392 function deleteObject(oldObj:DisplayObject) {
393 // do nothing if there isn't anything to do something with
394 if(!oldObj) { return; }
395 (oldObj as Object).dead = true;
396
397 // find where what we want to remove is
398 var pos = target.activeObjects.indexOf(oldObj);
399
400 // remove only it
401 target.activeObjects.splice(pos, 1);
402 }
403
404
405 //SpawnBox Gem[1,2] Frame 1
406 import flash.display.DisplayObject;
407
408 /////////////////////////////////////////////////////////////////
409 // README:
410 //
411 // All the objects you add to this movie clip will be made into a "list" of objects, using the
412 // provided function you can ask for one and I will manage creating one of them at random for you.
413 //
414 // YOU MUST "EXPORT FOR ACTIONSCRIPT" THE SMYBOL AS WE USE IT IN CODE OTHERWISE THINGS WONT WORK
415 //
416 // You can add the same thing twice, but that just means it will be twice as likely to show up
417 // I've hidden all the code you don't need to see or care about on srcBox so look there or don't. :)
418 //
419 /////////////////////////////////////////////////////////////////
420
421 var activeObjects = [gem1]; // I'm an array of all the objects that have been made, loop over me with a "for loop" to do things to all my objects
422
423 // call this function when you want to make a new random object ( you'll need to *add* me to the display tree as a *child* )
424 function createNewObject():DisplayObject {
425 return srcBox.createNewObject();
426 }
427
428 // call this function when you want to remove an object from your "active" objects ( don't forget to remove me from the display! )
429 function deleteObject(object) {
430 srcBox.deleteObject(object);
431 }
432
433
434 //Score frame 1
435 import fl.motion.easing.Sine;
436 import fl.transitions.Tween;
437 import fl.transitions.TweenEvent;
438 import flash.events.Event;
439
440 /////////////////////////////////////////////////////
441 // README:
442 //
443 //
444 // Call "addPoints" or "subPoints" to add or
445 // subtract points respectively.
446 // Feel free to adjust the max/min or the booleans
447 // they'll change the display to your liking
448 //
449 ////////////////////////////////////////////////////
450
451 var maxPoints:Number = Number.MAX_VALUE;
452 var minPoints:Number = 0;
453 var currentPoints:Number = 0;
454
455 var commaSeperator:Boolean = true;
456 var forceInteger:Boolean = true;
457 var animation:Boolean = true;
458
459 /////////////////////////////////////////////////////
460 //
461 //
462 // ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING :)
463 // you won't have to change this to pass
464 //
465 //
466 /////////////////////////////////////////////////////
467 var currentTween:Tween;
468 var _showPoints:Number = currentPoints;
469 updatePoints(currentPoints); // init everything
470
471 // add points
472 function addPoints(count:Number) {
473 // get rid of any decimals
474 if(forceInteger){ count = count|0; }
475
476 // see which number we should update with
477 if(currentPoints + count < maxPoints){
478 return updatePoints(currentPoints + count);
479 } else {
480 return updatePoints(maxPoints);
481 }
482 }
483
484 // subtract points
485 function subPoints(count:Number) {
486 // get rid of any decimals
487 if(forceInteger){ count = count|0; }
488
489 // see which number we should update with
490 if(currentPoints - count > minPoints){
491 return updatePoints(currentPoints - count);
492 } else {
493 return updatePoints(minPoints);
494 }
495 }
496
497 // shared funciton to actually show the value
498 function updatePoints(count:Number) {
499 // update the value
500 currentPoints = count;
501
502 // how long to take to aniamte the number up
503 var time:Number = animation ? 0.64 : 0.01;
504
505 // show the update
506 if(currentTween){ currentTween.stop(); }
507 currentTween = new Tween(this, "_showPoints", Sine.easeOut, _showPoints, currentPoints, time, true);
508 currentTween.addEventListener(TweenEvent.MOTION_CHANGE, _handlePointDelta, false, 0, true);
509
510 // just be helpfull and give the new value
511 return currentPoints;
512 }
513
514 // seperate function for animations sake
515 function _handlePointDelta(count:Number) {
516 // what's the text we're showing
517 var src:String = forceInteger ? (_showPoints|0).toString() : _showPoints.toFixed(2);
518
519 // setup some numbers
520 var string:String = "", remainder:Number;
521 var i:Number = 0, l:Number = src.length;
522
523 // got across the entire string
524 while(i < l) {
525 if(i){
526 // do we need a comma?
527 if(commaSeperator && src.substr(i, 1) != "."){
528 string += ",";
529 }
530 // if it not the first loop then we know we're dealing with blocks of 3
531 remainder = 3;
532 } else {
533 // if it's the first block
534 remainder = (l%3) || 3;
535
536 // handle negative comma seperators
537 if(remainder == 1 && src.substr(0, 1) == "-"){
538 remainder = 4;
539 }
540 }
541
542 // keep building the string
543 string += src.substr(i, remainder);
544
545 // move forward the number of characters we've pulled out
546 i += remainder;
547 }
548
549 // show it
550 counterTextField.text = string;
551 }
552
553 //End Rocket Frame 760
554 gotoAndPlay(1);