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
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
)
Thanks, Ignatz 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!
@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.
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
function setup()
spriteMode(CORNER)
tab={}
size=38
for x=1,25 do
tab[x]={}
for y=1,18 do
tab[x][y]=0
end
end
tx,ty=0,0
end
function draw()
background(40, 40, 50)
fill(255)
for x=1,25 do
for y=1,18 do
rect(x*size,y*size,size,size)
if tab[x][y]==1 then
sprite("Platformer Art:Block Grass",x*size,y*size,size,size)
end
end
end
end
function touched(t)
if t.state==BEGAN then
tx=t.x//size
ty=t.y//size
if tab[tx][ty]==0 then
tab[tx][ty]=1
else
tab[tx][ty]=0
end
end
end
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)
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.”).
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
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,