Brian Lin
asked on
Flash shooting game question
Hi,
I am making this shoot game that shooting number does not match with the shooting objects or sometimes the number shows NaN.
For this game, first, there are two layers, Scores and balls. In the scores layers, there is script for the generate problem and control the red cross. In the balls layer, it has script for the balls's random number and control them to move from right to left and left to right.
So, How these two part script part work ? First, score layer script generate problem then send the "answer" ( script line 3 to 16 ) to the balls' layer script then ball's script will generate a same answer number on one of these 18 balls.
Then the red cross should move when the mouse arrow movie within the shooting area ( left = -398 right = -11 top = -253 bottom = 56 ). Then the red corss will follow the mouse arrow within these area. And when click on mouse, the white ball will shoot out and hit the orange ball... then if it is right answer, orange ball will be gone and scroe layers script will generate a new problem then whole game will continue......
Any suggestions ? thanks download demo @ http://www.brianlinstudio.com/question/shooting_game.zip
I am making this shoot game that shooting number does not match with the shooting objects or sometimes the number shows NaN.
For this game, first, there are two layers, Scores and balls. In the scores layers, there is script for the generate problem and control the red cross. In the balls layer, it has script for the balls's random number and control them to move from right to left and left to right.
So, How these two part script part work ? First, score layer script generate problem then send the "answer" ( script line 3 to 16 ) to the balls' layer script then ball's script will generate a same answer number on one of these 18 balls.
Then the red cross should move when the mouse arrow movie within the shooting area ( left = -398 right = -11 top = -253 bottom = 56 ). Then the red corss will follow the mouse arrow within these area. And when click on mouse, the white ball will shoot out and hit the orange ball... then if it is right answer, orange ball will be gone and scroe layers script will generate a new problem then whole game will continue......
Any suggestions ? thanks download demo @ http://www.brianlinstudio.com/question/shooting_game.zip
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry, my friends account...
This is my account...
Cërf.
Cërf.
ASKER
yeah, this game is just about find answer on ducks ( balls ) and shoot the answer.....
So, what do you think of my idea?
Do you want to implement it?
I'm open to help you with any doubts you might have.
That's what we are hewre for, huh?
Cërf.
Do you want to implement it?
I'm open to help you with any doubts you might have.
That's what we are hewre for, huh?
Cërf.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Can I ask.... can I just make question to always show minus sign ?
generate();
function generate(){
whichNum=random(this._pare nt.ducks_m c.duckNumb ers.length );
answer=this._parent.ducks_ mc.duckNum bers[which Num];
eq1=random(70);
eq2=eq1-answer;
if(eq2<0){
//eq2=Math.abs(eq2);
//trace(eq1+"+ "+eq2+"="+answer);
//sign="+";
generate();
}else{
trace(eq1+"- "+eq2+"="+answer);
sign="-";
}
b=eq2;
a=eq1;
c=answer;
}
just remove those lines I have comented out and replace them with a call to the function again.
Billystyx
function generate(){
whichNum=random(this._pare
answer=this._parent.ducks_
eq1=random(70);
eq2=eq1-answer;
if(eq2<0){
//eq2=Math.abs(eq2);
//trace(eq1+"+ "+eq2+"="+answer);
//sign="+";
generate();
}else{
trace(eq1+"- "+eq2+"="+answer);
sign="-";
}
b=eq2;
a=eq1;
c=answer;
}
just remove those lines I have comented out and replace them with a call to the function again.
Billystyx
Really nice code Billystyx!
Have a good one,
Cërf.
Have a good one,
Cërf.
thanks:)
Billystyx
Billystyx
ASKER
thanks:) Billystyx
Brian
Brian
no worries!
ASKER
hi, Billystyx
I would like to ask, if I want to have two level of game.... first level "question" number range from 0 to 20 ( ex. 1-1 ~ 20-20 ) and second level "question" number range from 20 to 60 ( 20 -20 ~ 60 - 60 ). If I pass the 1st level and should go to the second level.... How can I do that ? thanks
I would like to ask, if I want to have two level of game.... first level "question" number range from 0 to 20 ( ex. 1-1 ~ 20-20 ) and second level "question" number range from 20 to 60 ( 20 -20 ~ 60 - 60 ). If I pass the 1st level and should go to the second level.... How can I do that ? thanks
You would need to set varaibles startpt and endpt on the _root for example, depending on level.
Then just access them in the function (where I have commented below), instead of using numbers, use those variables
generate();
function generate(){
whichNum=random(this._pare nt.ducks_m c.duckNumb ers.length );
answer=this._parent.ducks_ mc.duckNum bers[which Num];
Rand=[];
for(i=20;i<41;i++){//these variables you would set depending on level
//like startpt=20;endpt=41, and then inside the for loop there
//you would do for(i=_root.startpt;i<_roo t.endpt;i+ +){
Rand.push(i);
}
eq1=random(Rand.length);
eq1=Rand[eq1];
eq2=eq1-answer;
if(eq2<0){
//eq2=Math.abs(eq2);
//trace(eq1+"+ "+eq2+"="+answer);
//sign="+";
generate();
}else{
trace(eq1+"- "+eq2+"="+answer);
sign="-";
}
b=eq2;
a=eq1;
c=answer;
}
Billystyx
Then just access them in the function (where I have commented below), instead of using numbers, use those variables
generate();
function generate(){
whichNum=random(this._pare
answer=this._parent.ducks_
Rand=[];
for(i=20;i<41;i++){//these
//like startpt=20;endpt=41, and then inside the for loop there
//you would do for(i=_root.startpt;i<_roo
Rand.push(i);
}
eq1=random(Rand.length);
eq1=Rand[eq1];
eq2=eq1-answer;
if(eq2<0){
//eq2=Math.abs(eq2);
//trace(eq1+"+ "+eq2+"="+answer);
//sign="+";
generate();
}else{
trace(eq1+"- "+eq2+"="+answer);
sign="-";
}
b=eq2;
a=eq1;
c=answer;
}
Billystyx
ASKER
so, I put for(i=_root.startpt;i<_roo t.endpt;i+ +){ within the ducks ( balls ) area ?
ASKER
thanks for your last post....I would like to ask if I did right or not.....
I change from............
//give balls random number
for ( var i = 0; i < 18; i ++ ) {
var n = random( 50 )
this[ "duck_" + i ].num_txt.text = n;
this[ "duck_" + i ].num = n;
duckNumbers[i] = n;
}
to script like this ?
//give balls random number
for(i=_root.startpt;i<_roo t.endpt;i+ +){
var n = random( 50 )
this[ "duck_" + i ].num_txt.text = n;
this[ "duck_" + i ].num = n;
duckNumbers[i] = n;
}
After I change it, I got the trace shows "19- NaN=undefined"....
Did I change the wrong place ?
thanks
Brian
I change from............
//give balls random number
for ( var i = 0; i < 18; i ++ ) {
var n = random( 50 )
this[ "duck_" + i ].num_txt.text = n;
this[ "duck_" + i ].num = n;
duckNumbers[i] = n;
}
to script like this ?
//give balls random number
for(i=_root.startpt;i<_roo
var n = random( 50 )
this[ "duck_" + i ].num_txt.text = n;
this[ "duck_" + i ].num = n;
duckNumbers[i] = n;
}
After I change it, I got the trace shows "19- NaN=undefined"....
Did I change the wrong place ?
thanks
Brian
ASKER
Also, Can I make ball's number generate different random numbers after got hit each time ?
hello, just posted a response to your new question (as above), but when I sent it was deleted...
anyway, like this:
_root.startpt=20;
_root.endpt=61;
var invisible;
generate();
function generate(){
whichNum=random(this._pare nt.ducks_m c.duckNumb ers.length );
answer=this._parent.ducks_ mc.duckNum bers[which Num];
Rand=[];
for(i=_root.startpt;i<_roo t.endpt;i+ +){
Rand.push(i);
}
eq1=random(Rand.length);
eq1=Rand[eq1];
eq2=eq1-answer;
if(eq2<0){
generate();
}else{
trace(eq1+"- "+eq2+"="+answer);
sign="-";
}
b=eq2;
a=eq1;
c=answer;
}
Hope that helps:)
anyway, like this:
_root.startpt=20;
_root.endpt=61;
var invisible;
generate();
function generate(){
whichNum=random(this._pare
answer=this._parent.ducks_
Rand=[];
for(i=_root.startpt;i<_roo
Rand.push(i);
}
eq1=random(Rand.length);
eq1=Rand[eq1];
eq2=eq1-answer;
if(eq2<0){
generate();
}else{
trace(eq1+"- "+eq2+"="+answer);
sign="-";
}
b=eq2;
a=eq1;
c=answer;
}
Hope that helps:)
ASKER
hi,
thanks...I can see why it is not working..... Can I also ask, sometimes answer does not show up on the balls ( maybe 1 in 9 times ). How to fix that problem ? I think is it possible to generate new numbers when ball reach the end on each rows. and have answer among the new generate radom numbers.... also, about that new questions....I try to move the generate random number scripting from ball to shooting.....it is a big mass....maybe you can take a look @ http://www.brianlinstudio.com/question/numberQ4.fla.zip
thanks
Biran
Below is the question I delete -------
I have this games that question numbers show NaN and undefined. Also, It does not show random number on balls. I think it is the problem with "function generate()" under "scorekeeper" movie clip. I need different random numbers on balls after shoot each time. Also, there should be a new generate number for question. Answer needs to match one of number on orange ball..... Demo can download @ http://www.brianlinstudio.com/question/numberQ4.fla.zip thanks for any suggestions :)
thanks...I can see why it is not working..... Can I also ask, sometimes answer does not show up on the balls ( maybe 1 in 9 times ). How to fix that problem ? I think is it possible to generate new numbers when ball reach the end on each rows. and have answer among the new generate radom numbers.... also, about that new questions....I try to move the generate random number scripting from ball to shooting.....it is a big mass....maybe you can take a look @ http://www.brianlinstudio.com/question/numberQ4.fla.zip
thanks
Biran
Below is the question I delete -------
I have this games that question numbers show NaN and undefined. Also, It does not show random number on balls. I think it is the problem with "function generate()" under "scorekeeper" movie clip. I need different random numbers on balls after shoot each time. Also, there should be a new generate number for question. Answer needs to match one of number on orange ball..... Demo can download @ http://www.brianlinstudio.com/question/numberQ4.fla.zip thanks for any suggestions :)