This loop will go from 0 to the last cell on the horizontal axis (using boardW, the width of the board). Var aPiece = choose(piece.circle, piece.square, iangle)
Now we need to place the starting pieces for each side, so I’ll add this: //Place pieces They are the x and y position of the selected cell, and its piece type. The selected variables will be used to store the properties of the piece that would be selected during state 0, so that they could be moved to a new cell in state 1. Turn will store the side whose turn it is, and state will store the state of a turn. The arguments in the function are the grid width & height. Then the board grid will be created in the variable board. I’ll continue by adding this in the Create event: //BoardĬellSize is the size of each square cell in pixels.īoardW & boardH store how many cells there are in the board, horizontally and vertically, respectively. In this example, we’ll only be needing the sprite for each piece, but if you want to set up more data for them (like health, attacks, etc.), you can create more arrays like this, or use a 2D array. The array pieceSprite will store the sprite for each piece. Then I’m setting up the pieces in an enum called piece.
As you might have guessed, this will be used in the arrays that will be in the grid cells. In its Create event, I’ll add this: //Array contentsįirst I’m setting up an enum called ar, that will contain two members: piece and team. I’ll start by creating an object called oBoard. I’ve imported sprites for 3 example pieces: circle, square, and triangle. Now let’s start making the actual project. This way a team will be able to move one piece each turn. If it is, it will delete the piece at its original location, and move it to the new cell.Īfter that, the other team will be given their turn, and state will be reset to 0.
When the state is 1 and the player clicks on a cell, it will check whether that cell is empty. If it does, it will store that cell’s info (location, piece type) to some variables, and set the state to 1. When the player clicks on any piece, it will check whether that piece belongs to that team. In our project, there will be two states: 0 and 1. When a side is moving a piece, this variable will keep track of where that action has progressed. There will be another variable called state. When it is a team’s turn, they will be able to move one of their pieces to some other cell. A variable called turn will store whose turn it is (0 or 1). But if there is a piece at a cell, it will hold an array with the two aforementioned elements.īoth sides will take turns moving their pieces. So, if a cell in that grid is empty, its value will be 0. The arrays will contain only two elements: the first one will store the piece type (from the enum), and the second element will contain the team that piece belongs to (0 or 1). That grid, in each cell, will contain an array. Then we’ll create a DS grid for the main board. x, y is the cell position to access, //where 0, 0 would be the top-left cell //Readingįirst we’ll set up the pieces inside an enum. If you want to access or set a value in the grid, you can do it like you would with a 2D array, but using the # accessor: //Writing Each cell can hold a value.Ī grid can be created using ds_grid_create(w, h), where w and h are the width & height of the grid.Īll cells in a new grid hold 0. The board will contain different pieces, with each piece belonging to either team, like Chess.ĭS Grids are 2D data structures that contain a certain number of cells, which are determined by the width & height of the grid. In this project, there will be two teams.
DS GAME MAKER FULL VERSION FREE FREE
Here is one I made, which is free to look at on GitHub: Using this method, you can even build a Chess game. This is what we’ll create in this tutorial:
DS GAME MAKER FULL VERSION FREE HOW TO
Hey there! In this tutorial, you’ll learn how to create a turn-based board game using DS grids.