Tag Archives: Array

Array: Copy Values From One Array To Another – No Repeat

Created for a user on the forums but never actually posted because I was ninja’d.

This example has an array of names, each time space bar is pressed, a random name is chosen and moved to a new array.  That name is then removed from the original array so the names are never repeated.

DOWNLOAD

Advertisements

Auto Tiling Using Bitwise Numbers

This is an example of how you can use “Bitwise Numbers”, a tilemap and an array in Construct 2 to automatically tile a level for you.

The example is based on my old Construct Classic tutorial which can be found on my old tutorials blog HERE and is based on a wonderful post by Salt on his blog.  I recommend giving the blog post a read before opening the .capx as it explains the basics really well.

You can try the HTML5 Demo.

Use left click to place a tile, right click to remove, hold shift & left mouse button and drag to tile a rectangular area.

DOWNLOAD

Load a level from text file – No Plugins

Here’s an example of loading a level stored as a text file into an array with no external plugins.  Created for a user on the forums the example is a bit “hacky” but I created it to show that this sort of thing can be done without the need of external plugins.  The example also shows saving the array to JSON and then in layout 2 loading the JSON into a different array.

The level is stored as below in the text file:

0000000000
0124122320
0155482210
0565322660
0124458650
0565956560
0854856220
0545269550
0154852320
0000000000

DOWNLOAD

Quick note that this example only works with single digits to represent level data.

 

Dungeon/Cave Generation 1

An example of how you can simply create a randomly generated dungeon/cave for your games.  The example uses a “digging” approach to create the dungeon.  It stores the dungeon data  in an Array and tiles it using the “Tilemap” object.  It’s a nice start to adding a procedurally generated level to your game and can be easily expanded upon.

PREVIEW

DOWNLOAD

Array – Find Last index with value

Another array example created for a user on the Construct 2 forums.  This time it will find the last time a certain value appears in a 1D array and returns that index.  In the example the numbers are “0-5″ and it looks for the last index with a value of “0″.  But can be easily changed to suit your needs.

DOWNLOAD