// Changing this variable makes the calculation of the player's position go slightly off.
// Set it to 25 for the floor tiles (dots) to be perfectly lined up.
// Give it a go!
var tileScale = 9;
// Game object to supposedly reduce scope chains
function Game(){
// Game reference for when the this keyword is out of scope
var game = this;
// Out of bounds function
Array.prototype.outOfBounds = function(x, y){
return x < 0 || y < 0 || x >= this[0].length || y >= this.length;
}
// Variable declarations
this.map = [];
this.mapSize = 25;
this.tileScale = tileScale;
// Player circle of vision.
this.playerVision = 8;
this.elements = [];
// Function that executes when the browser resizes.
window.onresize = this.resizeViewport = function(initial){
game.viewportWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
game.viewportHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
game.windowSize = Math.min(game.viewportWidth, game.viewportHeight);
// Droid Sans Mono has a ratio of 3:4 (width:height), conveniently.
game.tileWidth = game.windowSize*.6 / game.tileScale;
game.tileHeight = game.windowSize*.8 / game.tileScale;
// The first call to this function is at a point where these functions are not defined.
if(initial !== true){
game.updateList(game.tiles);
game.updateList(game.elements);
game.updateCamera();
}
}
this.resizeViewport(true);
// Function for attaching elements to the screen
this.createElement = function(type, parent, properties){
var element = document.createElement(type);
for(var i in properties)element[i] = properties[i];
parent.appendChild(element);
return element;
}
// Find pythagorean distance, with distance x and y values found
this.pythagorean = function(dx, dy){
return Math.sqrt(dx*dx+dy*dy);
}
// Change hex value to RGB (in format of e.g. FFFFFF, without #)
this.toRGB = function(triplet){
var color = {};
var sequence = ["red",...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.