# loverock125

Member Since 24 Mar 2009
Offline Last Active Today, 06:16 PM

### Dijkstra'S Algorithm (And A*)

07 May 2013 - 11:52 AM

• Title: Dijkstra's Algorithm and A*
• Description: An example demonstrating Dijkstra's algorithm.  A* approach also included.
• GM Version: :GM81:
• Registered: yes
• File Type: .gm81
• File Size: 23KB
• File Link: Dijkstra's, A*
• Required Extensions: None
• Required DLLs: None

Summary

An example using Dijkstra's algorithm to find shortest path to a node.  You can find a detailed explanation of this algorithm here.

The project contains 2 rooms.  In the first room you construct your own graph and then find the shortest path between two nodes.  In the second room it's a top-down stage where you can see this in action.

Note: A* is a much more efficient approach in path-finding than Dijkstra's, though they are very similar.  A* approach takes into account an estimated distance between the available nodes and the target node before choosing a new node. You can find more about the A* approach here.

You can optimize the A* example included by using a sorted map instead of a priority queue along with a binary search algorithm, although it's not necessary.

On the left, an illustration of how Dijkstra's algorithm finds the shortest path and on the right the A* approach.

Free to use.

### Shattering Sprites

05 February 2013 - 07:54 PM

• Title: Example of shattering sprites
• Description: Turns sprites into pieces and scatters them
• GM Version: GM81
• Registered: Yes
• File Type: .gm81
• File Size: 27KB
• File Link: Download
• Required Extensions: None
• Required DLLs: None
• Tags: GMCPlatform, GMCEffect
Summary

This example turns any sprite into pieces and shoots them in random directions and at random speed. All it does is split the sprite into surfaces, store pieces in an array, scatters them (by giving them a random direction and a speed) and when they are done, frees the surfaces.

### Bloom Effect Example

03 February 2013 - 03:15 AM

• Title: Bloom Effect example
• Description: Adds bloom effect to sprites or surfaces, given a performance and threshold parameter.
• GM Version: GM81
• Registered: Yes
• File Type: .gm81
• File Size: 2.7MB (Because of 3 backgrounds)
• File Link: Download
• Required Extensions: None
• Required DLLs: None
• Tags: GMCTUTORIAL GMCSURFACES GMCEFFECT
Summary

This version goes from pixel to pixel of a surface and adds a bloom effect according to a threshold parameter. In other games this is usually done using shaders (They run on the GPU) which are extremely fast. You can find more about what the bloom effect is here.

Since shaders process each pixel individually, I've tried doing the same thing on the CPU using Game Maker. The example uses a custom script for getting the color of a pixel (by saving the surface externally and reading the bytes of the file) in order to speed up the process. It's still slow, but usually unnoticeable when the performance parameter is over 20 (Without sacrificing much of the original quality).

This is NOT fast enough to be used dynamically (e.g. applying it as a post-process effect to the back-buffer). It may become if you know of a DLL that gets the color of a pixel fast. You can try drawing the final image on a surface and dynamically apply a bloom effect (every 3-4 steps?) with a high performance parameter, but most probably it will still lower the fps. Nevertheless, this is useful (and fast enough) for a one-time pass over static background images or textures.

How it's done:

• Draw original image on surface
• Go from pixel to pixel and adjust the colors according to the threshold (Keep only bright ones)
• Blur the surface
• Combines the two surfaces together by drawing the blurred surface with an additive blend on top of the original image.

Screenshots of the steps above in the spoiler.

Spoiler

### Custom Particle System

27 January 2013 - 11:06 PM

• Title: Custom Particle System
• Description: A particle system similar to the built-in one
• GM Version: GM81
• Registered: Yes
• File Type: .gm81
• File Size: 129KB
• File Link: Download
• Required Extensions: None
• Required DLLs: None
• Tags: Particles, Effects
Summary

For Lite version download here.  Keep in mind that the lite version is slower.

This example is a simplified version of the built-in particle system.  You can find more information about what a particle system is here.  Only the basic parts of a particle system were implemented.  This is meant for the people who want to include their own functionality in a particle system.  Feel free to modify it and use it as you wish.

In the example you will find 5 effects.  I haven't spent too much time on making them look very realistic but you get a general idea on how to use it and what it does.

Screenshots in the spoiler.

Spoiler

### Blurring surfaces

19 January 2013 - 12:01 AM

Not sure if anybody will find this useful but here it is.  It blurs a surface and returns a new surface with the blurred texture.

```/*
blur_surface(surface, blurQuality, blurAmount);

surface: Surface to blur
blurQuality: Less = better quality, minimum 1
blurAmount: High = more blurring, minimum 0

Returns: New blurred surface
*/

var surface, blurAmount, blurQuality, blurSurface, tempSurface;

surface = argument[0];
blurQuality = argument[1] + 1;
blurAmount = argument[2];
blurSurface = surface_create(surface_get_width(surface), surface_get_height(surface));
tempSurface = surface_create(surface_get_width(surface) / blurQuality, surface_get_height(surface) / blurQuality);

surface_set_target(blurSurface);
draw_clear_alpha(c_black, 0);
draw_surface(surface, 0, 0);

repeat(blurAmount) {
surface_set_target(tempSurface);
draw_clear_alpha(c_black, 0);
draw_surface_stretched(blurSurface, 0, 0, surface_get_width(tempSurface), surface_get_height(tempSurface));
surface_reset_target();

surface_set_target(blurSurface);
draw_clear_alpha(c_black, 0);
draw_surface_stretched(tempSurface, 0, 0, surface_get_width(blurSurface), surface_get_height(blurSurface));
surface_reset_target();
}

surface_free(tempSurface);

return(blurSurface);
```

I also have a better blurring script but this is extremely slow (unusable, if you try this, use small surfaces such as 50x50).  This is because surface_get_pixel is extremely slow and game maker doesn't support shaders.  In the future, surface_get_pixel might become fast so here it is if anybody needs it:

Spoiler