Search Unity

How to design around Grids?

Discussion in '2D' started by Raiden-Freeman, Jan 15, 2014.

  1. Raiden-Freeman

    Raiden-Freeman

    Joined:
    May 7, 2013
    Posts:
    15
    Hello, I want to make a board game, particularily Battleship.

    I'm really good with coding, but unfortunately I lack basic knowledge about game software design.

    My problem: how to make a grid.

    Frist of all, I wanted to settle on a sprite "block" size, of which all my sprites are a multiple of. I have some free sprites, and after resizing them a bit, their greatest common divisor was 16, but I decided to use 32, as I'm not going to use anything that small.

    I'm targeting 720p-1080p, and I guess that I want all of my sprites to be 32x32 pixels (and multiples thereof). I have read that current game engines/hardware has no need for spites to be a power of 2, as they're fast enough (no need to do bitwise << for division), but I feel comfortable math-wise with powers of 2, so I settled on that.

    Is that correct? Should I avoid having a set sprite size, and use everything as is?

    The real issue is the grid. I want to know which coordinates (gridwise) I clicked when I click a tile on the grid. But I have multiple ways of doing that, and I don't know which is the best. Simplest way: I create an array/arraylist(if I want it resizable) and fill it with tiles, representing the grid tiles, when I click one of them I know which one it was; I place the grid tiles through a script, at the start of the scene, apart one frome the other relative to their dimensions. My problem with this, is that I can't fine tune where everything is, easily; if I want to change anything I have to modify variables on the script.

    Other way, I place the tiles manually through the editor. My problem with this, is that when I use Unity's snapping, I don't get the results I want. For example I have a 32x32 tile with a square on its edges, and the rest transparent. If I place 2 side by side, the edge their common edge will look 2 times thicker. To avoid that, I must have a different sprite with one edge missing, paired with another one having that edge, and it's generally really counterproductive.

    So I guessed that I could create the whole grid as a large sprite. Unfortunately I don't know of any other way to get where on the grid I clicked, except adding 100 square colliders, one for each tile (assumming it's a 10x10 grid).

    The final solution is to programmatically create the grid with calls to the GL class.

    Unfortunately my problem with all those solutions, is how to force snapping to the grid, of other objects, the ships in my case. The problem is that the centers of the objects are also their coordinates 0,0 point. As such I have to manually calculate a point (relative to the sprite size) on which the object and the tile will be aligned.

    I'm certain that people have already solved this, elegantly and optimally, so is there some tutorial on how to design a grid based game? If not, could you give me your ideas/thoughts?

    Thanks in advance!