00:00
00:00
Newgrounds Background Image Theme

sereneFalconer just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

As2 Bullet Collision Help

545 Views | 1 Reply
New Topic

As2 Bullet Collision Help 2013-02-04 23:00:10


Hello there, I am trying to make a Megan Style game using AS2 coding. I already have the character able to jump and shoot correctly. I will provide my entire project (not much is there) in case you all wish to help or have any questions.
The two main issues I have are:
1.The bullets aren't deleted when switching levels (which is switching frames).
2.Bullets don't collide with objects.

Here is a link to the .fla of it http://www.newgrounds.com/dump/item/38482154c368a1da18b42df0 f05be70e

The code for shooting is inside the character. It works, here it is for a reference.

//variable i for bullets
var i = 0;
var numbb = 0;
///// End Frame Start Code /////

onEnterFrame = function () {
if (numbb < 6){
if((Key.isDown(_root.ATTACKKEY)) and (_root.mcPLAYER.DIRECTION == "L")){//if the space bar is pressed
i++;
numbb += 1;
_root.mcPLAYER.gotoAndStop(7);
_root.attachMovie("BulletL", "BulletL" + i, _root.getNextHighestDepth());
_root["BulletL" + i]._x = mcPLAYER._x + 0;
_root["BulletL" + i]._y = mcPLAYER._y + -20;
}
if((Key.isDown(_root.ATTACKKEY)) and (_root.mcPLAYER.DIRECTION == "R")){//if the space bar is pressed
i++;
numbb += 1;
_root.attachMovie("BulletR", "BulletR" + i, _root.getNextHighestDepth());
_root["BulletR" + i]._x = mcPLAYER._x + 0;
_root["BulletR" + i]._y = mcPLAYER._y + -20;
}
}

The code is not on the character, but it is on the first frame of the main timeline and the code references the main character. For the bullet code, there are two seperate bullets as mentioned above.

Here is one for the bullet. "mcBulletR" is the bullet that shoots to the right and has the linkage name of "bulletR"

this.onEnterFrame = function()
{
if(_root.mcPLAYER.DIRECTION == "R") {
this._x += 10;
if (this._x >480)
{
_root.numbb -=1;
this.removeMovieClip(); }
}
if (_root.mcPLAYER.DIRECTION == "L") {
this._x += 10;
if (this._x >480)
{
_root.numbb -=1;
this.removeMovieClip();}
}
}

The bullet fires correctly. But it doesn't collide with the enemy. Although in this current version there is no line of code that references the bullet, I have tried a few things before, but here is the current code. This code is placed on the movie clip itself.

onClipEvent (enterFrame) {
if (this.hitTest(_root.mcPLAYER)==true) {
_root.health -= 1;}
//Health Clause
if ( _root.health<1) {
_root.health = 1;
}
if ( _root.health>100) {
_root.health = 100;
}
}

With all of this said:
How am I able to make bullets delete themselves when switching frames?
How am I able to make a movie clip realize that the bullet has made contact with it.

Response to As2 Bullet Collision Help 2013-02-05 04:33:05


ActonScript questions belong in the Flash forum, so you'll want to re-post this over there. Also, please wrap your code in the code tags. It makes things a lot easier to read.


BBS Moderator - Feel free to send me a PM if you have a problem!

BBS Signature