My favorites | Sign in
Project Logo
                
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package // do not copy
{ // do not copy
public class as3collab1 // do not copy
{ // do not copy

/* AS3 Code Collab! <http://www.newgrounds.com/bbs/topic/966360>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.

* A copy of the GNU General Public License is available at:
* <http://www.gnu.org/licenses/>.
*/

// === BEGIN INITIALIZATION ROUTINES ===
stage.frameRate = 30;
const CIRCLE_RADIUS_MIN:int = 25;
const CIRCLE_RADIUS_MAX:int = 50;
const CIRCLE_SPD:int = 7;
const CIRCLE_CREATION_DELAY:int = 500;
const GRAVITY:int = 5; //Gravity applied to particles ***Added by Calipe***
var particleVX:Number = 15; //Particle's max x velocity ***Added by Calipe***
var particleVY:Number = 50; //Particle's initial y velocity ***Added by Calipe***
var maxParticles:int = 10; //Max number of particles ***Added by Calipe***
var maxCircles:int = 50;
var circles:Array = new Array(); //lets make a container so we can easily access the circles?
var bgColor:int = 0x000000; //Background Color


var circleCreationTimer:Timer = new Timer(CIRCLE_CREATION_DELAY, 0);
circleCreationTimer.addEventListener(TimerEvent.TIMER, createCircleEvent, false, 10, false);
circleCreationTimer.start();

//Creates and adds the background to the display list ***Added by Calipe***

var bg:Bitmap = new Bitmap(new BitmapData(stage.stageWidth, stage.stageHeight, false, bgColor));
addChild(bg);

var textFormat:TextFormat = new TextFormat();

//Modify with the desired format ***Added by Calipe***
with (textFormat)
{
font = "Arial";
size = "12";
color = "0x0088FF";
bold = true;
}

var poppedCircles:int = 0; //Circle Counter Startup (Kajenx waz hur :3)
var poppedCirclesCounter:TextField = new TextField;
addChild(poppedCirclesCounter);
poppedCirclesCounter.x = 10;
poppedCirclesCounter.y = 10;
poppedCirclesCounter.selectable = false;
poppedCirclesCounter.text = "Popped: 0";
poppedCirclesCounter.setTextFormat(textFormat);

var mymenu:ContextMenu= new ContextMenu(); // context menu by **jaye19**
mymenu.hideBuiltInItems();
//Take that out if you dont want it to hide the default items of the right click menu
var txt:String='The AS3 Code Collab *Line By Line*';
//Change <strong>The AS3 Code Collab *Line By Line*</strong> to the text you wanna appear
var item:ContextMenuItem= new ContextMenuItem(txt);
mymenu.customItems.push(item);
this.contextMenu=mymenu;
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,item_select);
//===END INITIALIZATION ROUTINES ===

//===BEGIN EVENT HANDLERS ===
function createCircleEvent(timerEvent:TimerEvent):void
{
var newCircle:Sprite = createCircleSprite();
newCircle.x = Math.random()*(stage.stageWidth - newCircle.width);
newCircle.y = - newCircle.height;
circles.push(newCircle); //Here we add the circles to the array

newCircle.addEventListener(Event.ENTER_FRAME, onCircleEnterFrame, false, 5, true);
newCircle.addEventListener(MouseEvent.MOUSE_OVER, mouseOverListener, false, 0, true); //Registers the circle for the mouse over event ***Added by Calipe***

addChild(circles[circles.length - 1]);
swapChildren(poppedCirclesCounter, circles[circles.length -1]); //Keeps the counter on the top of the balls

}

// original content **PrettyMuchBryce** ( modified )
function onCircleEnterFrame(event:Event):void
{
var currentCircle:Sprite = event.currentTarget as Sprite;
currentCircle.y += CIRCLE_SPD;

if ((currentCircle.y - currentCircle.height) > stage.stageHeight)
{
currentCircle.removeEventListener(Event.ENTER_FRAME, onCircleEnterFrame); // EXTREMELY IMPORTANT FOR GARBAGE COLLECTION
removeChild(currentCircle);
circles.splice(circles.indexOf(currentCircle), 1);
}
}
//The event listener function that is triggered when the mouse over event is dipatched ***Added by Calipe***
function mouseOverListener(event:MouseEvent):void
{

popCircle(Sprite(event.target), mouseX, mouseY);
}

//Particles enter frame listener ***Added by Calipe***

function particleEnterFrame(event:Event):void
{


var tempParticle:MovieClip = MovieClip(event.target);
if ( tempParticle.y < stage.stageHeight)
{
checkIfParticlePopsCircle(tempParticle);

tempParticle.vy += GRAVITY;
tempParticle.x += tempParticle.vx;
tempParticle.y += tempParticle.vy;


}
else
{
removeChild(tempParticle);
tempParticle.removeEventListener(Event.ENTER_FRAME, particleEnterFrame, false);
}
}

//===END EVENT HANDLERS ===

//===BEGIN GENERAL FUNCTIONS===
function item_select(e:ContextMenuEvent):void // context menu by **jaye19**
{
var url:String='newgrounds.com';
/*Here, change newgrounds.com to the site it will lead to or <strong>url:String-'newgrounds.com'</strong> to s code that you like when you click the item*/
var site:URLRequest=new URLRequest(url);
navigateToURL(site);
}

function createCircleSprite():Sprite
{
var radius:int = CIRCLE_RADIUS_MIN + Math.random()*(CIRCLE_RADIUS_MAX - CIRCLE_RADIUS_MIN);
var tempCircle:Sprite = new Sprite();

tempCircle.graphics.lineStyle();
tempCircle.graphics.beginFill(Math.random()*0xFFFFFF);
tempCircle.graphics.drawCircle(radius, radius, radius);
tempCircle.graphics.endFill();

return tempCircle;
}
// ** Ben-Fox ** random display object getter
function getRandomSprite(sourceArray:Array = null):Sprite {
if (sourceArray == null) { //If no array reference is passed to the function...
//Choose any child on the stage to return.
return getChildAt(Math.floor(Math.random() * numChildren)) as Sprite;
} else {
//Return a reference from the specified array
return sourceArray[Math.floor(Math.random() * sourceArray.length)] as Sprite; //Just in case
}
}

// updated the circle pop, so mouse overs were not the only method for triggering them. ** deadlock32 **
function popCircle(targetCircle:DisplayObject, centerX:Number, centerY:Number):void
{
// Count popped circles
poppedCircles++;
poppedCirclesCounter.replaceText(8, poppedCirclesCounter.length, String(poppedCircles)); //Be sure to change the first argument if the initial title ever changes

removeChild(targetCircle);
circles.splice(circles.indexOf(targetCircle), 1);
targetCircle.removeEventListener(Event.ENTER_FRAME, onCircleEnterFrame);
createParticles(centerX, centerY);
}

//Creates the particles ***Added by Calipe***

function createParticles(centerX:Number, centerY:Number):void
{
for (var i:int = 0; i < maxParticles; i++)
{
var particle:MovieClip = new MovieClip();
particle.graphics.beginFill(Math.random() * 0xFFFFFF);
particle.graphics.drawCircle(0, 0, Math.random() * 10 + 5);
particle.vx = Math.random() * (particleVX*2) - (particleVX);
particle.vy = Math.random() * -particleVY;
particle.x = centerX;
particle.y = centerY;
particle.addEventListener(Event.ENTER_FRAME, particleEnterFrame, false, 0, true);
addChild(particle);
}
}

// added a function to check if a particle is touching another circle
// by deadlock32
function checkIfParticlePopsCircle(targetParticle:DisplayObject):void
{
var targetParticleRadius:Number = targetParticle.width * 0.5;
for each(var tempCircle:DisplayObject in circles)
{
var circleRadius:Number = tempCircle.width * 0.5;
var collisionDistanceMax:Number = targetParticleRadius + circleRadius;

var distanceApart:Number = Point.distance(new Point(targetParticle.x, targetParticle.y), new Point(tempCircle.x, tempCircle.y));

if(distanceApart <= collisionDistanceMax)
{
popCircle(tempCircle, tempCircle.x, tempCircle.y);
break;
}
// the above was 100%... for some reason if you wanna figure out why go for it
// I added the below to help compensate
if(tempCircle.hitTestPoint(targetParticle.x, targetParticle.y, true))
{
popCircle(tempCircle, tempCircle.x, tempCircle.y);
break;
}
}
}
// === END GENERAL FUNCTIONS ===

} // do not copy
} // do not copy
Show details Hide details

Change log

r7 by glto...@sbcglobal.net on Sep 14, 2008   Diff
context menu by jaye19 added.
Go to: 
Sign in to write a code review

Older revisions

r5 by glto...@sbcglobal.net on Sep 12, 2008   Diff
This is the start repository for
previous history please refer to this
link.
r4 by glto...@sbcglobal.net on Sep 12, 2008   Diff
This is the start repository for
previous history please refer to this
link.
All revisions of this file

File info

Size: 8594 bytes, 231 lines
Hosted by Google Code