About Vadym

Thanks for reading!
[dinosaur peeking in from the right] Hey! I now have a newsletter! Come take a look.
You can also follow me on Twitter or Tumblr.

GameMaker: Recursive folder copying

In some situations you may want to copy a folder from your GameMaker game. And it would seem trivial but not that easy. file_copy can only copy files, and folder functions only allow you to create, check, and search folders for files. However, given these standard functions, implementing a folder copying routine is fairly easy.

Idea used here is to find a list of files and folders via file_find_*, and then go through them, checking whether they are files or folders, copying or recursively calling recursively function script accordingly. Sure that poses a potential problem if you were to copy entire disc contents to other location, but you are probably not going to be doing that via GameMaker... right?

Attached example contains the function and brief demonstration of functionality (you have to input source/destination paths as text).

Download GMK

Code follows,

Continue reading

GameMaker: Basic 3d bone animations

This example demonstrates how to create fairly basic bones for use in GameMaker 3d games fairly easily. Such can be used for character and environment animations, provided that they can be split in rotatable parts to some extent.

Advantages

As you may know, GameMaker does not quite support vertex animations. That means that models have to be either composed on-fly (which is a slow method), or "baked" as a number per-frame models (which takes amounts of memory proportional to how smooth you want your animations look). Bone animations, on other hand, work fast (since only transformation calculations need to be done), and require small amounts of memory.

Implementation

Idea of bone transformations is that you have so called bones, which can be attached to other bones, which makes them rotate together. That means, to find transformation matrix (position, rotation, and scale) of any given bone, you need to go through all of its "parent" bones, combining matrices. Normally this would be a slightly tricky task (especially if engine of choice does not have matrix operations built in), but, fortunately, GameMaker includes a set of functions to manipulate matrices (d3d_transform_).

Attached example includes a minimal system for linking bones together, drawing them, and a sort of procedural animation example.

Download GMK

GameMaker: Shadow casting in platformer games

This is a very old example of mine actually (creation timestamp says Sep 2010), which I've recently fixed & improved at request.

It demonstrates a simple algorithm to cast shadow from instance in platformer game. So when player jumps, shadow is displayed on ground below (realism!).

For the sake of simplicity and performance, shadows are checked against bounding boxes by default. Pixel-perfect checking is added as a separate condition, requiring affected objects to be children of obj_complex.

If you're interested in how this works behind-the-scenes, here's an illustration:

Outlined instances are ones used for finding top-most position below the player (which shadow will be cast onto). Red line is a number of point checks to indicate top-most point on objects with precise masks.

As another random visual tweak, there's a piece of code added to make shadow shrink as caster gets further from ground. A small touch, but these add up over time.

Download GMK

Notepad++: Syntax highlighting for Killa 0.2

Some time ago I've made a UDL2 definition for Lua-based programming language called Killa.
Actually I was planning to wait until next version of language will be released (which alters standard module names, among other things), but apparently that isn't going to be that fast, so here it is.

If you don't know what Killa is, it's a Lua-based scripting language, which adds some JavaScript-like syntax parts (including proper for-loops, bitwise operators, ternary operators, assignment operators, and more) while keeping the pleasing parts of Lua in. Also it does not allow you to accidentally leak variables in global scope, which excludes possibility of common Lua "silent errors". There's also a topic about it here. You can read more about it there, if this sounds interesting for you.

Download UDL

GameMaker – Substitution “cipher”

This example provides a function to substitute all characters in a string, which present in first set of characters, by characters from second set. This can be used to substitute l/e/a/s/t/o characters in a string by 1/3/4/5/7/0 accordingly, turning your "Hello World" into "H3110 W0r1d" in single script call, or to replace/swap characters with completely irrelevant ones, providing simple "encryption" (e.g. Caesar cipher or various substitution methods) to challenge the player.

Functional part is presented by a single script, named string_subst(string, from, to), which returns string with all characters from set from replaced by according characters from set to. As long as both from and to are of equal length and do not contain repeating characters, output can be "decrypted" by passing parameters in swapped order, e.g.

var asrc, adst, source, encr, decr;
asrc = "0123456789"; // source "alphabet"
adst = "3456789012"; // destination "alphabet"
source = "51"; // source text
encr = string_subst(source, asrc, adst); // "encrypted" text
show_message(encr); // Displays "84;"
decr = string_subst(encr, adst, asrc); // "decrypted" text
show_message(decr); // Displays "51;"

Attached example demonstrates both "encryption" and "decryption", and has nice buttons.

Download GMK

Continue reading

Userstyle: Green fix for GameMaker Community forums

Userstyle for GameMaker Community forums, fixing theme colours back to loved green ones.

If you've been visiting GameMaker Community lately, you might've noticed that forum software update has switched the light theme to new default IPB blue theme.
That is going to be fixed soon (hopefully!), but until then, there's a small solution if you're not too keen of mixed standard blue-green-pink(?!) palette.

First, ensure that you have a browser plugin to add support for userstyle. Seems that a commonly used one is Stylish, but there are also other options.
Also ensure that forum is set to default (blue) theme.

Then, create a new style in said plugin.
"Applies to domain" field would to be set to "gmc.yoyogames.com", obviously. CSS contents can be downloaded here:

Download CSS

After clicking "Save" and refreshing page, theme will appear green-coloured, more or less mimicking the previously used green theme (except maybe slightly softer, since it's a quick CSS recolour of new standard theme).

Optionally, you can also download a ZIP archive with related files, so you can easily substitute links in CSS and host images wherever loads fastest for you.

Should be good.

Vector: Haxe icon

Haxe vector icon

Recently I was searching for at least relatively high-definition icon for Haxe (programming language), and found that there ... just isn't one. The best I could find was icon used on someone's blog, and that had white seams at shape intersections (suggesting anti-aliasing problems).
So I've made one.

The whole icon (after a few manual optimizations) is 1108 bytes, is in SVG format, and seems to meet proportions of original perfectly.
Also sections of icon are made to partially overlap "behind the scenes" to avoid earlier mentioned white seams on shape boundaries.

Download PNG Download SVG

Alternatively, if download links are not working, here's SVG code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
	"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg"
	xmlns:xlink="http://www.w3.org/1999/xlink"
	width="128px" height="128px"
	viewBox="0 0 128 128" xml:space="preserve">
<g>
	<rect fill="#f7941e" width="96" height="96" x="16" y="16"/>
	<polygon fill="#fdb813" points="0,0 4,32 16,64 64,16 32,4"/>
	<polygon fill="#faa61a" points="0,128 32,124 64,112 16,64 4,96"/>
	<polygon fill="#f36f21" points="128,128 124,96 112,64 64,112 96,124"/>
	<polygon fill="#f58220" points="128,0 96,4 64,16 112,64 124,32"/>
	<polygon fill="#ffcb08" points="0,0 64,16 32,0"/>
	<polygon fill="#fff200" points="0,0 0,32 16,64"/>
	<polygon fill="#fff200" points="0,128 16,64 0,96"/>
	<polygon fill="#f4813c" points="0,128 32,128 64,112"/>
	<polygon fill="#f7941e" points="128,128 64,112 96,128"/>
	<polygon fill="#f15922" points="128,128 128,96 112,64"/>
	<polygon fill="#f15922" points="128,0 112,64 128,32"/>
	<polygon fill="#ffcb08" points="128,0 96,0 64,16"/>
</g>
</svg>
 

GameMaker: Cycling random funky text

The idea behind this effect is simple enough - for every string character that should be randomized, replace it with any other character that has same width (so that the drawn string would not wiggle chaotically).

It uses 3 scripts total - one for general initialization, one for per-font init (creating a map of lists for what glyphs any given one could be replaced with), and one for actual string processing.

Can be handy for various abstract pieces, or as an interesting way to censor text.

Download GMK Live demo

Text versions follow,

Continue reading