Politics Mechanics

ASDW KL:O 4628 ←↑→↓



This week’s mechanic was inspired by the Ontario Provincial Election that took place the day after our meeting. Each of the four parties captures their votes by “talking” to voters. They are also able to steal voters from other parties, though that takes a little longer to do.

Development for this mechanic was interesting, in that we split two groups, one working in Unity, the other in Orbit Engine. This article reviews the Unity version. In particular it focuses on three implementations: Unity’s Polygon Collider, Zoom in algorithm, Player Collision physics side effects, and Image Tiling.
Unity’s Polygon Collider

I decided it would be pretty cool and simple to make the all the players be constrained within the boundaries of our province. To accomplish this, I used a halfway decent but lightweight free paint program Paint.net, used the magic wand tool to make a giant hole where the province is, leaving just the water. Then I imported this into Unity, and added a new component, Polygon Collider 2D.

Zoom in algorithm:

A basic concept we applied was orthographic projection (see the linked video time index for a good example of the difference between that and it’s cousin) . A simple algorithm inspired by Zack was employed that zooms in based on how far apart players are vertically and horizontally. This is achieved by simply changing the camera’s viewport size.

Player Collision physics side effects:

To actually make the voters appear, they are spawned at run-time to avoid having to manually create 100 to 200 voters. In typical game jam mentality, a simple loop iterates instantiating them in random positions, which so happen to overlap. Since the project is setup to obey 2D physics, this is actually an illegal state for the physics engine to emulate. However it interestingly remains stable until a collision occurs, which happens when a politician first wanders over bumping into them, causing the engine to do a domino effect until there are no more collisions to occur.

 

Image quality:

Another issue I contended with was the low quality images of our province. For mere online browsing it’s fine, but it immediately looked terrible the moment it was applied in game. It got significantly worse once the zooming feature was implemented. What I wound up doing was first up-scaling to vector with a random site I found online. Next I saved as a set of tiles at maximum resolution of 4096×4096, 16 of them in fact. This prevents the horrible pixelation that occurs when zoomed in. Interestingly this is by far the smallest deployment build, at only 350KB total. So while it takes an annoying few minutes to load in Unity on my older laptop, it still deploys excellently to web.

Anyone interested in examining the source code can see it here in our repository on GitHub. If you’re interested in participating in our club, come to our regular meetings, posted in the top-right corner. We’d be happy to explain more.

Credits:

I implemented all the code. Dante saved the game idea itself (I wanted a horrible political-RPG mechanic). Zack persuaded me that zooming was to implement. Morgan drew the basic cone shape.

Nastajus

About Nastajus

Recommended resources -- Moderate coders benefit from this: http://unitypatterns.com/ -- Intermediate version control: SourceTree -- Beginner version control: Github for Windows or Mac

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>