JavaScript World Creator by Christopher Topalian
JavaScript World Creator by Christopher Topalian
JavaScript
World Creator
by
Christopher Topalian
All Rights Reserved Copyright 2020-2021
<!-- All Rights Reserved Christopher Topalian Co
pyright 2020-2021 -->
<!-- Topalian JavaScript World Creator -->
<!--
CONTROLS
W is Up, S is Down, A is Left, D is Right.
CAMERA
Camera Follows Player
COORDINATES - Locations
Left Click Mouse to get X and Y coordinates
of any place on the screen.
COORDINATES - Structures
Left Click Mouse on any structure
to get that structure's coordinates and other inf
o.
SPEED
press numbers 1 to 9 to adjust Speed
TRANSPARENCY
press N for the player to be see-through
press M for solid
PLAYER MENU
press Z for Player Menu, to travel to locations q
uickly
STRUCTURE MODE
press B to Activate Structure Mode
While in Structure Mode,
Left Click Mouse to Create a Structure
press Shift + 1 to go to 1st Structure
press Shift + 2 to go to 2nd Structure, etc
press C to Color All Structures and Create a Ro
w Menu of Structures with GoTo Buttons to take p
erson to any Structure.
Left Click Mouse on any Structure to get coordi
nates and more.
press Delete Button to Remove All Structures
press Esc to End Structure Mode
Structure Info
Structure Data - Info
The structure data is stored in the structuresAr
ray.
This data is shown at the top of the screen in a
Text Area.
We can also view the data in the console of the
web browser.
Structure Data - Copy Button
The structuresArray data can be copied and pa
sted into the TopalianWorldDATA.js file and saved
.
As we make more structures, more data is adde
d to the structuresArray.
Structure Data - Download Button
The structuresArray Data can be downloaded a
s a text file,
using the Download button.
If the player decides to delete the structures, th
ey can then load the TopalianWorldDATA.js file ag
ain by pressing the Letter G on the keyboard.
-->
<!-- Works in Chrome, Firefox, Brave, and others -
->
<!-- Loads the FASTEST in the Chrome Browser (
MUCH FASTER) -->
<!-- See the Code in Action
https://collegeofscripting.weebly.com/ -->
<!-- See the Video Tutorials
https://www.youtube.com/watch?v=n3JzYJKXZ_A
and
https://youtube.com/scriptingcollege
-->
<!-- See more Code here
https://github.com/ChristopherTopalian -->
<!-- College of Scripting Music & Science -->
<html>
<head>
<title>Topalian JavaScript World Creator</
title>
<style>
#thePlayer{
position: absolute;
width: 70px;
height: 70px;
background: rgb(73, 100, 150);
z-index: 1001;
word-wrap: break-word;
font-family: Tahoma;
line-height: 18px;
font-size: 14px;
font-weight: bold;
</head>
<body onload = "whenLoaded();">
<!-- create the Player div-->
<div id = "thePlayer">WASD<br> to Move</div>
<!-- create the Background div -->
<div id = "theBackground"></div>
<!-- create the Text Area to show the Structure dat
a -->
<textarea id = "textAreaStructureData" placehold
er = "Structure Data" rows = "4" cols = "50" type
= "text">
</textarea>
<br>
<button id = "copyButton" class="ourButton" onc
lick = "copyIt();">COPY</button>    O
R    
//Show the structuresArray data in a Text Area tha
t is scrollable
function showData()
{
document.getElementById("textAreaStructureD
ata").value = "structuresArray=" + JSON.stringify
(structuresArray, null, ' ') + ";" + "\n\n" ;
}
//We can copy the Text Area easily by clicking the
Copy button
function copyIt()
{
let copyText = document.getElementById("text
AreaStructureData");
copyText.select();
copyText.setSelectionRange(0, 1000000);
document.execCommand("copy");
alert("Successfully COPIED. \nNow PASTE it in
TopalianWorldDATA.js");
//or we can download the structuresData Array to
our downloads folder as a text file with the extens
ion .js automatically added.
//this function below creates a text file called Top
alianWorldDATA.js.
//Each time we download it, it will change the nam
e to be TopalianWorldDATA(1).js and then the nex
t time TopalianWorldDATA(2).js and so on.
//so we make sure to change that name when putt
ing it in our folder to TopalianWorldDATA.js
function downloadData()
{
//get the data from the Text Area
//let data = document.getElementById("textArea
StructureData").value;
//get the data from the structuresArray and for
mat it nicely
let ourData = "structuresArray=" + JSON.stringi
fy(structuresArray, null, ' ') + ";" + "\n\n";
//create an anchor element
//we can choose .txt .html or in our case, we us
e .js
ourElement.download = "TopalianWorldDATA.js
";
//we choose the data and kind
let theKind = new Blob([ourData], {
type: "text/plain"
});
ourElement.href = window.URL.createObjectUR
L(theKind);
ourElement.click();
}
function structuresMenu()
{
let structureDiv = document.createElement("div
");
structureDiv.style.position = "absolute";
structureDiv.style.left = ourPlayer.x - 250 + 'px';
structureDiv.style.top = ourPlayer.y - 100 +'px';
structureDiv.style.color = "white";
structureDiv.style.zIndex = "1003";
structureDiv.style.border = "solid 5px rgba(0,0,
200,1.0)";
structureDiv.style.fontFamily = "exo";
structureDiv.style.fontWeight = "normal";
structureDiv.style.fontSize = "medium";
//structureDiv.style.background = "grey";
structureDiv.style.textAlign = "center";
structureDiv.setAttribute("class", "divBackgrou
nd");
//"+criteria+"
//structureDiv.id = whichArray[i].id;
//structureDiv.id = Math.floor(350000 + Math.ran
dom() * 9750000);
structureDiv.id = "structuresMenu"
//WE BUILD THE MENU USING innerHTML
structureDiv.innerHTML += '<div><hr><span st
yle="color:rgb(255, 255, 255)">STRUCTURE OPTI
ONS</span><hr>';
//keep, for using button option later
//structureDiv.innerHTML+= '<button onclick="a
ddListen(\'click\', createStructure);" class=\'ourBu
tton\'>STRUCTURE MODE ON</button><br>';
structureDiv.innerHTML += 'Letter B to Start Str
ucture Mode <hr>';
structureDiv.innerHTML += 'Left Click to Place
a Structure <hr>';
structureDiv.innerHTML += 'Shift + 1 to GoTo 1s
t Structure <hr>';
//keep, for using button option later
//structureDiv.innerHTML+= '<button onclick="c
olorAllStructures();" class=\'ourButton\'>Color All
Structures</button><br>';
structureDiv.innerHTML += 'Letter C Colors All
Structures<br> and Creates a Row Menu<br> to G
oTo Any Structure<hr>';
structureDiv.innerHTML += 'Left Click any Struc
ture for more info <hr>';
//keep, for using button option later
//structureDiv.innerHTML+= '<button onclick="r
emoveAllStructures();" class=\'ourButton\'>Remo
ve All Structures</button><br>';
structureDiv.innerHTML += 'Delete Button <br>
Removes All Structures<hr>';
//keep, for using button option later
//structureDiv.innerHTML+= '<button onclick="r
emoveListen(\'click\', createStructure);" class=\'o
/*
Get the Position of any Element that has specifie
d id
let posXY = {
x:parseInt(theRect.x) + parseInt(theRect.widt
h)/2 + window.scrollX,
y:parseInt(theRectY) + parseInt(theRect.heig
ht)/2
};
return posXY;
}
/*
Get the SIZE of any Element that has specified id
*/
function getSize(theId)
{
theId = document.getElementById(theId);
let theRect = theId.getBoundingClientRect();
let sizeXY = {
/*
This function below shows the name, id, posX, po
sY, sizeX and sizeY of any structure that we left cl
icked.
The 1st time we left click the structure, it shows
more info.
The 2nd time we left click the structure, it shows
only the simplified position data.
//NOTE: Need to redesign this function to work co
rrectly for when we click a second structure, whil
e the first structure's info is already open.
*/
let ourCounter = 1;
function getStructureInfo(theId)
{
theId = document.getElementById(theId);
if(ourCounter % 2) //if ourCounter is an odd nu
mber
{
//NOTE: It currently adds the 2px BORDER of
the structure to the position and size data. We wil
l redesign this later.
}
else //else if ourCounter is an even number
{
document.getElementById(theId.id).innerHTM
L = theId.id + "<br>" + parseInt(getPos(theId.id).x)
+ ", " + parseInt(getPos(theId.id).y);
//NOTE: It currently adds the 2px BORDER of
the structure to the position data. We will redesig
n this later.
ourCounter += 1;
}
/*
CREATE a STRUCTURE:
After the Letter B on the keyboard is pressed to a
ctivate Structure Mode, we can place structures i
n the world using the Left Mouse Button.
Esc Button is used to deactivate Structure Mode.
*/
let structuresArray = [ ];
let structureId = 1;
function createStructure(theEvent, theX, theY)
{
theX = theEvent.pageX;
theY = theEvent.pageY;
sizeX = 110;
sizeY = 45;
let ourStructure = document.createElement("di
v");
ourStructure.style.position = "absolute";
ourStructure.style.width = sizeX +'px';
ourStructure.style.height = sizeY +'px';
/*
//For a Top Left Coordinate System, use this wa
y below
ourStructure.style.left = theX +'px';
ourStructure.style.top = theY + 'px';
*/
//ourStructure.id = "STRUCTURE" + structureId;
ourStructure.id = "STRUCTURE" + (structureId
+ structuresArray.length);
ourStructure.setAttribute('onclick', 'getStructur
eInfo(\''+ourStructure.id+'\');');
ourStructure.style.color = "white";
ourStructure.style.zIndex = "1002";
let structureLocations =
{
name: ourStructure.id,
id: ourStructure.id,
posX: theX,
posY: theY,
sizeX: sizeX,
sizeY: sizeY
};
//add the new structure's name, id, posX, posY,
sizeX, and sizeY to our structuresArray
structuresArray.push(structureLocations);
console.log(JSON.stringify(structuresArray));
function createStructuresFromFile()
{
//console.log(JSON.stringify(structuresArray));
for(let z = 0; z < structuresArray.length; z++)
{
let ourStructure = document.createElement("di
v");
ourStructure.style.position = "absolute";
//For a Center Position System, use this way bel
ow
//We minus the structures size divided by itself.
//This way we place structures according to thei
r center, instead of their top left corner.
ourStructure.style.left = structuresArray[z].pos
X - (structuresArray[z].sizeX / 2) + 'px';
ourStructure.style.top = structuresArray[z].pos
Y - (structuresArray[z].sizeY / 2) + 'px';
/*
//For a Top Left Coordinate System, use this wa
y below
ourStructure.style.width = structuresArray[z].si
zeX +'px';
ourStructure.style.height = structuresArray[z].s
izeY +'px';
//"STRUCTURE" + structureId;
ourStructure.id = structuresArray[z].id;
ourStructure.setAttribute('onclick', 'getStructur
eInfo(\''+ourStructure.id+'\');');
ourStructure.style.color = "white";
ourStructure.style.zIndex = "1002";
ourStructure.style.fontFamily = "exo";
ourStructure.style.fontWeight = "bold";
ourStructure.style.fontSize = "medium";
ourStructure.style.background = "black";
ourStructure.style.textAlign = "center";
ourStructure.style.border = "solid 2px rgba(100,
100,255,1.0)";
document.body.append(ourStructure);
}
//console.log(JSON.stringify(structuresArray));
}
/*
Color All Structures
*/
function colorAllStructures()
{
let theStructure;
for(let x = 1; x <= structuresArray.length; x++)
{
theStructure = "STRUCTURE" + x;
document.getElementById(theStructure).styl
e.backgroundColor = "rgb(70,95,140)"
}
for(let x = 1; x <= structuresArray.length; x++)
{
theStructure = "STRUCTURE" + x;
removeElement(theStructure);
}
//reset the array
structuresArray = [ ];
//reset the structureId to 1
structureId = 1;
}
/*
By Pressing the C button, the player creates a me
nu that is populated with entries from each struct
ure made.
/*
//This code below allows us to create an id to b
e used for location data by our menu.
let idForPosition = document.createElement("di
v");
idForPosition.style.position = "absolute";
idForPosition.style.left = theX +'px';
idForPosition.style.top = theY -22 + 'px';
idForPosition.id = "rowOfStructures";
document.body.append(idForPosition);
*/
//used with structuresArray
for(let i = 0; i < whichArray.length; i++)
{
theX = theX + sizeX; //columns across
//filter for Multiple MONTHS
//if(whichArray[i].date.substring(0,2) == 8 ||
whichArray[i].date.substring(0,2) == 9)
//filter for a DATE
//if(whichArray[i].date.substring(0,10) == "0
2/29/2018")
//filter for Multiple DATES
//if(whichArray[i].date.substring(0,10) == "0
2/29/2018" || whichArray[i].date.substring(0,10) ==
"02/29/2020")
//filter for a DAY, of any month, of any year
//if(whichArray[i].date.substring(3,5) == 2)
//filter for a YEAR
//if(whichArray[i].date.substring(6,10) == 20
19)
//filter for MONTH and YEAR
//if(whichArray[i].date.substring(0,2) == 2 &
& whichArray[i].date.substring(6,10) == 2020)
//You can replace the if statement below,
//with one of the options above.
if(whichArray) //shows all items
{
let theTextArea = document.createEleme
nt("div");
theTextArea.style.position = "absolute";
theTextArea.style.left = theX + 17 +'px';
//theTextArea.style.top = theY + 30 +'px';
theTextArea.style.top = ourPlayer.y + 30
+'px';
theTextArea.style.color = "white";
theTextArea.style.zIndex = "998";
theTextArea.resize = "none";
theTextArea.style.height = sizeY - 50 +'px
';
//theTextArea.style.background = "grey";
theTextArea.style.textAlign = "center";
theTextArea.setAttribute("readonly", "tru
e");
theTextArea.setAttribute("class", "divBac
kground");
theTextArea.innerHTML += '<button oncli
ck="scrollToStructure(\''+whichArray[i].id+'\');" cl
ass=\'ourButton\'>GoTo</button><br>';
theTextArea.innerHTML += whichArray[i].
name + "<br>";
theTextArea.value += whichArray[i].name
+ "\n";
theTextArea.value += whichArray[i].id + "\
n";
theTextArea.value += whichArray[i].posX
+ "\n";
theTextArea.value += whichArray[i].posY
+ "\n";
theTextArea.value += whichArray[i].sizeX
+ "\n";
theTextArea.value += whichArray[i].sizeY
+ "\n";
idCounter += 1;
/*
If the Structures Row already exists, re
move it, and create a new Structures Row wherev
er the player is
*/
if(document.getElementById(theTextArea
.id))
{
removeElement(theTextArea.id);
document.body.append(theTextArea);
}
else
{
document.body.append(theTextArea);
}
}
}
}
}
/*
let theNotes =
[
{ note:"Here is a simple Note.", date:"08/22/199
8 12:00 AM", number:"1", tag:"note" },
{ note:"Here is the second note.", date:"08/29/2
018 12:00 AM", number:"2", tag:"note"},
{ note:"Here is the third note.", date:"09/07/201
9 12:00 AM", number:"3", tag:"note"},
{ note:"Here is the fourth note.", date:"10/16/20
20 10:19 AM", number:"4", tag:"note"}
];
function notesWithTextAreaRow(theX, theY, sizeX
, sizeY, whichArray, criteria1)
//This code below allows us to create an id to b
e used for location data by our menu.
let idForPosition = document.createElement("di
v");
idForPosition.style.position = "absolute";
idForPosition.style.left = theX +'px';
idForPosition.style.top = theY -22 + 'px';
idForPosition.id = "notesId";
document.body.append(idForPosition);
//used with theNotes array
for(let i = 0; i < whichArray.length; i++)
{
theX = theX + sizeX; //columns across
if(whichArray[i].tag == criteria1)
{
//filter for a MONTH, meaning, SHOW ONLY
1 month
//if(whichArray[i].date.substring(0,2) == 3)
//filter for Multiple MONTHS
//filter for a DATE
//if(whichArray[i].date.substring(0,10) == "0
2/29/2018")
//filter for Multiple DATES
//if(whichArray[i].date.substring(0,10) == "0
2/29/2018" || whichArray[i].date.substring(0,10) ==
"02/29/2020")
//filter for a DAY, of any month, of any year
//if(whichArray[i].date.substring(3,5) == 2)
//filter for a YEAR
//if(whichArray[i].date.substring(6,10) == 20
19)
//filter for MULTIPLE YEARS
//if(whichArray[i].date.substring(6,10) == 20
19 || whichArray[i].date.substring(6,10) == 2020)
//filter for MONTH and YEAR
//if(whichArray[i].date.substring(0,2) == 2 &
& whichArray[i].date.substring(6,10) == 2020)
let notesDiv = document.createElement("
div");
notesDiv.style.position = "absolute";
notesDiv.style.left = theX + 'px';
notesDiv.style.top = theY +'px';
notesDiv.style.color = "white";
notesDiv.style.zIndex = "1";
notesDiv.style.border = "solid 2px rgba(0
,0,100,1.0)";
notesDiv.style.fontFamily = "exo";
notesDiv.style.fontWeight = "normal";
notesDiv.style.fontSize = "medium";
notesDiv.style.width = sizeX +'px';
notesDiv.style.height = sizeY +'px';
//notesDiv.style.background = "grey";
notesDiv.style.textAlign = "center";
notesDiv.setAttribute("class", "divBackg
round");
//notesRow.id = whichArray[i].id;
notesDiv.id = Math.floor(350000 + Math.ra
ndom() * 9750000);
let theTextArea = document.createEleme
nt("textarea");
theTextArea.style.position = "absolute";
theTextArea.style.left = theX + 17 +'px';
theTextArea.style.top = theY + 30 +'px';
theTextArea.style.color = "white";
theTextArea.style.zIndex = "1";
theTextArea.style.border = "solid 2px rgb
a(0,0,100,1.0)";
theTextArea.style.fontFamily = "exo";
theTextArea.style.fontWeight = "normal";
theTextArea.style.fontSize = "medium";
theTextArea.style.width = sizeX - 30 +'px';
theTextArea.resize = "none";
theTextArea.style.height = sizeY - 50 +'px
';
//theTextArea.style.background = "grey";
theTextArea.style.textAlign = "center";
theTextArea.value += whichArray[i].date
+ "\n";
theTextArea.value += whichArray[i].numb
er + "\n";
theTextArea.value += whichArray[i].note
+ "\n";
theTextArea.id = Math.floor(350000 + Mat
h.random() * 9750000);
let printButton = document.createElemen
t("div");
printButton.style.position = "absolute";
printButton.style.left = theX + 4 +'px';
printButton.style.top = theY + 7 + 'px';
printButton.style.color = "white";
printButton.style.zIndex = "10";
function printTextArea(whichTextArea)
{
let mywindow = window.open('', 'PRINT', 'height
=800,width=1000 top=50, left=100');
mywindow.document.write('<style>img{width:7
5%;</style></head><body>');
mywindow.document.write('<h4>' + document.ti
tle + '</h4>');
mywindow.document.write(document.getEleme
ntById(whichTextArea).value);
startingText.style.left = ourPlayer.x + 160 +'px';
startingText.style.top = ourPlayer.y - 155 + 'px';
startingText.style.width = 400 +'px';
startingText.style.height = 325 +'px';
startingText.style.color = "white";
startingText.style.zIndex = "998";
startingText.style.fontFamily = "exo";
startingText.style.fontWeight = "bold";
startingText.style.fontSize = "13pt";
startingText.style.background = "black";
startingText.style.textAlign = "center";
//REMOVE BUTTON
startingText.innerHTML+= '<button onclick=rem
oveElement("startingMessage"); class="ourButto
n" style="margin-bottom: -4px">X</button></
div>';
//We Build our message using innerHTML
startingText.innerHTML+= '<div><hr style="mar
gin-bottom: 0px"><span style="color:rgb(255, 25
5, 255);letter-spacing: 1px;font-size:20px;line-
height:34px;">Dedicated to God the Father</
span><hr style="margin-top: 0px">';
startingText.innerHTML+= '<span style="color:r
gb(30, 175, 255);letter-spacing: 1px;font-
size:20px;line-height:19px;margin-bottom:-
15px">College of Scripting Music & Science</
span><hr><span style="color:rgb(126, 203, 255);li
ne-height:19px; font-size:20px;">Topalian JavaSc
startingText.id = "startingMessage";
//startingText.innerHTML += '<button onclick=re
moveElement("startingMessage"); class="ourBut
ton">Remove</button>';
document.body.append(startingText);
}
/*
theMenu.style.left = ourPlayer.x - 285 +'px';
theMenu.style.top = ourPlayer.y - 127 + 'px';
theMenu.style.width = 200 +'px';
theMenu.style.height = 240 +'px';
theMenu.style.color = "white";
theMenu.style.zIndex = "998";
theMenu.style.fontFamily = "exo";
theMenu.style.fontWeight = "bold";
theMenu.style.fontSize = "large";
theMenu.style.background = "black";
theMenu.style.textAlign = "center";
theMenu.style.border = "solid 2px rgba(100,100,
255,1.0)";
theMenu.style.paddingLeft = "20px";
theMenu.style.paddingRight = "20px";
theMenu.style.paddingTop = "4px";
//We Build the menu using innerHTML
theMenu.innerHTML+= '<div><hr><span style="
color:rgb(255, 255, 255)">MENU OPTIONS</
span><hr>';
theMenu.innerHTML+= '<span style="color:rgb(
126, 203, 255;font-family:arial; font-
style:normal">GoTo<br></span>';
theMenu.innerHTML+= '<button onclick="scroll
ToSection(\'structureData\');" class=\'ourButton\'>
Structure Data</button>';
theMenu.innerHTML+= '<button onclick="scroll
ToSection(\'notes\');" class=\'ourButton\'>Notes</
button><hr>';
theMenu.innerHTML+= '<span style="color:rgb(
126, 203, 255;font-family:arial; font-
style:normal">Instructions<br></span>';
removeElement("playerMenu");
//remove menu, choice made
removeElement("playerMenu");
//fix in progress
}
if (theSection=="notes")
{
ourPlayer.x = 100;
ourPlayer.y = getPos("notesId").y;
removeElement("playerMenu");
//remove menu, choice made
function sortByNumber(whichArray, direction)
{
if(direction == "up") //ASCENDING
{
whichArray.sort(function(a, b)
{
return a.number.localeCompare(b.number);
});
}
else if(direction == "down") //DESCENDING
{
whichArray.sort(function(b, a)
{
return a.number.localeCompare(b.number);
});
}
/*
We specify which array we want to sort and in
which direction we want it to be sorted (Ascendin
g or Descending)
*/
function sortIt()
{
//Sort by date
sortByDate(theNotes, "up"); //Ascending
//sortByDate(theNotes, "down"); //Descending
//Sort by number
//sortByNumber(theNotes, "up"); //Ascending
//sortByNumber(theNotes, "down"); //
Descending
}
function loadScript(scriptName)
{
let script = document.createElement('script');
script.onload = function() {
createStructuresFromFile();
};
/*
PLAYER PLAYER PLAYER PLAYER
*/
/* Player's start position and id, PlayerLocation */
let ourPlayer = {
x: 374,
y: 175,
speedMultiplier: 10,
playerId: document.getElementById("thePlayer
")
};
/*
CONTROLS CONTROLS CONTROLS CONTROL
S
*/
/* The Keyboard Letter Codes that are Being Pres
sed */
let keyboard = { };
keyboard.UP = 87; //87 is w, 38 is up arrow
function theControls(e)
{
if(e.keyCode == 90) //Letter z
{
playerMenu(); //open player menu of location
s
}
//SPEED
if(e.keyCode == 192) //tilda button on keyboard
{
ourPlayer.speedMultiplier = 1;
ourPlayer.playerId.innerHTML = "Speed 1";
}
if(e.keyCode == 49 || e.keyCode == 97) //number
1, or numpad 1
{
ourPlayer.speedMultiplier = 2;
ourPlayer.playerId.innerHTML = "Speed 2";
}
//change the text on the player object to indic
ate that structure mode has been activated
ourPlayer.playerId.innerHTML = "STRUC- <br
>-TURE<br> MODE<br>ON";
//Add an event listener for mouse clicks and
when clicked, make a structure at location of mou
se
window.addEventListener("click", createStru
cture, false);
//show the data from structuresArray in the T
ext Area
if(e.keyCode == 27) //Letter ESC to exit Structur
e Mode
{
//change the player object background color
ourPlayer.playerId.style.backgroundColor = "
rgb(73, 100, 150)"; //dark blue
//change the text on the player object to indic
ate that structure mode has been deactivated
ourPlayer.playerId.innerHTML = "STRUC-
<br>-TURE <br> MODE<br>OFF";
//Remove the event listener, that listens for m
ouse clicks. This deactivates structure creation m
ode
window.removeEventListener("click", create
Structure);
}
//Color Structures, Make a uniform row of menu
buttons to teleport to each of the structure we ma
de
if(e.keyCode == 67) //Letter c
colorAllStructures();
ourPlayer.playerId.innerHTML = "Colored <br
>All<br> Struc-<br>-tures";
}
if(e.keyCode == 46) //Delete Button
{
//We move the structures row offscreen, as a
simple way of clearing the screen of the row.
rowOfStructures(-1000, -1000, 10, 10, structur
esArray);
removeAllStructures();
ourPlayer.playerId.innerHTML = "Removed <
br>All<br> Struc-<br>-tures";
}
//STRUCTURE MODE
//Shift + 1 brings you to structure 1
//Shift + 2 brings you to structure 2
if(event.getModifierState("Shift") && e.keyCode
== 50)
{
console.log(structuresArray[1].posX);
ourPlayer.x = getPos("STRUCTURE2").x;
ourPlayer.y = getPos("STRUCTURE2").y;
scrollToSection(ourPlayer.x, ourPlayer.y);
}
//Shift + 3 brings you to structure 3
if(event.getModifierState("Shift") && e.keyCo
de == 51)
{
console.log(structuresArray[2].posX);
ourPlayer.x = getPos("STRUCTURE3").x;
ourPlayer.y = getPos("STRUCTURE3").y;
//Shift + 4 brings you to structure 4
if(event.getModifierState("Shift") && e.keyCo
de == 52)
{
console.log(structuresArray[3].posX);
ourPlayer.x = getPos("STRUCTURE4").x;
ourPlayer.y = getPos("STRUCTURE4").y;
scrollToSection(ourPlayer.x, ourPlayer.y);
}
//Shift + 5 brings you to structure 5
if(event.getModifierState("Shift") && e.keyCode
== 53)
{
console.log(structuresArray[4].posX);
ourPlayer.x = getPos("STRUCTURE5").x;
ourPlayer.y = getPos("STRUCTURE5").y;
scrollToSection(ourPlayer.x, ourPlayer.y);
}
//Shift + 6 brings you to structure 6
if(event.getModifierState("Shift") && e.keyCode
== 54)
//Shift + 7 brings you to structure 7
if(event.getModifierState("Shift") && e.keyCode
== 55)
{
console.log(structuresArray[6].posX);
ourPlayer.x = getPos("STRUCTURE7").x;
ourPlayer.y = getPos("STRUCTURE7").y;
scrollToSection(ourPlayer.x, ourPlayer.y);
}
//Shift + 8 brings you to structure 8
if(event.getModifierState("Shift") && e.keyCode
== 56)
{
console.log(structuresArray[7].posX);
ourPlayer.x = getPos("STRUCTURE8").x;
ourPlayer.y = getPos("STRUCTURE8").y;
scrollToSection(ourPlayer.x, ourPlayer.y);
}
//Shift + 0 brings you to structure 10
if(event.getModifierState("Shift") && e.keyCode
== 48)
{
console.log(structuresArray[9].posX);
ourPlayer.x = getPos("STRUCTURE10").x;
ourPlayer.y = getPos("STRUCTURE10").y;
scrollToSection(ourPlayer.x, ourPlayer.y);
}
//////// LOAD SCRIPT LOAD SCRIPT ////////
//Loads World Data of Structures Name, Id, Posi
tion and Size
if(e.keyCode == 71) //Letter g on keyboard
{
createStructuresFromFile();
//shows the structuresArray data in the Text
Area at the top of the screen
showData();
}
if(e.keyCode == 72) //Letter h on keyboard
{
newWindowReport();
}
//TRANSPARENCY
if(e.keyCode == 77) //Letter m
{
ourPlayer.playerId.style.opacity = "1.0";
}
if(e.keyCode == 78) //Letter n
{
ourPlayer.playerId.style.opacity = "0.2";
//Find out which key was pressed
let theKeyCode = e.keyCode || e.which;
keyboard[theKeyCode] = e.type == 'keydown';
};
/* Character Movement Updating */
let movePlayer = function(theX, theY){
ourPlayer.x += (theX || 0) * ourPlayer.speedMult
iplier;
ourPlayer.y += (theY || 0) * ourPlayer.speedMult
iplier;
ourPlayer.playerId.style.left = ourPlayer.x + 'px'
;
ourPlayer.playerId.style.top = ourPlayer.y + 'px'
;
};
/* Player Controls */
let playerMotion = function(){
if(keyboard[keyboard.LEFT]){
movePlayer(-1,0);
/*
CAMERA CAMERA CAMERA CAMERA
/*
Get the POSITION of our MOUSE ARROW
*/
function mousePos(theEvent)
{
let mouseX = theEvent.pageX;
let mouseY = theEvent.pageY;
let mousePos = "Mouse" + "<br>" + "X " + mou
seX + "<br>"+ "Y " + mouseY;
console.log(mousePos);
ourPlayer.playerId.innerHTML= mousePos;
//With Every mouse click, we update the Text Ar
ea to show the structuresArray data that we adde
d.
showData();
}
//Content is Positioned in Rows Based on the Fun
ctions Place in the Array
function contentContainer()
{
let contentArray =
[
function(){ notesWithTextAreaRow(100, yPos,
600, 500, theNotes, "note")},
//theX, theY, sizeX, sizeY, whichArray, criteria
1
//function(){ collegeLinksRow(100, yPos, 300,
50, collegeLinks)},
//theX, theY, sizeX, sizeY, whichArray
];
//add 900 to the yPos, between new section b
elow
yPos = yPos + 900;
}
//contentArray[0]();
//sector 1 line
makeLine(yPos, 1, "Cross this Line to ADD Mor
e content");
}
//// When the Page Loads ////
function whenLoaded()
{
//Load the World Data
loadScript("TopalianWorldDATA.js")
//open the player menu when game begins
//playerMenu();
//loads starting content to the page
contentContainer();
//opens message near player
startMessage();
//show the structuresArray data in the Text Area
showData();
//Add an event listener for left mouse click
window.addEventListener("click", mousePos, f
alse);
//Add an event listener for when person presse
s a key down
window.addEventListener("keydown", theContr
ols, false);
//Add an event listener for when person release
s a key
window.addEventListener("keyup", theControls
, false);
//Load Content based on the player's position.
let sector1 = 0;
function wasLineCrossed()
{
//player speed can be Extremely fast, so we allo
w large range of Y value to be able to trigger the e
vent
if(sector1 == 0)
{
if(Math.floor(getPos("thePlayer").y) > yPos &
& Math.floor(getPos("thePlayer").y) < yPos+40)
{
ourPlayer.playerId.innerHTML = yPos + " C
rossed";
//contentContainer2(); //loads more content
//removes the line
removeElement("sector1");
//only allow content to be added one time
let newWindow = window.open("","test","left=1
0 top=10 width=500, height=300,scrollbars=1,resi
zable=1", true);
//newWindow.document.open();
/*
THE GAME LOOP
*/
function doThisLoop()
{
playerMotion();
scrollIt();
wasLineCrossed();
requestAnimationFrame(doThisLoop);
}
doThisLoop();
//Update the Position of the player
movePlayer();
</script>
</body>
</html>
CollegeOfScripting.wordpress.com
Youtube.com/ScriptingCollege
Github.com/ChristopherTopalian