Posts tagged “algorithms”

◂ Back to all posts

Discrete physics on a 2D grid: back to basics

Last week, I talked about a fairly sophisticated attempt at solving my 2D discrete physics problem, which ultimately turned out to have unfixable flaws. But I need this problem solved for my game, so I decided to relax my requirements for the time being.

Continue reading

Discrete physics on a 2D grid: a dissatisfying solution

In last week’s post, I discussed my first two failed attempts at creating something like physics on a 2D grid. It gathered a good deal of attention on Reddit, with several replies from people claiming to have solved it, only to introduce new problems. As I already knew, this problem is surprisingly tricky!

Continue reading

Discrete physics on a 2D grid: how hard can it be?

In the last post, I described my requirements for a 2D discrete physics system I’m working on. Now that I’ve laid out what the system should do, let’s turn to the implementation.

Continue reading

Discrete physics on a 2D grid: setting the stage

For a new game I’m working on, I need some 2D “physics” that work in discrete time and discrete space. In other words: every object consists of one or more blocks aligned to a square grid, and time advances in turn-based steps. If you’re thinking of Sokoban, you’ve got the idea:

Continue reading

Twistago AI, part 1: Easy

This is the first part of a three-part series in which I explain how the artificial intelligence works in my latest game, Twistago. The AI has three different levels: easy, normal and hard. This is also the order in which I developed them, each level building upon the lessons and code of the previous, so it’s only natural that I do this writeup in that order as well, starting with the Easy level.

Continue reading

Terrain variations in Dragon Attack

Earlier this week, I added some variations to the procedural terrain in Dragon Attack.

Previously, the landscape was generated one segment at a time, forming a “chain” of rotated sprites. Each segment would have the same slope as the previous one, plus or minus a random number. To avoid going off the screen, the random number would be biased downwards near the top, and upwards near the bottom. This system worked great, but it made it pretty hard to implement variety in the terrain. For example, with just the previous height and slope as your “state”, how would you generate a mountain range?

Continue reading

A height map shader with only two texture lookups

Setup: suppose you have a monochrome texture that contains a height map. A value of 1 is highest, and 0 is lowest. You want to use this texture as a ‘bump map’ to shade a 2D polygon via GLSL, computing light and shadow from the gradient of the height map at any given point. Let’s assume there is a single light source, infinitely far away (so the light rays are parallel). This is the setup we use in the game Aranami.

Continue reading

The navigator

The Navigator is the part of the AI that is responsible for pathfinding. Actually, his algorithm is fairly straightforward. Given an objective by the Manager, the Navigator determines the shortest path through a series of waypoints that are defined in the level file, then hands each waypoint in turn to the Driver.

Continue reading

Driver code

There are a handful of racing games that let you race purely against your own best time, but the majority of them let you race against others. It adds an element of competition that you don’t get when racing alone. The solitary racer is someone who spends hours trying to figure out the optimal way to tackle that sharp corner, just to shave a tenth of a second off his best time. Not the kind of audience I’m targeting with a somewhat (albeit not completely) casual mobile racing game. Long story short, I need opponents.

Continue reading

Lid driven cavity

Since no existing code fit my requirements, I started working on my own fluid simulator a few weeks ago. The idea was to try both a grid-based and a particle-based method, and see which worked better for my situation. I started with the grid-based version.

Continue reading

Previous work

I looked around for existing code or libraries to do the fluid simulation for me. There are some, but most are either GPL-licensed or too expensive, so they are out of the question for a small-time independent developer like me. Some publications exist on the topic, most notably Jos Stam’s famous Real-Time Fluid Dynamics for Games from 2003. Mick West describes this algorithm in detail in his article Practical Fluid Dynamics. He provides a great overview of the basics, geared towards programmers. A somewhat more mathematical, but broader overview is in Michael Gourlay’s brilliant Gamasutra article Fluid Simulation for Video Games. He gives explanations of many techniques, their respective advantages and drawbacks. Many other interesting (academic) links are on the CFDtoy blog.

Continue reading