TASK 07 by SAPNA SINGH : COLLECTING STARS FOR CHRISTMAS TREE.

CODE for ROOT MOVIE
CODE for STARS
CODE for SNOW FLAKES
CODE for LITTLE SNOW FLAKES

CODE for root movieclip in Frame 1:

stop();

// sound container for collision
this.createEmptyMovieClip("soundContainer1", 1);
var buttonSound = new Sound(this.soundContainer1);

// background sound
// this one will loop, lways playing the same sound
this.createEmptyMovieClip("soundContainer2", 2);
var bgSound = new Sound(this.soundContainer2);
bgSound.attachSound("bgFunk");
bgSound.setVolume(10);
bgSound.start();
bgSound.onSoundComplete = function() {
bgSound.start();
};

// use arrow keys to trigger increments to _x and _y
// define character step sizes

var step = 6;

//count for the collisions
var count = 0;

// define key booleans so we can check them each frame

var keysPressed = new Array();
keysPressed["LEFT"] = false;
keysPressed["RIGHT"] = false;

// build event listener to handle key presses
function keyListener() {
}
keyListener.onKeyDown = function() {
switch (Key.getCode()) {
case Key.LEFT :
keysPressed["LEFT"] = true;
break;
case Key.RIGHT :
keysPressed["RIGHT"] = true;
break;
}
};
keyListener.onKeyUp = function() {
switch (Key.getCode()) {
case Key.LEFT :
keysPressed["LEFT"] = false;
break;
case Key.RIGHT :
keysPressed["RIGHT"] = false;
break;
}
};

// add event listener to key object
Key.addListener(keyListener);
this.onEnterFrame = function() {

// react to currently pressed buttons each frame
// create hypothetical new position,
// adjust it if it needs to be wrapped,
// then assign it back to the character's position

if (keysPressed["LEFT"]) {
var nextX = kid._x-step;
if (nextX<0) {
nextX = Stage.width;
}
kid._x = nextX;
box._x = nextX;
}
if (keysPressed["RIGHT"]) {
var nextX = kid._x+step;
if (nextX>Stage.width) {
nextX = 0;
}
kid._x = nextX;
box._x = nextX;
}


// collision between box & yellow stars
// the range for the x coordinates to allow collection

var left = (box._x)-20;
var right = (box._x)+40;


// collision for star1
var star1i = (star1._x)%1;
var star1a = (star1._x)-star1i;
var star1j = (star1._y)%1;
var star1b = (star1._y)-star1j;
if ((star1a>left) && (star1a<right)) {
if ((star1b>343) && (star1b<389)) {
count = count+1;
displayt.text = count;
buttonSound.attachSound("bwip");
buttonSound.setVolume(100);
buttonSound.start();
}
}

// collision for star2
var star2i = (star2._x)%1;
var star2a = (star2._x)-star2i;
var star2j = (star2._y)%1;
var star2b = (star2._y)-star2j;
if ((star2a>left) && (star2a<right)) {
if ((star2b>343) && (star2b<389)) {
count = count+1;
displayt.text = count;
buttonSound.attachSound("bwip");
buttonSound.setVolume(100);
buttonSound.start();
}
}

// collision for star3

var star3i = (star3._x)%1;
var star3a = (star3._x)-star3i;
var star3j = (star3._y)%1;
var star3b = (star3._y)-star3j;
if ((star3a>left) && (star3a<right)) {
if ((star3b>343) && (star3b<389)) {
count = count+1;
displayt.text = count;
buttonSound.attachSound("bwip");
buttonSound.setVolume(100);
buttonSound.start();
}
}

// collision for star4
var star4i = (star4._x)%1;
var star4a = (star4._x)-star4i;
var star4j = (star4._y)%1;
var star4b = (star4._y)-star4j;
if ((star4a>left) && (star4a<right)) {
if ((star4b>343) && (star4b<389)) {
count = count+1;
displayt.text = count;
buttonSound.attachSound("bwip");
buttonSound.setVolume(100);
buttonSound.start();
}
}

// collision for star5
var star5i = (star5._x)%1;
var star5a = (star5._x)-star5i;
var star5j = (star5._y)%1;
var star5b = (star5._y)-star5j;
if ((star5a>left) && (star5a<right)) {
if ((star5b>343) && (star5b<389)) {
count = count+1;
displayt.text = count;
buttonSound.attachSound("bwip");
buttonSound.setVolume(100);
buttonSound.start();
}
}

// collision for star6
var star6i = (star6._x)%1;
var star6a = (star6._x)-star6i;
var star6j = (star6._y)%1;
var star6b = (star6._y)-star6j;
if ((star6a>left) && (star6a<right)) {
if ((star6b>343) && (star6b<389)) {
count = count+1;
displayt.text = count;
buttonSound.attachSound("bwip");
buttonSound.setVolume(100);
buttonSound.start();
}
}

// collision for star7
var star7i = (star7._x)%1;
var star7a = (star7._x)-star7i;
var star7j = (star7._y)%1;
var star7b = (star7._y)-star7j;
if ((star7a>left) && (star7a<right)) {
if ((star7b>343) && (star7b<389)) {
count = count+1;
displayt.text = count;
buttonSound.attachSound("bwip");
buttonSound.setVolume(100);
buttonSound.start();
}
}

// collision for star8
var star8i = (star8._x)%1;
var star8a = (star8._x)-star8i;
var star8j = (star8._y)%1;
var star8b = (star8._y)-star8j;
if ((star8a>left) && (star8a<right)) {
if ((star8b>343) && (star8b<389)) {
count = count+1;
displayt.text = count;
buttonSound.attachSound("bwip");
buttonSound.setVolume(100);
buttonSound.start();
}
}

// collision for star9
var star9i = (star9._x)%1;
var star9a = (star9._x)-star9i;
var star9j = (star9._y)%1;
var star9b = (star9._y)-star9j;
if ((star9a>left) && (star9a<right)) {
if ((star1b>343) && (star1b<389)) {
count = count+1;
displayt.text = count;
buttonSound.attachSound("bwip");
buttonSound.setVolume(100);
buttonSound.start();
}
}
if (count>=25) {
gotoAndStop("congrats");
}
};

BACK TO TOP

CODE for STARS:

var faraway = 10;
var speed = .05;
var cx = Stage.width;
var cy = Stage.height;
var x = (Math.random()*cx)-cx;
var y = (Math.random()*cy)-cy;
var z = Math.random()*faraway;
var SelectX = Math.random()*cx;
function moveAlongY() {
z -= speed;
if (z<=0) {
z = faraway;
}
this._x = -x;
this._y = -y/z;
}
this.onEnterFrame = function() {
moveAlongY();
var i = (this._x)%1;
var a = (this._x)-i;
var j = (this._y)%1;
var b = (this._y)-j;
var left = (_root.box._x)-3;
var right = (_root.box._x)+3;
if ((a>left) && (a<right)) {
if ((b>343) && (b<389)) {
count = count+1;
displayt.text = count;
buttonSound.attachSound("bwip");
buttonSound.setVolume(100);
buttonSound.start();
}
}
};
stop();

BACK TO TOP

CODE for LITTLE SNOW FLAKES:

var faraway = 1;
var speed = .1;
var cx = Stage.width;
var cy = Stage.height;
var x = (Math.random()*cx)-cx;
var y = (Math.random()*cy)-cy;
var z = Math.random()*faraway;
var SelectX = Math.random()*cx;
function moveAlongY() {
z -= speed;
if (z<=0) {
z = faraway;
}
this._x = Math.random()*cx;
this._y = -y/z;
}
this.onEnterFrame = function() {
moveAlongY();
};
stop();

BACK TO TOP

CODE for SNOW FLAKES:

var faraway = 10;
var speed = .01;
var cx = Stage.width;
var cy = Stage.height;
var x = (Math.random()*cx)-cx;
var y = (Math.random()*cy)-cy;
var z = Math.random()*faraway;
var SelectX = Math.random()*cx;
function moveSnow() {
z -= speed;
if (z<=0) {
z = faraway;
}
this._x = -x;
this._y = -y/z;
}
this.onEnterFrame = function() {
moveSnow();
};
stop();

BACK TO TOP