Skip to content

mbianchidev/2dnd

Repository files navigation

2D&D

An epic tale of magic and dice, in 2d!

A browser-based JRPG combining Dragon Quest-style gameplay with Dungeons & Dragons 5E mechanics — featuring procedurally generated graphics, synthesized audio, and a massive explorable world.

Features

World & Exploration

  • Multi-chunk world — 10×9 grid of 20×15 tile chunks with diverse biomes (grass, forest, tundra, swamp, desert, volcanic, canyon)
  • 12 explorable cities — each with unique shops, inns, banks, and distinct procedural music
  • Dungeons — locked areas with tougher monsters and treasure chests
  • Fog of war — tiles reveal as you explore (cities auto-reveal on entry)
  • World map — zoomable/pannable overview with chunk details

Combat

  • D&D 5E dice mechanics — d20 attack rolls, critical hits on nat 20, critical misses on nat 1
  • Turn-based battles — initiative rolls, defend stance, flee attempts
  • 8 character classes — Knight, Ranger, Mage, Rogue, Paladin, Warlock, Cleric, Barbarian
  • Spells & abilities — class-specific spell trees and martial abilities unlocked by level
  • 6 boss fights — Cave Troll, Young Red Dragon, Frost Giant, Swamp Hydra, Volcanic Wyrm, Canyon Drake
  • Scrollable battle log — full combat history with mouse wheel scroll
  • Distinct attack sounds — normal hit, miss (whiff), and critical hit each have unique SFX

Character System

  • D&D 5E Point Buy — 27 points to allocate across 6 stats (8–15 range), or random 4d6-drop-lowest
  • Class stat boosts — applied on top of base allocation
  • Primary stat per class — determines to-hit modifier (STR for Knight, INT for Mage, CHA for Warlock, etc.)
  • ASI levels — gain stat points at levels 4, 8, 12, 16, 19
  • Equipment — weapons, armor, shields with click-to-equip and click-to-unequip
  • Appearance customization — skin color, hair style, hair color

Audio

  • Fully procedural — all music and sound effects synthesized via Web Audio API at runtime
  • Orchestral layers — strings (vibrato), brass stabs, kick drum, hihat on every track
  • Biome music — unique scale, tempo, and instruments per biome (9 biome profiles)
  • Boss music — each boss has a distinct musical profile
  • City music — 12 unique city vibes (pastoral, industrial, mystical, exotic, ominous, etc.)
  • Battle SFX — attack swoosh+impact, miss whiff, critical hit slam+sting+bell
  • Interaction SFX — chest open, dungeon enter, potion drink, terrain-specific footsteps
  • Weather ambient — rain patter, thunder, wind, snow, sandstorm, fog drone
  • Per-channel volume — Master, Music, SFX, Dialog sliders with localStorage persistence

Day/Night & Weather

  • 360-step day/night cycle — Dawn, Day, Dusk, Night with visual tints on overworld and battle
  • Celestial bodies — sun/moon in battle sky positioned by time of day
  • 6 weather types — Clear, Rain, Snow, Sandstorm, Storm, Fog
  • Biome-weighted weather — each biome has different probabilities
  • Combat effects — weather applies accuracy penalties and monster boosts
  • Particle effects — rain, snow, sand, storm, fog in both overworld and battle

Economy & Inventory

  • Shop system — buy and sell items in any shop
  • Sell tab — sell unwanted items for 50% of original cost
  • Sell restrictions — cannot sell quest items, treasures, or last equipment piece
  • Owned indicators — buy tab shows consumable count (e.g., "Potion (owned: 3)")
  • Item economy — full buy/sell cycle with economic balance

Quality of Life

  • Auto-save — saves after every step
  • Settings overlay — accessible from title screen and in-game menu (M → Settings)
  • Stacked items — battle inventory groups consumables (e.g., "Potion x3")
  • Bestiary — track discovered monsters with AC discovery via combat

Controls

Key Action
W/A/S/D Move on the overworld
SPACE Interact (enter town/dungeon, challenge boss)
E Equipment
M Menu (Resume / Settings / Quit)
N World map
C Codex
Mouse Click battle actions, shop items, UI elements

Tech Stack

  • Phaser 3 — game engine (rendering, input, scenes)
  • TypeScript — type-safe game logic (strict mode)
  • Vite — fast dev server and bundler
  • Vitest — unit testing
  • Web Audio API — procedural audio synthesis

Getting Started

# Install dependencies
npm install

# Start dev server (http://localhost:3000)
npm run dev

# Run tests
npm test

# Type check
npm run typecheck

# Production build
npm run build

Project Structure

src/
├── main.ts              # Entry point & Phaser config
├── config.ts            # Game constants, debug system, HTML debug panel
├── scenes/              # Phaser game scenes (file names drop "Scene" suffix)
│   ├── Boot.ts          # Asset gen, title screen, character creation
│   ├── Overworld.ts     # World map, movement, encounters — delegates to subsystems
│   ├── Battle.ts        # Turn-based combat, scrollable log, sky/weather
│   ├── Shop.ts          # Item shops & inn
│   └── Codex.ts         # Monster encyclopedia (formerly Bestiary)
├── systems/             # Core game logic & mechanics
│   ├── audio.ts         # Procedural audio engine (music, SFX, footsteps)
│   ├── combat.ts        # D&D combat mechanics
│   ├── player.ts        # Player state, leveling, Point Buy, inventory
│   ├── classes.ts       # Class definitions (stats, spells, abilities, hit die)
│   ├── appearance.ts    # Cosmetic customization (skin color, hair style/color)
│   ├── codex.ts         # Monster tracking & AC discovery (formerly bestiary)
│   ├── daynight.ts      # Day/night cycle (360-step)
│   ├── weather.ts       # Weather system (6 types, biome-weighted)
│   ├── debug.ts         # Debug hotkeys & slash commands (shared & overworld-specific)
│   ├── dice.ts          # D&D dice rolling utilities
│   ├── movement.ts      # Grid movement logic & chunk transitions
│   └── save.ts          # Save/load (localStorage)
├── renderers/           # Visual rendering subsystems
│   ├── map.ts           # Tile map rendering, weather particles, day/night tint
│   ├── city.ts          # City animals, NPCs, shop roofs, NPC textures
│   ├── player.ts        # Player sprite creation, equipment rendering
│   └── hud.ts           # HUD message display
├── managers/            # State management subsystems
│   ├── overlay.ts       # All UI overlays (equip, menu, settings, world map, inn, bank, teleport)
│   ├── specialNpc.ts    # Rare overworld NPCs (traveler, adventurer, merchant, hermit)
│   ├── npc.ts           # City NPC & animal adjacency detection helpers
│   ├── dialogue.ts      # NPC/animal/special dialogue display
│   ├── fogOfWar.ts      # Explored tile tracking & fog visibility
│   └── encounter.ts     # Random encounter enabled/disabled state
├── data/                # Game data definitions
│   ├── map.ts           # Core map types, constants, and re-exports (hub module)
│   ├── mapTypes.ts      # Shared types, enums (Terrain), and dimension constants
│   ├── dungeons.ts      # Dungeon interior map arrays
│   ├── cities.ts        # City interior maps, definitions, and utility functions
│   ├── chunks.ts        # World chunk map arrays and region colors
│   ├── monsters.ts      # Monster definitions & encounter tables
│   ├── spells.ts        # Spell definitions & level requirements
│   ├── items.ts         # Item definitions & shop inventory
│   ├── abilities.ts     # Martial ability definitions
│   ├── mounts.ts        # Mount definitions & speed data
│   ├── npcs.ts          # NPC templates, city NPC data, special NPC definitions
│   └── talents.ts       # Talent/perk definitions
├── utils/               # Shared utility modules
│   └── ui.ts            # Reusable UI panel/dimmer helpers
tests/
├── audio.test.ts        # Audio engine tests
├── combat.test.ts       # Combat calculation tests
├── config.test.ts       # Debug system tests
├── data.test.ts         # Game data integrity tests
├── daynight.test.ts     # Day/night cycle tests
├── dice.test.ts         # Dice utility tests
├── mounts.test.ts       # Mount system tests
├── movement.test.ts     # Grid movement tests
├── npcs.test.ts         # NPC data tests
├── player.test.ts       # Player system & Point Buy tests
├── save.test.ts         # Save/load tests
└── weather.test.ts      # Weather system tests

Debug Mode

Toggle the debug checkbox above the game canvas to enable:

  • Scrollable debug panel with live state and action logs
  • Cheat hotkeys (K=kill, H=heal, P=MP, G=gold, L=level, R=reveal map, V=fog, F=encounters)
  • Slash commands (/gold, /exp, /teleport, /spawn, /weather, /time, /audio, etc.)

License

ISC

About

A 2D game inspired by D&D, please do not sue me WoTC thanks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors