design patterns

Articles tagged with 'design patterns' deal with me discussing my usages of design patterns. These patterns can mostly be found in Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides.

Nordic Adventure and the Mediator Pattern

When I wrote Fusion, one of the mistakes that bogged me down was that all objects were on a single layer - the backgrounds, player, turrets, bullets, enemies and explosions all intermingled in the same space. This made it difficult to independently work on each section, since there was always concern that my work would impact another section.

Fusion turrets - strategies and flyweights

On a side note, it's been two weeks since my last post? That's awful. I feel like I've had a lot to talk about, just haven't had the time to write an article.

The goal

I've been working on fusion a good amount lately, and one of the major pieces of development work is the introduction of 3 new turret types - lasers, missiles and machineguns. This is in addition to the original turret, which has now been renamed the cannon. Each turret type has some advantages and disadvantages:

Using trigger_error to deprecate old PHP systems

If you spend enough time writing code, you'll eventually come across a better way to do something and have the desire to replace all of your previous code with this superior method. Or, you'll find a block of code that you can quickly see is useless or redundant and you want to get rid of it. In both of these scenarios, simply removing the old code and putting in the new code seems like the obvious answer, but it's not always so easy.

The magic column pattern

Ever since I changed jobs at the start of the year, I've been far more cavalier with trying new techniques and seeing how they pan out. I don't know where this sudden devil-may-care attitude came from, but I suspect it's lifting the burden of old systems from my shoulders and a mirror of the approach I have taken with Fusion. The old systems were so ingrained in me that they almost became a force of nature unto themselves that couldn't be changed by a mere mortal code jockey like myself.

Decorator pattern, part 2

While working on wsilent, I quickly realized that the decorator pattern was ideal for weapon powerups. A ship object contains a weapon subobject (built using the template method, as described in an earlier article), and the weapon subobject can be decorated with powerups. These powerups can do things like cloning the bullets for a spread shot, or cutting energy / reload times for a rapid shot. The powerups can also be combined to form a rapid spread shot, and can be added and removed dynamically and independently of one another.

Using the template method pattern

In my last post, I talked vaguely about a project I'm working on. In this post, I'll actually name it. I realized it was foolish to link to my github profile on this site, while not talk about what is clearly available in that github account. The project is a fork of the browser game wpilot. My fork, codenamed wsilent, aims to be a spiritual successor to the old multiplayer game Silent Death Online.

First shot at the decorator pattern

I picked up the much beloved Design Patterns about 6 months ago, but have only had a chance to use some of them in the time since. Patterns like the strategy, factory, facade and adapter all have fit neatly into the projects I've worked on. But because of the nature of PHP development, many patterns simply don't fit in; this is especially true for patterns that are mostly relevant to run-time changes.