PDA

View Full Version : Help with Basic Shooter!


newbieian
11-29-2007, 12:19 AM
I am making a Sniping game with Flash MX 2004 and I am having two problems. The first is concerning reloading your rifle and the display of your ammo. I am trying to have it so that when you click and fire a bullet from the six on your screen, one will disappear and continue to the point when none are left and you must click shift to reload it. However sometimes the display of the bullets is wacky, sometimes the bullets don't disappear, sometimes you can still shoot when out of ammo, and more. It worked earlier but doesn't work anymore.

The second problem is that I want to have multiple enemies on stage that you can kill. I had code that when you clicked on the enemies they would fall down and die while the others remained unaffected, yet it doesn't work now either. I also don't know where the code for the soldiers as well as the code for the ammo goes. Does it go on the button, frame, etc.?

Here it is:

This code is on the button for the first soldier which is inside a separate movie clip of that soldier.
onRelease = function () {
if (_currentframe == 1 && _root.ammo.checkAmmo()) {
play();
}
};

Here is the code for the ammo, it is on the first frame on the ammo layer.

bullets = [];
function up() {
if (bullets.length<6) {
n = "a"+random(10000);
duplicateMovieClip(original, n, this.getNextHighestDepth());
bullets.push(this[n]);
created = this[n];
created._x = bullets.length*20;
created._y = 20;
}
}
function down() {
if (bullets.length>0) {
bullets.pop().removeMovieClip();
}
}
function checkAmmo() {
return bullets.length>=0;
}
function reload() {
for (i=0; i<6; i++) {
up();
}
}
reload();
original._visible = false;

obj = new Object();
Key.addListener(obj);
obj.onKeyDown = function(){
if (Key.isDown(Key.SHIFT)){
reload();
}
}


At the moment one bullet is displayed instead of six, and it doesn't disappear upon shooting. The soldier doesn't respond at all upon shooting him either.

P.S. Am I working with Actionscript 2.0? I think I am, but I wanted to be sure. Btw, if you couldn't tell already I am not very good with Actionscript.

Thanks in advance,

Newbieian

newbieian
12-01-2007, 03:22 PM
The ammo works now, but my enemies don't respond when shot no matter what. I am not sure if the new ammo code somehow affects it. Can I email someone my flash and they look at it or could someone atleast give me the code necessary for the enemies?