Name them all and use those names, never use numbers. Things like final int CELL_EMPTY = 0, final int CELL_OUTSIDE_GRID = 1 (returned from getCell()), and whatever other states cells can be in. If you use variables 'width' and 'height' (you should) to specify the size of the grid, then looping through all values is as easy as two nested for loops. Initialize the cells programmatically, don't type them all out like that. Otherwise, you'll need special logic whenever checking adjacent cells. If a cell is outside the board, you can just check if it's equal to the value you use to denote outside the board. This is really useful when looking at all adjacent cells to a given cell in your game logic. Rather than throwing an error or something, you could return a special value that denotes a spot outside the board. In your getCell() function, it doesn't hurt to check that x and y are >= 0 and < width and height, respectively. Two dimensional arrays cause unnecessary headache IMO, especially if you later decide cells are objects (instead of a primitive like int).ĭeclare it like: tiles = new int Use a function to index into it like this: return tiles or return tiles. Use a one-dimensional array instead of a two-dimensional array. Here are some tips from my experiences working with 2d array games: Rect(rows * tile, cols * tile, tile, tile) The current code I have establishes the grid as an array but I am unsure how to get the cells to respond to click functions. Outline A series of yellow cells that will constantly update to surround the neighborhood of active cells. Inactive -> When clicked, an active black cell returns to white. The arrays are filled with random numbers in the Game::Init method: game.cpp. This is not a random choice: 4096 is 2 12, so actually (for a computer) it’s a nice round number. There is room for 4096 integers in each array. If the edge touches the edge of a base cell or the edge touches the edge of another active cell First, the arrays: two arrays are allocated to store x and y coordinates. Every other cell begins as inactive.īase Cells Constant and active blue cells in the middle, which cannot be removed.Īctive -> When clicked, an outline cell becomes black Outline cells will surround the base cells. Setup 21 cells across / columns 10 cells down / rowsĤ base cells vertically aligned in the centre of the board. I have established a set of rules that I am trying to accomplish. Hi all, I am pretty new to processing and am working on a tile based game project.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |