Free ActionScript

Flash AS2 & AS3 Tutorials, Game Code, Effects, Source Files & Sample Downloads

Smooth 4-way Player Movement

This Flash game example shows you how to create smooth 4-way player movement with acceleration & friction. This fla also shows you how to create a screen-wrap effect (think asteroids).

Custom Settings:

  • max velocity
  • acceleration
  • friction

Preview

Download Fla Sample

Download Fla Sample

Multiple Key Press Detection

Here is a simple fla example of multiple key press detection. It also shows you how to setup 4 way player movement using Arrow Keys and WASD.

Preview

Download Fla Sample

Download Fla Sample

Target Closest Enemy MovieClip

I’ve been thinking about how targeting the closest enemy would work and started experimenting with the algorithm. Basically AS has an array method called sortOn, that sorts objects properties in any order you want. Well, that’s the catch. It only sorts objects, not movieClips.

The work around is simple enough; when creating a new enemy object, just save a reference to the movieClip on stage inside the object’s property.

Preview

Download Fla Sample

Download Fla Sample

Update:
ActionScript 3 version of this script is available here:
http://www.freeactionscript.com/2011/07/game-enemy-manager/

Game Navigation Engine – Player movement

Game Navigation Engine Features

  • 4 directional player movement
  • Multi key press detection
  • Player rotation
  • Acceleration/deceleration

Preview

Download Fla Sample

Download Fla Sample