Jump to content


Gaming Question - Actions


  • You cannot reply to this topic
3 replies to this topic

#1 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 09 February 2007 - 04:12 PM

Ok, I'm making my first Flash game, woot! :D

So far I've gotten my character (Axel from Organization XIII of Kingdom Hearts, lol) to be able to move, jump, and use two different attacks (physical and a throwing attack).
I've even got a little Heartless AI, lol.

Now before I start making the damage system, I cannot figure out something.

For the attacks, I have them using a simple if to find if the key is down (control and shift keys for the two attacks), which is placed in the onClipEvent(enterFrame) loop. With this, the attacking clip only plays when the key is held, so it might not even display the full attack sequence, going back to the movement or standing frame. I need to have it display the full animation once per key stroke.

Here is my code for my character.

onClipEvent(load){
	power = 3.5;
	xspeed = 0;
	yspeed = 0;
	friction = 0.75;
	gravity = 1;
	thrust = 3;
}

onClipEvent(enterFrame){
	if(Key.isDown(Key.LEFT)){
		xspeed -= power;
		_xscale = -100;
		gotoAndStop('walking');
		_root.mugshot_mc.gotoAndStop('regular');
	}
	else if(Key.isDown(Key.RIGHT)){
		xspeed += power;
		_xscale = 100;
		gotoAndStop('walking');
		_root.mugshot_mc.gotoAndStop('regular');
	}
	if(Key.isDown(Key.CONTROL)){
		gotoAndStop('attacking');
		_root.mugshot_mc.gotoAndStop('angry');
	}
	if(Key.isDown(Key.SHIFT)){
		gotoAndStop('throw');
		_root.mugshot_mc.gotoAndStop('angry');
	}
	if(!Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.UP) && !Key.isDown(Key.CONTROL) && !Key.isDown(Key.SHIFT)){
		gotoAndStop('jumpDown');
		_root.mugshot_mc.gotoAndStop('regular');
	}
	
	xspeed *= friction;
	yspeed += gravity;

	if((_y - (_height / 2) - 6) > 0 && _y < 358)
		_y += yspeed;
	else{
		yspeed = 0;
		if((_y - (_height / 2) - 5) <= 0) _y += 5;
		else{
			if(!Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.CONTROL) && !Key.isDown(Key.SHIFT))
				gotoAndStop('stand');
			_y = 358;
		}
	}
	if((_x - (_width / 2) - 6) > 0 && (_x + (_width / 2) + 6) < 550)
		_x += xspeed;
	else{
		xspeed = 0;
		if((_x - (_width / 2) - 6) <= 0) _x += 5;
		else _x -= 5;
	}
	if(Key.isDown(Key.UP)){
		_y -= power * thrust;
		gotoAndStop('jumpUp');
	}
}

Edit -
Oh, I also would like to know how to spawn instances of my enemies? I can't seem to get duplicateMovieClip() to work.
I'll also need to be able to remove movieclips when my character kills them. I can make the _alpha fade to 0, but it keeps invisibly attacking my character because it's still physically there, lol.

Edited by Demonslay, 09 February 2007 - 06:58 PM.


#2 PixelHiveDesign

    Young Padawan

  • Members
  • Pip
  • 83 posts
  • Gender:Male

Posted 09 February 2007 - 09:12 PM

Action Animation Problem:
Have the key combo that activates the action sequence also set a flag variable. When the flag is set block conflicting animations from beganning, as well as prevent current animation from restarting. At the end of the action sequence animation, have the last frame unset the flag variable.

Spawning Problem:
Use attachMovie to put enemies on stage. Then you can use removeMovieClip() to permantly remove them.

To use attachMovie you must first find your enemy in your library, right click it, and assign it a Linkage name. Use the linkage name in the attachMovie function.

Good luck,

#3 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 09 February 2007 - 10:29 PM

Ok, I got the spawning working, I never knew about linkage, lol.
I've just given up on trying to remove the movieclips, doesn't seem to be working for me, so I just ran the damages the enemy does through a conditional that only gives damage if the enemy is at full opacity.

Now I've tried what you said with the flagging for the animation problem, but it's still pretty much doing the same thing, and I understand why, but don't know how to fix it.
It's basically checking each frame whether the key is simply pressed, and so if the key is released before the attack animation is done, it will go back to the default animation (standing), even though I've ran the flag through every conditional for standing and such.
I basically need something like onKeyDown or something, but I can't seem to get that to work.
Times I wish ActionScript was more like JavaScript, lol.

Edit-
Haha, just as soon as I posted this, I went back and found that my attacking flag wasn't being set correctly (at the beginning of the clipEvent loop, I set the _root.attacking variable to a simple variable in the frame, but then tried to manipulate that variable instead of the _root variable, lol). So now it works!

Thanks! :D

Edited by Demonslay, 09 February 2007 - 10:32 PM.


#4 PixelHiveDesign

    Young Padawan

  • Members
  • Pip
  • 83 posts
  • Gender:Male

Posted 10 February 2007 - 03:14 AM

Look up Listeners in the Help. They are the better way to handle what your doing.

Code would be like:

myKeyCapture = new Object();
myKeyCapture.onKeyDown = function(){
{ action code }
}

Key.addListener("myKeyCapture");


Of course all other states can be assigned functions as well. Anyway look them up.


Removing your enemies:

// Add a baddy to the game.
badguy = attachMovie("enemy_mc","badguy", 1);

// When good guy kicks ass. (course you might want a death animation before removal... but below is the key)
badguy.removeMovieClip();





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users