Free ActionScript

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

Advanced Weapon System

Made additional changes and improvements based on feedback from the community.

Change List v1.1.2

  • Sabdrenss128 helped optimize the remove object method
  • Added constants for weapon types
  • Optimized bullet/laser code
  • Removed laser memory leak bug
  • Other speed optimizations

Preview v1.1.2

Download Fla Sample

Download Fla Sample

Weapon Manager Methods

  • Add Weapon
  • Remove Weapon
  • Fire Weapons
  • Stop Weapons
  • Add Bullet
  • Remove Bullet
  • Add Solid Object
  • Remove Solid Object
  • Update Weapons
  • Update Bullets
  • Check Collisions

Weapon Methods

  • Constructor
  • Create Barrel
  • Fire Barrels
  • Update Rotation
  • Update Barrels
  • Create Display objects
  • Destroy Display objects
  • Destroy

Available Weapon Settings

  • ID
  • Skin
  • Current x, y, rotation
  • Max rotation speed
  • Reload speed
  • Bullet spread (accuracy)

Available Barrel Settings

  • Skin
  • Barrel Length
  • Current x, y, rotation

Available Bullet Settings

  • Skin
  • Bullet speed
  • Max travel distance
  • Bullet life time
  • Current x, y, rotation

Change List v1.1.1

  • Added Laser weapon
  • Gave bullets life timer
  • Removed unused vars
  • Added global shared vars
  • Updated package names

Refactored my AS3 multi-barrel gun code to be even more flexible using the Composition design pattern. This allowed me to create a weapon system that’s easily extendable to include different types of weapons.

Current implementation includes single, dual and quad barrel projectile guns and laser guns. Included weapon classes are easily duplicated to create additional different weapons. Laser guns can be set to pulse or beam settings. See examples for details.

I also added a WeaponManager class that handles creation, update and destroy functions of weapons, bullets and solid objects. Performs collision detection, display updates and more. Easily add your enemies thru the weapon manager and let it handle all the collision detection/reaction.

Added custom skin support for the Weapon platform, Barrel/Turret, Bullet & Laser beam. Laser beam is easily customizable as well.

Wish List

  • Give each bullet its own target
  • Fire one barrel at a time
  • Fire multiple bullets from one barrel
  • Add Guided Missile weapon
  • Better collision detection
  • Use interfaces
  • Add DisplayManager (perhaps use Blitting to draw graphics)
  • Use Vectors instead of Arrays

Projectile Weapon – Multi Barrel

A brand new AS3 multiple barrel weapon system written using OOP.

Available Settings

  • Number of Weapons – create multiple weapon platforms
  • Number of Barrels – each weapon platform can have multiple barrels
  • Weapon Rotation Speed – how fast the weapon rotates
  • Bullet Speed – how fast the bullet travels
  • Max Distance – how far the bullet can go before dying
  • Reload Speed – how long it takes to reload the weapon
  • Barrel Length – how far from barrel does the bullet starts
  • Bullet Spread – how accurate does the bullet fly towards target
  • Collision Detection – detect and respond to bullet collisions

Please note that this is the first version. It can be tweaked and optimized.

Preview

Download Fla Sample

Download Fla Sample

Update
Newer, better weapon script is available here:
http://www.freeactionscript.com/2011/08/advanced-weapon-system/

Projectile Weapon

AS3 update to my AS2 projectile weapon script. Features click-to-shoot (machine gun), collision detection, bullet gravity.

Available Settings

  • Bullet Speed – how fast the bullet travels
  • Max Distance – how far the bullet can go before dying
  • Reload Speed – how long it takes to reload the weapon
  • Barrel Length – how far from player does the bullet starts
  • Bullet Spread – how accurate does the bullet fly towards target
  • Gravity – gravity on/off

Preview

Download Fla Sample

Download Fla Sample

Update
Advanced multi-barrel OOP version of this weapon script is now available here:
http://www.freeactionscript.com/2011/08/advanced-weapon-system/

Flash Game Projectile Weapons

This is version 3 of my Flash game projectile weapons script. It is totally rewritten & optimized to support multiple weapons, multiple enemies & collision detection. All the functions are encapsulated for easy re-use.

Features:

Weapon

  • Number of bullets
  • Bullet speed
  • Bullet age
  • Reload speed

Weapon Management

  • Weapon Database
  • Weapon Database Search
  • Equip Weapon Function
  • Reload Weapon
  • Create Bullet
  • Update Bullet
  • Destroy Bullet

Enemy Management

  • Create enemy
  • Enemy Collision Detection with Bullets
  • Destroy Enemy
Download Fla Sample

Download Fla Sample

Update
AS3 version of this script is available here:
http://www.freeactionscript.com/2011/07/projectile-weapon/