Minecraft Game : Terrain Generation

This is my first post, so if thee are any mistakes, please tell me.

So I am coding a Minecraft type game right now (I have owned Codea for a year, so I am not trying to overwhelm myself). I have finished most of the menus and interactions, but I still have a question about terrain generation.
What I plan to do is use the method in Brickout Codea example for this. In the example, you have a class file with your class name, {…}, and a series of 1 and 0. A 1 representing a type of block in a table projected onto the screen, and a 0 representing an “air” pocket where another class file will place another type of block. I have sequences written, but I need help with using these sequences to place these blocks. I saw the example in Brickout, but didn’t quite understand.
So what I am asking is, what methods could I use to put the sequences through a formula and project all true number onto the screen.

If anyone wants example code, I am happy to provide :slight_smile:

Also, check out my other code examples (even my first professional (and quite funny) first app)

(By the way…
Ignatz, if you are reading this, you give me so much inspiration for going further :slight_smile:

have you seen these? They use a map like the one you describe.



(thank you for the kind words. I was where you are, not so long ago. Just keep practising!)

Thanks, Ignatz :slight_smile: These websites were just what I was asking for, so useful

The first website was VERY helpful because I was going to create multiple different classes for EACH type of block. But the example showed you could have MULTIPLE ids of blocks in a class, yay!

Sorry, Ignatz to bother you again…
But I couldn’t understand how the matrix and sprite generation worked…

I found another Codea example that would work perfectly, but I need help understanding it… the Drum Machine example

I started a new project, but decided to go at it with a different method.

Please explain how the equations work so I can understand how it works. Thanks!

(I want to know how the boxes-selection-thing works (tap the box and it highlights))

@gilbertASTUDENTios Are you after something like this. This is a 25x18 grid that has 1 of 4 random sprites drawn. Of course the grid can be any dimension you want, even larger than the screen. The sprites can be anything you want to draw at each position.

EDIT: Changed code to hide or show the sprites.


function setup()
    for x=1,25 do
        for y=1,18 do

function draw()
    background(40, 40, 50)
    for x=1,25 do
        for y=1,18 do
            if tab[x][y]==1 then
                sprite("Platformer Art:Block Grass",x*size,y*size,size,size)

function touched(t)
    if t.state==BEGAN then
        if tab[tx][ty]==0 then

It is sort of… but I was wondering how to sort of toggle the blocks (i.e. tap somewhere on the grid and a sprite goes there, tap again and it is removed)

There are many, many threads up here about using touch, and I have written an explanation here


@gilbertASTUDENTios I changed the code above to put a Sprite where you tap or to remove a tapped Sprite.

Oh my! Thank you so much! This was the perfect solution!
I will have to share my code for an app I am working on thats really cool!

I tested the code, edited it so it has a ‘spritemode’ variable… but when I change the settings for the sprite, all of the sprites change

(what I mean is…
I have a variable that changes a number, if the variable is 1, then a grass block is made
And when the variable is 2, a dirt block is made
but when switching between the variables, all of the sprites change)

I saw a ‘nil’ variable to save sprites… but I dont know how to use it… I was hoping that this variable could help save the sprites generated between transitions with spritemode.

Please share some code and thanks for the support!

You said you would share your code if asked — so I’m asking! Sounds fascinating. (By the way, I think it’s a little humorous to say “I decided not to challenge myself too much, so I’m just building Minecraft.”). :slight_smile:

Hey Uber,
I kind have moved on from MINECRAFT, I was aiming to make a quick game with all concepts imagined translated into LUA by these wonderful moderators :smiley:

So now I moved on to a new invaders type game with 1000+ lines which is all in standard code (no matrixes or any complicated equations). So you can take the above code and apply it to your own 2D minecraft, but now I have no code :neutral:

Sorry for any inconvinience but check out other examples. Good luck coding,