- I decided to use the size of 40px because 32 is very small in the cell. How can I create a space of 40 pixels around the entire area of ??the game (10x10 squares) to avoid the ship doesn't get along the margin.
- I need to create a space around each ship also.
In the tests that I did initially, the first part of the ship always appears on the X axis. How can I do for the ships appear in different orientations?
Not sure if you have done it already or not, but turning on grid while in the editor will help you get an overview. Just make it the same size as you ratio. So in your case 40 by 40. And its a good idea to turn on grid snapping as well, so you can visually test things. As I think what you want to do, requires that you can to some degree imagine how it works, before you start programming, otherwise you will loose control quite fast I think.
So no matter what ratio you are working with, just to keep it simple, you have to multiply the ratio with the amount of spaces you want in each direction, otherwise things could start to get messy.
To explain it a bit more clear:
If you want to use 40x40 sprites with 10 spaces in each direction, your layout should be 10 x 40 pixels. (only if the origin is at 0,0)
So layout width and height should be 400 pixels.
This is because when you have to move things around, like the crosshair or place ships, you know that you can always multiply 40 with an integer to place things correctly in the grid.
To make it even easier you move the origin of the sprites so instead of it being 20,20 as standard for a 40x40 sprite, you move it to 0,0. Again then you can multiply with an integer to get the correct position.
To explain that, imagine you have a grid like this.
(0,0)(1.0)(2,0)
(0,1)(1,1)(2,1)
(0,2)(1,2)(2,2)
The values in this grid will then be the factor you have to multiply with when placing things. So imagine that we want to place a sprite at the (2,2) position. You simply multiply 40 by 2 for both X and Y, which would place it at (80.80) if it was pixels.
If you have the origin in the middle of the sprite, i think it starts to get a bit more complicated. Because then you have to make the layout 40 pixel larger. There is nothing wrong in doing it, it just add confusion I think.
To explain it.
If you have two 40x40 sprites. 1 with Origin 0,0 and the other with origin 20x20 as standard.
And you want to work with spaces that are 40x40 as well.
Then if you place each sprite at position (0,0) in the grid i made above.
The actual position of each sprite would be:
Sprite_1 with 0,0 origin = 0,0 pixel
Sprite_2 with 20,20 origin = 20,20 pixel (Assuming that you want the sprite to be on the layout, you can put it at 0,0 but then it would go outside the layout.)
So if you want to place them at the last space in X axis for instant, you would have to multiply with 10 to get that position.
So it would be like this:
Sprite_1 position = 400,0
Sprite_2 position = 420,20 (which would throw it outside the layout again if the layout you use is 400,400px. The actual 10 position when the origin is in the centre should be 380,20px)
Therefore you need to make the layout 40 pixel larger if you don't have the origin in 0,0. And then you suddenly have to work with 20s as well. And as i said there is nothing wrong in doing it, it just add confusion i think.
The easiest way to see this for you self is to turn on "show grid" and "snap to grid" and set width and height to 40. And then place a 40x40 sprite which have the origin in the centre in the top left space in the grid and see how it behaves when you move it around.
Regarding the space around the ships
Then it really starts to get complicated. Because then you have to add that to all the calculations.
In the tests that I did initially, the first part of the ship always appears on the X axis. How can I do for the ships appear in different orientations?
You can use the grid i showed above. since it will go from 0-9 in each direction you just have to see how much you have to add or subtract from the sprite position to place it.
If this is a Ship with two parts:
(0,0)(1.0)(2,0)
(0,1)(X1)(2,1)
(0,2)(X2)(2,2)
X(1) = 1 part Position in grid (1,1)
X(2) = 2 part Position in grid (1,2)
X(1): Actual position would be (40*1,40*1) = 40,40 pixel.
X(2): Actual position (40*1,40*2) = 40,80 pixel.
Personally this way of doing it, is a lot harder than the first suggestion i posted, because you have a lot more rules to look out for :D
However you might be able to do some tricky things if you pin the ships together instead and then just move 1 part around....but that's just a thought.