Be a Supporter!
Index in for loops [AS2] Posted February 13th, 2011 in Game Development

I want to use an index for my hitTest. i would use a for loop to count how many times i(the variable) was less than 100 and increment i by one then i have two enemy movieclips one is enemy0 and the other enemy1 so when the player hitTests with either of the two an event would occur. as you can see im having a hard time explaining this so here is my code:
for (i = 0; i < 100; i++)
{
if (_root.enemy[i].hitTest(_x, _y + 3, true))//check if player hits top
{
_root.enemy[i].unloadMovie();//remove the enemy
}
else if (_root.enemy[i].hitTest(_x + 3, _y, true))//check to see if the player hits the side
{
this._x = -2417.2;//reset player position
this._y = 324.1;// ||
}
}
it would work before the loop nut when i tried to put the loop in it wont anymore

Response to: AS2 Vertical shooter problem Posted January 22nd, 2011 in Game Development

At 1/22/11 02:02 PM, sasuke2910 wrote:
if (Key.isDown(66) && shootLimiter>8) {
shootLimiter = 0;
missile = _root.attachMovie("Missile", "Missile", _root.getNextHighestDepth());
_root["missile" + _root.getNextHighestDepth()]._x = _x+1;
_root["missile" + _root.getNextHighestDepth()]._y = _y-12;
}

when i tryed this code i staill got the same problem it delets the current missile

Response to: AS2 Vertical shooter problem Posted January 22nd, 2011 in Game Development

At 1/22/11 02:29 PM, GodlyKira wrote: i over looked that it was as2 some how just replace missile.x +=whatever missile.y = whatever
to

missile.onEnterFrame = function() {
missile.x = whatever;
missile.y = whatever;
if (delete condition) {
delete onEnterFrame;
}
}

im sorry i cant quite understand what u are tying to say

Response to: AS2 Vertical shooter problem Posted January 22nd, 2011 in Game Development

do u think u can show me how to? im not that familiar with arrays

AS2 Vertical shooter problem Posted January 22nd, 2011 in Game Development

I have created a vertical shooter and when i press B to shoot a bullet the bullet shoots up but if i want to shoot another bullet the first one gets deleted and then the other bullet comes. Is there any to fix this?

Code for ship mc(on the stage):

if (Key.isDown(66) && shootLimiter>8) {
shootLimiter = 0;
var missile = _root.attachMovie("Missile", "Missile"+_root.getNextHighestDepth(), _root.getNextHighestDepth());
missile._x = _x+1;
missile._y = _y-12;
}
Code for missile(inside the mc edit window)

function onEnterFrame() {
_y -= 20;
}

Any help is appreciated tnx

Response to: AS2 - Platform shooting problem Posted November 1st, 2010 in Game Development

thanks so much and btw i did figure out the shooting myself

AS2 - Platform shooting problem Posted October 29th, 2010 in Game Development

Hey, this is my first post here and here is my question: I have AC2 and i have a platform game that does the basic jumping, sprite changing and such but i want to make it shoot bullets. i made a bullet instance (called laser) and i obviously have a player instance. the shooting code in my player is:
if (Key.isDown(Key.CONTROL)) {
laserCounter++;
_root.laser.duplicateMovieClip("laser"+l aserCounter,laserCounter);
_root["laser"+laserCounter]._visible = true;

}

this is under the onClipEvent so dont worry, and the code for my laser is:
onClipEvent (load) {

laserMoveSpeed = 40;
this._x = _root.player._x+10;
this._y = _root.player._y-15;

}
onClipEvent (enterFrame) {
if (_root.player.dir == 1) {
if (this._name<>"laser") {
_x += laserMoveSpeed;
}
}
if (_root.player.dir == 0) {
if (this._name<>"laser") {
_x -= laserMoveSpeed;
}
}
}
one laser is on the stage
anyways so when i test movies the bullet shoots to the left and the right when i press the corresponding dir keys and the CTRL button, but when i shoot lets say to the left and then face the right the bullet that was going left is now going right!!!
so if you guys could help me out that would be appreciated
thx