Minigame Monday: Node Problem

 Node Problem

  • The concept:

Back to Python for this one; I saw something I thought was pretty cool looking in the header for a website, so I decided to remake it and expand on it. The concept is a series of dots, moving randomly, that form lines between them as they approach each other, with the strength of the line increasing as they get closer. This creates a very cool looking effect, with shapes forming and vanishing as the nodes move past one another. This minigame therefore is less of a game, and more of a digital toy.

  • The challenge:

I decided that the best way to do this was to have a seperate class for the nodes, so each instance of a node would store the nodes position, speed and direction. It would also have a function to move the node, using a bit of trigonometry to calculate the correct position to move to:

self.pos = (math.sin(self.rot) * self.speed + self.pos[0],
             math.cos(self.rot) * self.speed + self.pos[1])

 For instancing the nodes, I used the following code:

        #Make sure we have self.noNodes nodes
        while len(self.nodes) < self.noNodes:
            self.nodes.append(Node(self.maxNodeSpeed))

I'm passing in maxNodeSpeed, as that's a variable I wanted to expose to the player, and self.nodes is my list of nodes in the main game class. Once I had the list of nodes created, all I had to do was draw lines between them when they were close. I wanted to have the lines become stronger as the nodes got closer together, and I wanted this to be configurable, so I needed to have an efficient way of increasing the weight of the line. Here was my solution:

for i in range(self.lineDiffusion - 1, -1, -1):
  if dist < LINEDISTHRESHOLD / (i + 1):
    pygame.draw.line(self.screen, (self.red/(self.lineDiffusion/(i+1)),  
                                    self.green/(self.lineDiffusion/(i+1)), 
                      self.blue/(self.lineDiffusion/(i+1))), n.pos, d.pos)
       break

Two things that are happening here; I'm looping backwards, checking if the nodes fall within the thresholds moving inward, that way the loop can break as soon as a line can be drawn, avoiding drawing unneeded lines. Secondly, to produce the strengths of colour I want, I'm simply dividing the colours by the subtlety of the line I want. This makes the colours closer to the black background, producing the desired effect.

  • The result:

Nodes

This was an interesting effect to create, and I was pleased with being able to do so without much trouble. It isn't exactly a game, so I intend to go back to something a little more traditional next week, but the result is quite fun to play with (at least in my opinion), and I kind of think feels like a digital fidget toy. You can try it for yourself at https://reddragonmakesgames.itch.io/node-problem and the code is on my github.
 

Comments

Popular posts from this blog

Armageddump (Boss Rush Jam 2023)

Introducing: Minigame Monday! (3D Minesweeper)

Minigame Monday: Covert Behaviour