-
Falling Objects Game
Can anyone steer me in a direction on how to build one? Like have money graphic fall down and if it hits a wallet your score goes up by one? But it keeps looping. Is there any easy way of doing this. I had started one and I got the looping to work but I was having a lot of trouble with the score...
-
like collect the falling money, that kind of game is what I am trying to achieve
-
Hype over content...
We get it, it's just that you've not been clear on what you want help with.
Perhaps have a read of the Read Me sticky near the top of this forum and come back with some of your own code that you've tried, and what exactly is wrong ( "I was having a lot of trouble with the score...", in what way ? It not adding up correctly, the collision detection between the wallet and the cash etc. etc.
Some code and a swf would make things a lot easier ).
Squize.
-
ok, I have a hitTest that is supposed to update the variable so the text of the score will go up one every time. But unfortunately, it works but it doesn't. It passes the number to the variable but the change doesn't appear until you enter the frame again. For example the money sign hits the piggy bank twice. the score will stay 0 but if you go back to the frame it will have a score of 2. How can I make it update live?
Here is the code I have on the frame
Code:
if (_root.money.hitTest(_root.pig)) {
_global.score += 1;
}
_root.score.text = _global.score;
stop();
someone suggested i use this
this.onEnterFrame = function()
{
if (_root.money.hitTest(_root.pig)) {
_global.score += 1;
}
_root.score.text = _global.score;
}
stop();
I tried this and the other method mentioned and neither worked
Code:
if (_root.money.hitTest(_root.pig)) {
_global.score += 1;
}
_root.score.text = _global.score;
stop();
this is what has happened so far
-
Hype over content...
You'll have to run an enterFrame, as it's something you need to test every frame.
I guess you've got a $ movielclip on your stage that you duplicate for all the falling cash ?
As a quick and dirty way of doing it, try
Code:
onClipEvent(load){
var hitWalletFlag:Boolean=false;
this.onEnterFrame=function(){
if(this.hitTest(_root.pig)){
if(hitWalletFlag==false){
trace("Delete this trace once it's working");
hitWalletFlag=true;
_root.score++;
_root.scoreText.text = _root.score;
}
}
}
}
I don't know how you're moving the cash, if you're using an enterFrame on the cash clips then just merge that in there with it.
Also change the instance name of your score text box to scoreText, it's not good to have both a variable named score and an instance with the same name, it's easy to get confused.
Squize.
-
ok so on my frame i have just stop();
on my falling object I have all this
Code:
onClipEvent (enterFrame) {
this._y += 5;
if (this.hitTest(_root.pig)) {
this._x = 10.5;
this._y = -54.5;
}
if (this._y > 500) {
this._x = 10.5;
this._y = -54.5;
}
}
onClipEvent(load){
var hitWalletFlag:Boolean=false;
this.onEnterFrame=function(){
if(this.hitTest(_root.pig)){
if(hitWalletFlag==false){
trace("Delete this trace once it's working");
hitWalletFlag=true;
_root.score++;
_root.scoreText.text = _root.score;
}
}
}
}
and on the object it hits (piggy bank) i have this
Code:
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
this._x -= 5;
}
if (Key.isDown(Key.RIGHT)) {
this._x += 5;
}
}
unfortunately this didn't work.
p.s. this is the repetition script that replicates the falling object...I have like 12 falling so it looks good when they all have this code on them
Code:
if (this.hitTest(_root.pig)) {
this._x = 10.5;
this._y = -54.5;
}
if (this._y > 500) {
this._x = 10.5;
this._y = -54.5;
}
-
Hype over content...
Code:
onClipEvent(load){
var hitWalletFlag:Boolean=false;
this.onEnterFrame=function(){
if(this.hitTest(_root.pig)){
if(hitWalletFlag==false){
trace("Delete this trace once it's working");
hitWalletFlag=true;
_root.score++;
_root.scoreText.text = _root.score;
this._x = 10.5;
this._y = -54.5;
return;
}
}
this._y += 5;
if (this._y > 500) {
this._x = 10.5;
this._y = -54.5;
}
}
}
Squize.
-
ok through your code which I modified some of the names of instances...I got it to partially work, it recognizes the hit but it restarts everything on the frame, like the objects falling flash and start over. But it does update the score
Code:
onClipEvent(load){
var hitWalletFlag:Boolean=false;
this.onEnterFrame=function(){
if(this.hitTest(_root.pig)){
if(hitWalletFlag==false){
hitWalletFlag=true;
_global.score++;
_root.score.text = _global.score;
this._x = 10.5;
this._y = -54.5;
return;
}
}
this._y += 5;
if (this._y > 500) {
this._x = 10.5;
this._y = -54.5;
}
}
}
Last edited by kraxyk; 06-16-2009 at 03:01 PM.
-
Hype over content...
Put some traces in there then and see what the values actually are as you play it.
btw I noticed you changed the reference to the text box back to score instead of scoreText. Again, don't make it harder for yourself by giving two different things the same name.
Squize.
-
well it seems the problem is because I am not using a duplication script and instead am putting that code on all the dropping money mc's. Do you have a duplicating random x script idea?
-
ok everything is working right now. The only problem i am having is detecting what the score is so I can have a picture change so I have this code and everything above the last //comment works. I want it to notice when the variable becomes 5 and change the picture. I did not come up with this code, I watched many video tutorials. Basically this randomly drops the ball and deletes it once its off stage. And if you catch it you get a point, and if you miss it you lose a point. It seams like I just can't get it to constantly check it. It checks it only once, you can see that if you through a trace in there
Code:
stop();
//random fall
allBalls = new Array();
depth = 0;
function makeNewClip() {
clearInterval(ranID);
ran = (Math.random()*4000)+1000;
ranID = setInterval(makeNewClip, ran);
newClip = _root.attachMovie('money', 'money'+depth, depth++);
allBalls.push(newClip);
newClip._x = Math.random()*340;
newClip._y = -50;
newClip.speed = (Math.random()*10)+10;
newClip.onEnterFrame = function() {
this._y += this.speed;
if (this._y>Stage.height) {
updateScore(-1);
this.removeMovieClip();
for (i=o; i<allBalls.length; i++) {
if (this == allBalls[i]) {
allBalls.splice(i, 1);
}
}
}
};
}
makeNewClip();
//piggy
_root.attachMovie('pig', 'pig_mc', -1);
pig_mc._y = Stage.height-40;
watchKeyboard = new Object();
watchKeyboard.onKeyDown = function() {
if (Key.isDown(KEY.LEFT)) {
pig_mc._x -= 5;
}
if (Key.isDown(KEY.RIGHT)) {
pig_mc._x += 5;
}
};
Key.addListener(watchKeyboard);
//Check Collision
_root.createEmptyMovieClip('watchCollision', -2);
watchCollision.onEnterFrame = function() {
for (i=0; i<allBalls.length; i++) {
if (allBalls[i].hitTest(pig_mc)) {
allBalls[i].removeMovieClip();
allBalls.splice(i, 1);
updateScore(1);
}
}
};
score = 0;
function updateScore(amount) {
score += amount;
score_txt.text = score;
}
updateScore(0);
//check
if (score == 5) {
_root.pic.gotoAndStop(2);
}
-
Senior Member
Put the score == 5 check inside updateScore function.
-
Originally Posted by kraxyk
ok everything is working right now. The only problem i am having is detecting what the score is so I can have a picture change so I have this code and everything above the last //comment works. I want it to notice when the variable becomes 5 and change the picture. I did not come up with this code, I watched many video tutorials. Basically this randomly drops the ball and deletes it once its off stage. And if you catch it you get a point, and if you miss it you lose a point. It seams like I just can't get it to constantly check it. It checks it only once, you can see that if you through a trace in there
Code:
stop();
//random fall
allBalls = new Array();
depth = 0;
function makeNewClip() {
clearInterval(ranID);
ran = (Math.random()*4000)+1000;
ranID = setInterval(makeNewClip, ran);
newClip = _root.attachMovie('money', 'money'+depth, depth++);
allBalls.push(newClip);
newClip._x = Math.random()*340;
newClip._y = -50;
newClip.speed = (Math.random()*10)+10;
newClip.onEnterFrame = function() {
this._y += this.speed;
if (this._y>Stage.height) {
updateScore(-1);
this.removeMovieClip();
for (i=o; i<allBalls.length; i++) {
if (this == allBalls[i]) {
allBalls.splice(i, 1);
}
}
}
};
}
makeNewClip();
//piggy
_root.attachMovie('pig', 'pig_mc', -1);
pig_mc._y = Stage.height-40;
watchKeyboard = new Object();
watchKeyboard.onKeyDown = function() {
if (Key.isDown(KEY.LEFT)) {
pig_mc._x -= 5;
}
if (Key.isDown(KEY.RIGHT)) {
pig_mc._x += 5;
}
};
Key.addListener(watchKeyboard);
//Check Collision
_root.createEmptyMovieClip('watchCollision', -2);
watchCollision.onEnterFrame = function() {
for (i=0; i<allBalls.length; i++) {
if (allBalls[i].hitTest(pig_mc)) {
allBalls[i].removeMovieClip();
allBalls.splice(i, 1);
updateScore(1);
}
}
};
score = 0;
function updateScore(amount) {
score += amount;
score_txt.text = score;
}
updateScore(0);
//check
if (score == 5) {
_root.pic.gotoAndStop(2);
}
i got a Question..
if i want attach 2 movie clip(money & paper) that will fall from the sky,
and i hittest the money, score will + 20 if i hittest the paper the score will + 5,
so what should i do?
can teach me?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|