3. Attaching a script in enemies node
-Name the script enemy_mob.gd
-Save your script in (res://scripts/enemie_mob.gd)
-Copy the code on your right to script (res://scripts/enemie_mob.gd)
4. Code Breakdown
-Grid & Movement Configuration:
-ROWS := 4 & COLUMNS := 11: Defines an 11-column by 4-row grid of enemies (44 enemies total).
-SPACE_X := 50 & SPACE_Y := 50: Sets the pixel spacing between each enemy horizontally and vertically.
-left_value, right_value, desend_speed: Variables reserved for setting screen boundary bounds and vertical descent step distance when changing direction.
-Grid Spawning (create_formation()):
-preload("res://scenes/enemy.tscn"): Preloads the individual enemy scene into memory once when the script initializes.
Nested for Loops: Iterates through each row (0..3) and column (0..10).
enemy_scene.instantiate(): Creates a new instance of the enemy scene.
add_child(enemy): Adds the instance as a child node under enemies.
enemy.row = row: Assigns the row index to the individual enemy instance, which triggers its corresponding color/sprite variant in enemy.gd.
enemy.position = Vector2(...): Calculates local $(X, Y)$ offset coordinates to arrange the enemies in a neat grid.