20150706

Map painting

The map editor has a few things it should be able to do:
  • Create a new (empty) map
  • Save a map
  • Load a map
  • Show a minimap of the whole map
  • Set brush tile type 
  • Set brush size
  • Set tiles
  • Erase tiles
Today, I did all painting-related things: setting tiles, changing brush tile types / brush size, and erasing tiles. Basically, you have a brush that is either 1, 3 or 5 cells wide. There are eight terrain types, plus an "empty" terrain type, which is effectively the eraser.

How did I make this work?

I made a HexTile prefab, which is a GameObject with a SpriteRenderer component (and also a child that would be the outline, but this will be only used in Game mode). This is what gets put here and there. At each frame, I check if the mouse button is down. If yes, I calculate which hex is the mouse pointing at, and then check if there is already a tile at that hex's center (with Physics2D.RayCast) - if yes, I delete it. Then I check which terrain type is selected (the buttons on the sidebar are a toolbar) and if it is not the empty terrain, I put a tile of said type to that hex. If the brush size is bigger, I do the same for the other hexes.

The result is here:


No comments:

Post a Comment