How to Make Minesweeper In Godot | Beginner Tutorial
Вставка
- Опубліковано 27 вер 2024
- Learn the basics of Godot by making a mine sweeper clone in this tutorial.
The code for the game is built from scratch and will re-create all the features of minesweeper. This will use tilemaps with various layers for the mines, numbers, grass and flag tiles. Recursion will also be used to reveal some of the tiles.
Code and assets for this video: github.com/rus...
Thank you soo much for making this! I've always wanting to do a more "challenging" project to start out with but all other tutorials were all outdated. Not only was this tutorial very insightful, it also provided a smooth lesson into each of godot's mechanics. Good job!
Thanks Russ! You are so underrated. From Pygame to Ursina to Godot. What a Legend!
Thanks for all the tutorials. If I could, I'd recommend solitaire next. Thanks again!
For some reason I hadn't considered card games, that could be an interesting one to work on!
Awesome!!!! Love your lessons!!!
Thanks!
thank you bro, im learning alot from this video.
I followed the video step by step and finished it !
And i actually learned a lot ,now i know how to use array and loop
And i think we no need a move_mine() function.
If first click is not empty cell, we can while a new_game() function until a cell is empty 🤔
Learning a lot with this tutorial. Short doubt: is there any Tilemap method that returns what item from your tileset you're clicking on? ie: a function that returns the original tileset position that corresponds to a given tile you click on. I'm just trying with get_cell_tile_data(number_layer, map_pos) to get the Number i'm clicking on but no success so far. Many thanks!
Do the new tilemap layers change the tutorial too much?
50:17 the flood fill algorithm. Get adjicent cells that meets a condition
Awesome tutorial to learn how to use arrays
Thanks!
If mines and numbers are never placed on top of each other couldn't we put them in the same layer?
can u make playlist for the basic pygame functions pls, it will help me learn alot better
at 17:30 you are using 2 for loops to iterate over the tilemap to search for the mines. why aren't you just using the mines array that you created before in the mines layer? that would mean you only need one for loop and a simple check if it is at the border.
then just add +1 around the mine cell. after each mine cell is looped through the surrounding cells should be set correctly.
to do the +1 you just need to add +1 to the atlas x coordinate.
this should simplify that part of the code quite a bit.
also i don't know if you change that later in the video, so this comment might not be as relevant.
now at 25:50 i'm really confused what you are doing. it seems that you are doing the inverse of what i thought should be done with the first part of my comment. why are you searching the 8 cells around an empty cell and hope that a bomb is in it? using that exact function on the bomb would give you all cells that need to increment it's shown number. you don't need to go through all empty cells of the tilemap and count the surrounding bombs that COULD be there.
for those interested, this is what i thought it would be.
@export var Columns : int = 16
@export var Rows : int = 16
@export var MineCount : int = 10
@export var Mine_positions : Array[Vector2i]
enum Layers {Background, Mines, Numbers, Gras, Pointer}
func create_mines():
var mine_texture = Vector2i(5,1)
for i in range(MineCount):
var mine_pos : Vector2i = Vector2i(randi_range(0, Columns-1), randi_range(0, Rows-1))
while Mine_positions.has(mine_pos):
mine_pos = Vector2i(randi_range(0, Columns-1), randi_range(0, Rows-1))
Mine_positions.append(mine_pos)
set_cell(Layers.Mines, mine_pos, 0, mine_texture)
func create_numbers():
var target_cell : Vector2i
for mine_pos in Mine_positions:
for x in range(3):
for y in range(3):
target_cell = mine_pos + Vector2i(x - 1, y - 1)
if target_cell != mine_pos and !Mine_positions.has(target_cell) :
if (target_cell.x >= 0 and target_cell.x = 0 and target_cell.y
hey russ, my pygame window suddenly started to take a while to load, do you know what might be the cause?
cool< want more video!
Working on it :)
i paused at 48:18 and accidentally completed a minesweeper lol
I hope you make a game match 3
you are amazing🙃😊
😀
I watched yours and CyberPotatos Godot 4 Tutorial. No comparison. His tut was faulty and unelegant. Big probs!
what language do you use in godot?
It's GD Script, Godot's own language. It's very similar to python
and js@@CodingWithRuss
@@CodingWithRussI'm learning python but Pygame is quite limited, if I learn python and then switch to Godot would it be possible to use Python the way it's used on Pygame, the same way in Godot?
@@MrYellowPlays Godot uses its own language GDScript but it is very similar to python so switching from pygame to godot will be easier if you are already learning python. There will still be a lot to learn in the godot engine itself as it is quite different to using pygame
Should I keep learning python or just switch to Godot straight away?@@CodingWithRuss
Thanks! Glad you're returning to the code along style
I know it's much more demanding in terms of time and effort, much appreciated Russ
Thanks again for the nice tutorial
Thanks again! Learned something new from this tutorial.
Glad to hear it!
This was very helpful, because I am new to Godot. That being said future viewers of this project should bear in mind that this tutorial is somewhat buggy. It is possible to get negative flags, the hover layer should disappear on game end and the left right mine sweep thing allows you to open surrounding cells even if flag count is greater than the number cell's number, it should not let you do this. Also the way that a mine is repositioned after the first click will result in mines being located in the top left corner at a higher rate than expected. But I did learn a lot about how Godot works so thanks :D