Tuesday, July 22, 2008

Creating Simple Enemy


In order to understand this short tutorial first read Character Elastic Movement and Adding mc speed using Numeric Stepper component posts. Next step is to create simple enemy and to animate that enemy.


We have new movie clip (green rectangle) that represents enemy in our game. Instance of enemy movie clip is on stage and that instance is named mc_enemy. First we want to create very basic enemy movement in single horizontal line. When enemy reaches stage end it changes direction. Before we define function for movement we want to give our new movie clip starting direction. Let’s make a deal : if direction has value 1, enemy goes left and if direction has value 2, enemy goes right.

Starting direction is determent by variable dir like this:

var dir:Number = new Number(1);

This will force our movie clip to start moving left when we define function onEnterFrame for movie clip mc_enemy. Function is simple, has 4 if conditional statement and they define simple enemy movement. We have modified coordinates where enemy movie clip changes direction for 15 pixels, which is half of movie clip’s width. In this way border bounce is better.




Download : file.

Next time we will see how we can detect collision between our Hero and Enemy.
Posted by flanture at 01:35:46 | Permanent Link | Comments (0) |

Wednesday, June 11, 2008

Character elastic movement


Flash game characters doesn’t have to move only in standard way, press left arrow key to move left, right arrow key to move right, space to jump etc. In this new flash game, main character (hero) will move differently. Hero will be dragable and on click, he will perform elastic move. Start position and destination position will be symmetrical in relation to Stage center. Enemy can be destroyed only if mouse is not pressed, otherwise, hero health will decrease.

Now, code. First we import related classes:

import mx.transitions.Tween;
import mx.transitions.easing.*;

We need to define simple onPress, onReleaseOutside and onRelease methods for movie clip of our hero, mcHero. Method onRelease has two functions, findSimPoint() and doTween(). It is obvious that findSimPoint() calculates symmetrical point of hero x and y in relation to Stage center. DoTween(), well, performs the tween! Code comes with comments.


Download hero.fla




Posted by flanture at 15:48:03 | Permanent Link | Comments (0) |