shalimog
January 3rd, 2008, 09:35 PM
Hey all! This is my FIRST time producing a game ... first time coding with actionscript EVER! I'm trying to create a catch game... everything is working good... basically, there's a hand at the bottom sliding left/right with your cursor, and it catches the various shapes. You gain points when you catch a shape, and you lose points if they fall off the screen. I want the game to END after 10 seconds, displaying your score to the left.
So I got the counter and everything but can't seem to get the balls to stop falling!!! What are some ways I can do this?
And here's what I'm working on:
http://shalinguyen.com/catch/catch.html
Here's all my code:
//this produces random balls that fall from the sky
depth = 0;
allBalls = new Array();
function makeOne() {
clearInterval(ranOneID);
ran = (Math.random()*4000)+1000;
ranOneID = setInterval(makeOne, ran);
One = _root.attachMovie('circle', 'circle'+depth, depth++);
allBalls.push(One);
//trace(allBalls);
One._x = Math.random()*550;
One._y = -50;
One.speed = (Math.random()*10)+5;
One.onEnterFrame = function() {
this._y += this.speed;
if (this._y>Stage.height) {
updateScore(-5);
for (i=0; i<allBalls.length; i++) {
if (this == allBalls[i]) {
allBalls.splice(i, 1);
}
}
this.removeMovieClip();
}
};
}
function makeTwo() {
clearInterval(ranTwoID);
ranTwoID = setInterval(makeTwo, ran);
Two = _root.attachMovie('square', 'square'+depth, depth++);
allBalls.push(Two);
//trace(allBalls);
Two._x = Math.random()*550;
Two._y = -100;
Two.speed = (Math.random()*9)+5;
Two.onEnterFrame = function() {
this._y += this.speed;
if (this._y>Stage.height) {
updateScore(-5);
for (i=0; i<allBalls.length; i++) {
if (this == allBalls[i]) {
allBalls.splice(i, 1);
}
}
this.removeMovieClip();
}
};
}
function makeThree() {
clearInterval(ranThreeID);
ranThreeID = setInterval(makeThree, ran);
Three = _root.attachMovie('three', 'three'+depth, depth++);
allBalls.push(Three);
//trace(allBalls);
Three._x = Math.random()*550;
Three._y = -100;
Three.speed = (Math.random()*8)+5;
Three.onEnterFrame = function() {
this._y += this.speed;
if (this._y>Stage.height) {
updateScore(-5);
for (i=0; i<allBalls.length; i++) {
if (this == allBalls[i]) {
allBalls.splice(i, 1);
}
}
this.removeMovieClip();
}
};
}
function makeFour() {
clearInterval(ranFourID);
ranFourID = setInterval(makeFour, ran);
Four = _root.attachMovie('four', 'four'+depth, depth++);
allBalls.push(four);
//trace(allBalls);
Four._x = Math.random()*550;
Four._y = -100;
Four.speed = (Math.random()*7)+5;
Four.onEnterFrame = function() {
this._y += this.speed;
if (this._y>Stage.height) {
updateScore(-5);
for (i=0; i<allBalls.length; i++) {
if (this == allBalls[i]) {
allBalls.splice(i, 1);
}
}
this.removeMovieClip();
}
};
}
function makeFive() {
clearInterval(ranFiveID);
ranFiveID = setInterval(makeFive, ran);
Five = _root.attachMovie('five', 'five'+depth, depth++);
allBalls.push(five);
//trace(allBalls);
Five._x = Math.random()*550;
Five._y = -100;
Five.speed = (Math.random()*6)+5;
Five.onEnterFrame = function() {
this._y += this.speed;
if (this._y>Stage.height) {
updateScore(-5);
for (i=0; i<allBalls.length; i++) {
if (this == allBalls[i]) {
allBalls.splice(i, 1);
}
}
this.removeMovieClip();
}
};
}
makeOne();
makeTwo();
makeThree();
makeFour();
makeFive();
//
_root.attachMovie('slider', 'slider_mc', -1);
slider_mc._y = Stage.height-20;
slider_mc._x = 300;
//KEYBOARD PROPERTIES
//watchKeyboard = new Object();
//watchKeyboard.onKeyDown = function() {
// if (Key.getCode() == Key.LEFT) {
// slider_mc._x -= 10;
// }
// if (Key.getCode() == Key.RIGHT) {
// slider_mc._x += 10;
// }
//};
//Key.addListener(watchKeyboard);
slider_mc.onMouseMove = function() {
this._x = _xmouse;
//if ( this._y >=450){this._y=450;}
//if ( this._y <= 54){this._y=54;}
if ( this._x >=575){this._x=575;}
if ( this._x <= 30){this._x=30;}
updateAfterEvent();
};
Mouse.hide();
//
_root.createEmptyMovieClip('watchCollision', -2);
watchCollision.onEnterFrame = function() {
for (i=0; i<allBalls.length; i++) {
if (allBalls[i].hitTest(slider_mc)) {
//trace('we hit the slider');
allBalls[i].removeMovieClip();
allBalls.splice(i, 1);
updateScore(10);
}
}
};
score = 0;
function updateScore(amount) {
score += amount;
score_txt.text = score;
}
updateScore(0);
This is my timer code:
var seconds = 5;
var miliseconds = 10;
function tellTime() {
if (miliseconds<10) {
time_txt.text = seconds+":"+"0"+miliseconds;
} else {
time_txt.text = seconds+":"+miliseconds;
}
miliseconds--;
if (miliseconds<0) {
miliseconds = 10;
seconds--;
}
if (seconds<0) {
clearInterval(id);
time_txt.text = "Game Over";
gotoAndPlay(50);
}
}
id = setInterval(tellTime, 100);
stop();
So I got the counter and everything but can't seem to get the balls to stop falling!!! What are some ways I can do this?
And here's what I'm working on:
http://shalinguyen.com/catch/catch.html
Here's all my code:
//this produces random balls that fall from the sky
depth = 0;
allBalls = new Array();
function makeOne() {
clearInterval(ranOneID);
ran = (Math.random()*4000)+1000;
ranOneID = setInterval(makeOne, ran);
One = _root.attachMovie('circle', 'circle'+depth, depth++);
allBalls.push(One);
//trace(allBalls);
One._x = Math.random()*550;
One._y = -50;
One.speed = (Math.random()*10)+5;
One.onEnterFrame = function() {
this._y += this.speed;
if (this._y>Stage.height) {
updateScore(-5);
for (i=0; i<allBalls.length; i++) {
if (this == allBalls[i]) {
allBalls.splice(i, 1);
}
}
this.removeMovieClip();
}
};
}
function makeTwo() {
clearInterval(ranTwoID);
ranTwoID = setInterval(makeTwo, ran);
Two = _root.attachMovie('square', 'square'+depth, depth++);
allBalls.push(Two);
//trace(allBalls);
Two._x = Math.random()*550;
Two._y = -100;
Two.speed = (Math.random()*9)+5;
Two.onEnterFrame = function() {
this._y += this.speed;
if (this._y>Stage.height) {
updateScore(-5);
for (i=0; i<allBalls.length; i++) {
if (this == allBalls[i]) {
allBalls.splice(i, 1);
}
}
this.removeMovieClip();
}
};
}
function makeThree() {
clearInterval(ranThreeID);
ranThreeID = setInterval(makeThree, ran);
Three = _root.attachMovie('three', 'three'+depth, depth++);
allBalls.push(Three);
//trace(allBalls);
Three._x = Math.random()*550;
Three._y = -100;
Three.speed = (Math.random()*8)+5;
Three.onEnterFrame = function() {
this._y += this.speed;
if (this._y>Stage.height) {
updateScore(-5);
for (i=0; i<allBalls.length; i++) {
if (this == allBalls[i]) {
allBalls.splice(i, 1);
}
}
this.removeMovieClip();
}
};
}
function makeFour() {
clearInterval(ranFourID);
ranFourID = setInterval(makeFour, ran);
Four = _root.attachMovie('four', 'four'+depth, depth++);
allBalls.push(four);
//trace(allBalls);
Four._x = Math.random()*550;
Four._y = -100;
Four.speed = (Math.random()*7)+5;
Four.onEnterFrame = function() {
this._y += this.speed;
if (this._y>Stage.height) {
updateScore(-5);
for (i=0; i<allBalls.length; i++) {
if (this == allBalls[i]) {
allBalls.splice(i, 1);
}
}
this.removeMovieClip();
}
};
}
function makeFive() {
clearInterval(ranFiveID);
ranFiveID = setInterval(makeFive, ran);
Five = _root.attachMovie('five', 'five'+depth, depth++);
allBalls.push(five);
//trace(allBalls);
Five._x = Math.random()*550;
Five._y = -100;
Five.speed = (Math.random()*6)+5;
Five.onEnterFrame = function() {
this._y += this.speed;
if (this._y>Stage.height) {
updateScore(-5);
for (i=0; i<allBalls.length; i++) {
if (this == allBalls[i]) {
allBalls.splice(i, 1);
}
}
this.removeMovieClip();
}
};
}
makeOne();
makeTwo();
makeThree();
makeFour();
makeFive();
//
_root.attachMovie('slider', 'slider_mc', -1);
slider_mc._y = Stage.height-20;
slider_mc._x = 300;
//KEYBOARD PROPERTIES
//watchKeyboard = new Object();
//watchKeyboard.onKeyDown = function() {
// if (Key.getCode() == Key.LEFT) {
// slider_mc._x -= 10;
// }
// if (Key.getCode() == Key.RIGHT) {
// slider_mc._x += 10;
// }
//};
//Key.addListener(watchKeyboard);
slider_mc.onMouseMove = function() {
this._x = _xmouse;
//if ( this._y >=450){this._y=450;}
//if ( this._y <= 54){this._y=54;}
if ( this._x >=575){this._x=575;}
if ( this._x <= 30){this._x=30;}
updateAfterEvent();
};
Mouse.hide();
//
_root.createEmptyMovieClip('watchCollision', -2);
watchCollision.onEnterFrame = function() {
for (i=0; i<allBalls.length; i++) {
if (allBalls[i].hitTest(slider_mc)) {
//trace('we hit the slider');
allBalls[i].removeMovieClip();
allBalls.splice(i, 1);
updateScore(10);
}
}
};
score = 0;
function updateScore(amount) {
score += amount;
score_txt.text = score;
}
updateScore(0);
This is my timer code:
var seconds = 5;
var miliseconds = 10;
function tellTime() {
if (miliseconds<10) {
time_txt.text = seconds+":"+"0"+miliseconds;
} else {
time_txt.text = seconds+":"+miliseconds;
}
miliseconds--;
if (miliseconds<0) {
miliseconds = 10;
seconds--;
}
if (seconds<0) {
clearInterval(id);
time_txt.text = "Game Over";
gotoAndPlay(50);
}
}
id = setInterval(tellTime, 100);
stop();