Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-05-2012, 06:51 PM   #1
artS
Registered User
 
Join Date: Apr 2011
Posts: 5
Question [AS2] Space Invaders Game - Shooting bullets problem

Hello guys :eek: . Ehm, im working in an space invaders game :o . And I am having trouble making my ship's bullets hit the enemy (they can hit the enemy, but only from an especific axis/location . I have searched A LOT on internet (but not enough) and I think the problem is that I don't know how to use arrays xD but it's just what I think ... So if you can help me I would really appreciate it. ;)

Use "A" to shoot bullets.

Here you can see the .swf:
ahttpo://dl.dropbox.com/u/48909441/nave.swf

Here you can download the .fla:
ahttpo://dl.dropbox.com/u/48909441/nave.fla

//To open the links, remove the "a" and the "o" in "http". Because actionscript forums do not let me post links or images, because I only have 3 posts.
artS is offline   Reply With Quote
Old 04-05-2012, 07:13 PM   #2
neilmmm
Senior Member
 
neilmmm's Avatar
 
Join Date: Oct 2005
Location: dorset
Posts: 1,637
Default

welcome artS

please post your appopriate code at the same time - you much more likely to get a response
neilmmm is offline   Reply With Quote
Old 04-05-2012, 10:02 PM   #3
artS
Registered User
 
Join Date: Apr 2011
Posts: 5
Default

Quote:
Originally Posted by neilmmm View Post
welcome artS

please post your appopriate code at the same time - you much more likely to get a response
This is the code inside the first frame:

// DEFINE UNIQUE VARIABLE FOR ATTACHMOVIE FUNCTION
id = 0;

This is the code inside my ship(only the code for shooting bullets):

onClipEvent (load) {

// DEFINE ASCII CODING FOR THE SHOOT KEY - click here for references
shootkey = 65;

// DEFINE OTHER VARIABLES
fps = 24;
delay = 0.25;
fdelay = fps * delay;
count = fdelay;

// CREATE A NEW FUNCTION CALLED "SHOOT" WITH INPUT VARIABLE NAMED "ROTA"
shoot = function (rota) {

// INCREASES "ID" VARIABLE BY ONE TO ENSURE UNIQUENESS OF EACH ATTACHED CLIP
_root.id++;

// CREATE A NEW OBJECT CALLED "INITOBJECT"
initObject = new Object();

// GIVE IT COORDINATES ACCORDING TO THE SHOOTER
initObject._x = _x;
initObject._y = _y;

// GIVE IT A ROTATION (DEGREES) ACCORDING TO THE INPUT VARIABLE "ROTA"
initObject._rotation = rota;

// ATTACH BULLET CLIP TO INITOBJECT
_root.attachMovie("bullet", "bullet" + _root.id, _root.id, initObject);

// END "SHOOT" FUNCTION
};

// END "LOAD" FUNCTION
}

// "ENTERFRAME" REPEATS THE FOLLOWING STATEMENTS WHEN CLIP IS ON STAGE
onClipEvent (enterFrame) {

// IF BULLET IS NOT DELAYED LONG ENOUGH...
if (count < fdelay) {

// COUNT UP BY ONE
count++;

// OTHERWISE, IF BULLET IS DELAYED LONG ENOUGH AND SHOOT KEY IS PUSHED DOWN...
} else if (Key.isDown(shootkey)) {

// RESET COUNT
count = 0;

// SHOOT BULLETS... EXAMPLE - HERE I HAVE ONE STRAIGHT AND TWO SIDE BULLETS

shoot(0);

}

// END "ENTERFRAME" FUNCTION
}

This is the code inside the bullets movie clip
// DEFINE VARIABLES
speed = 20;
xmin = -_width;
ymin = -_height;
xmax = Stage.width + _width;
ymax = Stage.height + _height;

// "ENTERFRAME" REPEATS THE FOLLOWING STATEMENTS WHEN CLIP IS ON STAGE
this.onEnterFrame = function() {

// TRAVEL ACCORDING TO ROTATION
_x += speed * Math.sin(_rotation * Math.PI / 180);
_y -= speed * Math.cos(_rotation * Math.PI / 180);

// REMOVE ITSELF WHEN IT GETS OFFSTAGE
if (_x < xmin || _x > xmax || _y < ymin || _y > ymax) {
this.removeMovieClip();
}

// END "ENTERFRAME" FUNCTION
};

if(this.hitTest(_root.enemigo)){
//direccion de la animacion
_root.enemigo.nextFrame();
unloadMovie(this);

}
artS is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:31 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.