Game Weapon System Class (OOP)

Wednesday, November 25th, 2009 | Game Examples AS3, Weapon System | 1 Comment

I’ve been working on a weapon class to add to the space shooter game. Will post a demo as soon as it’s ready.

The weapon will be composed of independent systems: a targeting system (fire towards mouse, fire at closest target), a launching system (projectile, rocket, missile, laser), and an ammo loading system.

Each system will be completely independent and will not need to know how other systems operate to do it’s own job.

Here’s a little diagram to make it easier to understand (work in progress):

Weapon Class Diagram

Tags: , , , , ,

Player Movement with Velocity

Monday, November 9th, 2009 | Game Examples AS3, Space Shooter | 2 Comments

Expending on the previous space shooter example, I’ve added velocity to player movement.

› Continue reading

Tags: , , ,

AS3 Basics - Naming Conventions

Monday, November 2nd, 2009 | Basics, Game Examples AS3 | No Comments

Use precise, meaningful, contextually relevant names that are as descriptive as possible. Limit the use of unnecessary abbreviations.

    Example: defaultImagePreview
    NOT: dfltImgPrv

Start each instance name with a lowercase letter, and intercap the remaining words.

    Examples: menuItem, sectionTitle

Apply the same conventions to variable names.

    Examples: accountNumber, startingPoint, currentProductName

Begin a class name with an uppercase letter. Write class names in mixed case when it’s a compound or concatenated word. Keep package names as short as possible, using reverse domain naming conventions.

    Examples: com.client.project.component.ClassName

Name functions and methods in the form of verbs, since they perform actions.

    Examples: getUserName(), calculateTaxes(), createSubMenu()

Name booleans with an appropriate, positive prefix, such as “is”, “has”, “can”, or “should”, for an easier determination between true and false.

    Examples: isSoundOn, isFinished, isOpen, isLoggedIn, hasLicense, canEvaluate

Use complement names for complement entities: get/set, add/remove, create/destroy, start/stop, insert/delete, increment/decrement, old/new, begin/end, first/last, up/down, min/max, next/previous, open/close, show/hide.

    Examples: getUserName, setUserName
    addThumbnailImage, removeThumbnailImage
    showAnimation, hideAnimation

Private variable names may be prefixed with an underscore or $ symbol as long as consistency is maintained.

Tags: , , , ,

Center MovieClip based on browser size

Monday, October 19th, 2009 | Game Examples AS3, User Interface | No Comments

Put the code below on the first frame of your flash movie. Add a movieclip to stage and give it the instance name “myMovie”. This AS3 code will dynamically center your movieclip based on browser size.

?View Code ACTIONSCRIPT
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
 
function resizeHandler(e:Event):void
{
  myMovie.x = (myMovie.stage.stageWidth / 2) - (myMovie.width / 2);
  myMovie.y = (myMovie.stage.stageHeight / 2) - (myMovie.height / 2);
}
 
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, resizeHandler);
 
stage.dispatchEvent(new Event(Event.RESIZE));
//the end

Tags: , , ,

Simple Accordion Menu

Thursday, October 15th, 2009 | Game Examples AS3, User Interface | 4 Comments

This is a very simple accordion menu. It uses the free TweenLite tweener for movement.

› Continue reading

Tags: , , , ,

Custom number range sliders

Friday, October 9th, 2009 | Game Examples AS3, User Interface | No Comments

I needed a custom range slider for selecting prices. It needed to have two draggers. One of low price, one for high price. Here is the result.

Low and High value is calculated based on the size of the slider track.

Easy to use and easy to customize. Only 3 movieclips make up the whole thing. Doesn’t use annoying built in flash components.

› Continue reading

Tags: , , , , , , , ,