Categories
Game Creation Mastering Development

Find grid cells in 2D grid based on object size and rotation

I am working on a game that uses a grid system that allows the player to place buildings in the world. Each cell in the grid is 64×64. All buildings will be a multiple of 64×64, so everything will evenly fit in the the grid.

Below shows an example of a building that is 128×64 and placed at grid position 64×64. The client sends the server the “base” cell, which in this case is 1,1 (@64×64), and knows the building that is being build is 128×64 so it sets both cells to the “occupied” state which means a building is placed in those 2 grids.

Example no rotation

The problem I am having is allowing the client to rotate the building either 90, 180, or 270 degrees.

For example, if the client wanted to place the same building, but rotated 90 degrees, it would look like this:

Example 90 rotation

Basically what I am asking is: Given the client sends to server the location to build 64×64, and sends 90 for the rotation, how can I (on the server) figure out which cells are going to be build on?

Currently I am using this code to get the grids, but it doesn’t allow for rotation since I have no idea.

https://pastebin.com/UaaUa7jZ

Any help would be appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *