Bantumi coders!

Started by Iam Montoya
Code Breakdown: Part I

  1. establish four or five colors for the stones.
    Suggestion: We could also use four or five nice graphics, instead of just changing RGB for a circle. How would we use the graphics instead of just vector circles? How would the code change? (Meaning, we wont be able to just attachMovie at that point, or we would have to attach it four or five times.)

  2. Once all 48 seeds are loaded and on screen, they need to be distributed to the 12 wells. How should we do that? Should we just put them there automatically? Should we show animation of stones going over there one by one?

  3. Every well needs to show a number that displays how many stones are in each well.
    1-2, Ok, but I think that the real problem is not distributing the stones, but it’s placing them aroung the board when the user has decided to play.

3 is easy.

  1. AI :trout:

I started with step 1 of phase I.

[AS]

//establish colors to be used and put then in the array "colors"
colors=[“FF0000”,“00CCFF”,“0000FF”,“FF9900”];
//bring the seeds into the movie and assign the seeds a random color
for(i=0;i<48;i++){ //we’re gonna do this 48 times, starting at 0 through 48.
randomcolor=Math.floor(math.Random()*4); //choose a random number each time
this.attachMovie(“seed”,“seed”+i,i); //attach a new instance and give it a new name
colorassigned=(colors[randomcolor]); //use random number from “randomcolor” to pick value from the “colors” array.
colorassigned=“0x”+colorassigned; //add “0x” in front of it, so we can use the string as a full hex number in setRGB() below;
mycolor=new Color(“seed”+i); //create a new color object for each seed created in the loop
mycolor.setRGB(colorassigned); //set the color of each object

}

[/AS]

btw, I know you guys know how to do this. Im commenting the code, because I figure we will use this later to demonstrate to the rest of the users how we completed the project. Heck, we should probably submit it to a magazine when we’re done. (Computer Arts is my choice, or Kirupa…the Magazine).

Change the code at will, but please post any new changes.

That covers step1. Change it at will.

Pom, you got step 2?

Should we attach an updated FLA every time?

I don’t have Flash at the moment, but we could discuss HOW we’re going to do step 2 and 2bis :slight_smile:

*Originally posted by Iammontoya *
**I started with step 1 of phase I.

[AS]

//establish colors to be used and put then in the array "colors"
colors=[“FF0000”,“00CCFF”,“0000FF”,“FF9900”];
//bring the seeds into the movie and assign the seeds a random color
for(i=0;i<48;i++){ //we’re gonna do this 48 times, starting at 0 through 48.
randomcolor=Math.floor(math.Random()*4); //choose a random number each time
this.attachMovie(“seed”,“seed”+i,i); //attach a new instance and give it a new name
colorassigned=(colors[randomcolor]); //use random number from “randomcolor” to pick value from the “colors” array.
colorassigned=“0x”+colorassigned; //add “0x” in front of it, so we can use the string as a full hex number in setRGB() below;
mycolor=new Color(“seed”+i); //create a new color object for each seed created in the loop
mycolor.setRGB(colorassigned); //set the color of each object

}

[/AS]

btw, I know you guys know how to do this. Im commenting the code, because I figure we will use this later to demonstrate to the rest of the users how we completed the project. Heck, we should probably submit it to a magazine when we’re done. (Computer Arts is my choice, or Kirupa…the Magazine).

Change the code at will, but please post any new changes. **
Monty, if you want the loop to run 48 times, you either have to change the condition to <= 47 or < 48. < 47 will run the loop 47 times if you’re starting from 0.

Also for the stones, I was thinking we could use a single graphic for all the stones and just change its tint. Maybe we could have EG come up with something.

What do you mean? It says <48. :slight_smile: j/k It said 47 before because in the original code I was duplicating the movie clip and not attaching it. Forgot to change it back…hhehee…thanks for the update.

Hmm… if you call me Monty Im gonna change my name… yeah… that’s what Im gonna do! :slight_smile:

The code above is using a single graphic, just changing the RGB value. I thought, however, that more colorful stones in PS or something would look nice. I’ll post an amateurish example later.

Guys, why aren’t we doing this in AS2? :sure:

:stuck_out_tongue:

lol i would love to, but i dont know how many of us own mx2004

how about we create a class and expand on it with prototypes?



BantumiClass = function () // constructor
{ 
	this.timeline = _root.createEmptyMovieClip("seeds", 0);
	this.colors = ["FF0000","00CCFF","0000FF","FF9900"];
} 

bcp = BantumiClass.prototype; // lazy shortcut

bcp.attachPiece = function (timeline, i)
{
	return timeline.attachMovie("seed", "seed"+i, i); // attaches a seed onto the stage
}

bcp.setColor = function( mc )
{
var colorObj = new Color( mc ),
randColor = Math.floor(math.Random()*4);
colorObj.setRGB(randColor);
}

/*
bcp.setXY = function (mc,x,y)
*/

bcp.addPiece = function (well, i)
{
var clip = well.attachPiece(i);
this.setColor(clip);
//setXY(clip,x,y)
}

bcp.createWell = function (wellNumber)
{
var well = this.timeline.createEmptyMovieClip("well"+wellNumber, wellNumber)
for ( var i=0 ; i<4 ; i++ ) this.addPiece(well, i);
}

bcp.init = function ()
{
for ( var n=0 ; n<8 ; n++ ) this.createWell(n);
}

delete bcp;

Im sure a lot of this can be optimized or cleaned, i’ll probably post a modified version once i get home from school :slight_smile:

Here’s an example.

I don’t have MX 2004, but I will help whenever possible.

Ivan, I edited your code slightly… [AS]//establish colors to be used and put then in the array "colors"
colors = [“FF0000”, “00CCFF”, “0000FF”, “FF9900”];
for (var i = 1; i<=48; i++) {
//get a random color chosen from the colors array
var randomColor = “0x”+colors[random(colors.length)];
//attach clip using newSeed as an ID for later reference
var newSeed = this.attachMovie(“seed”, “seed”+i, i);
//create color object assigned to newSeed clip and set the color to the random color chosen
var myColor = new Color(newSeed).setRGB(randomColor);
}[/AS]

I own MX2004, but I hate it. Until I love it, Im not touching AS2 unless Im forced.

I hate FlashMX2004 professional, that is. The other products seem fine.

I like the streamlined code, Lost.

*Originally posted by lostinbeta *
**I don’t have MX 2004, but I will help whenever possible.

Ivan, I edited your code slightly… [AS]//establish colors to be used and put then in the array "colors"
colors = [“FF0000”, “00CCFF”, “0000FF”, “FF9900”];
for (var i = 1; i<=48; i++) {
//get a random color chosen from the colors array
var randomColor = “0x”+colors[random(colors.length)];
//attach clip using newSeed as an ID for later reference
var newSeed = this.attachMovie(“seed”, “seed”+i, i);
//create color object assigned to newSeed clip and set the color to the random color chosen
var myColor = new Color(newSeed).setRGB(randomColor);
}[/AS] **
There’s a problem with using setRGB, though. When you use it on a graphic, it will force a fill, so you’ll basically get circle’s of different colors.
I was thinking of having a semi-transparent fill inside each symbol and we could just change that so it looks like it’s being tinted.
Otherwise, we could always just use those four graphics above and randomly load them:

for (var i = 0; i < 48; ++i) {
this.attachMovie("seed"+random(4), "seed"+i, i); // assuming the four marbles are named "seed0", "seed1", etc...to "seed3"
}

*Originally posted by Iammontoya *
**I like the streamlined code, Lost. **

Thanks Ivan, if you want more streamlined you can go [AS]colors = [“FF0000”, “00CCFF”, “0000FF”, “FF9900”];
for (var i = 1; i<=48; i++) {
new Color(this.attachMovie(“seed”, “seed”+i, i)).setRGB(“0x”+colors[random(colors.length)]);
}[/AS] But frankly, that gets to the point where it’s just a pain to read and manage :stuck_out_tongue:

gotta love those one-liners :stuck_out_tongue:

true…Thor… I only used setRGB for our current example. What I would really like to do is use graphics like the attached (Im sure someone will do better). Im not sure how I would go about that, though, because at that point, tint and RGB are both out. We’ll just need to use the 4 separate graphics. Does that make sense?

you’re scaring me, Lost.

That should be easy Ivan.

Store the linkageIDs of the clips in an array and choose from that during the attachMovie().

[edit]it’s halloween, i’m allowed to be scary :thumb:[/edit]