Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Tips for making the game

A topic by ozlosys created Feb 02, 2021 Views: 180 Replies: 4
Viewing posts 1 to 5
Host (1 edit)

This is for people to post tips for making ASCII art, game design or just handy tips.

My tips:

\n to make a new line

console.log("text"); to output

console.clear(); to clear the console

console.table(array_name); to output an array of objects in an orderly fashion

use document.addEventListener() to listen for key presses and other events:

"mousedown"(detect when mouse is down), "mouseup"(opposite of mousedown), "keydown"(when a key is held down), "keyup" (the opposite of keyup)

you can use console.group to make an inventory, like so:

var inventory = ["cat", "dog", "dog"];
console.group("inventory");
for(var i = 0; i < inventory.length; i++) {
    console.log(inventory[i]);
}
console.groupEnd();

make sure to put a console.groupEnd(); after it, or else anything you type will become part of the inventory group.

Another helpful tip: you can style console output --> https://developer.mozilla.org/en-US/docs/Web/API/console#Styling_console_output

(1 edit) (+1)

To make the console control the game, where the user types in commands:

Object.defineProperty(window, 'yes', {
get: function() {
console.log("Will do!")
}
});
Object.defineProperty(window, 'no', {
get: function() {
console.log("I won't!")
}
});

So the user can type "yes" or "no" into the console then press enter. You make a getter for window.yes variable and window.no variable where you can do game logic.

(4 edits)

You also can use an array of styles, say, [style1, style2, style1 (to revert the styles)], and then, after making a string of what to output (say,
‘%c stuff \n
stuff \n
%c other stuff that’s styled differently %c’
), destructure it with console,log(string, ...styles). This way, you can change the style for one character (say, your player) instead of using ascii art. 

(1 edit)

Also, just saying even though this is pretty much general: 
1- Using array.length calculates the length of the array, and if you put it inside the parentheses of a for loop, it recalculates for nothing. As a small optimization, store the length in a variable, say, var length = array.length, and then, in the for loop, i < length. 

2- Instead of looping through indexes, you can use a for of loop if you aren’t using the value of ‘i’. 

For example: 

for (var item of array) {
console.log(item);
}
Of course, you don’t need to, but I feel like it’s something basic that many people don’t know, so I’m just posting it here.