Getting a Gist Of My Code

 

I know I don’t post very often – believe me, 2015 and 2016 have been a helluva ride – but I have been writing a lot of code. I mean, a lot. A lot of the code I write, since it’s Unity, I have compartmentalized in scripts that I import over to a multitude of projects. Seeing as how a lot of these are used and fleshed out in projects that will never see the light of day, I thought “Hey, why not just put them up on the site?”

So, I’ve created a Github account, and I’m placing them in their own GitHubGists (or Repositories, if they span multiple files). This would be a quick, dirty, and effective way to get my code out to you guys so maybe, just maybe, it can actually be used in a project somewhere.

Any code I put up in my Gist, I’ll also link to it somewhere on this site as well for direct linkage.

So, go have a look at my GitHub Gist! Maybe you can find something useful there!

SUDDEN GLORY Development – Particles and flashy bits

Here’s a small video of me working on some of the particle effects (and the game logic that spawns them), and some of the art assets (and the logic on how they behave).

For the particles, the idea is that when certain things get destroyed, they leave a crater behind (or some burnt wreckage). I also wanted a random chance to spawn other things, like fire, smoke, electrical arcs, and what-not. The script I created uses a “chance” variable for calculating the odds in which a special “additional” effect would spawn.

For the art, I have these big battle ships, and they have weak points for the other team to attack. However, I have no way to convey to the player that they needed to attack these points. So, I’m creating “ship components” that will flash to show they are “points of interest,” and since all you do is fly and shoot, you’ll naturally try shooting it, and it’ll explode. See? Conveyance.

More of these are likely to come. Stay tuned. I also use that channel to put up my Twitch streams, so… uhh… like and subscribe? I guess? Is that how the TubeYou works?

 

Link: Game Programming Patterns – The Observer

Link: Game Programming Patterns – The Observer

OK, first off: No, I’m not dead. 2: No, I’m not a zombie. 3: Yes, zombies are considered dead. 4: I’d like to take a moment to consider a pivotal part of any game programmer’s arsenal of design patterns: The Observer.

The observer pattern, to put it simply, is an object that will only perform a specific action when another object/objects (called “the subject”) are in a particular state. A gentleman by the name of Bob Nystrom is working on an online (and soon physical) book regarding game programming, called GameProgrammingPatterns.com. In his book, he describes the fundamentals and design of the Observer pattern in a fun and simple way that can have even the most basic programmer up-and-running with Observers in no time; like a strange digital voyeur of code.

OK. That was disturbing.

Anywho, go run over to his site, and check out the other “chapters” he’s done. His book is still a WIP, but it’s already a classic. Take care!

David León, and his Zelda Dungeon Generation in Unity3D

Zelda Dungeon Generation in Unity3D

The other day, I found a post in Reddit’s /r/Unity3D to random procedural Zelda-style map generation using a binary-tree by a dude named David León, a game programmer. He goes on to explain his method for generating the maps, and even has downloads to his source code. He also has a bunch of other tutorials for creating a rougelike-style maps and so-on. Really great stuff, and if you’re looking for a little inspiration for random map generation, check out David León’s tumblr.

Link: Two’s Complement

Link: Two’s Complement

You wanna know what always used to break my brain back in school? Two’s complement. For those of you unversed in nerd geek, i’s the computer’s way of interpreting negative and positive binary numbers by using the left-most bit as the sign.

Examples:

Lets talk in nybbles here (4 bits instead of 8). In a perfect unsigned world, the number 15 is expressed as 1111 in binary. However, speaking in signs, this is -1.

Continue reading Link: Two’s Complement

Link to the Path: A* Pathfinding for Beginners

A* Pathfinding for Beginners

OK, so a while back I posted a link for a simple implementation for A* Pathfinding for C/C++. The page gets a bunch of hits, but I get a lot of people asking me to explain it. Well, it’s not my code to really explain, and I haven’t tested it out for myself. Rather than go through and make a huge tutorial, I figured I’d take the lazy route, and provide you with a resource to help explain it a bit. This page breaks down A*Pathfinding to the basics and gives a great explanation down to even the heuristics (If you don’t know that word, you’ll need this link).

So, now with this in hand, pathfinding should be easier to grasp now. Give it another go, and let me know how it turns out! Good luck!

Quick Code Tip: Fix Precision with Floating Points

Let’s say you have a floating point value of 200.21, and you convert it to an int, like so:

int amount = (int)(famount * 100);

Depending on processor, libraries, compiler and tons of other stuff, your value may APPEAR to be 200.21, but when you do your conversion the value comes out to 20020. What happened to that extra 1?!

Well, though you may see 200.21, the computer is actually storing 200.209999999… (because, you know, 0.999… == 1).

This doesn’t happen all the time, but when it does, it’s a pain. So how do we fix this?

Just add 0.5. Seriously.

int amount = (int)((famount * 100) + 0.5f));

Bam. Let’s break this down, PEMDAS style.

(famount * 100)
Ok, so we know that famount is not 200.21, but 200.2099999… This now brings us to 20020.99999…

((20020.999…) + 0.5f)
The 0.5 now brings us to 20021.49999… Like magic.

int amount = (int)(20021.4999…)
Saving all the pennies.

Good job. You just saved the world from mathematical inaccuracy.

Until next time, take care. (After that, do whatever the heck you want.)