Haxe: Neko Server-client communication example (chat)

Recently I've been searching for examples of client-server communication in Haxe, however could not find anything specific. After some search and asking around, I was pointed to sys.net.Socket class, but the actual means of usage remained unclear. It was also confirmed to mirror POSIX socket functionality. Indeed it does that, though, given that Haxe implementation uses exceptions rather than return values, usage remained uneasy.

After some experimenting, I've figured a semi-simple way of using "blocking" sockets.

Continue reading

GameMaker: Finding resources by name

If you have been working with GameMaker, it might have been not a single time when you would really want to be able to do something like:

instance_create(x, y, 'obj_item' + string(irandom_range(1, 3)));

However, as you probably noticed, you cannot simply do that. That's because resource indexes are integers, and not strings. It is normally recommended that you do something like this:

var i;
switch (irandom_range(1, 3)) {
	case 1: i = obj_item1; break;
	case 2: i = obj_item2; break;
	case 3: i = obj_item3; break;
}
instance_create(x, y, i);

That works (and actually is one of fastest approaches to this), though it's doubtful fun to create these structures by hand. And even more doubtful fun if you need complex concatenation rules (e.g. spr_player_{attack}_{1}). Another thing you can see done often is:

execute_string('instance_create(x, y, obj_item' + string(irandom_range(1, 3)) + ');');
// Some say that you're a horrible person if you use such code.

However, this can be a performance pitfall, since the game has to parse a piece of code at every call. Oh, and also this won't work in GameMaker: Studio, since dynamic scripting functions have been excluded entirely.

At this point you're probably going to ask "And what are you going to suggest then?". I suggest a ds_map. This can be considered an elegant solution, since look-up will take about the same time for a given number of resources, and the only (relatively) time-consuming operation needs to be executed once at game start.

Example attached covers the initialization part for you, providing simple interface for actual lookup:

instance_create(x, y, object_find('obj_item' + string(irandom_range(1, 3))));

Download GMK Download GMZ

GameMaker: Circular cooldown rectangle

GameMaker: Cooldown rectangle

I do not know the exact name of this visual effect (angular/clockwise fade-in/fade-out?), but it is one of the most common things that you can see in interface of RPG and RTS games, displaying progress of construction/upgrade/ability cooldown. So, to the point...
You can read how this is actually being implemented, or just scroll down to the bottom of post and grab the code and/or GMK file.
Implementation of such is actually pretty simple, Continue reading

Love2d: Haxe: Ray-circle intersection test


HaxeNME version. Love2d version works equally to this.
Click and drag different parts for interaction.

By user request on Love2d IRC channel, yesterday I've made this nice function to do intersection/collision check between a ray (for clearance, here, a ray is a infinite line with starting point but no end point) and a circle.
Underlying code is fairly simple, though it does not even require understanding to use the function.
Love2d version takes advantage of multi-return values.
Haxe version has slightly longer code due for more optimal implementation of interface.

Download Haxe .hx
Download Love2d .love

Love2d: Semi-turn-based platformer

A very rushed Haxe version to demonstrate how it looks in motion.
Does not necessarily represent features of love2d version in this post.

This was originally going to be a short reply-fix for a topic on love2d forum, but it seems that author did get somewhere with figuring that out on ones own, and I've quite overdone it in terms of a simple answer, so I formatted the code nicely, added several more features, and made this example.

Just in case above demonstration does not work, this example demonstrates a specific approach to game dynamic, where game logic occurs once per interval, while things are drawn and receive input at higher rate. I do not recall any actual platformer games that would use this principle, but a good example of such game is Snake (original grid-based version).
Example includes grid-to-point collision checking, actual specific platformer behaviour (with adjustable values), and value tweening (to make player movement nice & smooth).

Download (2KB .love)

GameMaker: Lightning between points



Poorly animated and still previews of lightning

This intermediate example demonstrates creation of a nice-looking lightning effect in GameMaker.

A 8-parameter, well-commented 50-line script gives a lot of freedom in relation to drawing lightning effects between points, controlling "density", "width", and actual drawing behaviour. It is also optimized to skip drawing if lightning is not going to overlap view area.

And it looks pretty cool, overall.

Download GMK

Code follows,

Continue reading

GameMaker: View following two objects at once


This example is going to be of great use for everyone making local multi-player games, as well games requiring to display two objects on screen at once generally.
Effect here is, that view is positioned and scaled (if needed), to include two given instances at once.
Example provides a single function that does this sort of trick for you, absolutely painlessly and easily.

Download GMK

GameMaker: Connectable objects


I'm not a specialist on topic of weird helicopters, but it would be one of those.

This secretely awesome example provides a system to 'connect' objects together, meaning that 'child' objects will be positioned relative to their 'parent' in means of both position and rotation. Also you can (in turn) also make those 'child' objects 'connectors', meaning potentially infinite number of 'levels' of instances behaving separetely.
For ones that might have this example from my old website, it is worth checking out again, since it has been rewritten almost completely, delivering quite cleaner naming, as well as easier access to child object properties, and some optimizations.
This example can be particularly useful for games involving 'modular' vehicles, as well as multi-object bosses.

Download GMK