Handling Larger Maps in AS3

I have been working on some ideas for a TD game that would be both entertaining and original, and I feel that – with the help of a couple friends’ input – I’m on the way to something worth developing. Since I have already put together much of the “guts” for a TD game, I am hoping that I will be able to quickly put together a prototype in my free time. Ideally, once I have a prototype together, I will be able to find a sponsor to pay for development, and I would then be able to focus some solid time on the project, but that is a bit optimistic at this point, since we are still in the baby conceptual stage.

Without giving too much away on my idea, I’m going to try to cover some concepts and specific ideas that I have had to resolve in order to visualize different portions of the interface and interactions. The first thing I realized was, to fully succeed with the idea I want to implement, I would have to be able to support fairly large maps (in some remote cases, massive may be a better term). Having been a long time RTS (Real Time Strategy) player, I decided to take some cues from them and implement a similar map-handling system. Surprisingly, once things started falling into place, it was quite easy to tweak and get working to a satisfactory level.
Continue reading

Tower Defense in AS3 – Part IV

Many of you have been waiting patiently for this post, and let me say that I have worked many hours to get this where it is today. I wanted to get my code to the point where it was solid enough that I would actually publish something with it, and I believe it is there. Thanks to those who have encouraged me to finish this post, and I look forward to seeing how it is used!

In introduction, let me say a few things about this post: first, I have tried to alter my scope slightly in order to be more accessible to readers who may not have access to a full licensed copy of Flash. So, to help with that and make these lessons more accessible, I have decided to write them in such a way as to be compiled by the Flex SDK, a fully open source framework to allow anyone to build robust Flash applications. I prefer to use the full Flex Developer 3 for development and release, but even without it, you can compile full AS3 or Flex applications using only the SDK from the command line. One other major benefit to doing my development with Flex Builder is the ability to publish my source code for all to view online as well as download.

Obviously, this opens up the accessibility to a much broader range of individuals looking to learn Actionscript 3 or Flex. So, all this to say that the code in this post, while doing practically the same thing as the previous posts (and keeping the majority of the same logic), cleans up a ton of structural issues to lend itself more cleanly towards a completed project. That being said, we are simply focusing on the Tower object itself this time. I will leave it to your imagination and time to read through the rest of the cleaned – and fully documented, I might add – code. I may find time to write some more generalized posts on the Flex framework itself in days to come, but for now, suffice to say that the main file that is compiled as the application (in our case, called “MagicTD.as”) will be instantiated as the main() function and will serve as our entire platform base. You will notice on line 12 of this file all the variables needed to set up our SWF with the desired dimensions, background color and framerate.

So, without further ado, let’s jump right into our Tower class.
Continue reading

Tower Defense in AS3 – Part II

In this segment, we will be covering creep movement within a map, and to stay true with our original intent, everything in this tutorial will be drawn manually using the graphics package in the Sprite object within Flash. This way, we don’t have to worry about downloading images or the file size involved with such extras. Of course, were this a real TD game to be published, we would whip up some original artwork and animations to give our game a little more flair, but in this case, the simpler the better!

The code additions you can expect to find in Part II of this series include drawing our map (or “road”), creating and moving our creeps along that road and recognizing when a creep has completed the course successfully. Anyone familiar with Tower Defense games will recognize the importance of having a trigger to know when each creep finishes. Depending on the rules of your particular game, you may wish to have the creep run another circuit upon completion or simply vanish from existence, but in either case, there will be significant effects from that little guy getting away. Sometimes it costs us money to banish him back to the beginning, and in other games, we simply lose one of our lives and take one step closer to defeat.
Continue reading

Tower Defense in AS3 – Part 1

In keeping with my desire to learn as much about how the game development world works, I have spent some time looking into developing simple games in Flash over the course of the last couple years. Recently, I renewed my pursuit of this game medium, and I have been striving to learn some of the ins and outs of Actionscript 3. Having written a handful of basic Flash applications in Actionscript 2 — from the loader and controls of a full media presentation to an MP3 player and dynamic slideshow — I feel I had a solid understanding of the principles of Flash, both in the timeline, layering and scripting realms.

However, when I began working with AS3, whole worlds began to open up as I saw the potential unleashed by implementing a much more true OOP support into the code base. One of the most useful things that AS3 encourages is the understanding and use of the layering hierarchy of sprites and movie clips on the stage. As you add children to specific sprites or movie clips, they inherit their parent’s visibility spectrum and appear truly as part of that element on the stage. This may well have been a feature of AS2 as well, but I never took the time to learn that aspect deeply enough, since I did most of my work from modifying timeline animations.

I decided some time ago that one of the best ways to learn Flash would be to write a game that implements many of the features, such as vector layering and stage positioning. Furthermore, with my addiction to Tower Defense (TD) style games, I thought it only fitting to develop one myself and share my learning progress with others who may also be interested in the same type of application. This post is the first in a series that will follow my progress from manually drawing the GUI on which the game will be played (this post) to creating the basic Creeps and Towers which will make up the substance of the game. For those who are anxious to get started and don’t want to read everything in detail, I will provide a download link at the close of each post with the full source for the project to that point.
Continue reading