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

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

Snip:

--[[
Does a ray-circle intersection test.
Parameters:
	x1, y1, di - x, y, direction (radians) of ray
	x, y, r - position & radius of circle
Returns:
	result - whether collision occurred
	x - collision X
	y - collision Y
	distance - distance from ray start to collision point
]]
function ray2circle(x1, y1, di, x, y, r)
	local vx = math.cos(di)
	local vy = math.sin(di)
	
	-- get relative XY of circle (relative to ray origin):
	x = x - x1
	y = y - y1
	
	-- rotate it based on ray direction (as if ray starts at XY=0 and goes at +X):
	local tx = x * vx + y * vy
	local ty = x * vy + y * -vx
	
	-- clear misses:
	if (tx < -r) or (ty > r) or (ty < -r) then
		return false, nil, nil, nil
	end
	
	-- find X coordinate that line hits rotated circle at
	th = math.abs(math.cos(math.asin(ty / r))) * r
	
	-- too far behind
	if (tx + th < 0) then
		return false, nil, nil, nil
	end
	
	-- line start is inside the circle:
	tx = tx - th
	if (tx < 0) then
		return true, x1, y1, 0
	end
	
	--
	return true, x1 + tx * vx, y1 + tx * vy, tx
end

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: “flawed” AI path finding

In some cases, you may want object's AI to not pick exactly perfect path.

This example demonstrates creation of a basic "flawed" AI, that uses a rather plain method of finding path. Such will still make it reach destination in many cases, but will also allow player to "fool" the AI, making it stuck in dead ends or T-intersections (if player is standing right behind the wall).

To illustrate simplicity of concept, example is largely made in Drag & Drop.

Download

Continue reading

GameMaker: Angular motion


It's like drifting. On a spaceship. In space.

This is an example of managing angular motion in GameMaker.
In turn, that means having angular speed with acceleration, friction, and limitation.
Such can be particularly useful for simulating a more 'smooth' rotation behaviour, when object will not start or stop rotating instantly.
If combined with relatively properly written code for linear motion, this can grant pretty nice behaviour for space games.
Also there's a "trail" effect added, originally just to demonstrate how it works.
Everything is pretty nice and simple.

Download GMK

GameMaker: Animating backgrounds

This simplistic example demonstrates how to cycle backgrounds in a room at a fixed rate, as you would do with images in a sprite.
Obvious advantage of cycling (animating) room backgrounds is that these are handled and drawn by engine, which makes them generally faster than something you can achieve in a short amount of time.
Seen method supports any number of backgrounds larger than zero.

Download GMK