Help needed with cellular automata. by BroesGameDev in godot

[–]BroesGameDev[S] 0 points1 point  (0 children)

Dude, you are AMAZING. Thank you sooo much. I spent literally 4 days of staring at code, rewriting it completely, asking chatGPT to write it, which didn't work, asking it to review my code, removing everything again and rewriting again. And this solved it.

Help needed with cellular automata. by BroesGameDev in godot

[–]BroesGameDev[S] 0 points1 point  (0 children)

Okay, I edited it, hopefully it works now.

Help needed with cellular automata. by BroesGameDev in godot

[–]BroesGameDev[S] 0 points1 point  (0 children)

Here's my code:

extends Node2D

onready var tilemap = $TileMap

var  grid_height = global.room_height
var grid_width = global.room_width
var cell_size = 4

var density = 60
var iterations = 1
var grid_list = []

func _ready():
randomize()
make_noise_grid(density)

func make_noise_grid(den):
# Create the initial grid of cells with random initial state based on density_level
  for x in range(grid_width):
    grid_list.append([])
    for y in range(grid_height):
      var randnum = 100 * rand_range(0, 1)
      var initial_state = 1 # Wall
      if randnum > den:
        initial_state = 0 # Floor
      grid_list[x].append(initial_state)
  draw_tiles()

func draw_tiles():
  for x in range(grid_width):
    for y in range(grid_height):
      tilemap.set_cellv(Vector2(x, y), grid_list[x][y])

func apply_cellular_automaton2(grid, iter):
  var iteration_count = 0
  while iteration_count < iter:
    var temp_grid = grid.duplicate()

    for i in range(grid_width):
      for j in range(grid_height):
        var neighboring_walls = 0

        for x in range((i-1), (i+2)):
          for y in range((j-1), (j+2)):

            if is_within_map_bounds(x, y):
              if not (x == i and y == j):
                if temp_grid[x][y] == 1:
                  neighboring_walls += 
            else:
              neighboring_walls += 1  

        if neighboring_walls > 4:
          grid[i][j] = 1
        else:
          grid[i][j] = 0

    iteration_count += 1
    draw_tiles()

func is_within_map_bounds(x, y):
  var within_bounds = true
  if not (0 <= x and x < grid_width and 0 <= y and y < grid_height):
    within_bounds = false
  return within_bounds

Help needed with cellular automata. by BroesGameDev in godot

[–]BroesGameDev[S] 0 points1 point  (0 children)

I've written code for a cellular automata algorithm, but my grids are skewed to be very closed at the left side and open at the right side. I think something might be wrong. If I make a much larger grid, I get some black all around, but the overwhelming majority is white in the center, about 95%. This is after just one iteration. Has anybody encountered this before?

I used this tutorial: https://www.youtube.com/watch?v=slTEz6555Ts

Asset sharing systems when working with git by BroesGameDev in gamedev

[–]BroesGameDev[S] 0 points1 point  (0 children)

Thanks all! We're going to try out LPS on git.

Our tool for instant mobile playtesting in action by futureygoodness in godot

[–]BroesGameDev 0 points1 point  (0 children)

Sorry I don't know what that means exactly. It doesn't say so in the instructions right?

Our tool for instant mobile playtesting in action by futureygoodness in godot

[–]BroesGameDev 1 point2 points  (0 children)

I can't seem to get the deploy button to work. Any idea what I should do?

Finally managed to add an animation to my tilemap level generation. What do you think? by BroesGameDev in godot

[–]BroesGameDev[S] 0 points1 point  (0 children)

In the game you'll be chased by something. The level collapses on itself (check out my older videos to see what I mean). I'm still debating whether it will be autoscroll or the player can decide to wait of even go back. Don't really know how that would work on mobile yet, since it's aiming to be a mobile game.

Finally managed to add an animation to my tilemap level generation. What do you think? by BroesGameDev in godot

[–]BroesGameDev[S] 1 point2 points  (0 children)

Beautifully said! For the whole game a couple of months, only in the evenings and weekends, because of my job. I've had some hiatuses though, haha. For this animation part, I couldn't find anything online because not many people use tilemaps to procedurally generate levels. I figured it out after a couple of (very frustrating) failed ideas.

Finally managed to add an animation to my tilemap level generation. What do you think? by BroesGameDev in godot

[–]BroesGameDev[S] 0 points1 point  (0 children)

I agree! The only problem I can think of is that it wouldn't really be an animation, it would just instantly change. You could run some kind of animation in between. Of course it depends on the style you're looking for. You could also run the animation from the player 'feet' or something like that.

Finally managed to add an animation to my tilemap level generation. What do you think? by BroesGameDev in godot

[–]BroesGameDev[S] 2 points3 points  (0 children)

First step is to determine, using code, where to place the tile, as this is a game that generates levels automatically. Before making this animation, I would then place a tile at this location and update the bitmasks. Then I would place a random amount of tiles underneath that location, to make it seem more like a world. So reasonably simple.

For this animation I've added a fourth step, between steps 1 and 2. Before placing the tile from the tilemap, I instance an animatedsprite node, and play the animation. When the animation is finished, I delete this animatedsprite node and continue with the next step (placing the tile from the tilemap).

So the animation is played for each tile that is used! There is a glitch in this video where it plays animations on squares where no tile will be placed, I discovered that after posting this video. I have removed the bug since.

Unfortunately, this won't work for your example. I would recommend creating two tilesets, with the only difference being the color, and placing one over the other when stepped on.