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.

C#: Get current keyboard layout\input language

Get current input language on Windows with C#

On some occasions, you may want to get a "global" input language - that is, the keyboard layout used by the current foreground window\application\whatever. Basically, simulating the behaviour of the language panel on Windows.

The common use cases are on-screen keyboards, fullscreen applications, and widgets.

While I wasn't able to find a premade function that get this particular thing during my searches, it turned out not to be too hard to assemble:

Continue reading

Top-down bouncing loot effects

GIF
In action

A little while ago, I was asked about what would be a good approach to creating an effect for a top-down game where coins would fly out of a smashed object. Not recalling any tutorials on the matter, I've made an example of this exact thing, and this is a post detailing everything related to such an effect.

Continue reading

Adding hotkeys to switch to N-th screen on Windows

Keyboard shortcuts for switching between desktops on Windows

For quite a while, the multi-screen setup on my desktop was powered by Synergy.
Which, I should say, is pretty neat, aside of it's complete unwillingness to send non-English keystrokes to additional devices.

Slightly more recently I've switched to using a more conventional dual-screen setup.
Which, of course, is more convenient (being able to drag a window to the second screen without having to sync the related media first), one thing would seem to be missing — the "hotkeys".

Moving the mouse over an entire monitor (or two) only to click something and move it back is not all that exciting, and Synergy's keyboard shortcuts for moving the mouse to N-th screen (while remembering the old position for returning) were a welcome feature.

Windows, unfortunately, does not seem to have any "built-in" keyboard shortcuts for swithing to a given screen, but that can be easily fixed with help of an AutoIt script:

Continue reading

C# + .NET: Minimalistic asynchronous UDP example

Recently I have been experimenting with networking in Unity3d.

As you may know, there are various systems to aid you with building networked applications in Unity, ranging in approaches and capabilities.

However, if you are more familiar with the regular socket APIs, or just need to port a bit of existing code, you would probably rather have a couple of simple methods to send and receive data.

So here's just that, using .NET's System.Net.Sockets.UdpClient to asynchronously receive and handle data as it arrives:

Continue reading

C#: Implicit conversion from null to struct (and more)

MyStruct some = null; // some == MyStruct(...)

This is a small post about a rather specific construct in C# syntax, permitting to assign "null" to struct-typed variables (which are non-nullable) and treat this specific case as you please.

If you did not come here looking for this particular thing, you may or may not be in a dire need of the post's subject, but explanation may be of interest.

Continue reading

GameMaker: applying “with” to multiple objects

As you may know, GameMaker Language has a Pascal-like "with" structure:

with (value) { code }

but it's not exactly like the Pascal version. In GameMaker, it can take an instance:

var bullet = instance_create(x, y, obj_bullet);
with (bullet) direction = 180;

or an object type (and will apply the expression to each instance of it):

with (obj_bullet) instance_destroy();

This can be rather handy under the multiple circumstances.

However, initially the same block can not be applied to multiple values, and that's less handy.

Sometimes you can cheat by applying the expression to a shared "parent" type of objects, but that is not always the case (and can have side effects if there are more object types meeting the condition).

So let's consider your options for applying a piece of code to all instances of several types: }

Continue reading

Introducing: hxpico8

Have you heard of PICO-8? It's a "fantasy console" with little built-in sprite/code/level/sound/music editors and a carefully crafted spec. And (slightly changed) Lua scripting. And a web player export (example). A rather interesting option if you like working with restrictions and/or tiny pixelart.

Long story short, I've made a little Haxe compiler target that generates compact Lua code that runs on PICO-8. This post covers reasoning, some technical details, and tricks used to accomplish this.

Continue reading

GameMaker: Tetris in full Drag & Drop


Click to launch the HTML5 version of the game

First, take a look at the above link. There's score, 7 tetriminos, slowly growing difficulty - standard things for a Tetris game. The catch? There isn't a single line of code. Nor a single variable. It's all done in GameMaker's "drag & drop" visual scripting.

The story of how this even happened is like so - yesterday was another day when my internet connection disappeared for half of the day without any logical reason whatsoever. As I look at the top of my now-static TweetDeck timeline, and notice this bunch of tweets from Vlambeer's Rami Ismail. While you can generally agree with points outlined, few things could have had better clarification:

  1. Difficulty depends not only on developer's coding skills, but also on the tools used.

    For example, making a "space invaders" game in most modern tools with built-in memory management, collisions, and function sets is easy enough, but should you go lower level... storing invader information in an array? Storing and moving around dynamically created player and invader bullets?? Programming trajectories and destructible defenses??? Not as much careless fun as you may have envisioned. Pong may seem suddenly simpler with base requirements of just a bunch of variables and inverting ball x/y velocity for bounces.

    Additionally, certain tools are best suited for certain task. For example, it is easy to make a turn-based puzzle game in PuzzleScript (hence the name) due to the way engine is based on "rule" definitions. Making a platformer game in PuzzleScript, however, is a much harder feat. It isn't, by no means, impossible, but requires more planning than it would take with a "platformer-centric" engine.

  2. Game development isn't just about having the right tools/resources/experience, but also actually using them creatively. As such, programming in general is often about finding an approach to the problem that isn't the most blatantly obvious or expected but produces results more efficient in terms of computer of development time.

To not make it all look like a rant or a opinion piece, the rest of this post is about creative use of tools - particularly, making the aforementioned Tetris in GameMaker without a single line of code or variable.

Continue reading