How do you plan a good board?

1

I already wanted to make two games in java but I could not finish them because I had no idea how they were designed well. I have several questions, all of them more, pointing to the same side:

1. How do I design the board well? Is it done in a one-dimensional array or bi (x-y) each with the instances of the corresponding sprites?

2. To the "tiles" as I do so that they have a mouse listener? So far that was my biggest problem (I thought I saw the mouse click x, yy compared to the x, and for each instance of the map ... but I noticed that the machine got very hot from so many loops for..something bad)

    
asked by MatiEzelQ 18.03.2016 в 01:24
source

1 answer

3
  

1. How do I design the board well? Is it done in a one-dimensional array or bi (x-y) each with the instances of the corresponding sprites?

There is not much difference between doing:

Tile tile = tilesMap[x][y];

and this other

Tile tile = tilesMap[x * width + y];

In terms of performance, in this answer from SOen, you can see that there is no substantial difference either.

This decision is more a matter of personal preference, than a technical question. I would use the first, since it generates different bytecodes and it is not known if in the future there may be specific optimizations.

  

To the "tiles" as I do so that they have a mouse listener? So far that was my biggest problem (I thought I saw the mouse click x, yy compared to the x, and for each instance of the map ... but I noticed that the machine got very hot from so many loops for..something bad)

What I would do is a function that translates the coordinates of the screen to the coordinates of the map or board.

It's just a matter of scale, if it was a chessboard, the scale is 8 x 8, if it's a world with scroll and zoom, with a little math you calculate it, the point here is that the coordinates of the screen and the trablero are in different "domains", therefore you need a way to translate from one sense to the other (and vice versa to draw).

With the coordinates of the board, it will be easy to find what is below.

    
answered by 18.03.2016 / 01:56
source