Pointers on how to make a game like Territorial.io?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By _Jim

I’m a newbie to game dev, and I’m trying to practice by making a clone of territorial.io, I’ve been reading up on documentation and I’ve finished the initial GUI/HUD just trying to get familiar with Godot, however I’m completely stuck and I have no idea where to start on recreating important elements of the game scenes.

I have a couple of gray areas that despite reading Godot docs I’m still struggling with, for example:

Picking a node to represent playing arena, its scale should be increased or decreased based on mouse-wheel to simulate zooming on playing field, with maximum and minimum zoom bounds.

Picking which node to create player’s controlled territory, first I tried instantiating an instance of Polygon2D and try to manipulate it but the result is far from the game is like. The player territory in the game is sort of a collection of pixels!

Player territory can be expanded over neutral areas, and stop expanding when it collides with other players’ territories.

Player territory can be expanded over other players territory by clicking over them and choosing the attack option.

Player territory can only expand within specific area or shape to simulate maps and islands, and also non-accessible areas like water.

With regards to the territory, maybe a cell.tscn file that represents a single little square, and an arena.tscn file that has a bunch of cell.tscn as children. Each cell could have some properties, like integers i and j representing what row and column that cell is in, and a boolean representing whether it’s a water cell or land cell. Each cell could also have an integer variable representing the player who owns that cell, or 0 if it’s still neutral. The logic for player L territory expansion into player K (where K=0 means expansion into neutral) could be something like “if L expanding into K, then for each cell owned by player L check if that cell is neighbours with a cell owned by player K and if so then change the player K cell to be owned by player L”. There’s perhaps more to consider, like how much attacking force vs defending force. Also, it might be more efficient to keep a list for each player containing the cell indices (i,j) that lie on their territory boundary, so that not every internal cell needs to get iterated over during expansion. And maybe keeping a dictionary somewhere with indices-to-cell-node pairs, so something similar to

onready var cell_scene = load("cell.tscn")
var indices_to_cells = {}

func _ready():
    for i in range(1000):
        for j in range(1000):
            var new_cell = cell_scene.instance()
            indices_to_cells[(i,j)] = new_cell

But where exactly to put that dictionary, or if it’s even needed, I’m not sure.

haydenv | 2022-07-15 23:19

Thank you so much this is actually really insightful and helpful, I’d try fiddling with the suggested approach and see where it goes from there.

Much love <3

_Jim | 2022-07-16 00:02

Thank you. You have revealed the solution very well. I found it interesting and useful

Mason_Stevenson | 2022-11-03 00:57