It looked something like this:
But that was to absolutely no satisfaction. So the only reasonable thing to do was to spend the entire evening coding an "intelligent" tile placer. Which sees corners, straights etc.
The way I did this, though hacky, I guess, was to have a thingy place hundreds of tiles in a pattern derived from a 32 x 32 bitmap that was actually the blueprint for the ****. So if the bitmap had a pixel at a given position, the thingy would automatically place a "block" at that position relative to the grid size of the game.
A pixel at position 3 x 5 in the blueprint bitmap would result in a "block" being placed at 3*32 x 5*32 pixels relative to the ****. Pretty cool. And simple. Hacky.
When all the needed "blocks" had been placed, each "block" would then run their own little code. That code basically checks its surroundings. First in direction 0, which is straight to the right. Then direction 45, which is upper right, then 90, which is straight up, etc.
Each time the "block" saw another block it would count +1 in a variable called "blocks", each time it didn't see anything it would count +1 in a variable called "voids".
After having gathered the needed intel to form a sort of matrix of where there were blocks and where there weren't, it would determine in which average direction there were blocks.
Average direction of "voids"/"blocks" in degrees:
1: 247-------------2: 270-------------3: 315
1: 247-------------2: 270-------------3: 315
So if the little block saw 5 blocks to the right,45,up,135,left it would have an average accumulated cluster of blocks in the direction of 90, or straight up. So the void would naturally be at 270, or straight down. After that assessment it was just a matter of "skinning" the individual "blocks" with a corner graphic if it was at a corner, or a straight graphic if it had neighbors whom desired it to be straight.
The result looks a bit like this -
- but not really, you'll have to play the game to see. -_-'
The ones inside the shape are a bit misleading, they are actually to be skinned black, so they are present but not visible.
I know it is not very groundbreaking, but I felt like a freaking god when I nailed that one!
Auto tile placer works. Happy smiley. Numbers just debug. I feel like a freaking god! pic.twitter.com/pFxckqgNjs
— Andreas I\I Grontved (@andreasng____) March 20, 2014
Ingen kommentarer:
Send en kommentar