I am creating a catch game where basically there is a falling object and a slider to catch the object using the keyboard to control left and right movements. I have a few questions and I wonder if you might be able to advise me how to adapt the script below? It would be appreciated if anyone can help. Sorry to ask a few questions.
I’ll ask the questions first then post the script below for you to see how it is:
Q1. I have found actionscript code that I like for the movement of the slider but it currently has to sit onClipEvent (load) to work, i was wondering if you know how to incorporate that script back on to the timeline and if it is sensible to do this? This Script is also posted below.
Q2. For some reason the slider (called ‘cocktail’ in the code) now sits below the falling object (movieclip ‘good’) and the movieclip gets removed when the top of ‘good’ hits the ‘cocktail’, it is what I want becuase it needs to fall into the glass, but it is visible above the glass until the top is in, it needs to be at a depth lower than the glass I think so it’s blocked out of view?
Q3. I want to add a second falling clip called ‘bad’ but I want this to fall at a different rate to ‘good’ perhaps 1 of bad to every 10 of good. I want the score of bad to be different and to be able to adjust the frequency of the fall as levels progress.
I am looking to have scores as: ‘good’ falling of stage= -2, ‘bad’ falling off stage= 10, ‘good’ falling in glass (a catch)= 5, ‘bad’ falling in glass= -30
Also, how can I say if the score goes in to a negative/minus figure below 0 that it needs to remain at 0 and not go to -10 for example.
Q4. I want to trigger the falling movieclips to play themselves when hittest the ground (say 10 pixels up from bottom of the screen to explode just before they leave the screen) Any ideas? In the falling clip I can put ‘stop’ on first frame and animate the explosion from frame 2 onwards once I ca get it to trigger the play of MC correctly.
Q5. Finally, the slider ‘cocktail’ actionscript(currently on the movieclip) has a nice friction slow down etc so when moving right and suddenly pressing left it would be great to get the glass to very slightly rotate on it’s bottom right corner maybe only 10 or 15 degrees but enough to give the glass a shor tilt before it returns back to no rotation, then mirror this effect to do the same when going the other way.
I’m sorry again that there are so many questions but if you can help with even one or two I would be extremely grateful.
Thanks
Below is the actionscript:
Terry
Actionscript on Fr 1 On main _root timeline:
//this produces random balls that fall from the sky
depth = 0;
allBalls = new Array();
function makeNewClip() {
clearInterval(ranID);
ran = (Math.random()250)+500;
ranID = setInterval(makeNewClip, ran);
newClip = _root.attachMovie(‘good’, ‘good’+depth, depth++);
allBalls.push(newClip);
//trace(allBalls);
newClip._x = 140 + Math.random() 430;
newClip._y = -50;
newClip.speed = (Math.random()5)+5;
newClip.onEnterFrame = function() {
this._y += this.speed;
if (this._y>Stage.height) {
updateScore(-2);
for (i=0; i<allBalls.length; i++) {
if (this == allBalls) {
allBalls.splice(i, 1);
//trace(allBalls)
}
}
this.removeMovieClip();
}
};
}
//
makeNewClip();
//
//
_root.createEmptyMovieClip(‘watchCollision’, -2);
watchCollision.onEnterFrame = function() {
for (i=0; i<allBalls.length; i++) {
if (allBalls*.hitTest(cocktail_mc._x, cocktail_mc._y, true)) {
//trace(‘we hit the cocktail’);
allBalls*.removeMovieClip();
allBalls.splice(i, 1);
updateScore(5);
}
}
};
score = 0;
function updateScore(amount) {
score += amount;
score_txt.text = 'Score is '+score;
}
updateScore(0);
//Actionscript on slider MC, my slider MC is called ‘cocktail’:
onClipEvent (load) {
power = 0.5;
yspeed = 0;
xspeed = 10;
friction = 0.95;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
xspeed -= power;
}
if (Key.isDown(Key.RIGHT)) {
xspeed += power;
}
xspeed *= friction;
yspeed *= friction;
_y += yspeed;
_x += xspeed;
}