Tag: Tower Defence

“Tower Defence” update!

I’ve spent a lot of my downtime the last few days crawling through C++ in a debugger and gathering crash data via adb from my tablet with the aim of fixing threading bugs! A few core classes lightly stripped down and occasionally rewritten, a few things jiggled about and we have something that’s stable [on Windows].

I left several copies of this code running the other day as a test — none explicitly crashed, although there are persistent memory leak issues over time which eventually lead to a freeze on the second thread, which does a lot of the work.

But in my testing all the sessions ran for at least half an hour at double speed (only a debug option right now, sorry), notching up an impressive health of over -5000. Besides the threading fixes everything else is basically the same as in the previous demo, so still lots of unfinished/unfixed/placeholder content and code.

Download this new demo of Tower Defence.

“Tower Defence” release

Progress with Tower Defence has been slow recently with moving and the general disruption that brings, but the other day I did manage to settle in and resolve a few long standing nasty bugs which brings the game to a much more playable level. As such, I felt it might be prudent to make a demo available so people can actually try this thing out themselves rather than watching my boring videos.

I’m a long way from guaranteeing it’s crash free. There are also bugs galore (see full release notes after the break), and a few things are disabled for being either half implemented or inconsistent in performance or reliability, but it gives an impression of the project. This release is in the form of a Windows binary, although if there’s any interest in OSX/Linux/mobile builds I’ll happily crank one out and you’re welcome to see if it works.

Download build 43.

Continue reading ““Tower Defence” release”

Tower Defence prototype code

Today I’m happy to offer some code from my early prototypes of “Tower Defence.” It’s super basic: No maze generating algorithms yet, not much in the way of gameplay.

A random maze is created (i.e, each map tile is 50/50 whether its walkable or not), start and end points generated and a route found between them using A*, and an “enemy” (green square) moves along the path. You can create a single weapon type – the gun – which fires very slow moving bullets at the enemy.

This code also contains remnants of my quick and dirty collision system, though Box2D is actually running the show.

Untitled

Continue reading “Tower Defence prototype code”

Haxe ColorTransforms

Within the nme.geom package of Haxe NME you’ll find Matrices, Points, Vectors, Rectangles and… ColorTransform? It seems a slightly odd place to put it but it can be useful in your project to dynamically alter object colours. I wanted to talk briefly on how I’ve used it across my previous Pinball project and now, in Tower Defence.

Sometimes you want the same object to appear multiple times in your project, but with subtle variations. Behavioral changes can be accomplished in code by subclassing, size variations by scaling, but what if you wanted it red in one instance and green in another?

Including the same image twice with different colours feels redundant even if the images in question are quite small, so what are your options? In Pinball I used ColorTransform to colorize the lights and lighting effects with the image files themselves being greyscale. Now in Tower Defence I’m using it on some UI elements (the slider knob’s that change colour dependent on value).

Let’s step through how this works. First, of course, you have to create a graphic you want to use. Here’s the image of the slider knob in Tower Defence, as it came out of Photoshop…

radio_btn_mid

Continue reading “Haxe ColorTransforms”

Removing bodies in Box2D

Hello, today I bring you another lesson learnt.

When you choose Haxe for a project there are a few 2D physics engines available, mostly ports of other popular engines like Box2D. There are actually a few distinct ports to Haxe of various versions of B2D, but the most up-to-date and the one I’ve been using is Joshua Granick’s port of 2.1a. You can get it from Haxelib by opening a command prompt / terminal and running “haxelib install box2d”

In brief, it’s fantastic. Once you get a handle on how it works and where all the bits you want to use are it’s pretty simple, a far cry from the engine I initially experimented with – Physaxe – which was basically 20 pages of pure maths disguised as classes and functions! But there are some small issues I’ve run across while using it, and here comes the latest.

Continue reading “Removing bodies in Box2D”

I’ve been implementing a second thread of execution in my current game project for the last few days. I had already tried and mostly failed to do this in a previous project.

At that time there was almost no instruction online as to how threads worked in NME, but that has changed recently thanks to the (always excellent) Joshua Granick, whose blog post, “Using Threads with NME“, lists out some basic scenarios for communication between threads. There’s also some useful nuggets of information in this forum thread.

Continue reading “Thread synchronization in Haxe NME”

In my new “Tower Defence” project I need to know when certain things are touching, or when object A is within range of object B, and other nonsenses like that.

In the early days of this project I implemented a collision system again with just two shape types: Rectangle and circle. It worked well enough, but the performance was awful. I had knocked together a few arrays and an update loop, but more advanced stuff like knowing which objects could be safely ignored to speed the whole process up takes time to write and test. Having experience with it previously, I  dropped Box2D in to my project so I could begin prodding.

Continue reading “Using Box2D as a collision system”