Making a Beat-Em-Up Fighting Game in Flash: Part SIX OK time for the fun stuff, WEAPONS!! Making your character able to pick up weapons won't be much of a stretch to code if you've been following me up until now. Don't worry about having to rip the sprites from a gif- I'll include them all in zip from now on. Grab them HERE
Let's analyse what happens (in code) when a character picks up a
weapon. First we put the weapon somewhere on the screen. Say, at x:250
y;300, -anywhere'll do. Then we want to say "Okay, so if Rick is
touching the mc (hitTest) and we have DOWN pressed, pick up the weapon
(attach weapon to rick_mc instead of _root). But let's piss around with all of that later. Firstly, let's just get the art side working. Study the following picture;
Using a weapon also adds a couple of new animations for the rick_mc, one of him swinging the blade, and a single frame for picking it up. You can go ahead and add those right away to the end of your current mc. Make sure to name the frames that contain the new movieclips 'chop' and 'pickup'.
What you do is in the first frame you keep the stationary floor-based movieclip for Rick to pick up. You then stick cleaver1.png in one frame and cleaver1invert.png in another and align them up. In SplatterHouse the weapons only flash for about a millisecond, so in order to copy that effect you need to extend the first frame (by using F5) until it's about 20 frames long. So make a new movieclip symbol to do all that in ('cleaverflick'), and then go into 'cleaver' and add this new symbol to the first frame.
Good. Next let's deal with the 'pickup' frame. For this and the rest of
the cleaver animations, we have to be careful to orientate them
correctly with Rick. So instead of just plopping cleaver3.png anywhere
on the screen, we're going to make sure it fits Ricks hand by building
it in the rick_mc first.
Next we have to start making animated movieclips for the weapons. Get's trickier from here on in, so bear with me. Let's deal with the chop animation. Go into rick_mc, then into
the rickchop level. What you need to do next is create another
temporary layer, so Edit/Insert Layer as before.
Now select the entire layer so that every frame is blacked-in and
right-click Convert to Keyframes. Lock the layer that contains Rick
swinging with nothing and in the first frame of the temp layer drag
cleaver7.png to the proper place. 2nd frame, cleaver3.png, 3rd frame
cleaver5.png and ecetera. Right NOW, we have to make a symbol for the
new animations, so select the entire weapon layer again (so all the
frames are blacked out) then right-click CUT. Go Insert New Symbol/New
Movieclip/'cleaverchop', and within this new mc go to the first frame,
right-click and paste. We're not quite done yet though.
So there you have it, repeat the process for every animation, naming
each weapon frame the same name as the rick_mc frame to complicate
things a little less. Next up, let's get Rick actually moving correctly with the weapon, and following that we'll adjust the zombie code correctly to deal with the new death sequence. To start. Let's get that weapon on the screen. Go into your code, and at the very top type; _root.attachMovie("cleaver", "cleaver", 9 , {_x:250, _y:300});
Which attaches our weapon dynamically. We now have an mc we can
refer to by the name 'cleaver' at depth 9. Run the file and you should
see it appear, flashing away.
This is done by using attachmovie. As you might or might not know, all Flash is, is movies. Even the stage is an mc in itself, titled level0.
Put this code at the very top of your AS script.
function CheckForWeapon()
{
if(rick_mc.hitTest(cleaver) and rick_mc.crouch)
{
removeMovieClip(cleaver);
rick_mc.attachMovie("cleaver", "weapon", 9);
rick_mc.weapon.gotoAndStop("pickup");
rick_mc.pickup=true;
rick_mc.weaponheld=true;
}
};
So what this does is it checks for Ricks proximity to the weapon and if
he is crouching (rick_mc.crouch on its own is the same as
rick_mc.crouch==true). If so it deletes the cleaver movieclip from the
screen and creates a new instance of it, which is then set to the
'pickup' frame. We've also jus t created two new variables to rick_mc pickup and weaponheld,
and changed the mc instance name from 'cleaver' to 'weapon'. So
accordingly we should add them to the Initalise function for Rick.
function Initialize()
{
rick_mc.step=15;
rick_mc.attack = false;
rick_mc.stance= 1;
rick_mc.crouch=false;
keydown=false;
rick_mc.uvel=40;
rick_mc.gravity=6;
rick_mc.jump=false;
//New variables:
rick_mc.pickup=false;
rick_mc.weaponheld=false;
}
And put the following line within the main onEnterFrame event to check this function at the speed of the framerate.
if(!rick_mc.weaponheld) CheckForWeapon(); The next important bit is editing the section that deals with Rick crouching so that it can also be used for picking-up weapons. if (Key.isDown (Key.DOWN) )
{
if(rick_mc.weaponheld && !rick_mc.pickup)
rick_mc.weapon.gotoAndStop("crouch");
if(rick_mc.pickup)
{
rick_mc.gotoAndStop("pickup");
rick_mc.weapon.gotoAndStop("pickup");
rick_mc.pickup=false;
}
The rest is pretty straightforward, we simply need to add another check to every movement so that not only is the rick_mc frame changed but also the weapon frame. function Jump()
{
if (Key.isDown (Key.LEFT) )
{
rick_mc.stance=0;
rick_mc._x-=rick_mc.step;
}
else if (Key.isDown (Key.RIGHT) )
{
rick_mc.stance=1;
rick_mc._x+=rick_mc.step;
}
if(!rick_mc.attack)
{
if (Key.isDown (Key.DOWN))
{
if(rick_mc.weaponheld)
rick_mc.weapon.gotoAndStop("crouch");
rick_mc.gotoAndStop("crouch");
rick_mc.crouch=true;
}
else if (!Key.isDown () )
{
if(rick_mc.weaponheld)
rick_mc.weapon.gotoAndStop("jump");
rick_mc.gotoAndStop("jump");
rick_mc.crouch=false;
}
}
if (Key.isDown (Key.CONTROL) && keydown==false)
{
rick_mc.attack=true;
}
rick_mc._y-=rick_mc.uvel;
rick_mc.uvel-=rick_mc.gravity;
if(rick_mc._y+20 > ground_mc._y-115)
{
rick_mc.jump=false;
rick_mc._y=ground_mc._y-115;
rick_mc.uvel=40;
}
}
function Movement()
{
if (Key.isDown (Key.RIGHT) )
{
rick_mc.stance=1;
rick_mc._x+=rick_mc.step;
rick_mc.gotoAndStop("walk");
if(rick_mc.weaponheld)
rick_mc.weapon.gotoAndStop("walk");
}
else if (Key.isDown (Key.LEFT) )
{
rick_mc.stance=0;
rick_mc._x-=rick_mc.step;
rick_mc.gotoAndStop("walk");
if(rick_mc.weaponheld)
rick_mc.weapon.gotoAndStop("walk");
}
else if (Key.isDown (Key.DOWN) )
{
if(rick_mc.weaponheld && !rick_mc.pickup)
rick_mc.weapon.gotoAndStop("crouch");
if(rick_mc.pickup)
{
rick_mc.gotoAndStop("pickup");
rick_mc.weapon.gotoAndStop("pickup");
rick_mc.pickup=false;
}
else
{
rick_mc.gotoAndStop("crouch");
}
rick_mc.crouch=true;
}
else if (!Key.isDown () )
{
rick_mc.gotoAndStop("stance");
rick_mc.crouch=false;
if(rick_mc.weaponheld)
rick_mc.weapon.gotoAndStop("stance");
}
//Jump check needs to be out of the else..if loop or character
//will not jump while walking.
if (Key.isDown (Key.UP))
{
rick_mc.gotoAndStop("jump");
rick_mc.jump=true;
}
if (Key.isDown (Key.CONTROL) && keydown==false)
{
rick_mc.attack=true;
}
};
function Attack()
{
if(rick_mc.jump)
{
rick_mc.gotoAndStop("crouchkick");
if(rick_mc.weaponheld)
rick_mc.weapon.gotoAndStop("crouchkick");
}
else
{
if (Key.isDown (Key.DOWN))
{
if(rick_mc.weaponheld && !rick_mc.pickup)
rick_mc.weapon.gotoAndStop("crouchkick");
rick_mc.gotoAndStop("crouchkick");
}
else
{
if(rick_mc.weaponheld)
{
rick_mc.weapon.gotoAndStop("chop");
rick_mc.gotoAndStop("chop");
}
else
{
rick_mc.gotoAndStop("punch");
}
}
}
};
Chapter 7 will be all about health and damage. We'll give both Rick and the zombies the ability to lose health and die, aswell as cover dropping weapons when you get hit.
Questions/advice/tutorial errors: email to youngdude77@hotmail.com GO TO PART 7 | |