Tuesday, February 18, 2014

Spawny Twonk...

I had one simple aim for tonight's Game Maker session: make the traps spew out enemies. I started off by importing some temporary sprites for the enemy from the C64 version of Citadel, which also included "appear-from-trap" animations.It's a pretty straightforward process for a trap to generate an instance of an object - the real trick was to organise the enemy code so that the object can have different states (appear, patrol, destroyed, etc.).

Once the little blighter was successfully emerging from the gloom, it was time to add some rudimentary movement code. If you recall, the player in Citadel moves one square at a time, and the same is true of the enemies; thus, I looked for a way to allow the enemies to use the same movement logic as the player (rather than re-invent the wheel - or at least, duplicate wads of code - for every entity in the game). Luckily, Game Maker has a handy script system, which is essentially a function that you can call from anywhere but affects the object which called it.

Simply: say I had a movement script that adjusted the player's X and Y co-ordinates. If I call this from the player object, the player moves. If I call this from the enemy object, the enemy moves. Pretty neat, and a stellar way to modularize code.

In order to test the movement script, I then had to plug in some rudimentary AI - in this case, I made the enemy follow the player left and right (merely to check that the code was working and the enemy didn't try to fly through walls).

Flushed with success, I rounded off the night by starting on a rudimentary weapons system; after all, I'm not teaching the enemies to hunt me down unless I'm armed. :)