The Double conversion dance in Swift

The Double conversion dance in Swift

Today’s game tasks included a fun algebra formula that we all learned in grade school.  Fun you say?   Well, yes!   The Distance Formula computes the distance between two points.   Here it is –


Pretty easy to follow.   Take the x position of first and second points and the y position of the first and second points and plug them into the equation, then take the square root of the result.

Why am I employing this equation in the DuneTraveller game?   Well, I want the player to “search” around his current location to look for hidden clues and items.   To know where to search he has to have been told to search somewhere OR he could just be hitting the “S” key on his own in a shotgun approach to finding stuff.

When the current level loads, I read and cache all of the hidden search points and when the player hits the “S” key (“S” is for search!) I loop through the cache and compute the distance from the player to each one of the search area points.   If the distance is less than or equal to the declared radius then the item is revealed.  It could be a hidden note, or maybe even some loot.

The problem I encountered is the rather dearth of conversion functions in Swift.   The second problem is that the output of some of the built in math functions is inconsistent. “pow” which is used to compute something like “what is 4 squared?” outputs a decimal.  However “sqrt” takes a double.   Turns out there is no direct conversion in Swift.

Thanks to this post on Stack Overflow the code looks like this –

Screen Shot 2020-04-21 at 3.30.33 PM

You will also notice I still wasn’t finished with my conversion party after getting the square root.  I had to cast the searchRadius (which is an integer) into a double before performing the comparison.

It’s fun learning a new language’s quirks.

Dune Traveller – progress for April 2020

Dune Traveller – progress for April 2020

Since leaving in March 2020, I have not been sitting around watching TV and playing video games – I’ve been writing one.

The week after I resigned, I –

I’m excited about everything I’ve learned because it seems like I’m making real progress.

Unity – First Impressions

Unity – First Impressions

While studying game development over the past few years, I regularly come across articles on Unity.  For those of you who don’t know, Unity is an extremely popular game development software development kit that enables you to create cross-platform games. I took a break from my own game development on the Mac platform using SpriteKit (which I will return to very shortly) so that I could get a feel for Unity.

The book I bought to help me, Patrick Felicia’s “Unity 2D Game Development”, is in my favorite format – it presents the concepts quickly using trivial examples while building a working (crappy) game. I’m about 70 pages in and I’m enjoying it immensely.

The Good

It is a very drag-n-drop approach to creating content.  This enables you to quickly assemble a working game, especially if you purchase the game assets (sprites, backgrounds, etc).

You can use Visual Studio to write the C# scripts that attach to the game events and objects.

It’s free!

The Not So Good

There doesn’t seem to be any compile time checking of the code (I hate calling it “scripts”) you write, so if you misspell or miscapitalize string literals, you won’t be able to easily figure out what’s going wrong.

This was a quick first impression.   I’ll post one more update when I finish the very short book.

Reblog – Remove distraction of JunkMail arrival

This post 2 Steps to Auto Mark Junk Emails as Read is a godsend.   At my job I get a ton of unsolicited commercial email (UCE).   After I black list the domains of the companies that SPAM me, I still get distracted when new emails arrive because it makes the Junk Mail folder bold and a count gets incremented.

This article shows you how to silence both the count of unread emails and also automatically mark new junk emails as read.   You’ll never be distracted by unwanted SPAM again!