Posts in Category: Uncategorized

A* Pathfinding In Game

I wrote a post on implementing a simple A* Pathfinding algorithm a couple months ago. When I went to add it to my game I ran into some interesting differences I wanted to write an update on.

Here is the algorithm working on my game server. Both player and NPC are red blocks. When the player is within viewable range of the NPC, the NPC will start chasing it.

The pathfinding algorithm allows the NPC to maneuver around blocked tiles.

Coordinate to Tile Mapping

One thing I discovered while incorporating it into my game was my simple example had a 1:1 coordinates to tile ratio. Coordinates 0,0 was the first tile, and 0,1 was the second tile. When tiles were 16×16 pixels, the coordinate to index mapping broke.

To address this, I needed to pass  map width and map height in tiles, as well as the tile size so it was known when a new row started and the bounds of the map.

I did this by creating a map struct that contained the width, height, size, and pointer to the tile vector.

Game Jam #7

Reeeally late in posting this, but I’m determined to post about my game jam back in July where the theme was time manipulation. The dynamic was a little different, I had an “idea person” to help move the creative process along and blocks. I was paired up with Jacq, sound engineer and creative mind. After a few iterations of rehashing the fundamentals of our game, we finally came up with a platformer that fit  the theme. From this experience I had some takeaways to apply to my next jam.

Idea People are AWESOME
Having a person to handle the brainstorming while you’re coding has its benefits. It’s easier to cut and run when hitting a wall, as the other person has already been thinking into alternatives, opposed to wasting time on something that just isn’t working because you don’t have any better ideas.

Skillsets can become dusty
This was a frustrating lesson to learn. After not touching Flixel for a month and a half, working with basics like movement and sprite placement was more difficult than it should have been.

There’s an easier way to prototype
My toolset has been pretty low level. I use ActionScript, and while I utilize the Flixel framework with libraries, it still requires a lot of coding. At the end of the jam I surmized I would have developed my prototype faster with a prototyping framework such as Construct 2 or Stencyl.  Both allow the rapid prototyping of platformers, such as this one without coding.

For those interested, the source and demo can be found here:

PHPUnit with YAML

After diving into some database integration testing, I found that my data model was incompatible in a XML format. Using hash tags is a no-no, as it’s against XML specifications. Well darn, what is a coder to do? YAML to the rescue.

First, what is YAML? Besides it being fun to say, it’s a “human friendly data serialization language”. HFDSL doesn’t sound as cool as YAML, and just like PHP, you shouldn’t look to far into the acroymn, less you are fond of infinite loops.

“YAML is a recursive acronym for “YAML Ain’t Markup Language“. Early in its development, YAML was said to mean “Yet Another Markup Language“,[3] but was retronymed to distinguish its purpose as data-oriented, rather than document markup.” – Wikipedia

Fantastic, moving on…

PHPUnit uses YAML as a supported format for creating datasets. Tables, columns, and rows are split up using colons, dashes and spacing to define your database objects. For example, let’s say we have a dataset of books.

books: #table name
  - #begin a new record, followed by key: value pair
    id: 1
    title: Moby Dick
    author: Herman Melville
    id: 2
    title: The Hobbit
    author: J. R. R. Tolkien

This will add two rows to the table books with its respective data.

YAML can definitely be easier to read in some scenarios, as there is less to read. After using it for a couple months, it has kind of grown on me as well. It is a nice format to use  for config files when XML is overkill.