Friday, August 31, 2012

Failed Singleton Base Class

Failed Singleton base class:
package com.JM.baseClasses.designPatterns.singleton_baseClass{
 //A singleton pattern baseclass.
 //for any object that should never have
 //more than one instance.
 public class Singleton_BaseClass {
  private static var oneInstanceExists:Boolean = false;

  public function Singleton_BaseClass() 
    throw new Error("classes that derive from singleton can only be instantiated ONCE.");
    oneInstanceExists = true;

The idea was to make multiple singleton classes that could extend from this base class. And make it so you could only have ONE instance of each unique singleton class. This base class did not work, because all classes that extend from "Singleton_BaseClass" share the same static variables. I was hoping each class that extended from the "Singleton_BaseClass" would get a UNIQUE copy of the static variable "oneInstanceExists". This has not been the case. Idea to make this work: Make "oneInstanceExists" a dictionary instead of a boolean. Make classes derived from "Singleton_BaseClass" self-identify their type and load that type into the dictionary. The base-class constructor will check to make sure the type does not already exist in the dictionary. If it does, we throw an error.

Thursday, August 23, 2012

Sin Blast Pooler Class

This is a demo of a sin-wave based particle effect I coded. In order to code this effect I made a "sinParticle" class and then a compound particle effect class called "sinBlast". I then made a pooling class that holds "sinBlast" instances so that their instantiation is easy to implement and efficient on memory and processing power. NOTE: You need to wait about 3 seconds before clicking as the screen needs to get ready. I'll work on fixing this glitch later.

Monday, August 13, 2012

Liquid Boom Box

I made this as a demo for the collision class I wrote. All code written from the ground up in AS3.0.

AS3 Optimization: Rectangle Vector Vs. 4 Integer Vectors

Speed Test:

I honestly thought the vector of rectangles would be faster
because I am only accessing using an index ONCE vs FOUR times.
And I know that cutting down on that with the use of a temp
variable has helped me speed up things in the past.

For example:

is slower than:
temp = something[i];

Maybe the four vectors are faster because I am using integers?
And the rectangle type uses number type?

Anyways: I ran 3 tests:
5 vs 43 milliseconds
8 vs 68 milliseconds
4 vs 35 milliseconds

import flash.geom.Rectangle;
import flash.utils.Timer;

var t1:int;
var t2:int;
var tt:int;
var g:int;

//rectangle in vectors:
var T:Vector. = new Vector.(10);
var L:Vector. = new Vector.(10);
var B:Vector. = new Vector.(10);
var R:Vector. = new Vector.(10);


var VEC:Vector. = new Vector.(0);

for(var i:int = 0; i<10; i++)
	var t:int = 1*i;
	var l:int = 2*i;
	var b:int = 3*i;
	var r:int = 4*i;
	//Make vectors:
	T[i] = t;
	L[i] = l;
	B[i] = b;
	R[i] = r;
	//Make rectangle:
	VEC[i] = new Rectangle(t,l,b,r);

var retNum:int = 12345;
var rec:Rectangle;
var n:int;
var temp:int;

for(n=0; n

Friday, August 10, 2012

Liquid Bomb Surface LBS

Refactored an effects class I made so that it is easily instantiated. Reasoning: If I decide to implement this code 3 months for now, it will be really simple. Took about a day and a half to refactor everything, but it is worth it. I am going to use this code to create a missile defense game, a chain reaction game, and maybe an asteroid type game. It might be a little bit bad of me to use the same effect in all 3 games, so I will think of ways to edit my particle system when I work on the first game. Though the first game will NOT have any edits to the system as I just want the bear minimum required to make a missile defense game with these effects.