Global

Methods

createDeathParticles(target, cellSize) → {Array.<Object>}

Creates death effect particles for defeated entities Implements visual feedback system
Parameters:
Name Type Description
target Object The defeated entity
cellSize number Size of grid cell for scaling
Source:
Returns:
Array of particle objects
Type
Array.<Object>

findTowersInRange(enemy, towers) → {Array.<Object>}

Finds towers within enemy attack range Implements targeting system for enemies
Parameters:
Name Type Description
enemy Object Enemy doing the targeting
towers Array.<Object> Array of potential tower targets
Source:
Returns:
Array of towers in range
Type
Array.<Object>

generatePath(grid) → {Promise.<Array.<{x: number, y: number}>>}

Generates a valid path through the game grid using a modified depth-first search. This algorithm ensures: - Path always moves from left to right - No diagonal movements - No path segments touch each other (except at turns) - Path is always completable
Parameters:
Name Type Description
grid Array.<Array.<string>> 2D array representing the game grid
Source:
Returns:
Promise resolving to array of path coordinates Implementation uses: - Backtracking algorithm pattern - Constraint satisfaction - Random selection for variety
Type
Promise.<Array.<{x: number, y: number}>>

getPathPosition(progress, path) → {Object}

Calculates a position along the path based on a progress value Implements smooth entity movement along path segments
Parameters:
Name Type Description
progress number Progress along path (0-1)
path Array.<{x: number, y: number}> Array of path coordinates
Source:
Returns:
Interpolated position along path Uses: - Linear interpolation (lerp) - Path segment traversal - Normalized progress tracking
Type
Object

handleAOEEffect(target, tower, enemies, particles, cellSize)

Handles AOE (Area of Effect) damage and visual effects Implements area damage system
Parameters:
Name Type Description
target Object Primary target
tower Object Tower dealing AOE damage
enemies Array.<Object> All enemies for AOE calculation
particles Array.<Object> Particle array for effects
cellSize number Grid cell size
Source:

handleEnemyAttack(enemy, tower, particles, timestamp, cellSize)

Handles enemy attack execution and effects Implements enemy combat mechanics
Parameters:
Name Type Description
enemy Object Attacking enemy
tower Object Target tower
particles Array.<Object> Particle array for effects
timestamp number Current game timestamp
cellSize number Grid cell size
Source:

handleSlowEffect(target, tower, timestamp, particles, cellSize)

Handles slow effect application and stacking Implements status effect system
Parameters:
Name Type Description
target Object Enemy to apply slow to
tower Object Tower applying the effect
timestamp number Current game timestamp
particles Array.<Object> Particle array for effects
cellSize number Grid cell size
Source:

handleTowerAttack(tower, target, projectiles, particles, timestamp, cellSize)

Handles individual tower attack logic including special effects Implements tower ability system
Parameters:
Name Type Description
tower Object Attacking tower
target Object Target enemy
projectiles Array.<Object> Projectile array
particles Array.<Object> Particle array
timestamp number Current game timestamp
cellSize number Grid cell size
Source:

initializeDragAndDrop(canvas, gameState) → {Object}

Initializes drag and drop functionality for tower placement Implements HTML5 Drag and Drop API
Parameters:
Name Type Description
canvas HTMLCanvasElement Game canvas element
gameState Object Current game state
Source:
Returns:
Drag handlers and state information
Type
Object

placeTower(gameState, towerType, position)

Places a tower in the game grid Implements tower placement validation and state updates
Parameters:
Name Type Description
gameState Object Current game state
towerType string Type of tower to place
position Object Grid position for placement
Source:

processEnemyAttacks(enemies, towers, particles, timestamp, cellSize)

Processes enemy attack behaviors and targeting Implements enemy combat AI
Parameters:
Name Type Description
enemies Array.<Object> Array of enemy objects
towers Array.<Object> Array of tower objects
particles Array.<Object> Particle effect array
timestamp number Current game timestamp
cellSize number Grid cell size
Source:

processTowerAttacks(towers, enemies, projectiles, particles, timestamp, cellSize)

Processes tower attacks and targeting Implements combat mechanics and special abilities
Parameters:
Name Type Description
towers Array.<Object> Array of tower objects
enemies Array.<Object> Array of enemy objects
projectiles Array.<Object> Array of projectile objects
particles Array.<Object> Array of particle objects
timestamp number Current game timestamp
cellSize number Size of grid cell for scaling
Source:

renderEnemies(ctx, enemies)

Renders all enemies with health indicators and effects Implements visual state representation
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Canvas rendering context
enemies Array.<Object> Array of enemy objects
Source:

renderGrid(ctx, grid)

Renders the game grid with path and hover previews Implements visual feedback for player actions
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Canvas rendering context
grid Array.<Array.<string>> Game grid state
Source:

renderUI(ctx, gameState)

Renders game UI elements with clean state management Implements heads-up display (HUD) pattern
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Canvas rendering context
gameState Object Current game state
Source:

updateEnemies() → {void}

Updates all enemy states including movement, health, and status effects Implements core game loop mechanics for enemy behavior Key features: - Path following - Health management - Status effect processing - Collision detection
Source:
Returns:
Type
void

updateParticles(particles, timestamp, deltaTime) → {Array.<Object>}

Updates particle effects with time-based animation Implements particle system lifecycle management
Parameters:
Name Type Description
particles Array.<Object> Array of particle objects
timestamp number Current game timestamp
deltaTime number Time elapsed since last frame
Source:
Returns:
Updated particles array
Type
Array.<Object>