Category Archives: Software

BrakeNeck One Month Game

Last year my good friend, Victor Chelaru had the idea to try to build a small video game in a single month. The goal was to create a game that was fun and polished, but also to identify and fix workflow problems and bugs that slow down the dev process.

We tabled the idea for a few weeks but resurrected it in December. On Dec 19 we committed our first rough ideas to github, determined to finish a small game by Jan 19. We wrapped it up on schedule! I’m proud of how it turned out. It looks neat, is fun to play and was accomplished in a very short amount of time.

This game is open source and uses the FlatRedBall game engine. It’s also a free starter project built into the FRB tools.

Youtube
GitHub
Starter Project

Snapchat: Get Off My Lawn

WE recently hired a 30 year old, single, male software developer and an 18 year old, single, female admin assistant. Both of them are active users of Snapchat and were eager to show me how it works. I downloaded the app, added them as friends…and never used it after the first week.

It’s not that I don’t like its functionality. It just bores me. And it has no place in my life. I tried to think about why it’s a useless app to me and I realized: it’s because I’m old, married and “uninteresting”. Normally I’d find that depressing but in this case, it was a positive realization.

I hate Snapchat because it’s exactly counter to the life I have built. It’s transitory, unsubstantial. You capture a memory and, moments later, it’s gone. I remember when life was like that. Relationships were short term. Time was not super important. And I was eager to leave bad decisions in the past without a lot of evidence they happened. Snapchat fits that lifestyle. Snapchat makes it difficult or impossible to post photos from your gallery. It forces you to take extra action to save a photo, otherwise it’s gone forever.

I don’t have that life. The significant and interesting memories I make are perhaps fewer in quantity, but greater in quality. The relationships I have are long term and the passage of time is a burden I feel more keenly. The memories I capture, I want to keep.

I want to back my photos and videos up to Google’s cloud. Forever. I like how Google creates “remember this day” galleries. I want to remember those days. I want to pause more and enjoy the good times I’ve had with friends and family. I want to keep those memories fresh, not discard them seconds after they’ve happened as if I have an endless amount of time for disposable memories.

Maybe that’s not just getting old? Maybe that’s maturity.

Authorization Errors with WordPress API

I have wanted to explore the use of WordPress as a back end for Single Page Applications for some time. I installed the WordPress REST API v2 and have tried various types of authentication. I’m not a big fan of OAuth so I originally tried Basic Authentication just to get things working. GETting page information worked just fine with or without authentication because GET requests generally don’t require auth. However, POST or PUT requests would fail with a 401.

I thought maybe it was because the Basic Authentication plugin was pretty old and not well tested with the latest version of WordPress. So, I also tried using Application Passwords, which is cooler and safer anyway. Unfortunately, I only got 401s with that too.

After much Googling with few results, and having minimal time to pursue information, I gave up and moved on. Recently, however, I’ve had renewed interest in being able to interact with WordPress via an Angular2 app. I dusted off my test blog with the WordPress API installed and started poking at it again. I crawled through the REST API plugin code to try to figure out why authentication was failing and found the “rest_cannot_edit” message in the class-wp-rest-posts-controller.php file. After tracing the path of authentication through WordPress core and plugins, I became suspicious that authentication was not even being attempted. I serialized the $request object available to the permissions check methods and returned it with the 401 response. Sure enough, no authorization header was present in the request object!

I took my inspection higher and realized that the Authorization header was being stripped at the server level, before WordPress or even PHP could use the information. I’m aware that some shared hosts do this but I was testing this on a VPS. I did not expect my VPS provider to have that set up by default. I found some .htaccess rules that would work around this but they didn’t seem to work (my .htaccess skills are rusty at best).

After going down a couple of rabbit holes related to server settings and PHP configurization I contacted my server support team via live chat. While waiting for them to respond I took another look at the .htaccess file and moved some stuff around on a whim. To my surprise, my next Postman request returned a post object with an updated title!

So after all of my work and suspicions that plugins were outdated, my password was wrong and a hundred other false leads… it turned out to just be an annoying server config that was not mentioned on any wiki I could find on my provider site.

So, if you have 401 Not Authorized response on all WordPress Rest API requests, you’ve checked your username, password, base64 encoding and header formatting…it’s probably your hosting provider and it may be possible to allow the HTTP Auth via your .htaccess file. WordPress’ .htaccess file looks like this out of the box:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Update it to look like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Enable HTTP Auth
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

# END WordPress

The [L] at the end of those lines means “last” so the server will stop processing the file after the wordpress conditions are met, before the auth rule is applied. So, the auth rules need to come before the WordPress default rules or they will never be applied!

Hopefully this helps the next person, I wasted a lot of time on this.

Isometric Occlusion

I ran a tech blog called SyndicateX for a long time, which had an Isometric Occlusion post. I was cleaning up a hosting account and I rarely wrote posts so I just took the blog down and redirected the domain – destroying the Isometric Occlusion post. I didn’t think anybody would care. Later I discovered that I was getting quite a few visitors looking for the post… So I started this blog and am reposting the Isometric Occlusion content for all you searchers!

Occlusion basically means “blockage” so when I say Isometric Occlusion I’m referring to the process of figuring out when objects are/should be blocking other objects in an isometric game. Isometric games simulate 3D in a 2D space and buildings can be dynamic shapes so there’s no magic calculation for how occlusion should be applied.

A few years ago, before I discovered Satellite Reign, I wanted to build a game that would be an homage to Syndicate by Bullfrog. I started working on a game called Animosity Inc and posted this video:

A few people asked how I did the isometric occlusion and managed depths of characters in 2D space, to simulate 3D. I think there are potential issues and maybe better ways to handle this but here’s how I did it a few years ago. the image below shows a node network, which civilians move around on, choosing nodes at random to wander the city. The player characters can also move around the city, sometimes rendering in front of buildings, sometimes behind. As a player character moves behind a building, the structure should fade so that you can see your character. In the picture below, the player (green circle) is behind a building that is faded out. Civilians (red circles) move from in front of a building to behind it, rendering at correct depths.

Civilians move around the city on a node network.
Civilians move around the city on a node network.

Each isometric building has two polygons. The green polygon is the Occlusion poly. The red polygon is the Collision poly. The small orange circle under the character is their Collision poly. Each update cycle two collisions are performed. The character is not allowed to move through the building footprint so it has restrictive collision that alters movement. The character is allowed to move through the occlusion poly but the building should fade out. So in that collision event I change both the building’s alpha value, as well as the character’s Z depth. I move the character sprite behind the building sprite if colliding so that the building renders over the character. This is less important for player characters, which make the building fade, but very important for civilians, which move around the buildings and don’t cause occlusion events.

Occlusion collision diagram.
Occlusion collision diagram.
  • Civilian 1 is not colliding with anything. It is rendered on top of everything
  • Civilian 2 is occluded by the building. It’s drawn just below the building depth so it appears behind
  • Civilian 3 is in front of the building. If he tries walking straight upwards, he will collide with the building footprint before he collides with occlusion. This is important because he shouldn’t be drawn behind the building, which will happen if he collides with the occlusion polygon.
  • Buildings have two sprites: the “footprint” sprite that shows the building’s footprint on the ground, and the building sprite that fades out.

I have no idea if this will work at scale. There are probably better, more efficient systems but this was what I came up with a few years ago. Good luck and let me know if this system does or doesn’t work for you!