Archive for the ‘Programming’ Category

The Results of 3 Hours of Programming

January 29th, 2012 1 comment

So after doing 3 hours of programming from scratch I only have the bare bones of my game completed. I did manage to make my level select screen and the rest of the game is in much better shape than it was before. Unfortunately the new game is still a good 3-4 hours short of being a full prototype.

This is what I had after 45 minutes of programming

I think the lesson to learn from this is don’t attempt to complete a prototype from scratch in one sitting if you’re not a great programmer. Also, don’t start at 11 PM if you know staying up past 2 AM isn’t a realistic expectation. I’m guessing the people that do this from scratch thing probably have more tools than just basic actionscript 3 at their disposal. Once I have my game working again I may have to look into it to see what’s out there.

Unexplained Bugs

January 26th, 2012 No comments

My game has been on Flash Game License for a week now and in that time all 3 of my friend’s with fan accounts have logged in and tried it. The first one discovered the error caused by code encryption. The second one told me that they couldn’t figure out how to end turn, but after looking into that I couldn’t find an issue. The third one reported the same issue as the second one. So I dug a little deeper.

Apparently, moving units is causing the “End Turn” button to disappear. The third tester also found that when clicking on an enemy unit, the game completely locked up. I have yet to reproduce either of these things even when playing the game online on a different computer. So I guess it’s back to the drawing board on the buttons.

Additional Game Progress
In the meantime, I’ve been working on adding a level selection screen up front. It’s making me realize how bad a decision it was to treat the “Main” class as though it were the class for my battle screen. I don’t have a “destroy” function to quickly make everything disappear when I want to go back to the stage selection screen.

That’s a lesson for anyone starting on their first game. Make every screen the user might see it’s own class and make the “Main” class (the one that runs every time the game is opened) as minimal as possible. It should contain a static variable referencing the window itself and should create an instance of whatever class will contain your opening screen and then attach it to the window. That way when you switch up which screen your game opens with you only need to change which class is called. Don’t do what I did. You’ll have to rewrite most of it later.

Code Encryption and the Stage

January 22nd, 2012 No comments

So I’ve learned a valuable lesson when it comes to flash code and code encryption software. Don’t use the default “stage” variable outside of the initialization function.

So for those of you not familiar with flash, the screen that is displayed when you open something in flash is called the “stage”. It is created automatically when code is compiled and everything that shows up on the screen has to be added as a child of the stage. So if you want 3 airplanes to appear on the screen your function call should look something like this:

tempAirplane = new Airplane();

tempAirplane = new Airplane();

tempAirplane = new Airplane();

Encrypting your code is a necessary step when publishing a flash game, otherwise anyone could copy your flash game, decompile it, and change whatever details they wanted to pass the game off as their own. Unfortunately, when the code is encrypted some things may break. In the case of Kindisoft’s secureSWF, almost all references to the stage become broken. The only things that seem to be left intact are those in the initialization function that’s called the first time the stage is created. So keyboard events created during that time will stay intact and any children added to the stage at that time will be added, but from there on out, you will need to rely on adding children to the objects added during the initialization function. So I added a “stageSprite” object and then added everything else to that. My new calls to add objects look like this:

stageSprite.addEventListener(Event.ENTER_FRAME, enterFrame);
stageSprite.addEventListener(Event.MOUSE_LEAVE, mouseLeaving);
stageSprite.addEventListener(MouseEvent.MOUSE_MOVE, mouseEntering);
stageSprite.addEventListener(MouseEvent.MOUSE_DOWN, onClick);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);

tempAirplane = new Airplane();

tempAirplane = new Airplane();

tempAirplane = new Airplane();

Before the changes, my action menu stopped appearing when a unit was clicked and my onClick functions to select a target to move or attack stopped working. Post changes, everything seems to work great. Now that it’s working online with the code encryption I can start working on new things. Next step is creating a navigation menu to actually allow multiple maps to be selected from (right now it only loads one map that can be played endlessly). I also need to design a company logo to appear when the game loads. Any ideas for maps that might be fun?

Strategy Game AI

January 12th, 2012 2 comments

So I had an epiphany today. Up until this point I had been planning on using a Monte Carlo-like algorithm to create a near universal strategy game AI. I knew it was something I could do, but it would require a decent time investment and might take too long to run before it could actually generate a good quality turn.

Then I realized, I want the enemies to be zombies. And why should zombies have an intelligent AI controlling them? So I think I can make the AI in my game work in almost exactly the same way that my movement works. During the AI turn for each unit, I’ll start from what’s next to them and then fan out til I hit the first enemy. Then I’ll randomly pick one of the shortest paths to that enemy and move the unit as close as it can get during it’s turn. It’s so simple, but makes so much sense for zombies. I haven’t finished updating it for the AI, but here’s the code I have for determining the total movement area available for a given unit.

//******Set starting tile as character’s current position******
currentNewTiles.push(new Array(attachedCharacter.currentHorPos, attachedCharacter.currentVertPos));

if(startDistance == 0) {

moveSquares.unshift(new MoveSquare(new Array(), attachedCharacter.currentHorPos, attachedCharacter.currentVertPos, squareType));

mapCheckArray[attachedCharacter.currentHorPos][attachedCharacter.currentVertPos] = 0;

//******Iterate through each possible move******
for (var moveCount:int = 1; moveCount <= endDistance; moveCount++) {

oldNewTiles = new Array();
oldNewTiles = currentNewTiles;
currentNewTiles = new Array();

//******For each space that was reached during the last move******
for each (var oldCoord:Array in oldNewTiles) {

var oldHeight:int = Main.tileMap.mapArray[oldCoord[1]][oldCoord[0]].tileHeight;

//******For each posible direction******
for (var directionCount:int = 0; directionCount < 4; directionCount++) {

//******Set new coord equal to old + new direction, but won’t go off map******
var newCoord:Array = new Array(Math.min(Math.max(oldCoord[0] + xArray[directionCount], 0), Main.mapWidth – 1),
Math.min(Math.max(oldCoord[1] + yArray[directionCount], 0), Main.mapHeight – 1));
var moveBlocked:Boolean = false;
var oldMoveCount:int = mapCheckArray[oldCoord[0]][oldCoord[1]];
var isImpassable:Boolean = Main.tileMap.mapArray[newCoord[1]][newCoord[0]].impassable;
var movesRequired:int =
var newTeam:int;
var tempCharacter:Character = Character.getCharacterAt(newCoord[0], newCoord[1]);

if (tempCharacter == null) {

newTeam = -1;

else {

newTeam = tempCharacter.characterTeam;


if (isImpassable) {

moveBlocked = true;

else if((oldMoveCount + movesRequired) > endDistance) {

moveBlocked = true;

else if (newTeam != characterTeam && newTeam != -1) {

moveBlocked = true;


if (squareType != “MOVE”) {

movesRequired = 1;

if (moveCount >= startDistance) {

newTeam = -1;

else {

newTeam = characterTeam;

moveBlocked = false;

//******Check if tile was reached previously or impassable******
if (mapCheckArray[newCoord[0]][newCoord[1]] > (oldMoveCount + movesRequired) && !moveBlocked) {

bestPathArray[newCoord[0]][newCoord[1]] = new Array();

for each(var tempVar:String in bestPathArray[oldCoord[0]][oldCoord[1]]) {


if (newTeam == -1) {

var squareFound:Boolean = false;

for (var i:int = 0; i < moveSquares.length; i++) {

if (moveSquares[i].horPos == newCoord[0] && moveSquares[i].vertPos == newCoord[1]) {

squareFound = true;
moveSquares[i] = new MoveSquare(bestPathArray[newCoord[0]][newCoord[1]], newCoord[0], newCoord[1], squareType);


if(!squareFound) {

moveSquares.unshift(new MoveSquare(bestPathArray[newCoord[0]][newCoord[1]], newCoord[0], newCoord[1], squareType));


currentNewTiles.push(new Array(newCoord[0], newCoord[1]));
mapCheckArray[newCoord[0]][newCoord[1]] = oldMoveCount + movesRequired;





I’m using actionscript 3 for the code if you’re curious. And here’s the result of all that code.

What a beautiful movement area

If there’s anything you’re interested in learning about what I’ve done so far or about the game development process, let me know in the comments.

Categories: Programming Tags: