Hi, welcome to the second video of project four, we're going to continue working on our pathfinding project. We're going to continue also from where we left off in the last video, so please start there. And we're going to be working on the environment customization. We want to give some ability to our mouse to paint an environment. What we're describing an environment is we're starting with tiles that are going to be floor tiles and we're going to be painting. So we're going to be able to change the type of some of these tiles to represent walls that would eventually become obstacles in our pathfinding algorithm. So let's just jump into the code and create this kind of customization. So here it is where we left off, we have an environment which is grid, as you can see in the environment class, and basically instantiating a series of tiles. Each one of them that could be different types, floor, wall, or others, that we don't have representation for them yet, and we don't have a display function for them. So we're going to just be transitioning from only drawing floor tiles to also drawing wall tiles. So let's imagine what we want to do. We're going to probably, like here in the draw function, do something along the lines of if the mouse is pressed, right? So let's say if mouse pressed, And then we can check, right? We can check if the mouse Button is the left mouse button, right? Is it the left mouse button? Let's mark here, so we're pressing the left mouse, let's paint in the position of the mouse, the current cell, wherever the mouse is. Let's change that to be a cell type of one, right? Change cell type 21, let's call that a wall, right? And maybe if we press Equals, right, so maybe the other button, we can maybe revert it back to floor, right? Again, you could have different types, I'm going to do an example that is rather simple between these two types. But again, it's quite interesting to kind of take this problem further. We will have a conversation towards the end of the week of where this system can actually go, right? So this is kind of a little bit what we want to do now. The thing that we are realizing that we're missing is some function that would allow us to paint or to execute this line of code. This would probably be a function of our environment. So let's go into our environment and let's think about the problems that we have here. First of all, we want to be able to convert. And we've done this already with the vector field, it's a very similar problem, but because the data structure that we're using, it's a nested list, it's slightly different, we are going to do it again. So we're going to get a cell by providing a coordinate, right? So we could call get_cell. So we want to be able to provide a coordinate such as x, y and get a cell associated with that, right? And I'm repeating something that we did already in the vector field, but it's going to be slightly different the way we access the cell, right? So let's do x, it's going to be an integer. We know that where x is divided by the float(self.world_x) and divided by self.columns. I think this is also close here, right? So what we're trying to do is just divide the world by the number of columns, right? And we can do that for the x and y, Right, so we are converting world coordinates into indices, right? Indices in the grid, right? So we could check that if x is not smaller than the length of self cells, right? And this is just a check for us not to provide an index that is out of bounds. So if the length of the column is represented by self.cells[0], right? Any column, we know that all columns will have the same length. So the first cell, it's perfectly fine to evaluate here, then, well, the cell that we will return, it's going to be self.cells x and y. So notice that we're using here this notation of index in this list that it's nested, so first we access the x and then the y, it's in the second square brackets. So here we can return the cell, else we could say return none, right? The cell will be returned correctly if we provide a coordinate within the domain of the screen. So technically this shouldn't have an issue because we're trying to access the mouse should always give us information within the screen and that's where we actually get the appropriate cell, right? So now that we have the get_cell function, which is allowing the mouse to convert the coordinates from the mouse into an index coordinate, we can actually do our paint function. We're going to call this paint_cell. So this is going to take the x and y as well, x, y and the type in this case, right? Because we know that we can define the type of a tile by changing its, the type is an integer, right? So let's say that the cell is going to be equal to self.get_cell here, we're using this function already that we have get_cell is a function that we wrote, and we're going to pass on the x and y information. And the type, sorry, not just x and y, to collect the cell first. And then we can say if cell.current_type = type. So it's pretty straightforward, what we're just saying is collect that cell and change its type. And this is the function that the mouse is going to invoke from outside the environment, right? So basically we have everything we need to allow for this execution now. Remember that the integer, if you go to the tile, the type, or basically our current type is either 0 for floor, wall, resource and water, right? So 0, 1, 2 and 3 in terms of indices, right? So let's use this function here, paint_cell, in what we started doing at the beginning of this video, right, which is call the my_environment.paint_cell. And we're going to say that the paint_cell, the x and y coordinate would be mouse x, mouse y. And in this case, the wall will be an integer of 1, so the type of tile is going to be 1. We're going to do the same thing for our right mouse button that will convert things back to a floor by typing 0, 0 is the index of the type floor, right? So let's see what we have so far here. So I'm running into one error here. So this is paint_self, let's see. Okay, so if we press left mouse button, we can like construct right mouse button should allow us to delete right or go back to tile. So this is going to be great because we're going to be able to create an environment, something like a labyrinth or something along those lines. And then start making a calculation of how do we reach from one point to another one and create a kind of the optimal path between those points, right? So, yeah, we have kind of a customizable environment. So we continue in the next video. I'll see you then.