Discuss Scratch

WolfieTundra
Scratcher
10 posts

Hex Map Generator (infinite or at least big)

Well, I'm planning on making a game that has a hex tiled base map, but I've got no idea on how to make it infinite; help would be great
AStefex
Scratcher
100+ posts

Hex Map Generator (infinite or at least big)

WolfieTundra wrote:

Well, I'm planning on making a game that has a hex tiled base map, but I've got no idea on how to make it infinite; help would be great
Could you share the project? If I can see it, it would be easier.
gtoal
Scratcher
1000+ posts

Hex Map Generator (infinite or at least big)

WolfieTundra wrote:

Well, I'm planning on making a game that has a hex tiled base map, but I've got no idea on how to make it infinite; help would be great
same way you make any map infinite. With a seed and a pseudo random number based on grid position. Just adapt the PRNG system from something like https://scratch.mit.edu/projects/129226713/ and use the hex tile coordinates from https://scratch.mit.edu/projects/24148560/
WolfieTundra
Scratcher
10 posts

Hex Map Generator (infinite or at least big)

gtoal wrote:

WolfieTundra wrote:

Well, I'm planning on making a game that has a hex tiled base map, but I've got no idea on how to make it infinite; help would be great
same way you make any map infinite. With a seed and a pseudo random number based on grid position. Just adapt the PRNG system from something like https://scratch.mit.edu/projects/129226713/ and use the hex tile coordinates from https://scratch.mit.edu/projects/24148560/

Hmm… It seems to be way too complicate for me…
gtoal
Scratcher
1000+ posts

Hex Map Generator (infinite or at least big)

WolfieTundra wrote:

gtoal wrote:

WolfieTundra wrote:

Well, I'm planning on making a game that has a hex tiled base map, but I've got no idea on how to make it infinite; help would be great
same way you make any map infinite. With a seed and a pseudo random number based on grid position. Just adapt the PRNG system from something like https://scratch.mit.edu/projects/129226713/ and use the hex tile coordinates from https://scratch.mit.edu/projects/24148560/

Hmm… It seems to be way too complicate for me…
Come on, you can work this out…

define Draw Visible Map (cx) (cy) pixel offset (px) (py)
set [y v] to [-5]
repeat (12)
set [x v] to [-7]
repeat (16)
select costume ((x) + (cx)) ((y) + (cy)) :: custom
go to x: (((x) * (32)) - (px)) y: (((y) * (32)) - (py))
stamp
change [x v] by (1)
end
change [y v] by (1)
end

define select costume (x) (y)
f x,y: (x) (y) orientation: (0) range: 0.. (2) -1 :: custom
set [left v] to (hashval)
f x,y: ((x) + (1)) (y) orientation: (0) range: 0.. (2) -1 :: custom
set [right v] to (hashval)
f x,y: (x) ((y) + (1)) orientation: (1) range: 0.. (2) -1 :: custom
set [top v] to (hashval)
f x,y: (x) (y) orientation: (1) range: 0.. (2) -1 :: custom
set [bot v] to (hashval)
set [new tile # v] to (join (top) (join (right) (join (bot) (join (left) (set #)))))
switch costume to (new tile #)

define f x,y: (a) (b) orientation: (leftright) range: 0.. (n) -1
set [hashval v] to (((leftright) * (237137)) + (((a) * (842993)) + ((b) * (640027))))
set [hashval v] to ((round (((hashval) / (((a) mod (17)) + (7))) + (((hashval) / (((b) mod (31)) + (17))) + ((hashval) / (((leftright) * (10)) + (3)))))) mod (n))

you redraw the whole map any time you scroll the world.

each map tile has an absolute x,y in world coordinates (not screen coordinates)

f(x,y) picks a tile (costume numbered in the range 0 to n-1) for each x,y square. It always returns the same value for any x,y.

There's an extra parameter ‘leftright’ that I use for some other purpose which you could always set to the same value if you don't need t yourself.
WolfieTundra
Scratcher
10 posts

Hex Map Generator (infinite or at least big)

gtoal wrote:

WolfieTundra wrote:

gtoal wrote:

WolfieTundra wrote:

Well, I'm planning on making a game that has a hex tiled base map, but I've got no idea on how to make it infinite; help would be great
same way you make any map infinite. With a seed and a pseudo random number based on grid position. Just adapt the PRNG system from something like https://scratch.mit.edu/projects/129226713/ and use the hex tile coordinates from https://scratch.mit.edu/projects/24148560/

Hmm… It seems to be way too complicate for me…
Come on, you can work this out…

define Draw Visible Map (cx) (cy) pixel offset (px) (py)
set [y v] to [-5]
repeat (12)
set [x v] to [-7]
repeat (16)
select costume ((x) + (cx)) ((y) + (cy)) :: custom
go to x: (((x) * (32)) - (px)) y: (((y) * (32)) - (py))
stamp
change [x v] by (1)
end
change [y v] by (1)
end

define select costume (x) (y)
f x,y: (x) (y) orientation: (0) range: 0.. (2) -1 :: custom
set [left v] to (hashval)
f x,y: ((x) + (1)) (y) orientation: (0) range: 0.. (2) -1 :: custom
set [right v] to (hashval)
f x,y: (x) ((y) + (1)) orientation: (1) range: 0.. (2) -1 :: custom
set [top v] to (hashval)
f x,y: (x) (y) orientation: (1) range: 0.. (2) -1 :: custom
set [bot v] to (hashval)
set [new tile # v] to (join (top) (join (right) (join (bot) (join (left) (set #)))))
switch costume to (new tile #)

define f x,y: (a) (b) orientation: (leftright) range: 0.. (n) -1
set [hashval v] to (((leftright) * (237137)) + (((a) * (842993)) + ((b) * (640027))))
set [hashval v] to ((round (((hashval) / (((a) mod (17)) + (7))) + (((hashval) / (((b) mod (31)) + (17))) + ((hashval) / (((leftright) * (10)) + (3)))))) mod (n))

you redraw the whole map any time you scroll the world.

each map tile has an absolute x,y in world coordinates (not screen coordinates)

f(x,y) picks a tile (costume numbered in the range 0 to n-1) for each x,y square. It always returns the same value for any x,y.

There's an extra parameter ‘leftright’ that I use for some other purpose which you could always set to the same value if you don't need t yourself.

i Sincerely don't understand this, i've been a while on scratch, but never handled that kind of stuff, but yesterday i managed to make something a bit simpler, it might not be infinite but it's pretty big https://scratch.mit.edu/projects/172398449/
Check it out to see kinda of the idea of the tiles
gtoal
Scratcher
1000+ posts

Hex Map Generator (infinite or at least big)

what you implemented cannot work for an unbounded map. You select clone costumes at random. If you implemented scrolling and if you scrolled off the map and then back on again, the next time those tiles were re-created they would have different costumes. I was trying to show you a way that selected a costume based on the virtual location rather than a random number, so that when you revisted it, the same costume would be regenerated.
WolfieTundra
Scratcher
10 posts

Hex Map Generator (infinite or at least big)

gtoal wrote:

what you implemented cannot work for an unbounded map. You select clone costumes at random. If you implemented scrolling and if you scrolled off the map and then back on again, the next time those tiles were re-created they would have different costumes. I was trying to show you a way that selected a costume based on the virtual location rather than a random number, so that when you revisted it, the same costume would be regenerated.

i know, but i think i'll let it like that, sorry but i really don't understand that script you posted, i'm still too dumb…

Powered by DjangoBB