mirror of
https://github.com/Such-Software/wownerogue.git
synced 2026-10-17 22:31:26 +02:00
Start implementing torches and light and add some new tiles
This commit is contained in:
@@ -141,7 +141,9 @@ var GameState = {
|
||||
for (let y_scan = 0; y_scan < screenHeight; y_scan++) {
|
||||
if (this._map[y_scan]) {
|
||||
for (let x_scan = 0; x_scan < screenWidth; x_scan++) {
|
||||
if (this._map[y_scan][x_scan] === 0) { // Find first floor tile
|
||||
const tile = this._map[y_scan][x_scan];
|
||||
// Check for both legacy (0) and new ("'1", "'2") floor tiles
|
||||
if (tile === 0 || tile === "'1" || tile === "'2") {
|
||||
this._player.x = x_scan;
|
||||
this._player.y = y_scan;
|
||||
console.warn(`Player moved to fallback position: (${this._player.x}, ${this._player.y})`);
|
||||
@@ -167,8 +169,9 @@ var GameState = {
|
||||
if (!this._map[y] || this._map[y][x] === undefined) {
|
||||
return false; // Unknown tiles block light
|
||||
}
|
||||
// Tile type 0 = floor (transparent), 1 = wall (blocks light)
|
||||
return this._map[y][x] === 0;
|
||||
const tile = this._map[y][x];
|
||||
// Check for both legacy (0) and new ("'1", "'2") floor tiles
|
||||
return tile === 0 || tile === "'1" || tile === "'2";
|
||||
}.bind(this));
|
||||
|
||||
// If map was NOT built from initialVisibleTiles, compute FOV now
|
||||
@@ -355,7 +358,9 @@ var GameState = {
|
||||
this._visibleTiles = {};
|
||||
|
||||
const fov = new ROT.FOV.PreciseShadowcasting(function(x, y) {
|
||||
return this._map[y] && this._map[y][x] === 0; // 0 = passable, 1 = wall
|
||||
const tile = this._map[y] && this._map[y][x];
|
||||
// Check for both legacy (0) and new ("'1", "'2") floor tiles
|
||||
return tile === 0 || tile === "'1" || tile === "'2";
|
||||
}.bind(this));
|
||||
|
||||
fov.compute(this._player.x, this._player.y, 6, function(x, y, r, visibility) {
|
||||
|
||||
+59
-4
@@ -20,16 +20,39 @@ var options = {
|
||||
tileWidth: 32, // Width of a single tile in pixels
|
||||
tileHeight: 32, // Height of a single tile in pixels
|
||||
tileSet: tileSet,
|
||||
|
||||
// GAME CONFIGURATION - Change these to select different assets
|
||||
gameConfig: {
|
||||
playerType: "@", // Options: "@", "@2"
|
||||
treasureType: "$W", // Options: "$W" (Wownero), "$M" (Monero), "$B" (Bitcoin), "$" (Regular)
|
||||
monsterType: "~", // Options: "~", "~2"
|
||||
|
||||
// Floor tile configuration
|
||||
primaryFloor: "'1", // Main floor tile (99% of floors)
|
||||
secondaryFloor: "'2", // Alt floor tile (1% of floors)
|
||||
floorVariation: 0.01, // Percentage of secondary floor tiles (0.01 = 1%)
|
||||
|
||||
// Torch configuration
|
||||
torchEnabled: true, // Enable/disable torch placement
|
||||
torchDensity: 0.15, // Percentage of wall tiles that get torches (0.15 = 15%)
|
||||
torchTile: "torch" // Torch tile identifier
|
||||
},
|
||||
tileMap: {
|
||||
// Keep your existing tile mappings
|
||||
"'": [0, 0], // Floor
|
||||
"'1": [0, 0], // Floor
|
||||
">": [32, 0], // Exit
|
||||
"@": [64, 0], // Player
|
||||
"~": [96, 0], // Monster
|
||||
"$W": [960, 0], // Wownero Treasure
|
||||
"$M": [992, 0], // Monero Treasure
|
||||
"'2": [1024, 0], // Alt floor
|
||||
"<": [0, 32], // Entrance
|
||||
"=": [32, 32], // Monster Entrance
|
||||
"#": [64, 32], // Wall
|
||||
"$": [96, 32], // Treasure
|
||||
"$B": [96, 32], // Bitcoin Treasure
|
||||
"@2": [960, 32], // Player Alt
|
||||
"~2": [992, 32], // Monster Alt
|
||||
"torch": [1024, 32], // Torch
|
||||
// ... include all other necessary character mappings ...
|
||||
"a": [128, 0],
|
||||
"b": [160, 0],
|
||||
@@ -109,11 +132,13 @@ var options = {
|
||||
"^": [736, 64],
|
||||
")": [768, 64],
|
||||
"[": [800, 64],
|
||||
"]": [832, 64],
|
||||
"$": [832, 64], // remap to regular dollar sign
|
||||
"{": [864, 64],
|
||||
"%": [896, 64],
|
||||
"^": [928, 64],
|
||||
" ": [992, 64]
|
||||
"\'": [960, 64], // New quotes mapping
|
||||
"\"": [992, 64],
|
||||
" ": [1024, 64]
|
||||
}
|
||||
};
|
||||
|
||||
@@ -121,3 +146,33 @@ var options = {
|
||||
window.tileSet = tileSet;
|
||||
window.tileMap = options.tileMap;
|
||||
window.options = options;
|
||||
|
||||
// Helper functions to get configured tile types
|
||||
window.GameTiles = {
|
||||
getPlayerTile: function() {
|
||||
return options.gameConfig.playerType;
|
||||
},
|
||||
|
||||
getTreasureTile: function() {
|
||||
return options.gameConfig.treasureType;
|
||||
},
|
||||
|
||||
getMonsterTile: function() {
|
||||
return options.gameConfig.monsterType;
|
||||
},
|
||||
|
||||
getFloorTile: function(useVariation = false) {
|
||||
if (useVariation && Math.random() < options.gameConfig.floorVariation) {
|
||||
return options.gameConfig.secondaryFloor;
|
||||
}
|
||||
return options.gameConfig.primaryFloor;
|
||||
},
|
||||
|
||||
getTorchTile: function() {
|
||||
return options.gameConfig.torchTile;
|
||||
},
|
||||
|
||||
shouldPlaceTorch: function() {
|
||||
return options.gameConfig.torchEnabled && Math.random() < options.gameConfig.torchDensity;
|
||||
}
|
||||
};
|
||||
|
||||
+41
-12
@@ -24,10 +24,17 @@ var RenderEngine = {
|
||||
const entrance = gameState.entrance;
|
||||
const exit = gameState.exit;
|
||||
const treasure = gameState.treasure;
|
||||
const torches = gameState.torches || []; // New torch positions
|
||||
const visibleTiles = gameState.visibleTiles || {};
|
||||
const exploredTiles = gameState.exploredTiles || {};
|
||||
const message = gameState.message;
|
||||
|
||||
// Get configured tile types from options
|
||||
const playerTile = window.GameTiles ? window.GameTiles.getPlayerTile() : '@';
|
||||
const treasureTile = window.GameTiles ? window.GameTiles.getTreasureTile() : '$W';
|
||||
const monsterTile = window.GameTiles ? window.GameTiles.getMonsterTile() : '~';
|
||||
const torchTile = window.GameTiles ? window.GameTiles.getTorchTile() : 'torch';
|
||||
|
||||
const playerWX = player.x;
|
||||
const playerWY = player.y;
|
||||
const centerX = Math.floor(this._screenWidth / 2);
|
||||
@@ -54,26 +61,40 @@ var RenderEngine = {
|
||||
tileType = visibleTiles[wy][wx];
|
||||
baseFg = this.defaultFg;
|
||||
|
||||
if (tileType === 1) {
|
||||
// Handle new string-based tile system
|
||||
if (tileType === '#') {
|
||||
baseChar = '#'; // Wall
|
||||
} else if (tileType === "'1" || tileType === "'2") {
|
||||
baseChar = tileType; // Use the specific floor tile type
|
||||
} else if (tileType === 'torch') {
|
||||
baseChar = '#'; // Torch tiles are walls with torches on top
|
||||
} else if (tileType === 1) {
|
||||
baseChar = '#'; // Legacy wall support
|
||||
} else if (tileType === 0) {
|
||||
baseChar = "'"; // Floor
|
||||
baseChar = "'1"; // Legacy floor support - use primary floor
|
||||
} else {
|
||||
baseChar = "'"; // Default to floor for safety
|
||||
tileType = 0;
|
||||
// Use the tile type directly if it's a string
|
||||
baseChar = tileType || "'1"; // Default to primary floor for safety
|
||||
}
|
||||
|
||||
} else if (exploredTiles[wy] && exploredTiles[wy][wx] !== undefined) {
|
||||
tileType = exploredTiles[wy][wx];
|
||||
baseFg = this.defaultFg;
|
||||
|
||||
if (tileType === 1) {
|
||||
// Handle new string-based tile system for explored tiles
|
||||
if (tileType === '#') {
|
||||
baseChar = '#'; // Wall
|
||||
} else if (tileType === "'1" || tileType === "'2") {
|
||||
baseChar = tileType; // Use the specific floor tile type
|
||||
} else if (tileType === 'torch') {
|
||||
baseChar = '#'; // Torch tiles are walls with torches on top
|
||||
} else if (tileType === 1) {
|
||||
baseChar = '#'; // Legacy wall support
|
||||
} else if (tileType === 0) {
|
||||
baseChar = "'"; // Floor
|
||||
baseChar = "'1"; // Legacy floor support - use primary floor
|
||||
} else {
|
||||
baseChar = "'"; // Default to floor for safety
|
||||
tileType = 0;
|
||||
// Use the tile type directly if it's a string
|
||||
baseChar = tileType || "'1"; // Default to primary floor for safety
|
||||
}
|
||||
} else {
|
||||
// No visible or explored tile - render empty space
|
||||
@@ -125,21 +146,28 @@ var RenderEngine = {
|
||||
|
||||
// Render treasure
|
||||
if (treasure && treasure[0] === wx && treasure[1] === wy && this.isVisible(wx, wy, visibleTiles)) {
|
||||
charStack.push('$');
|
||||
charStack.push(treasureTile);
|
||||
fgStack.push("transparent"); // Use transparent for now
|
||||
bgStack.push("transparent");
|
||||
}
|
||||
|
||||
// Render torches (check if this tile has a torch)
|
||||
if (this.isVisible(wx, wy, visibleTiles) && visibleTiles[wy][wx] === 'torch') {
|
||||
charStack.push(torchTile);
|
||||
fgStack.push("transparent"); // Use transparent for now
|
||||
bgStack.push("transparent");
|
||||
}
|
||||
|
||||
// Render monster
|
||||
if (monster && monster.x === wx && monster.y === wy && this.isVisible(wx, wy, visibleTiles)) {
|
||||
charStack.push('~');
|
||||
charStack.push(monsterTile);
|
||||
fgStack.push("transparent"); // Use transparent for now
|
||||
bgStack.push("transparent");
|
||||
}
|
||||
|
||||
// Render player (always on top)
|
||||
if (wx === playerWX && wy === playerWY) {
|
||||
charStack.push('@');
|
||||
charStack.push(playerTile);
|
||||
fgStack.push("transparent"); // Use transparent for now
|
||||
bgStack.push("transparent");
|
||||
}
|
||||
@@ -152,7 +180,8 @@ var RenderEngine = {
|
||||
// Validate characters are in tileMap
|
||||
for (let i = 0; i < charStack.length; i++) {
|
||||
if (!charStack[i] || (window.options?.tileMap && !window.options.tileMap.hasOwnProperty(charStack[i]))) {
|
||||
charStack[i] = "'";
|
||||
// Default to primary floor if tile not found
|
||||
charStack[i] = "'1";
|
||||
}
|
||||
if (!fgStack[i]) fgStack[i] = "transparent";
|
||||
if (!bgStack[i]) bgStack[i] = "transparent";
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ const UI = {
|
||||
// After animations are complete, set static text
|
||||
setTimeout(function() {
|
||||
$('#banner, #bannercursor').fadeOut(500, function() {
|
||||
$('#staticbanner').text("THE WOWNGEON");
|
||||
$('#staticbanner').text("WOWGUE - A Wownero Roguelike").fadeIn(500);
|
||||
});
|
||||
}, 14000);
|
||||
},
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 56 KiB |
Binary file not shown.
+88
-5
@@ -4,7 +4,19 @@ const ROT = require('./rot.js');
|
||||
* Dungeon generation utilities
|
||||
*/
|
||||
class DungeonGenerator {
|
||||
static generate(width, height) {
|
||||
static generate(width, height, options = {}) {
|
||||
// Default options for dungeon generation
|
||||
const defaultOptions = {
|
||||
floorVariation: 0.01, // 1% secondary floor tiles
|
||||
torchEnabled: true, // Enable torch placement
|
||||
torchDensity: 0.15, // 15% of wall tiles get torches
|
||||
primaryFloor: "'1", // Primary floor tile
|
||||
secondaryFloor: "'2", // Secondary floor tile
|
||||
torchTile: "torch" // Torch tile type
|
||||
};
|
||||
|
||||
const config = { ...defaultOptions, ...options };
|
||||
|
||||
// Create dungeon using ROT.js Map.Digger
|
||||
const digger = new ROT.Map.Digger(width, height, {
|
||||
roomWidth: [3, 9],
|
||||
@@ -22,6 +34,9 @@ class DungeonGenerator {
|
||||
map[y][x] = value;
|
||||
});
|
||||
|
||||
// Create enhanced map with floor variations and torches
|
||||
const enhancedMap = this.enhanceMapWithVariations(map, config);
|
||||
|
||||
// Get rooms that were created
|
||||
const rooms = digger.getRooms();
|
||||
|
||||
@@ -50,20 +65,88 @@ class DungeonGenerator {
|
||||
treasureCenter[1] + Math.floor(Math.random() * 3) - 1
|
||||
];
|
||||
|
||||
// Ensure the treasure is on a floor tile
|
||||
if (map[treasure[1]][treasure[0]] !== 0) {
|
||||
// Ensure the treasure is on a floor tile (check for both floor types)
|
||||
const treasureTile = enhancedMap[treasure[1]][treasure[0]];
|
||||
if (treasureTile !== config.primaryFloor && treasureTile !== config.secondaryFloor) {
|
||||
treasure[0] = treasureCenter[0];
|
||||
treasure[1] = treasureCenter[1];
|
||||
}
|
||||
|
||||
return {
|
||||
map: map,
|
||||
map: enhancedMap, // Return the enhanced map with variations
|
||||
rooms: rooms,
|
||||
entrance: entrance,
|
||||
exit: exit,
|
||||
treasure: treasure
|
||||
treasure: treasure,
|
||||
torches: this.getTorchPositions(enhancedMap, config) // Include torch positions
|
||||
};
|
||||
}
|
||||
|
||||
// Enhanced map creation with floor variations and torch placement
|
||||
static enhanceMapWithVariations(basicMap, config) {
|
||||
const height = basicMap.length;
|
||||
const width = basicMap[0].length;
|
||||
const enhancedMap = Array(height).fill().map(() => Array(width).fill(null));
|
||||
|
||||
for (let y = 0; y < height; y++) {
|
||||
for (let x = 0; x < width; x++) {
|
||||
const cell = basicMap[y][x];
|
||||
|
||||
if (cell === 0) {
|
||||
// Floor tile - randomly choose primary or secondary
|
||||
if (Math.random() < config.floorVariation) {
|
||||
enhancedMap[y][x] = config.secondaryFloor;
|
||||
} else {
|
||||
enhancedMap[y][x] = config.primaryFloor;
|
||||
}
|
||||
} else if (cell === 1) {
|
||||
// Wall tile - maybe add a torch
|
||||
if (config.torchEnabled && this.shouldPlaceTorch(basicMap, x, y, config.torchDensity)) {
|
||||
enhancedMap[y][x] = config.torchTile;
|
||||
} else {
|
||||
enhancedMap[y][x] = '#'; // Regular wall
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return enhancedMap;
|
||||
}
|
||||
|
||||
// Determine if a torch should be placed on this wall tile
|
||||
static shouldPlaceTorch(map, x, y, torchDensity) {
|
||||
// Only place torches on walls that are adjacent to floors (for lighting logic)
|
||||
const height = map.length;
|
||||
const width = map[0].length;
|
||||
|
||||
// Check if this wall tile is adjacent to at least one floor tile
|
||||
const adjacentToFloor = [
|
||||
[-1, 0], [1, 0], [0, -1], [0, 1] // Adjacent cells
|
||||
].some(([dx, dy]) => {
|
||||
const nx = x + dx;
|
||||
const ny = y + dy;
|
||||
return nx >= 0 && nx < width && ny >= 0 && ny < height && map[ny][nx] === 0;
|
||||
});
|
||||
|
||||
return adjacentToFloor && Math.random() < torchDensity;
|
||||
}
|
||||
|
||||
// Get positions of all torches for client-side rendering
|
||||
static getTorchPositions(enhancedMap, config) {
|
||||
const torches = [];
|
||||
const height = enhancedMap.length;
|
||||
const width = enhancedMap[0].length;
|
||||
|
||||
for (let y = 0; y < height; y++) {
|
||||
for (let x = 0; x < width; x++) {
|
||||
if (enhancedMap[y][x] === config.torchTile) {
|
||||
torches.push([x, y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return torches;
|
||||
}
|
||||
|
||||
static getRandomRoomCenter(rooms, excludeFirst = false, excludeLast = false) {
|
||||
if (!rooms || rooms.length === 0) return null;
|
||||
|
||||
+17
-5
@@ -4,7 +4,7 @@ const Monster = require('./monster.js');
|
||||
const DungeonGenerator = require('./dungeon.js');
|
||||
|
||||
class Game {
|
||||
constructor(socketId, mapWidth, mapHeight) {
|
||||
constructor(socketId, mapWidth, mapHeight, gameConfig = {}) {
|
||||
this.socketId = socketId;
|
||||
this.width = mapWidth || 25; // Reduced default size to match client display
|
||||
this.height = mapHeight || 19; // Reduced default size to match client display
|
||||
@@ -16,11 +16,13 @@ class Game {
|
||||
this.fee = 0; // Amount player paid
|
||||
this.visibleTiles = {}; // Will store visible tiles
|
||||
this.fov = null; // FOV calculator
|
||||
this.gameConfig = gameConfig; // Store game configuration
|
||||
this.generateDungeon();
|
||||
}
|
||||
|
||||
generateDungeon() {
|
||||
this.dungeon = DungeonGenerator.generate(this.width, this.height);
|
||||
// Pass game configuration to dungeon generator
|
||||
this.dungeon = DungeonGenerator.generate(this.width, this.height, this.gameConfig);
|
||||
|
||||
if (this.dungeon.entrance) {
|
||||
this.player.moveTo(this.dungeon.entrance[0], this.dungeon.entrance[1]);
|
||||
@@ -33,11 +35,16 @@ class Game {
|
||||
this.monster.moveTo(center[0], center[1]);
|
||||
}
|
||||
|
||||
// Initialize FOV calculator
|
||||
// Initialize FOV calculator - need to check for multiple floor types now
|
||||
this.fov = new ROT.FOV.PreciseShadowcasting(
|
||||
(x, y) => {
|
||||
// Return true if the tile is transparent (can see through it)
|
||||
return this.dungeon.map[y] && this.dungeon.map[y][x] === 0;
|
||||
if (!this.dungeon.map[y] || this.dungeon.map[y][x] === undefined) return false;
|
||||
const tile = this.dungeon.map[y][x];
|
||||
// Check if it's any type of floor tile (primary or secondary)
|
||||
const primaryFloor = this.gameConfig.primaryFloor || "'1";
|
||||
const secondaryFloor = this.gameConfig.secondaryFloor || "'2";
|
||||
return tile === primaryFloor || tile === secondaryFloor;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -83,10 +90,14 @@ class Game {
|
||||
console.log(`Move: (${this.player.x},${this.player.y}) -> (${newX},${newY})`);
|
||||
|
||||
// Check if the move is valid (not into a wall and within map bounds)
|
||||
// Updated to handle new floor tile types
|
||||
const primaryFloor = this.gameConfig.primaryFloor || "'1";
|
||||
const secondaryFloor = this.gameConfig.secondaryFloor || "'2";
|
||||
|
||||
if (this.dungeon &&
|
||||
this.dungeon.map[newY] &&
|
||||
this.dungeon.map[newY][newX] !== undefined &&
|
||||
this.dungeon.map[newY][newX] === 0) { // 0 is floor
|
||||
(this.dungeon.map[newY][newX] === primaryFloor || this.dungeon.map[newY][newX] === secondaryFloor)) {
|
||||
|
||||
this.player.moveTo(newX, newY);
|
||||
console.log(`Player moved to ${newX},${newY} in game for socket ${this.socketId}`);
|
||||
@@ -133,6 +144,7 @@ class Game {
|
||||
entrance: this.dungeon ? this.dungeon.entrance : null,
|
||||
exit: this.dungeon ? this.dungeon.exit : null,
|
||||
treasure: this.dungeon ? this.dungeon.treasure : null,
|
||||
torches: this.dungeon ? this.dungeon.torches : [], // Include torch positions
|
||||
};
|
||||
|
||||
// Debug logging to verify entity data
|
||||
|
||||
+18
-2
@@ -43,10 +43,26 @@ function getAllUsers() {
|
||||
}
|
||||
|
||||
// Add this method to your User function/class
|
||||
User.prototype.startGame = function(width, height) {
|
||||
User.prototype.startGame = function(width, height, gameConfig = {}) {
|
||||
console.log(`Creating new game for user ${this.socketid} with dimensions ${width}x${height}`);
|
||||
|
||||
// Default game configuration - can be customized per user/game
|
||||
const defaultConfig = {
|
||||
playerType: "@", // Options: "@", "@2"
|
||||
treasureType: "$W", // Options: "$W" (Wownero), "$M" (Monero), "$B" (Bitcoin), "$" (Regular)
|
||||
monsterType: "~", // Options: "~", "~2"
|
||||
primaryFloor: "'1", // Main floor tile (99% of floors)
|
||||
secondaryFloor: "'2", // Alt floor tile (1% of floors)
|
||||
floorVariation: 0.01, // Percentage of secondary floor tiles (0.01 = 1%)
|
||||
torchEnabled: true, // Enable/disable torch placement
|
||||
torchDensity: 0.15, // Percentage of wall tiles that get torches (0.15 = 15%)
|
||||
torchTile: "torch" // Torch tile identifier
|
||||
};
|
||||
|
||||
const config = { ...defaultConfig, ...gameConfig };
|
||||
|
||||
try {
|
||||
this.game = new Game(this.socketid, width, height);
|
||||
this.game = new Game(this.socketid, width, height, config);
|
||||
return this.game;
|
||||
} catch (err) {
|
||||
console.error("Error creating game:", err);
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Test script to demonstrate the new tile system
|
||||
* Shows floor variations, torch placement, and configurable assets
|
||||
*/
|
||||
|
||||
const DungeonGenerator = require('../src/backend/dungeon.js');
|
||||
|
||||
console.log("🏛️ WOWNGEON TILE SYSTEM TEST");
|
||||
console.log("=" * 50);
|
||||
|
||||
// Test 1: Default Configuration
|
||||
console.log("\n🔧 Test 1: Default Configuration");
|
||||
const defaultConfig = {
|
||||
playerType: "@",
|
||||
treasureType: "$W",
|
||||
monsterType: "~",
|
||||
primaryFloor: "'1",
|
||||
secondaryFloor: "'2",
|
||||
floorVariation: 0.01,
|
||||
torchEnabled: true,
|
||||
torchDensity: 0.15,
|
||||
torchTile: "torch"
|
||||
};
|
||||
|
||||
const dungeon1 = DungeonGenerator.generate(20, 15, defaultConfig);
|
||||
console.log(`Generated dungeon: ${dungeon1.map.length}x${dungeon1.map[0].length}`);
|
||||
console.log(`Entrance: [${dungeon1.entrance}]`);
|
||||
console.log(`Exit: [${dungeon1.exit}]`);
|
||||
console.log(`Treasure: [${dungeon1.treasure}]`);
|
||||
console.log(`Torches: ${dungeon1.torches.length} placed`);
|
||||
|
||||
// Count tile types
|
||||
const tileCounts = {};
|
||||
for (let y = 0; y < dungeon1.map.length; y++) {
|
||||
for (let x = 0; x < dungeon1.map[0].length; x++) {
|
||||
const tile = dungeon1.map[y][x];
|
||||
tileCounts[tile] = (tileCounts[tile] || 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
console.log("\n📊 Tile Distribution:");
|
||||
Object.keys(tileCounts).sort().forEach(tile => {
|
||||
console.log(` ${tile}: ${tileCounts[tile]} tiles`);
|
||||
});
|
||||
|
||||
if (tileCounts["'1"] && tileCounts["'2"]) {
|
||||
const floorTotal = tileCounts["'1"] + tileCounts["'2"];
|
||||
const variationPercent = (tileCounts["'2"] / floorTotal * 100).toFixed(2);
|
||||
console.log(` Floor variation: ${variationPercent}% secondary floors`);
|
||||
}
|
||||
|
||||
// Test 2: Custom Configuration
|
||||
console.log("\n🔧 Test 2: Custom Configuration (Bitcoin theme)");
|
||||
const customConfig = {
|
||||
playerType: "@2",
|
||||
treasureType: "$B",
|
||||
monsterType: "~2",
|
||||
primaryFloor: "'1",
|
||||
secondaryFloor: "'2",
|
||||
floorVariation: 0.05, // 5% variation
|
||||
torchEnabled: true,
|
||||
torchDensity: 0.25, // 25% more torches
|
||||
torchTile: "torch"
|
||||
};
|
||||
|
||||
const dungeon2 = DungeonGenerator.generate(15, 10, customConfig);
|
||||
console.log(`Generated custom dungeon: ${dungeon2.map.length}x${dungeon2.map[0].length}`);
|
||||
console.log(`Torches in custom dungeon: ${dungeon2.torches.length}`);
|
||||
|
||||
// Test 3: Show a small visual sample
|
||||
console.log("\n🗺️ Sample Dungeon (15x12):");
|
||||
const sampleDungeon = DungeonGenerator.generate(15, 12, defaultConfig);
|
||||
|
||||
console.log(" 012345678901234");
|
||||
for (let y = 0; y < sampleDungeon.map.length; y++) {
|
||||
let line = y.toString().padStart(2) + " ";
|
||||
for (let x = 0; x < sampleDungeon.map[0].length; x++) {
|
||||
let char = sampleDungeon.map[y][x];
|
||||
|
||||
// Add entities for display
|
||||
if (sampleDungeon.entrance && sampleDungeon.entrance[0] === x && sampleDungeon.entrance[1] === y) {
|
||||
char = '<';
|
||||
} else if (sampleDungeon.exit && sampleDungeon.exit[0] === x && sampleDungeon.exit[1] === y) {
|
||||
char = '>';
|
||||
} else if (sampleDungeon.treasure && sampleDungeon.treasure[0] === x && sampleDungeon.treasure[1] === y) {
|
||||
char = '$';
|
||||
}
|
||||
|
||||
// Display character mapping
|
||||
if (char === "'1") char = '.';
|
||||
else if (char === "'2") char = ':';
|
||||
else if (char === 'torch') char = 'T';
|
||||
else if (char === '#') char = '#';
|
||||
|
||||
line += char;
|
||||
}
|
||||
console.log(line);
|
||||
}
|
||||
|
||||
console.log("\nLegend:");
|
||||
console.log(" . = Primary floor ('1)");
|
||||
console.log(" : = Secondary floor ('2)");
|
||||
console.log(" # = Wall");
|
||||
console.log(" T = Torch");
|
||||
console.log(" < = Entrance");
|
||||
console.log(" > = Exit");
|
||||
console.log(" $ = Treasure");
|
||||
|
||||
console.log("\n✅ Tile System Test Complete!");
|
||||
console.log("\nFeatures verified:");
|
||||
console.log(" ✓ Configurable player/treasure/monster types");
|
||||
console.log(" ✓ Floor tile variations (primary/secondary)");
|
||||
console.log(" ✓ Configurable torch placement");
|
||||
console.log(" ✓ Enhanced dungeon generation");
|
||||
console.log(" ✓ Torch position tracking");
|
||||
@@ -0,0 +1,117 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Test script to demonstrate the new tile system
|
||||
* Shows floor variations, torch placement, and configurable assets
|
||||
*/
|
||||
|
||||
const DungeonGenerator = require('./src/backend/dungeon.js');
|
||||
|
||||
console.log("🏛️ WOWNGEON TILE SYSTEM TEST");
|
||||
console.log("=" * 50);
|
||||
|
||||
// Test 1: Default Configuration
|
||||
console.log("\n🔧 Test 1: Default Configuration");
|
||||
const defaultConfig = {
|
||||
playerType: "@",
|
||||
treasureType: "$W",
|
||||
monsterType: "~",
|
||||
primaryFloor: "'1",
|
||||
secondaryFloor: "'2",
|
||||
floorVariation: 0.01,
|
||||
torchEnabled: true,
|
||||
torchDensity: 0.15,
|
||||
torchTile: "torch"
|
||||
};
|
||||
|
||||
const dungeon1 = DungeonGenerator.generate(20, 15, defaultConfig);
|
||||
console.log(`Generated dungeon: ${dungeon1.map.length}x${dungeon1.map[0].length}`);
|
||||
console.log(`Entrance: [${dungeon1.entrance}]`);
|
||||
console.log(`Exit: [${dungeon1.exit}]`);
|
||||
console.log(`Treasure: [${dungeon1.treasure}]`);
|
||||
console.log(`Torches: ${dungeon1.torches.length} placed`);
|
||||
|
||||
// Count tile types
|
||||
const tileCounts = {};
|
||||
for (let y = 0; y < dungeon1.map.length; y++) {
|
||||
for (let x = 0; x < dungeon1.map[0].length; x++) {
|
||||
const tile = dungeon1.map[y][x];
|
||||
tileCounts[tile] = (tileCounts[tile] || 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
console.log("\n📊 Tile Distribution:");
|
||||
Object.keys(tileCounts).sort().forEach(tile => {
|
||||
console.log(` ${tile}: ${tileCounts[tile]} tiles`);
|
||||
});
|
||||
|
||||
if (tileCounts["'1"] && tileCounts["'2"]) {
|
||||
const floorTotal = tileCounts["'1"] + tileCounts["'2"];
|
||||
const variationPercent = (tileCounts["'2"] / floorTotal * 100).toFixed(2);
|
||||
console.log(` Floor variation: ${variationPercent}% secondary floors`);
|
||||
}
|
||||
|
||||
// Test 2: Custom Configuration
|
||||
console.log("\n🔧 Test 2: Custom Configuration (Bitcoin theme)");
|
||||
const customConfig = {
|
||||
playerType: "@2",
|
||||
treasureType: "$B",
|
||||
monsterType: "~2",
|
||||
primaryFloor: "'1",
|
||||
secondaryFloor: "'2",
|
||||
floorVariation: 0.05, // 5% variation
|
||||
torchEnabled: true,
|
||||
torchDensity: 0.25, // 25% more torches
|
||||
torchTile: "torch"
|
||||
};
|
||||
|
||||
const dungeon2 = DungeonGenerator.generate(15, 10, customConfig);
|
||||
console.log(`Generated custom dungeon: ${dungeon2.map.length}x${dungeon2.map[0].length}`);
|
||||
console.log(`Torches in custom dungeon: ${dungeon2.torches.length}`);
|
||||
|
||||
// Test 3: Show a small visual sample
|
||||
console.log("\n🗺️ Sample Dungeon (10x8):");
|
||||
const sampleDungeon = DungeonGenerator.generate(10, 8, defaultConfig);
|
||||
|
||||
console.log(" 0123456789");
|
||||
for (let y = 0; y < sampleDungeon.map.length; y++) {
|
||||
let line = y.toString().padStart(2) + " ";
|
||||
for (let x = 0; x < sampleDungeon.map[0].length; x++) {
|
||||
let char = sampleDungeon.map[y][x];
|
||||
|
||||
// Add entities for display
|
||||
if (sampleDungeon.entrance && sampleDungeon.entrance[0] === x && sampleDungeon.entrance[1] === y) {
|
||||
char = '<';
|
||||
} else if (sampleDungeon.exit && sampleDungeon.exit[0] === x && sampleDungeon.exit[1] === y) {
|
||||
char = '>';
|
||||
} else if (sampleDungeon.treasure && sampleDungeon.treasure[0] === x && sampleDungeon.treasure[1] === y) {
|
||||
char = '$';
|
||||
}
|
||||
|
||||
// Display character mapping
|
||||
if (char === "'1") char = '.';
|
||||
else if (char === "'2") char = ':';
|
||||
else if (char === 'torch') char = 'T';
|
||||
else if (char === '#') char = '#';
|
||||
|
||||
line += char;
|
||||
}
|
||||
console.log(line);
|
||||
}
|
||||
|
||||
console.log("\nLegend:");
|
||||
console.log(" . = Primary floor ('1)");
|
||||
console.log(" : = Secondary floor ('2)");
|
||||
console.log(" # = Wall");
|
||||
console.log(" T = Torch");
|
||||
console.log(" < = Entrance");
|
||||
console.log(" > = Exit");
|
||||
console.log(" $ = Treasure");
|
||||
|
||||
console.log("\n✅ Tile System Test Complete!");
|
||||
console.log("\nFeatures verified:");
|
||||
console.log(" ✓ Configurable player/treasure/monster types");
|
||||
console.log(" ✓ Floor tile variations (primary/secondary)");
|
||||
console.log(" ✓ Configurable torch placement");
|
||||
console.log(" ✓ Enhanced dungeon generation");
|
||||
console.log(" ✓ Torch position tracking");
|
||||
Reference in New Issue
Block a user