Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with videogame actionscript 1

Status
Not open for further replies.

goaganesha

Programmer
Dec 4, 2001
178
BE
Hi,
I’m making a videogame like spaceinvaders. Enemy ships are at the top of the screen moving from left to right. They are supposed to drop a shot under following circumstances :

1 :skullshotInAir = false (skullshotInAir is a global variable which is initially set to false in the first frame of the main scene) This variable makes shure there can only be one shot in the air at the same time.

2 :The enemy’s x position has to be in a range of +-7pixels of the "myship mc " This is to avoid that the "myship" can stand still for a long period.

3 : the skullship isn’t allready shot.

Here’s the code I put in the object panel of the "shot mc "
//===============================================
onClipEvent (enterFrame)

{
//min and max values my ship

myshippos = _root.myship._x;
myshipmin = myshippos - 7;
myshipmax = myshippos + 7;

//bounds skullship

bounds = _root.skulltotaal.skull.getBounds(_root);
xpos = ((bounds.xMax - bounds.xMin)/2) + bounds.xMin;
//conditions to fire

if(!_root.skullshotInAir && !_root.skullDead && xpos >= myshipmin && xpos <= myshipmax)

{

trace (_root.skullshotInAir);
this._x = xpos;
this._y = bounds.yMax + 20;
this._visible = true;
_root.skullshotInAir = true;
trace (_root.skullshotInAir);

}
else
{
if(this._y > 300)
{
this._visible = false;
_root.skullshotInAir = false;
}
else
{
this._y = this._y + 12;
}
}
}
//=============================================================
At the moment there are two &quot;skullshipmc’s&quot; and two &quot;shot mc’s &quot;. The 2 &quot;skullmc’s&quot; are in the &quot;skulltotaal mc&quot; which is moving from left to right.
Here’s what’s going wrong :

The shots start to fall when the skullship reaches the myship –7 xvalue but then the shot keeps hanging till it reaches the myship +7 xvalue and than it comes down. They are supposed to fall right away between these values .

Both shots fall even if there still is another shot from the other &quot;skullmc&quot; in the air.

Thanx for your help.
Regards, goaganesha
 
Isn't there anyone who can help me with this?

Let me know if you need to see the fla.

regards, goaganesha
 
I'll have a look if you like - give us a link to the .fla
 
The link was down when I tried it - what's your e-mail?
 
Hi wangbar,

I don't want to be a nag but did you get the chance to download the .fla?
regards, goaganesha
 
Yes, I've got it downloaded at work but I wasn't in the office today. I'll get on to it ASAP though...
 
Got it - the problem is that you have two clips with the same script on them (the shots from the skull ships).

The script itself is absolutely fine (which is why neither of us could see a problem right away) but because both are testing for the same conditions they interfere with each other and screw things up - delete one of the shots and the game works as it should.

Nice work by the way!
 
Okay, so I jumped too quick - only one ship is firing...

What you need to do now is make a link between the idividual shots and their parent ships which isn't there yet. The reason the shot was hanging before is that xpos is shared between the two skulls in &quot;skulltotaal&quot; - it was true as soon as one ship crossed xmin but didn't become false until the second ship crossed xmax.

All you have to do is change the code slightly so that you're testing for the skull's individually. Something like...

if (!_root.skullshotInAir && !_root.SkullOneskullDead && SkullOnexpos>=myshipmin && SkullOnexpos<=myshipmax)

would be the result depending how you set up the variables. Sorry about jumping in too soon earlier!
 
Thanx for your help, wangbar.
I would have never found the problem myself.
Hope that one day I will be able to help you with a problem.

regards, goaganesha
 
Well, the design company I work for just went bust this morning: got any jobs going? LOL
 
Join the club , wangbar ;-)

I'm unemployed since February for the same reason.

But still,I think there are more webdesign jobs available in the UK than here in little Belgium.

regards, goaganesha
 
Hi wangbar,

the problem is still there. When I was going to change the code I found out that I allready had made a difference between the _root.skulldead variable. One shot has this code:

if(!_root.skullshotInAir && !_root.skullDead && xpos >= myshipmin && xpos <= myshipmax)

the other shot has this code:

if(!_root.skullshotInAir && !_root.skull1Dead && xpos >= myshipmin && xpos <= myshipmax)

note that the firts time it's _root.skullDead and the second time it's _root.skull1Dead
The xpos has the same name but is this a problem since it is a local variable?

when I change the code to:


myshipmin = myshippos - 1;
myshipmax = myshippos + 1;


the shots go perfect if myship is standing still but when it moves , chances are small that the skull is right above my ship. Doesn't this also prove that the xposition of the different skulls don't interfere with each other?

regards, goaganesha
 
I just got it.

I've deleted the second shot mc and changed the code of the first one to:


onClipEvent (enterFrame)

{
//min and max values my ship

myshippos = _root.myship._x;
myshipmin = myshippos - 7;
myshipmax = myshippos + 7;

//bounds skullship

bounds = _root.skulltotaal.skull.getBounds(_root);
xpos = ((bounds.xMax - bounds.xMin)/2) + bounds.xMin;
bounds1 = _root.skulltotaal.skull1.getBounds(_root);
xpos1 = ((bounds1.xMax - bounds1.xMin)/2) + bounds1.xMin;

//conditions to fire

if(!_root.skullshotInAir && !_root.skullDead && xpos >= myshipmin && xpos <= myshipmax)

{


this._x = xpos;
this._y = bounds.yMax + 20;
this._visible = true;
_root.skullshotInAir = true;


}

else if(!_root.skullshotInAir && !_root.skull1Dead && xpos1 >= myshipmin && xpos1 <= myshipmax)

{


this._x = xpos1;
this._y = bounds1.yMax + 20;
this._visible = true;
_root.skullshotInAir = true;


}


else
{
if(this._y > 300)
{
this._visible = false;
_root.skullshotInAir = false;
}
else
{
this._y = this._y + 12;
}
}
}
 
Very nice. Make sure you post the finished game so we can have a play...
 
Ok wangbar I'll post it as soon as it is finished.
By the way, it was your first reply what made me find the solution.

Thanx!

regards, goaganesha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top