Be a Supporter!

As2 Bullet Collision Help

  • 181 Views
  • 1 Reply
New Topic
iam2ku4u
iam2ku4u
  • Member since: Jan. 7, 2008
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
As2 Bullet Collision Help Feb. 4th, 2013 @ 11:00 PM

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.

Dean
Dean
  • Member since: Feb. 16, 2008
  • Offline.
Forum Stats
Moderator
Level 46
Gamer
Response to As2 Bullet Collision Help Feb. 5th, 2013 @ 04:33 AM

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 + Chat Moderator - Feel free to send me a PM if you have a problem!
Want to instant message me? [ Skype - DeanNewgrounds ]

BBS Signature