Sure.
This fires up the board builder. Just creates the "dartboard" like structure.
extends Node
class_name BoardBuilder
# This class is responsible for building individual boards for the game
# in a virtual sense. The "virtual board" contains arrays of board cells by
# rank and file with each board cell containing information specific to the cell.
# This information includes the corner boundaries in Vector3 format, the center
# (centroid) position of each cell in Vector3, whether or not a cell is occupied
# by a piece and if so, a reference to the actual piece occupying the cell.
const BoardRank := preload("res://scripts/Logic/boardRank.gd");
const BoardCell := preload("res://scripts/Logic/boardCell.gd");
# Inner ring. The bulls-eye if you will.
const ASCENSION_RING_RADIUS: float = 2.0;
const BOARD_THICKNESS: float = 0.075;
const BOARD_SEPARATION: int = 3;
# Identifies the board we're working with
var BoardIndex: int;
# Contains the ranks
var Ranks: Array[BoardRank] = [];
func _init(board: int, ranks: int, files: int) -> void:
# Set our board index
BoardIndex = board;
# For each rank, create a Rank object.
for r in range(ranks):
_createRank(r, files);
func _createRank(_rank: int, _files: int) -> void:
var boardY = (BoardIndex * BOARD_SEPARATION) + BOARD_THICKNESS;
var _inner = _plotRingVertices(_files, _rank, Vector3(0, boardY, 0));
var _outer = _plotRingVertices(_files, _rank + 1, Vector3(0, boardY, 0));
Ranks.append(BoardRank.new(_inner, _outer));
func GetRank(rank: int) -> BoardRank:
return Ranks[rank];
func _plotRingVertices(columns: int, radiusFromCenter: int, pivotPoint: Vector3) -> Array[Vector3]:
var _v: Array[Vector3] = [];
var slice = 2 * (PI / columns);
for _c in columns:
var angle = slice * _c;
var newX = (pivotPoint.x + radiusFromCenter + ASCENSION_RING_RADIUS) * cos(angle);
var newZ = (pivotPoint.z + radiusFromCenter + ASCENSION_RING_RADIUS) * sin(angle);
_v.append(Vector3(newX, pivotPoint.y, newZ));
return _v;
This builds the individual rings or ranks for the board which creates the distinct BoardCell objects.
extends Node
class_name BoardRank
const BoardCell := preload("res://scripts/Logic/boardCell.gd");
var _innerVertices: Array[Vector3];
var _outerVertices: Array[Vector3];
var _cells: Array[BoardCell] = [];
func _init(innerV: Array[Vector3], outerV: Array[Vector3]) -> void:
_innerVertices = innerV;
_outerVertices = outerV;
_generateCells();
func _generateCells() -> void:
for _cell in range(_innerVertices.size()):
var leftSide: int = _cell;
var rightSide: int = _cell + 1;
if (rightSide == _innerVertices.size()):
rightSide = 0;
_cells.append(BoardCell.new(
_innerVertices[rightSide],
_outerVertices[rightSide],
_innerVertices[leftSide],
_outerVertices[leftSide]
));
func GetCell(cell: int) -> BoardCell:
return _cells[cell];