First Iteration

Purpose
The first iteration establishes 9 movie clips on the stage using ‘for’ loops. There are three different colors, red, green, and blue, each with three clips. The clips will populate the screen in random locations. The clips will establish a random target x and y coordinate value. Each frame, the clips will compare their current location against their target location by comparing x and y coordinates. If the comparison results in a match, then the clip will acquire a new random target value. If the current x/y is less than the target x/y, then clip will add the speed value to the current x/y. Or else, it will subtract the speed value from the current x/y. This will be checked for on each frame.

Also on each frame, the clips will make a collision check to see if they hit another movie clip. If a collision is detected, a decision needs to be made on who wins, on the basis of the color of the movieclips involved. The color of the clips ‘R/G/B’ sets up a circular hierarchy, similar in concept to ‘rock/paper/scissors’. If Red and Green hit, then Red will win. If Green and Blue hit, Green will win. If Blue and Red hit, Blue will win. If the two colors are the same, they will result in a tie. The consequence of winning is a speed change. The speed of the winner increases by 1. The speed of the loser decreases by 1, unless speed is already at 0. Hitting a ball of your own color resets the speed of both balls to the starting value again.

I’d like there to be a rebound effect of some sort, though I highly suspect I’ll have to tweak things. After a collision, for now, the rebound will be to ‘teleport’ the lower movie clip in the stack to a random location, to begin again. Because of this, I think that there needs to be a dynamic text field on each of the clips to allow us to track the ‘teleports’.

Expectations
I expect that the results will be fairly straightforward as far as simulations go. The speed changes add some variability, since it will be possible for a losing streak to end up with several stopped movie clips on the screen. One area I would like to address next would be figuring out some sort of logical result which would seem to obey physics with regards to the rebound angles. The trouble is that I left my physics class in high school right about when we talked about velocity, and with a speed and a distance change… my brain is already shuddering.

Pseudocode
// Establish the movie clips on the stage.
Set up a loop to do the following 9 times:
Create an instance of a movie clip and give it a sequential number appended to its name.
Attach that movie clip to the stage by generating a random number (anywhere from 5 px in from each border, (Math.random()*stagewidth/stageheight-10)+5) for _x and for _y.
Initialize that movie clip.

// Initializing the movie clip function
Whatever called upon the Initialize function gets assigned the following:
a number to display in its dynamic text field
a color to display graphically based on the number appended to whatever called upon Initialize (1,4,7 = red, 2,5,8 = green, or 3,6,9 = blue)
a color attribute used for collisions which contains 1 for red, 2 for green, 3 for blue
a targetX and a targetY
an initial speed of 5 pixels per frame

// Motion function
Is targetX > currentX? If so, add speed to this movieclip’s._x position.
Or else, is targetX == to currentX? If so, targetX is random() again.
Otherwise, subtract speed from this movieclip’s._x position.

Is targetY > currentY? If so, add speed to this movieclip’s._y position.
Or else, is targetY == to currentY? If so, targetY is random() again.
Otherwise, subtract speed from this movieclip’s._y position.

// Collision detection function
Check to see if there’s a hit between this movieclip and anything that’s in this movieclip’s space on the parent timeline.
If there is, call upon the hitResolution function.
Otherwise, do nothing.

// hitResolution function
Compare the object that called this function/the one ‘being hit’, with the object that is in that movieclip’s space on the parent timeline.

Check the colorCollision variable.
If this object == that object, both object speeds are set to 5 again.
If this.colorCollision < that.colorCollision OR this-that==2, then add 1 to this.clip’s speed.
If that.colorCollision < this.colorCollision OR that-this==2, then add 1 to that.clip’s speed.

Change direction
If this.level < that.level then that._x/y is assigned to random coordinates,
else this._x/y is assigned to random coordinates.

// The engine to make it go
this.onEnterFrame to make it all run. Every time the frame is loaded after the first time the code runs, each movie clip will do the following things:
move
detect collisions

That should be it. Tomorrow morning I’ll code it while waiting for the gas company to arrive, and hopefully have test results to talk about.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s