OZONE Asylum
Forums
Server-Side Scripting - Oh my!
Godot and Auto-Tiling WJ-style
This page's ID:
33334
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Okay, I was talking slightly backwards in a few spots. If you've noticed, know that cinnamon whiskey was involved. I still managed to write, but not quite as cleanly as I wanted. My tile map is a bit sloppy. I used Krita and my mouse real quick and and dirty. Guides turned on, but no snapping. It's a bit of a mess. Why? Because I want variations in my lines. A little more visually interesting and not just a bunch of perfectness. However, even with sloppy painting, even a straight hallway can become pattern-esque, repetitive. Even a series of small alcoves will still all look the same and defeat the purpose. Using above lay-out and bit order, imagine a hallway like this: [code] +--+--+--+--+--+--+--+--+ |..|..|..|..|..|..|..|..| |48|48|48|48|48|48|48|48| +--+--+--+--+--+--+--+--+ |12|12|12|12|12|12|12|12| |..|..|..|..|..|..|..|..| +--+--+--+--+--+--+--+--+ [/code] Even with imperfections in the wall tiles, it will still manage to become repetitive. With sloppy painting *and* transforms, that same hallway can become this: [code] +--+--+--+--+--+--+--+--+ |..|..|..|..|..|..|..|..| |12|48|21|41|14|48|84|48| +--+--+--+--+--+--+--+--+ |28|12|82|21|14|81|12|42| |..|..|..|..|..|..|..|..| +--+--+--+--+--+--+--+--+ [/code] Suddenly, a little more visually interesting. And it tiles just fine. However, this means that there can not be any visual directional clues in the tile map. Which I'm okay with for two reasons. The first being that this is a project for me and only me, and all of this suites me just fine. The second reason is that Godot *does* support normal maps. They can be in the environment, but I've only played with them a little bit. If I do decide on putting in lighting information, shouldn't be too difficult with normal maps (even if I do have to cobble it a bit). Transforms? When I first starting playing with tile maps in Godot, I noticed 4 little buttons: horz flip, vert flip, +90, and -90. And I was all excited because I saw the potential of doing the above. So I de-constructed the transforms into this sequence: [code] transf=[ 0, -1610612736, 1610612736, -1073741824, 536870912, -536870912, 1073741824, -2147483648] [/code] The first is no transform. The next 3 are +90, +180, and +270. The last four are the same rotations, but with flip horz first. There are 8 unique transforms because things become the same when flip horz and flip vert are both used. Yes, order does matter. That is, flip before rotate. The transform data is held in the second number using the last 4 bits of 32. And type-casting, one of the things that I love to hate, comes into play a little bit. Since playing with bits, would expect unsigned ints. But some of those numbers are negative. Linux's Calculator doesn't want to show bits for anything other than unsigned ints, and I didn't want to cobble some code to actually see the bits in terminal. I know that they are there because of the sign. I don't know if this is a foible or not, but it really did annoy me for a few minutes. But it's all good. With that sequence of transforms, I had to make an equivalency table. If you transform a tile a certain way, what tile does it become? I see this process backwards in my head and it took me a few tries to get it straightened out. And this little beastie looks like this: [code] transm= [[ 0, 0, 0, 0, 0, 0, 0, 0], [ 1, 4, 8, 2, 2, 8, 4, 1], [ 2, 1, 4, 8, 1, 2, 8, 4], [ 3, 5, 12, 10, 3, 10, 12, 5], [ 4, 8, 2, 1, 8, 4, 1, 2], [ 5, 12, 10, 3, 10, 12, 5, 3], [ 6, 9, 6, 9, 9, 6, 9, 6], [ 7, 13, 14, 11, 11, 14, 13, 7], [ 8, 2, 1, 4, 4, 1, 2, 8], [ 9, 6, 9, 6, 6, 9, 6, 9], [10, 3, 5, 12, 5, 3, 10, 12], [11, 7, 13, 14, 7, 11, 14, 13], [12, 10, 3, 5, 12, 5, 3, 10], [13, 14, 11, 7, 14, 13, 7, 11], [14, 11, 7, 13, 13, 7, 11, 14], [15, 15, 15, 15, 15, 15, 15, 15]] [/code] Take the transform sequence, the equivalency table, and plug them into the code to for the final Python script: [code] #!/usr/bin/env python # -*- coding: utf-8 -*- from PIL import Image import random # positions of individual tiles in the tile map # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 tilepos=[196608, 196611, 131072, 131073, 0, 131075, 196610, 65539, 196609, 65536, 1, 131074, 3, 2, 65537, 65538] # the transforms transf=[ 0, -1610612736, 1610612736, -1073741824, 536870912, -536870912, 1073741824, -2147483648] # transform equivalency table transm= [[ 0, 0, 0, 0, 0, 0, 0, 0], [ 1, 4, 8, 2, 2, 8, 4, 1], [ 2, 1, 4, 8, 1, 2, 8, 4], [ 3, 5, 12, 10, 3, 10, 12, 5], [ 4, 8, 2, 1, 8, 4, 1, 2], [ 5, 12, 10, 3, 10, 12, 5, 3], [ 6, 9, 6, 9, 9, 6, 9, 6], [ 7, 13, 14, 11, 11, 14, 13, 7], [ 8, 2, 1, 4, 4, 1, 2, 8], [ 9, 6, 9, 6, 6, 9, 6, 9], [10, 3, 5, 12, 5, 3, 10, 12], [11, 7, 13, 14, 7, 11, 14, 13], [12, 10, 3, 5, 12, 5, 3, 10], [13, 14, 11, 7, 14, 13, 7, 11], [14, 11, 7, 13, 13, 7, 11, 14], [15, 15, 15, 15, 15, 15, 15, 15]] # for the second digit in the sequence of 3 # modify as needed as per *.tres file tresindex=0 # pixel map ping = Image.open('pixelmap01a.png') # image dimensions width,height=ping.size # final output fo=[] def thresh0255(n): # way over-the-top, but not taking any chances return int( float(n/255.0) + 0.5 ) * 255 # start grabbing bits for transparency for y in range(height-1): for x in range(width-1): a=thresh0255(ping.getpixel((x,y))[3])&1 b=thresh0255(ping.getpixel((x+1,y))[3])&2 c=thresh0255(ping.getpixel((x,y+1))[3])&4 d=thresh0255(ping.getpixel((x+1,y+1))[3])&8 e=(a|b|c|d) if e==15: # only if all 4 bits are opaque m=thresh0255(ping.getpixel((x,y))[0])&1 n=thresh0255(ping.getpixel((x+1,y))[0])&2 o=thresh0255(ping.getpixel((x,y+1))[0])&4 p=thresh0255(ping.getpixel((x+1,y+1))[0])&8 curtile=m|n|o|p rn=random.randint(0,7) newtile=transm[curtile][rn] newtrans=transf[rn] newpos=tilepos[rn] inmap = (y<<16)|x intrans = newtrans | tresindex intile=tilepos[newtile] fo.extend([inmap,intrans,intile]) # output for easy cut-n-paste print("tile_data = PoolIntArray{}".format(tuple(fo))) [/code] It's so cute. Nothing terribly fancy. Some information, some bitwise ops, scanning with overlap, and a hint of randomness. Boom. Done. It amazes me that such a short and straight-forward script can do what this little guy does. "That's a neat system you got there. Mind if I play with it?" So... what have I got? I can pixel paint maps using bitmask(2x2) for 16 tiles instead of bitmask(3x3) for 47 (48?) tiles. And my 2x2 does everything that a 3x3 can do. It can even do a little bit more. Why create 47 (48?) tiles when I only need 16? Yes? I've also got a better understanding of how Godot handles certain kinds of information. I have de-constructed (or reverse-engineered) a few other things, and I can do even more tricks for when I feel the need. Okay, I'm starting to get angry and I need to call it a night. I should be drunk on power, but certain things about all of this really piss me off. Yeah, I'm leaning in that direction right about now (and it has nothing to do with cinnamon whiskey... I promise). I really did enjoy all of this. Having a bit of my mojo back, even if for a small oasis. Thank you, Doc, for keeping the lights on. And thanks to the rest of you for listening to me rant, ramble, and rampage. play.fiddle.learn edit: tabs vs spaces... ugh edit2: omg, can you figure it out? I hope so because my rampage mode is OFF [small](Edited by [url=https://ozoneasylum.com/user/351]warjournal[/url] on 10-18-2020 14:04)[/small] [small](Edited by [url=https://ozoneasylum.com/user/351]warjournal[/url] on 10-18-2020 14:06)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »
Maximum Security
OZONE
DHTML/Javascript
Server-Side Scripting - Oh my!
CSS - DOM - XHTML - XML - XSL - XSLT
Stupid Basic HTML
Visual Therapy
Photoshop
Photoshop Pong, Anyone?
***WARNING*** BIG SIG APPROACHING
Photography
3D Modelling & Rendering
Multimedia/Animation
Print Graphics
Holding Pens
Philosophy and other Silliness
Outpatient Counseling
Site reviews!
Mad Scientists' Laboratory
Getting to know the Grail