Skip to content

LINX - Example Game Built with CASCADA

Territory network game demonstrating CASCADA Framework features


Overview

LINX is a complete game example built with CASCADA Framework to demonstrate:

  • Graph-based gameplay (Nodes & Edges)
  • Vue UI integration (MainMenu + GameHUD)
  • Visual themes system
  • Energy economy
  • Bot AI
  • Infinite mode with persistent scores

Source code: src/game/territory/

Play: pnpm devhttp://localhost:5173


Game Rules

Objective

Create closed polygons between nodes to capture enemy territory. The player with the most controlled area after 60 seconds wins the round.

Mechanics

  1. Click → Create your node (your color)
  2. Drag between your nodes → Form connections
  3. Closed polygon (3-6 nodes) → Capture territory
  4. Enemies inside polygon → Captured and destroyed
  5. Double-click node → Delete it (breaks all territories)
  6. Energy management → Spend wisely or get eliminated

Energy Economy

  • Starting energy: 100
  • Create node: -10 energy
  • Capture enemy: +30 energy
  • Destroy enemy edge: +5 energy
  • Out of energy → Eliminated!

First Polygon Rule

Your first polygon must:

  • Be exactly 3 nodes (triangle)
  • Capture an enemy inside

If it fails → instant elimination!

Infinite Mode

  • Rounds last 60 seconds
  • Score carries over between rounds
  • Energy persists
  • Lost a round? → Eliminated
  • Keep playing until final elimination

Architecture

How LINX Uses CASCADA Framework

Platform Layer:

src/platform/base-config.ts → Used by game config

Core Layer:

src/core/ui/ui-manager.ts → UI management
src/core/ui/vue-ui-bridge.ts → Vue integration
src/core/config/visual-themes.ts → Theme system

Game Layer (LINX):

src/game/config/game-config.ts → Extends base config
src/game/territory/scenes/territory-game-scene.ts → Main game logic
src/game/scenes/main-menu-scene-vue.ts → Menu with Vue
src/game/ui/main-menu-ui.vue → Menu Vue component
src/game/ui/game-hud.vue → HUD Vue component

Layer hierarchy respected:

Game → uses Core + Platform
Core → uses Platform
Platform → independent

Visual Themes

LINX demonstrates the theme system with 4 styles:

1. Minimal (Default)

  • Black & white
  • Monospace font
  • Clean and simple

2. Neon Grid

  • Cyberpunk aesthetic
  • Cyan/Magenta/Yellow
  • Glow effects
  • Scanlines

3. Brutalist

  • Industrial style
  • Gray tones
  • Thick strokes
  • Noise effects

4. Liquid Crystal

  • Holographic
  • Color shifting (HSL rotation)
  • Smooth animations

Implementation: src/core/config/visual-themes.ts


Vue UI Integration

Features:

  • Horizontal swipeable theme selector
  • Reactive theme switching
  • Smooth animations
  • Responsive layout

Code:

vue
<template>
  <div class="main-menu">
    <h1>LINX</h1>
    <button @click="$emit('start-game')">START</button>
    <!-- Theme selector -->
  </div>
</template>

Game HUD (game-hud.vue)

Features:

  • Timer (top center)
  • Score and area (top right)
  • Energy bar (bottom center)
  • Hints (center, auto-hide)

Code:

vue
<template>
  <div class="game-hud">
    <div class="timer">{{ formattedTime }}</div>
    <div class="energy-bar" :style="{ width: energyPercent + '%' }"></div>
  </div>
</template>

Reactivity:

typescript
// In TerritoryGameScene.ts
this.vueBridge.updateProps("game-hud", {
  time: this.gameTime,
  energy: myPlayer.energy,
  score: myPlayer.score,
});

100% reactive! Props update → Vue re-renders instantly.


🤖 Bot AI

LINX includes simple bot AI to demonstrate game systems:

Bot behavior:

  • Create nodes randomly in valid positions
  • Form polygons when 3+ nodes are available
  • Target areas with enemies inside
  • Manage energy (stop creating if low)

Implementation: src/game/territory/scenes/territory-game-scene.tsbotAction()


Game State Management

Entities

Nodes:

typescript
interface Node {
  id: string;
  x: number;
  y: number;
  playerId: string;
  energyValue: number;
  visual?: Phaser.GameObjects.Arc;
  glow?: Phaser.GameObjects.Arc;
}

Edges:

typescript
interface Edge {
  id: string;
  fromNodeId: string;
  toNodeId: string;
  playerId: string;
  energyValue: number;
  energyFlow: number; // 0-1 for animation
  visual?: Phaser.GameObjects.Graphics;
}

Territories:

typescript
interface Territory {
  id: string;
  playerId: string;
  polygonNodes: string[]; // Node IDs
  area: number; // Calculated via Shoelace formula
  visual?: Phaser.GameObjects.Graphics;
}

Cleanup

Manual (old way):

typescript
for (const node of this.nodes.values()) {
  node.visual?.destroy();
  node.glow?.destroy();
}
this.nodes.clear();
// Repeat for edges, territories...

With EntityRegistry (future):

typescript
this.entityRegistry.clearRegion("game-area"); // 1 line!

Technical Highlights

1. Polygon Area Calculation

Using Shoelace formula for arbitrary polygons:

typescript
private calculatePolygonArea(nodes: Node[]): number {
  let area = 0;
  const n = nodes.length;
  for (let i = 0; i < n; i++) {
    const j = (i + 1) % n;
    area += nodes[i].x * nodes[j].y;
    area -= nodes[j].x * nodes[i].y;
  }
  return Math.abs(area) / 2;
}

2. Color Contrast Check

Ensuring distinct player colors:

typescript
private getColorDistance(c1: number, c2: number): number {
  const r1 = (c1 >> 16) & 0xff;
  const g1 = (c1 >> 8) & 0xff;
  const b1 = c1 & 0xff;
  // ... same for c2
  return Math.sqrt((r2 - r1) ** 2 + (g2 - g1) ** 2 + (b2 - b1) ** 2);
}

Minimum distance: 100 (RGB space).

3. Camera Parallax

Subtle movement based on pointer:

typescript
update() {
  this.cameraOffsetX += (this.pointerX * 0.01 - this.cameraOffsetX) * 0.1;
  this.cameraOffsetY += (this.pointerY * 0.01 - this.cameraOffsetY) * 0.1;
  this.cameras.main.setScroll(this.cameraOffsetX, this.cameraOffsetY);
}

4. Energy Flow Animation

Animated edges:

typescript
update(delta: number) {
  for (const edge of this.edges.values()) {
    edge.energyFlow += delta * 0.001;
    if (edge.energyFlow > 1) edge.energyFlow = 0;
    // Redraw edge with energyFlow position
  }
}

📈 Lessons Learned

What Worked Well

Vue UI integration - 58% less code than Phaser UI
Theme system - Easy to add new styles
Graph theory terminology - Professional, clear
Strict layer hierarchy - Clean separation

Challenges

UI duplication bug - Fixed with proper cleanup in initVueUI()
Territory validation - Complex geometry checks
Bot AI - Simple but effective

Future Improvements

🔮 EntityRegistry - Automatic cleanup
🔮 IoS integration - Multi-level gameplay
🔮 Multiplayer - Colyseus integration
🔮 Mobile controls - Touch optimizations


Key Takeaways for Your Game

If you're building a game with CASCADA, LINX demonstrates:

  1. Start with Core - Use UIManager, themes, etc.
  2. Extend Platform - Game config extends base config
  3. Vue for UI - Faster development, better UX
  4. Clean architecture - Respect layer hierarchy
  5. Iterate quickly - HMR for instant feedback

📂 File Structure

src/
  ├── platform/
  │   └── base-config.ts          ← Phaser base config
  ├── core/
  │   ├── ui/
  │   │   ├── ui-manager.ts       ← Used by LINX
  │   │   └── vue-ui-bridge.ts    ← Used by LINX
  │   └── config/
  │       └── visual-themes.ts    ← Used by LINX
  └── game/
      ├── config/
      │   └── game-config.ts      ← Extends base-config
      ├── scenes/
      │   ├── boot-scene.ts
      │   ├── preloader-scene.ts
      │   └── main-menu-scene-vue.ts
      ├── territory/
      │   └── scenes/
      │       └── territory-game-scene.ts  ← Main game logic
      └── ui/
          ├── main-menu-ui.vue    ← Menu Vue component
          └── game-hud.vue        ← HUD Vue component

LINX is a complete, working example of CASCADA Framework in action!

Use it as a reference for your own games.


🔮 Multi-Scale Concepts for LINX

Want to see how LINX could scale across all 5 abstraction levels?

📖 LINX Multi-Scale Gameplay Concepts

Three complete variants of scaling LINX from NANO to MEGA:

  • Concept 1: Fractal Aggregation (territories → super-nodes)
  • Concept 2: Energy States (rise and fall between levels)
  • Concept 3: Temporal Zoom (time speed + automation)

Each with detailed mechanics, implementation guides, and sales/marketing advantages.

🎯 Implementation Plan

📖 LINX Game Modes Menu

Structured menu with 4 playable modes:

  • Classic Mode - Current implementation (NANO only, infinite)
  • Fractal Mode - Concept 1 as playable game
  • Ascension Mode - Concept 2 as playable game
  • Temporal Mode - Concept 3 as playable game

All modes share visual themes (Minimal, Neon Grid, Brutalist, Liquid Crystal).

📊 Implementation Status

📖 LINX Implementation Summary

Current status and development roadmap:

  • ✅ Documentation complete (20k+ words)
  • ✅ Architecture designed (BaseGameScene)
  • ✅ Menu structure ready (4 mode cards)
  • 🚧 Classic Mode (migration in progress)
  • ⏳ Other modes (planned)

MIT Licensed