Here it is.
Category Archives: Prototypes
Codify Dungeon Roller
Made this on the plane flight to Singapore. Shows some of the new features in Codify 1.1
Can You Express a Concept with Game Mechanics Only?
This game came out of an argument about whether one could design a game to express a specific idea using only game mechanics. My argument was that you can’t – that you need to at least imply some relation to the real world to express ideas.
So that night I decided to spend a few hours prototyping an abstract game based on my idea of “supply and demand.” You can play it here.
I’m not sure whether I succeeded. I’ve asked people to play it and tell me what they thought it represented, some of the answers I received:
- Bacteria
- Social Networks
- Finance
- Balance
Out of those, balance was probably the closest to what I intended to express.
Cartoon Styled Explosions
I wrote this processing prototype to generate cartoon styled explosions for our next game. It took about two hours to get the basic burst effect. I’ll be adding debris trails and smoke to it when I next get some time, as well as PNG sequence output. For the moment you can click the link below to try the demo for yourself and get the source code.
The base effect consists of additive and subtractive expanding circles, with some randomness. An initial additive burst creates the colour, which is subtracted by using a delayed subtractive burst. There are many magic numbers and it’s hacky code, but it’s only for PNG sprite output.
Let me know if you find it useful!
Click here to play with the Processing demo – also includes source code. Left click to make an explosion, right click for a random colour explosion. Left clicking while an explosion is in progress will pause the effect.
Conveyor Belts and You
I recently had to implement a 2D conveyor belt animation in code, where sprites had to rotate around a capsule of any size with a constant velocity. It turns out it is pretty simple, but it required a few hours to figure it out. I’m posting the math here for anyone who is interested.

This is an image of what I am talking about. (Sorry about the MSPaint artwork, I’m just a programmer!) This shape is defined by 2 parameters. L, the length of the line on the top and bottom, and r, the radius of the half circles.
Here is another image with more labels and examples of the sprites rotating around.

There are 4 points marked here: t1, t2, t3, and t4. They are at the positions where the half circles at the ends meet the line segments joining them. The boxes are sprites and are supposed to be equal distances apart, and the arrows show the motion involved.
First thing to notice is that the structure is symmetric about 180 degree rotations, so for now I’ll just work on half of it.

I’ll work in units from t=0 to t=1, where t=0 is the point t1, and t=1 is the point t3.
You might recall that the arclength of a segment of angle a (in radians) on a circle of radius r is a*r. This means the length around the end from t1 to t2 is pi*r (another way to think about that is that its half the circumference of the circle).
The length from t2 to t3 is L.
The trick to the solution is finding the value of t2 from [0,1], then interpolating on the circle or the line depending on which side t lies.
Of course, we could set t2 to anything, but if it is too small, then the sprites will zip around the circle too fast (and slow down when they reach the line segment), or if it is too large, then the opposite will happen (they will speed up when they reach the line segment). We want to find the value of t2 that will maintain a constant velocity around the corner and along the edge.
Seeing as the total length around the corner and along the line is 1 t unit, we can equate this to the length in physical units. This is L+pi*r. Ie, converting from physical units to t units means we have to divide by L+pi*r.
Now, the point t2 is the proportion of the distance around the corner with respect to the total distance. This is pi*r/(L+pi*r) in t units.
So now, we interpolate the angle and calculate the position on the circle for points with 0 <= t <= t2. ie,
a = -pi/2 + (t/t2)*pi*r (the angle in radians around the half circle, starting at -pi/2 and going to pi/2)
p = (cos(a)*r+L/2, sin(a)*r) (we add half of L to x in order to move it right)
(assuming we are using the center of the capsule as the origin of the coordinate system)
As a side effect, we can also save a in order to rotate the sprites when we render them.
Now, if t2 < t <= 1:
a = pi/2
p = ( lerp(L/2, -L/2, (t-t2)/(1-t2) ), r) (lerp means linear interpolation, ie go from (L/2, r) to (-L/2, r) as t goes from t2 to t3)
That is it for half of the animation. Now you just need to modify it, so that it is flipped for t from 1 to 2
if t>1: #assuming t < 2 still, though I guess you could just take the fraction part
t -= 1 #make t go from 0 to 1 again
p, a = calculate pos as above
p = (-p.x, -p.y)
a += pi
And that is it. Good luck if you use this! It makes for a neat effect.
This was originally posted to my blog, dylansale.tumblr.com

