mid-process integrating blessed library

This commit is contained in:
lee2sman 2021-03-14 01:41:45 -05:00
parent 76c8b6077d
commit 256b79e01b
1 changed files with 191 additions and 52 deletions

243
dotd.js
View File

@ -3,6 +3,7 @@ const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const argv = yargs(hideBin(process.argv)).argv
const Charlatan = require('charlatan');
const blessed = require('blessed');
const fs = require("fs");
const generator = require("project-name-generator");
@ -18,8 +19,13 @@ const placesFile = ".places.txt";
const terrainFile = ".terrain.txt";
//globals
const width = 20;
const height = 4;
//blessed-specific, to write to screen
let screen, box;
let gameTitle = "Embarassed Cake Watering Hole";
// game vars
const width = 50;
const height = 8;
const movesInADay = 24;
let dungeon;
let roomItems = [];
@ -48,7 +54,7 @@ let parseArgs = () => {
createItems();
createBooks();
createPlaces();
createGraves();
createGraves();
} else {
loadDungeon();
loadTerrain();
@ -151,7 +157,7 @@ let movePlayer = () => {
}
}
} else { //you are asleep
console.log("you've drifted off asleep for the night and will wake tomorrow refreshed.");
console.log("You've drifted off asleep for the night and will wake tomorrow refreshed.");
//player.avatar = '😴'
}
}
@ -207,11 +213,13 @@ let createDungeon = () => {
//---------------CREATE PLAYER ----------------------------------
let createPlayer = () => {
const avatars = ['👳','👶','🧛','🕵','👲','🧕','👵','👧','🧔','👸','🤠','']
//const avatars = ['👳','👶','🧛','🕵','👲','🧕','👵','👧','🧔','👸','🤠','']
//const avatars = ['☺','☺'];
let chooseAvatar = Math.floor(Math.random() * avatars.length);
//let chooseAvatar = Math.floor(Math.random() * avatars.length);
player.avatar = avatars[chooseAvatar];
//player.avatar = avatars[chooseAvatar];
player.avatar = '@';
player.life = movesInADay;
@ -234,7 +242,9 @@ let createItems = () => {
let currentItemsInRoom = [];
for (let i = 0; i < numToSpawn; i++){
const items = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,.:;!?"'`^~ ̄_&#%+-*=<>()[]{}⦅⦆|¦/\¬$£¢₩¥".split("");
//east asian wide unicode
//const items = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,.:;!?"'`^~ ̄_&#%+-*=<>()[]{}⦅⦆|¦/\¬$£¢₩¥".split("");
const items = "123456789ABCDEFHIJKLMNOPQRSTUVWXYZabcdefghijklmonqrsntuvwxyz,.:!?\"'`^~_&#%+-*=<>(){}/\$".split("");
//make sure it wasn't chosen previously in this board
do {
@ -274,7 +284,8 @@ let createBooks = () => {
let numToSpawn = Math.round(Math.random() * 2)
for (let i = 0; i < numToSpawn; i++){
const items = ["📗","📕","📘","📙","📒","📓","📔"];
//const items = ["📗","📕","📘","📙","📒","📓","📔"];
const items = ['⎅','⏍','◫'];
whichItem = Math.floor(Math.random()*items.length);
@ -332,7 +343,8 @@ let createPlaces = () => {
for (let i = 0; i < numToSpawn; i++){
const buildings = ['🏛️','⛺','🏚️','⛩️','🗿']
//const buildings = ['🏛️','⛺','🏚️','⛩️','🗿']
const buildings = ['⌂','⏏','☖','☗']
const placeTypes = ['Village','Village','Village','House','House','Market','Market','Market','Crossroads','Place','Outpost','Trading Post','House','Shack','Meeting Place','Saloon','Watering Hole','Stall','Hideout','Cart','Camp','Camp','Camp','Camp','','','','Zone of Ill Repute']
let whichBuilding = buildings[Math.floor(Math.random()*3)];
@ -365,6 +377,8 @@ let createGraves = () => {
let name = Charlatan.Name.name();
let gravestones = ['✝','✟','☨','✞'];
let whichGravestone = choose(gravestones);
let prefix = ["Here lies","RIP","","","","Resting place of ","Beloved"]
let reason = ["Made an enemy","Wasn't afraid to be","Tried","Died while","Passed while performing","Tried out","Dissapeared investingating","Wandered off while looking for","Last seen","Loved","Adored","A lifelong fan of","Our favorite at","The best at","Always in our hearts","Keep","Always be","Always","Just","Tried","Couldn't stop","Only ever found","Died","Passed while","Couldn't stop","Forgot to try","Never stopped","We'll always think of you when we're","It's not the same"]
@ -373,7 +387,8 @@ let createGraves = () => {
places.push(
{
"name": epitaph,
"symbol": "⚰️",
// "symbol": "⚰️",
"symbol": whichGravestone,
"position":
{
"x":Math.floor(Math.random()*width),
@ -383,45 +398,8 @@ let createGraves = () => {
)
}
//-----------------PEOPLE----------------------------------------
let people =
[
{
"name": "wizard",
"emoji": "🧙",
"life": 3
},
{
"name": "woman",
"emoji": "🧝",
"life": 3
},
{
"name": "man",
"emoji": "🧔",
"life": 3
},
{
"name": "woman",
"emoji": "👵",
"life": 3
},
{
"name": "man",
"emoji": "👴",
"life": 3
},
{
"name": "person",
"emoji": "🧓",
"life": 3
}
]
//----------------create zone---------------
/*
let landscapes = ['🏔️','🌿','🌱','🌾','🌻','🌵']
let plants = ['🌹','🌺','🌻','🌼','🌷','🎋']
@ -429,6 +407,7 @@ let plants = ['🌹','🌺','🌻','🌼','🌷','🎋']
let shrines = ['⛩️','🗿']
let emojiitems = ['🍄','🌰','🦴','🧵','🧶','👓','🕶','🥽','👞','👟','🥾','🥿','👑','💼']
*/
let debug = () => {
//console.log(dungeon)
@ -448,8 +427,11 @@ let dungeonToStrings = () => {
let createTerrain = () => {
let forestTerrain = ['🎄', '🌳','🌲']
let plants = ['🌹','🌺','🌻','🌼','🌷','🎋','🍄','🌰','🌿','🌱','🌾','🏔️']
let forestTerrain = ['ᚠ','ᚡ','ᚴ','ᚵ','ᚶ','ᛉ','ᛘ','ᛠ'];
//let forestTerrain = ['🎄', '🌳','🌲']
let plants = ['ሥ','ሥ','ቂ','ቁ','ቄ','ቃ','ቅ','ቆ','ቇ','ቈ','ቊ','ቋ','ቌ','ቍ','ቜ','ቝ']
//let plants = ['🌹','🌺','🌻','🌼','🌷','🎋','🍄','🌰','🌿','🌱','🌾','🏔️']
//
for (let y = 0; y < height; y++){
for (let x = 0; x < width; x++){
@ -568,7 +550,140 @@ let checkDay = () => {
}
}
//----------------------------SET UP BLESSED----------------------
let initBlessed = () => {
screen = blessed.screen({
smartCSR: true
});
screen.title = gameTitle;
// Create a box perfectly centered horizontally and vertically.
box = blessed.box({
top: 'center',
left: 'center',
width: '50%',
height: '50%',
content: "Welcome to "+gameTitle,
tags: true,
border: {
type: 'line'
},
style: {
fg: 'white',
bg: 'cyan',
border: {
fg: '#f0f0f0'
},
hover: {
bg: 'green'
}
}
});
// Append our box to the screen.
screen.append(box);
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
return process.exit(0);
});
screen.key(['right', 'l'], function(ch, key) {
console.log('moved right');
player.position.x++;
loop();
});
screen.key(['left', 'h'], function(ch, key) {
console.log('moved left');
player.position.x--;
loop();
});
screen.key(['down', 'j'], function(ch, key) {
console.log('moved down');
player.position.y++;
loop();
});
screen.key(['up', 'k'], function(ch, key) {
player.position.y--;
console.log('moved up');
loop();
});
screen.render();
}
let keyHandler = () => {
// If box is focused, handle `enter`/`return` and give us some more content.
//
console.log('box.content: '+box.content);
//box.setContent('hello {red-fg}{green-bg}world{/}');
box.key('enter', function(ch, key) { //writes to screen, focus needed
for (let i = 0; i < dungeon.length; i++){
box.setLine(i, dungeon[i].join(''));
}
});
//box.content = "test test"; //writes to screen, no focus needed
screen.render();
}
let drawToBox = () => {
//start with dots
for (let y = 0; y < height; y++){
for (let x = 0; x < width; x++){
dungeon[y][x] = ".";
}
}
//specify terrain locations
for (let i = 0; i < terrain.length; i++){
dungeon[terrain[i].position.y][terrain[i].position.x] = terrain[i].symbol;
}
//specify item locations
for (let i = 0; i < roomItems.length; i++){
dungeon[roomItems[i].position.y][roomItems[i].position.x] = roomItems[i].symbol;
}
//specify places location
for (let i = 0; i < places.length; i++){
dungeon[places[i].position.y][places[i].position.x] = places[i].symbol;
}
//specify player location
dungeon[player.position.y][player.position.x] = player.avatar;
let dungeonStr = "";
for (let i = 0; i < height; i++){
dungeonStr+=(dungeon[i].join("")+"\n");
}
//return dungeonStr;
//
box.setContent(dungeonStr);
/*
for (let i = 0; i < dungeon.length; i++){
box.setLine(i, dungeonStr[i]);
}
*/
}
//--------------------------MAIN GAME LOOP-------------------------
let main = () => {
//----INIT
initBlessed();
checkDay();
parseArgs();
@ -579,8 +694,32 @@ let main = () => {
let dungeonWithItems = dungeonWithItemsToStrings();
drawDungeon(dungeonWithItems);
//keyHandler();
//debug();
//debug();
}
let loop = () => {
//
//Probably need to reload these things as you move
loadDungeon();
loadTerrain();
loadItems();
loadPlaces();
loadPlayer();
loadInventory();
grab();
movePlayer();
checkCollision();
//blessed
//
screen.realloc();
drawToBox();
screen.render();
}
main()