Forum Topic: bit of actionscript help

(98 views • 4 replies)

This topic is 1 page long.

<< < > >>
Sad

vgthing

Reply To Post Reply & Quote

Posted at: 6/16/09 11:41 PM

vgthing DARK LEVEL 07

Sign-Up: 05/29/08

Posts: 30

I'm working on a shooter game based on Gradius. I'm not too far in, but I already have a couple problems:

I have a stary background that looks really nice and everything, but whenever I shoot, some of the stars disappear. here are the codes that I'm using:

background:

for (c=0; c<100; c++) {
var star:MovieClip = this.createEmptyMovieClip("star"+c, c);
star._x = random(600);
star._y = random(375);
with (star) {
_yscale = random(40)+40;
_xscale = star._yscale;
lineStyle(3, 0xFFFFFF);
lineTo(0, 1);
}
star.onEnterFrame = function() {
this._x -= this._xscale*0.015;
if (this._x<0){
this._x = 620;
this._y = random(375);
}
};
}

and gun:

if (Key.isDown(Key.SPACE)) {
if (fire === true) {
fire = false;
shotCounter++;
_root.shot.duplicateMovieClip("shot"+sho tCounter, shotCounter);
_root["shot"+shotCounter]._visible = true;
_root.shot.gotoAndStop (2)
}
}
if (fire === false) {
reload++;
}
if (reload>reloadTime) {
fire = true;
reload = 0;
}

onClipEvent (load) {
bulletSpeed = 30;
this._y = _root.VicViper._y+2;
this._x = _root.VicViper._x+28;
}
onClipEvent (enterFrame){
this._x += bulletSpeed;
if (this._x>=+620) {
this.removeMovieClip();
}
if (this.hitTest( _root.fan)){
_root.score+=100;
_root.fan.gotoAndPlay( 10 );
this.removeMovieClip();
}
}

On a side note, I'm also having trouble with hitTest on the enemies (fans).
If anyone can help me out, it would be greatly appreciated!

Destroy the Core!!

BBS Signature

None

Afro-Ninja

Reply To Post Reply & Quote

Posted at: 6/17/09 12:18 AM

Afro-Ninja EVIL LEVEL 37

Sign-Up: 03/02/02

Posts: 13,466

according to your loop, the stars occupy depths 0-99

when you create bullets for the player, they start at depth "shotCounter," which I assume starts at 0? if this is the case then your shot counter needs to start at 100

no two movieclips can share the same depth, so each time you fire a shot it's going to replace one of the stars you've created

BBS Signature

None

vgthing

Reply To Post Reply & Quote

Posted at: 6/17/09 12:57 AM

vgthing DARK LEVEL 07

Sign-Up: 05/29/08

Posts: 30

wow, thanks! I can't believe I missed that! it was really helpful.

I still can't get the hitTest with the shot and enemies to work though, and I can't figure out why...
here's the code:

if (this.hitTest( _root["fan"+numfan])){
_root.score+=100;
_root["fan"+numfan].gotoAndPlay( 10 );
this.removeMovieClip();
}

Again, thanks in advance!

Destroy the Core!!

BBS Signature

None

Afro-Ninja

Reply To Post Reply & Quote

Posted at: 6/17/09 02:58 AM

Afro-Ninja EVIL LEVEL 37

Sign-Up: 03/02/02

Posts: 13,466

At 6/17/09 12:57 AM, vgthing wrote: if (this.hitTest( _root["fan"+numfan])){
_root.score+=100;
_root["fan"+numfan].gotoAndPlay( 10 );
this.removeMovieClip();
}

Again, thanks in advance!

are you running that through a loop? you need to loop through and check each fan on the screen

BBS Signature

None

vgthing

Reply To Post Reply & Quote

Posted at: 6/17/09 03:18 AM

vgthing DARK LEVEL 07

Sign-Up: 05/29/08

Posts: 30

ok, gotcha. it works now. Thanks for all the help! it probably would have taken me hours to figure it out on my own! :)

Destroy the Core!!

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 12:50 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!