0 votes

I am currently trying to make my own version of famous games and also programming simple games (like one that imitates the Linux terminal and you play using commands).
Now I'm trying the most classic game I know; Tetris.

For that I'm using 8x8 graphics, in a window of 120x240 pixels, with a play field of 104 pixels wide. All of this is divided in 8x8 squares, so the whole window is 15x30 squares.
I need to make the squares the tetrominos are made of appear and reappear in these sectors.
The problem is I don't know how to make the squares appear and dissapear.
I have three ways in mind;

1.- Instead of making the squares appear and form the tetrominos, I just make png files of each tetromino, place a bunch of them otside the window where no player can see them and move them instead of drawing new ones. MEDIOCRE
2.- I place one square of every colour in every sector of the play field and make them visible and invisible depending on the value of a 2D array that represents it. Example; number 0 means all invisible, number 1 means red visible only....
3.- This is the one I actually want to do; have only the squares I need, no invisibility allowed. So it means I need to draw them dinamically.
For this I first tried using the main node (the one that gives it's name to the scene) to draw a square at the beggining of the game in the middle of the play field using

var greensq = preload("res://greensq.png")

and in the ready function

draw_texture(greensq, Vector2(32, 32))

Of course this didn't work so I created a Node2D and used the exact same code, but didn't work. Then I realised and moved the draw texture function to the draw() function.
It didn't work either so I browsed the internet for a while and tried

var sprgreensq = Sprite.new()

In the draw function too, but it didn't work. I made sure to move this node to the top so it isn't covered by any other nodes (I placed some decorative pngs and a background).
Then I tried making all of those other nodes invisible but it didn't work either.

So I need any way of making the graphics of a tetris game to work.

Now I had diner, and I'm going to study calculus for a couple of hours before going to sleep so I will answer your replies tomorrow after class ( it is 22:24 now, so I'll answer in anywhere from 17 hours to 25 hours).
Thank you in advance for your help!

in Engine by (70 points)

I'm gonna go now. Again, I'm going to use what you taught me right now a lot tomorrow and try to make it as good as I can.
Thank you a lot for your help!

That's a lot of questions for a comment.

can I instance them from a script, so that I can destroy them when not used and so that I don't place 350 of them?


var tetro = preload("path to tetromino scene").instance()

Also, is there a way to change their shape from script?

It depends on how you implement the tetrominoes and the bricks in general. When I upload an example you could look for your answer there.

Also one more thing, how can I change their colours?

Every Node2D has a modulate and self-modulate property. They are both colors that the Node2D's color gets multiplied by. The difference between the two is that modulate effects the node and its children, while self-modulate only effects the node itself. modulate would be more useful here.

Here it is. Sorry if it looks complex to you. I hope I did a good job with the comments. If not, ask away.

You still there?

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.