initial git commit for pets
440
css/css.css
Normal file
@ -0,0 +1,440 @@
|
||||
*|* {
|
||||
margin:0;
|
||||
padding:0;
|
||||
-webkit-user-select:none;
|
||||
-moz-user-select:none;
|
||||
-ms-user-select:none;
|
||||
user-select:none;
|
||||
/* FF scroll bars */
|
||||
scrollbar-width:thin;
|
||||
scrollbar-color:rgba(100,100,100,0.5) rgba(0,0,0,0);
|
||||
/* MS scroll bars */
|
||||
scrollbar-base-color: rgba(0,0,0,0);
|
||||
scrollbar-face-color: rgba(100,100,100,0.5);
|
||||
scrollbar-3dlight-color: rgba(100,100,100,0.5);
|
||||
scrollbar-highlight-color: rgba(100,100,100,0.5);
|
||||
scrollbar-track-color: rgba(0,0,0,0);
|
||||
scrollbar-arrow-color: rgba(0,0,0,0);
|
||||
scrollbar-shadow-color: rgba(0,0,0,0);
|
||||
scrollbar-dark-shadow-color: rgba(0,0,0,0);
|
||||
}
|
||||
|
||||
/* Chrome scroll bars */
|
||||
::-webkit-scrollbar {
|
||||
width:5px;
|
||||
}
|
||||
::-webkit-scrollbar-button {
|
||||
}
|
||||
::-webkit-scrollbar-track {
|
||||
background:rgba(0,0,0,0);
|
||||
width:5px;
|
||||
}
|
||||
::-webkit-scrollbar-track-piece {
|
||||
}
|
||||
::-webkit-scrollbar-thumb {
|
||||
width:5px;
|
||||
background:rgba(100,100,100,0.5);
|
||||
}
|
||||
::-webkit-scrollbar-corner {
|
||||
}
|
||||
::-webkit-resizer {
|
||||
}
|
||||
|
||||
body {
|
||||
position:absolute;
|
||||
background:rgba(0,0,0,1);
|
||||
color:rgba(255,255,255,1);
|
||||
display:flex;
|
||||
flex-wrap:wrap;
|
||||
justify-content:space-evenly;
|
||||
height:100vh;
|
||||
}
|
||||
|
||||
span {
|
||||
margin:5px;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style:none;
|
||||
}
|
||||
|
||||
#outer_infoLog {
|
||||
position:absolute;
|
||||
top:0;
|
||||
left:0;
|
||||
width:calc( 30vw - 2em);
|
||||
height:calc( 50vh - 2em);
|
||||
}
|
||||
|
||||
#infoLog {
|
||||
overflow:auto;
|
||||
height:calc(50vh - 3em);
|
||||
}
|
||||
|
||||
#outer_infoMarket {
|
||||
position:absolute;
|
||||
top:50vh;
|
||||
left:0;
|
||||
width:calc(30vw - 2em);
|
||||
height:calc(50vh - 2em);
|
||||
}
|
||||
|
||||
#outer_player {
|
||||
position:absolute;
|
||||
top:0;
|
||||
left:30vw;
|
||||
height:calc(100vh - 2em);
|
||||
width:calc(70vw - 2em);
|
||||
}
|
||||
|
||||
.outer {
|
||||
padding:calc(1em - 10px);
|
||||
border:solid 5px rgba(100,100,100,1);
|
||||
}
|
||||
|
||||
.title {
|
||||
width:100%;
|
||||
text-align:center;
|
||||
border-bottom:solid 1px rgba(100,100,100,1);
|
||||
}
|
||||
|
||||
#playerStats {
|
||||
display:flex;
|
||||
justify-content:space-around;
|
||||
}
|
||||
|
||||
#outer_playerStats {
|
||||
height:5vh;
|
||||
}
|
||||
|
||||
#playerInv {
|
||||
height:12vh;
|
||||
overflow:auto;
|
||||
display:flex;
|
||||
justify-content:left;
|
||||
flex-wrap:wrap;
|
||||
}
|
||||
|
||||
.item {
|
||||
width:3em;
|
||||
height:3em;
|
||||
margin:1em;
|
||||
border:none 1px rgba(100,100,100,1);
|
||||
cursor:pointer;
|
||||
transition:250ms;
|
||||
position:relative;
|
||||
cursor:pointer;
|
||||
background-repeat:no-repeat;
|
||||
background-size:contain;
|
||||
}
|
||||
|
||||
.item .itemCount {
|
||||
position:absolute;
|
||||
color:rgba(100,150,200,1);
|
||||
bottom:0;
|
||||
right:0;
|
||||
height:1.3em;
|
||||
min-width:1.3em;
|
||||
line-height:1.3em;
|
||||
text-align:center;
|
||||
font-size:0.6em;
|
||||
border-radius:0.65em;
|
||||
background:rgba(100,50,0,0.8);
|
||||
padding-left:2px;
|
||||
padding-right:2px;
|
||||
margin:0;
|
||||
}
|
||||
|
||||
.item .itemCost {
|
||||
position:absolute;
|
||||
bottom:0;
|
||||
left:0;
|
||||
margin:0;
|
||||
color:rgba(200,200,10,1);
|
||||
font-size:0.8em;
|
||||
background:rgba(10,10,10,0.8);
|
||||
}
|
||||
|
||||
.item .itemName {
|
||||
display:none;
|
||||
overflow:hidden;
|
||||
width:100%;
|
||||
margin:0;
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
.item:hover {
|
||||
width:3.5em;
|
||||
height:3.5em;
|
||||
margin:0.75em;
|
||||
transition:250ms;
|
||||
}
|
||||
|
||||
.itemDesc {
|
||||
position:fixed;
|
||||
left:5vw;
|
||||
width:90vw;
|
||||
height:10vh;
|
||||
bottom:10vh;
|
||||
z-index:11;
|
||||
text-align:center;
|
||||
background:rgba(0,0,0,1);
|
||||
overflow:hidden;
|
||||
border:solid 1px rgba(100,100,100,1);
|
||||
justify-content:center;
|
||||
align-items:center;
|
||||
display:none;
|
||||
}
|
||||
|
||||
.item:hover .itemDesc {
|
||||
display:flex;
|
||||
}
|
||||
|
||||
.itemEgg {
|
||||
background-image:url("../img/Egg.svg");
|
||||
}
|
||||
|
||||
.itemFood {
|
||||
background-image:url("../img/Food.svg");
|
||||
}
|
||||
|
||||
.itemWater {
|
||||
background-image:url("../img/Water.svg");
|
||||
}
|
||||
|
||||
.itemToy {
|
||||
background-image:url("../img/Toy.svg");
|
||||
}
|
||||
|
||||
.itemTreasure {
|
||||
background-image:url("../img/Treasure.svg");
|
||||
}
|
||||
|
||||
.itemSEgg {
|
||||
background-image:url("../img/SEgg.svg");
|
||||
}
|
||||
|
||||
.itemNexus {
|
||||
background-image:url("../img/Nexus.svg");
|
||||
}
|
||||
|
||||
#infoMarket,#platerInv {
|
||||
display:flex;
|
||||
flex-wrap:wrap;
|
||||
justify-content:left;
|
||||
align-items:flex-start;
|
||||
align-content:flex-start;
|
||||
overflow-y:auto;
|
||||
overflow-x:hidden;
|
||||
}
|
||||
|
||||
#infoMarket {
|
||||
height:calc(50vh - 3em);
|
||||
}
|
||||
|
||||
#playerActions {
|
||||
height:5vh;
|
||||
overflow:auto;
|
||||
display:flex;
|
||||
justify-content:space-around;
|
||||
}
|
||||
|
||||
#playerPets {
|
||||
height:52vh;
|
||||
overflow:auto;
|
||||
display:flex;
|
||||
justify-content:left;
|
||||
flex-wrap:wrap;
|
||||
}
|
||||
|
||||
.pet {
|
||||
position:relative;
|
||||
background:rgba(0,0,0,1);
|
||||
width:calc(calc(52vh - 5rem) * 0.6 );
|
||||
height:calc(52vh - 5rem);
|
||||
margin:1em;
|
||||
padding:1em;
|
||||
border:solid 1px rgba(100,100,100,1);
|
||||
border-radius:2vw;
|
||||
cursor:pointer;
|
||||
transition:250ms;
|
||||
}
|
||||
|
||||
.pet:hover:not(.selected) {
|
||||
background:rgba(10,10,10,1);
|
||||
width:calc(calc(calc(52vh - 5rem) * 0.6 ) + 4px);
|
||||
height:calc(calc(52vh - 5rem) + 4px);
|
||||
margin:calc(1rem - 2px);
|
||||
transition:250ms;
|
||||
}
|
||||
|
||||
.selected {
|
||||
background:rgba(20,10,0,1);
|
||||
border:solid 4px rgba(200,150,50,1);
|
||||
cursor:default;
|
||||
}
|
||||
|
||||
.pet span {
|
||||
display:inline-block;
|
||||
margin:0;
|
||||
}
|
||||
|
||||
.gender0 {
|
||||
color:rgba(250,150,200,1);
|
||||
}
|
||||
|
||||
.gender1 {
|
||||
color:rgba(100,100,250,1);
|
||||
}
|
||||
|
||||
.dead {
|
||||
display:none;
|
||||
}
|
||||
|
||||
.petName {
|
||||
width:100%;
|
||||
text-align:center;
|
||||
}
|
||||
.petAge,.petAffection {
|
||||
width:50%;
|
||||
text-align:center;
|
||||
}
|
||||
.petHealth,.petHydration,.petNurishment,.petStomach {
|
||||
width:80%;
|
||||
text-align:right;
|
||||
padding-right:20%;
|
||||
}
|
||||
|
||||
.petHydration {
|
||||
color:rgba(10,100,200,1);
|
||||
}
|
||||
|
||||
.petNurishment {
|
||||
color:rgba(200,100,10,1);
|
||||
}
|
||||
|
||||
.petStomach {
|
||||
color:rgba(100,50,0,1);
|
||||
}
|
||||
|
||||
.petAction {
|
||||
position:absolute;
|
||||
/* border:solid 1px rgba(100,100,100,1); */
|
||||
height:calc(calc(calc(52vh - 5rem) * 0.6 ) / 2);
|
||||
width:calc(calc(calc(52vh - 5rem) * 0.6 ) / 2);
|
||||
overflow:hidden;
|
||||
bottom:calc(calc(calc(52vh - 5rem) * 0.6 ) / 4);
|
||||
left:calc(calc(calc(calc(52vh - 5rem) * 0.6 ) / 4) + 1rem - 1px );
|
||||
display:block;
|
||||
justify-content:center;
|
||||
align-items:center;
|
||||
background-size:cover;
|
||||
text-align:center;
|
||||
line-height:calc(calc(calc(calc(52vh - 5rem) * 0.6 ) / 2));
|
||||
font-size:400%;
|
||||
color:rgba(255,255,255,0.4);
|
||||
text-shadow:-1px -1px rgba(0,0,0,0.2), 1px 1px rgba(0,0,0,0.2), -1px 1px rgba(0,0,0,0.2), 1px -1px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.eating {
|
||||
background-image:url("../img/eating.svg");
|
||||
}
|
||||
|
||||
.drinking {
|
||||
background-image:url("../img/drinking.svg");
|
||||
}
|
||||
|
||||
.playing {
|
||||
background-image:url("../img/playing.svg");
|
||||
}
|
||||
|
||||
.walking {
|
||||
background-image:url("../img/walking.svg");
|
||||
}
|
||||
|
||||
.sleeping {
|
||||
background-image:url("../img/sleepingA.svg");
|
||||
}
|
||||
|
||||
.bathing {
|
||||
background-image:url("../img/bathing.svg");
|
||||
}
|
||||
|
||||
.pooping {
|
||||
background-image:url("../img/pooping.svg");
|
||||
}
|
||||
|
||||
.petPoop {
|
||||
position:absolute;
|
||||
bottom:0;
|
||||
right:0;
|
||||
height:5vw;
|
||||
width:4vw;
|
||||
color:rgba(100,50,0,0.5);
|
||||
}
|
||||
|
||||
.actionButton {
|
||||
padding:5px;
|
||||
width:5em;
|
||||
height:1em;
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
.enabled {
|
||||
border:solid 1px rgba(200,100,0,1);
|
||||
background:rgba(100,50,0,0.8);
|
||||
color:rgba(50,150,100,1);
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
.enabled:hover {
|
||||
border-color:rgba(200,200,100,1);
|
||||
background:rgba(150,100,50,1);
|
||||
color:rgba(100,200,250,1);
|
||||
|
||||
}
|
||||
|
||||
.disabled {
|
||||
background:rgba(100,100,100,1);
|
||||
color:rgba(10,10,10,1);
|
||||
}
|
||||
|
||||
.water {
|
||||
color:rgba(10,100,200,1);
|
||||
}
|
||||
|
||||
.food {
|
||||
color:rgba(200,100,10,1);
|
||||
}
|
||||
|
||||
.coins {
|
||||
color:rgba(200,200,100,1);
|
||||
}
|
||||
|
||||
.dialog_back {
|
||||
position:fixed;
|
||||
left:0;
|
||||
top:0;
|
||||
width:100vw;
|
||||
height:100vh;
|
||||
background:rgba(0,0,0,0.8);
|
||||
}
|
||||
|
||||
.dialog_title {
|
||||
position:absolute;
|
||||
top:0;
|
||||
left:0;
|
||||
background:rgba(100,100,100,1);
|
||||
color:rgba(0,0,0,1);
|
||||
text-align:center;
|
||||
height:2vh;
|
||||
width:100%;
|
||||
}
|
||||
|
||||
.dialog_content {
|
||||
position:absolute;
|
||||
left:0;
|
||||
top:2vh;
|
||||
width:100%;
|
||||
height:calc(100% - 2vh);
|
||||
}
|
17
img/Egg.svg
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
<svg width="48" height="48" version="1.1" viewBox="0 0 12.7 12.7" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
<metadata>
|
||||
<rdf:RDF>
|
||||
<cc:Work rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
|
||||
<dc:title/>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g transform="translate(0,-284.3)" fill="#e5bea1">
|
||||
<circle cx="6.4592" cy="292.48" r="4.3211"/>
|
||||
<path transform="scale(-1)" d="m-2.1382-292.68a4.3211 8.2725 0 0 1-2.1605 7.1642 4.3211 8.2725 0 0 1-4.3211 0 4.3211 8.2725 0 0 1-2.1605-7.1642"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 818 B |
17
img/Food.svg
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
<svg width="48" height="48" version="1.1" viewBox="0 0 12.7 12.7" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:osb="http://www.openswatchbook.org/uri/2009/osb" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
<metadata>
|
||||
<rdf:RDF>
|
||||
<cc:Work rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
|
||||
<dc:title/>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g transform="translate(0,-284.3)" stroke="#aaa">
|
||||
<ellipse cx="6.402" cy="285.87" rx="6.1185" ry="1.0158" fill="#7c7c7c" stroke-width=".26458"/>
|
||||
<path d="m0.37265 290.72-0.088588-4.6332c2.0712 1.2496 8.3281 1.0029 10.689 0.60106 0.47795-0.10294 1.0983-0.39041 1.4798-0.62927 0.0069 0-0.07927 2.2212-0.07927 4.6705v4.4534c-2.3034 1.2699-6.9645 2.7418-11.992 0.0229-0.00486 0-0.00884-2.0185-0.00884-4.4855z" fill="#868686" stroke-width=".265"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.0 KiB |
18
img/Nexus.svg
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
<svg width="48" height="48" version="1.1" viewBox="0 0 12.7 12.7" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:osb="http://www.openswatchbook.org/uri/2009/osb" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
<metadata>
|
||||
<rdf:RDF>
|
||||
<cc:Work rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
|
||||
<dc:title/>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g transform="translate(0,-284.3)">
|
||||
<path d="m6.2641 296.71-0.94058-3.1927-2.6376 2.0301 1.1157-3.1358-3.3271 0.0921 2.7458-1.8812-2.7458-1.8812 3.3271 0.0921-1.1157-3.1358 2.6376 2.0301 0.94058-3.1927 0.94058 3.1927 2.6376-2.0301-1.1157 3.1358 3.3271-0.0921-2.7458 1.8812 2.7458 1.8812-3.3271-0.0921 1.1157 3.1358-2.6376-2.0301z" fill="#49f1e7"/>
|
||||
<circle cx="6.2474" cy="290.6" r="3.8921" fill="#00397a" fill-opacity=".5"/>
|
||||
<circle cx="6.2975" cy="290.62" r="1.1526" fill="#d4e7ff"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.1 KiB |
22
img/SEgg.svg
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
<svg width="48" height="48" version="1.1" viewBox="0 0 12.7 12.7" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
<metadata>
|
||||
<rdf:RDF>
|
||||
<cc:Work rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
|
||||
<dc:title/>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g transform="translate(0,-284.3)">
|
||||
<circle cx="6.4592" cy="292.48" r="4.3211" fill="#b7342e"/>
|
||||
<path transform="scale(-1)" d="m-2.1382-292.68a4.3211 8.2725 0 0 1-2.1605 7.1642 4.3211 8.2725 0 0 1-4.3211 0 4.3211 8.2725 0 0 1-2.1605-7.1642" fill="#b7342e"/>
|
||||
<g fill="#211cb8">
|
||||
<circle cx="4.744" cy="287.88" r=".80181"/>
|
||||
<circle cx="8.2352" cy="291.34" r="1.4199"/>
|
||||
<circle cx="4.6605" cy="290.52" r=".4009"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1003 B |
17
img/Toy.svg
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
<svg width="48" height="48" version="1.1" viewBox="0 0 12.7 12.7" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:osb="http://www.openswatchbook.org/uri/2009/osb" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
<metadata>
|
||||
<rdf:RDF>
|
||||
<cc:Work rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
|
||||
<dc:title/>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g transform="translate(0,-284.3)" stroke="#854e00">
|
||||
<ellipse cx="9.0976" cy="288.66" rx="3.4548" ry="3.5016" fill="#c6c000" stroke-width=".29558"/>
|
||||
<path d="m6.2971 290.65c-1.3628 1.0569-3.1274 2.3164-3.9783 2.2283-0.35923-0.0846-1.4399 0.32932-1.8059 1.0346-1.0181 1.3737 1.2609 2.5757 1.8321 2.0691 1.0029-0.34445 1.3404-1.4426 1.4657-2.3344 0.46565-1.1261 1.7855-1.7712 2.8267-2.5731z" fill="#a57813" stroke-width=".29512px"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.0 KiB |
17
img/Treasure.svg
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
<svg width="48" height="48" version="1.1" viewBox="0 0 12.7 12.7" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:osb="http://www.openswatchbook.org/uri/2009/osb" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
<metadata>
|
||||
<rdf:RDF>
|
||||
<cc:Work rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
|
||||
<dc:title/>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g transform="translate(0,-284.3)">
|
||||
<ellipse cx="6.591" cy="290.69" rx="3.0474" ry="6.0949" fill="#c6c000" stroke="#854e00" stroke-width=".265"/>
|
||||
<path d="m7.5359 286.68c1.1821 3.3018 0.76949 5.8561-0.047247 8.221" fill="none" stroke="#fff14e" stroke-linecap="round" stroke-linejoin="round" stroke-width=".265"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 943 B |
20
img/Water.svg
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
<svg width="48" height="48" version="1.1" viewBox="0 0 12.7 12.7" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
<metadata>
|
||||
<rdf:RDF>
|
||||
<cc:Work rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
|
||||
<dc:title/>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g transform="translate(0,-284.3)" stroke="#aaa">
|
||||
<ellipse cx="6.402" cy="285.87" rx="6.1185" ry="1.0158" fill="#211cb8" fill-opacity=".39216" stroke-width=".26458"/>
|
||||
<ellipse cx="6.4019" cy="295.57" rx="6.1185" ry="1.0158" fill="#211cb8" fill-opacity=".39216" stroke-width=".26458"/>
|
||||
<path d="m12.52 285.9v9.6856" fill="none" stroke-width=".26458px"/>
|
||||
<path d="m0.23623 295.56v-9.7093" fill="none" stroke-width=".26458px"/>
|
||||
<path d="m0.37265 290.72v-4.4855l0.18308 0.0904c1.5072 0.7443 7.2631 0.94488 10.417 0.36301 0.55872-0.10308 1.0178-0.23242 1.2639-0.35611 0.06128-0.0308 0.1171-0.056 0.12402-0.056 0.0069 0 0.0126 2.004 0.0126 4.4534v4.4534l-0.13584-0.0685c-0.63695-0.32137-2.2665-0.57318-4.3163-0.66698-0.79842-0.0365-3.0637-0.0146-3.7453 0.0362-1.8874 0.14085-3.1544 0.36938-3.6817 0.66407-0.057209 0.032-0.10799 0.0581-0.11285 0.0581s-0.00884-2.0185-0.00884-4.4855z" fill="#211cb8" fill-opacity=".39216" stroke-width=".023624"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.5 KiB |
66
img/sleeping.svg
Normal file
@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
id="svg8"
|
||||
version="1.1"
|
||||
viewBox="0 0 12.7 12.7"
|
||||
height="48"
|
||||
width="48">
|
||||
<defs
|
||||
id="defs2" />
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
transform="translate(0,-284.3)"
|
||||
id="layer1">
|
||||
<path
|
||||
d="m 12.544086,291.13458 a 6.2129841,3.6065619 0 0 1 -3.1064926,3.12338 6.2129841,3.6065619 0 0 1 -6.2129842,0 6.2129841,3.6065619 0 0 1 -3.10649187,-3.12338 l 6.21298407,0 z"
|
||||
id="path817-6"
|
||||
style="fill:#ff4794;fill-opacity:1;stroke:none;stroke-width:0.37394682;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
transform="scale(-1)"
|
||||
d="m -0.11811733,-291.13458 a 6.2129841,6.7585144 0 0 1 -3.10649217,5.85304 6.2129841,6.7585144 0 0 1 -6.2129841,0 6.2129841,6.7585144 0 0 1 -3.1064924,-5.85304 l 6.2129846,0 z"
|
||||
id="path817-6-7"
|
||||
style="fill:#ff4794;fill-opacity:1;stroke:none;stroke-width:0.5119043;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<ellipse
|
||||
transform="scale(1,-1)"
|
||||
ry="0.078764349"
|
||||
rx="1.3622699"
|
||||
cy="-288.70844"
|
||||
cx="3.6043639"
|
||||
id="path819"
|
||||
style="fill:#060606;fill-opacity:1;stroke:none;stroke-width:0.08545341;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<ellipse
|
||||
transform="scale(1,-1)"
|
||||
ry="0.078764349"
|
||||
rx="1.3622699"
|
||||
cy="-288.70844"
|
||||
cx="9.1548223"
|
||||
id="path819-3"
|
||||
style="fill:#060606;fill-opacity:1;stroke:none;stroke-width:0.08545341;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
d="m 9.179981,291.92255 a 2.8185732,0.15326484 0 0 1 -1.4092867,0.13273 2.8185732,0.15326484 0 0 1 -2.8185732,0 2.8185732,0.15326484 0 0 1 -1.4092866,-0.13273"
|
||||
id="path836"
|
||||
style="fill:#060606;fill-opacity:1;stroke:none;stroke-width:0.13405241;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<circle
|
||||
r="2.3032925"
|
||||
cy="289.71213"
|
||||
cx="4.7128906"
|
||||
id="path870"
|
||||
style="fill:#f7f7f7;fill-opacity:1;stroke:none;stroke-width:0.25837499;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.6 KiB |
23
img/sleepingA.svg
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
|
||||
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
|
||||
<!-- Animated using aniGen version 0.8.1 Quality of Life - http://anigen.org -->
|
||||
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" id="svg8" version="1.1" viewBox="0 0 12.7 12.7" height="48px" width="48px" preserveAspectRatio="xMidYMid" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:anigen="http://www.anigen.org/namespace" anigen:version="0.8.1">
|
||||
<sodipodi:namedview id="base" bordercolor="#666666" borderopacity="1" inkscape:cx="11.784929656440347" inkscape:cy="-5.342449044989291" inkscape:zoom="45.25483399593905"></sodipodi:namedview><defs id="defs2"></defs>
|
||||
<metadata id="metadata5">
|
||||
<rdf:rdf id="rdf:rdf5965">
|
||||
<cc:work rdf:about="" id="cc:work212">
|
||||
<dc:format id="dc:format4152">image/svg+xml</dc:format>
|
||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" id="dc:type537"></dc:type>
|
||||
<dc:title id="dc:title1614"></dc:title>
|
||||
</cc:work>
|
||||
</rdf:rdf>
|
||||
</metadata>
|
||||
<g transform="matrix(0.9816211615000157 0 0 1 0.13430445240662436 -283.29998779296875)" id="layer1" inkscape:transform-center-x="null" inkscape:transform-center-y="-1">
|
||||
<path d="m 12.544086,291.13458 a 6.2129841,3.6065619 0 0 1 -3.1064926,3.12338 6.2129841,3.6065619 0 0 1 -6.2129842,0 6.2129841,3.6065619 0 0 1 -3.10649187,-3.12338 l 6.21298407,0 z" id="path817-6" style="fill: rgb(255, 71, 148); fill-opacity: 1; stroke: rgb(255, 71, 148); stroke-width: 0.373947; stroke-miterlimit: 4; stroke-dasharray: none; stroke-opacity: 1; fill-rule: nonzero; stroke-linecap: round; stroke-linejoin: round;"></path>
|
||||
<path transform="scale(-1)" d="m -0.11811733,-291.13458 a 6.2129841,6.7585144 0 0 1 -3.10649217,5.85304 6.2129841,6.7585144 0 0 1 -6.2129841,0 6.2129841,6.7585144 0 0 1 -3.1064924,-5.85304 l 6.2129846,0 z" id="path817-6-7" style="fill: rgb(255, 71, 148); fill-opacity: 1; stroke: rgb(255, 71, 148); stroke-width: 0.511904; stroke-miterlimit: 4; stroke-dasharray: none; stroke-opacity: 1; stroke-linecap: round; stroke-linejoin: round;"></path>
|
||||
<ellipse transform="scale(1,-1)" ry="0.078764349" rx="1.3622699" cy="-288.70844" cx="3.6043639" id="path819" style="fill:#060606;fill-opacity:1;stroke:none;stroke-width:0.08545341;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"></ellipse>
|
||||
<ellipse transform="scale(1,-1)" ry="0.078764349" rx="1.3622699" cy="-288.70844" cx="9.1548223" id="path819-3" style="fill:#060606;fill-opacity:1;stroke:none;stroke-width:0.08545341;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"></ellipse>
|
||||
<path d="m 9.179981,291.92255 a 2.8185732,0.15326484 0 0 1 -1.4092867,0.13273 2.8185732,0.15326484 0 0 1 -2.8185732,0 2.8185732,0.15326484 0 0 1 -1.4092866,-0.13273" id="path836" style="fill:#060606;fill-opacity:1;stroke:none;stroke-width:0.13405241;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"></path>
|
||||
<circle r="2.30329" cy="289.712" cx="4.71289" id="path870" style="fill:#f7f7f7;fill-opacity:1;stroke:none;stroke-width:0.25837499;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"><animate attributeType="auto" attributeName="r" values="0.5;2.3032925;0.5" calcMode="spline" keyTimes="0;0.5;1" keySplines="0 0 1 1;0 0 1 1" dur="1s" begin="0s" repeatCount="indefinite" additive="replace" accumulate="none" fill="freeze" id="animate3886"></animate><animate attributeType="auto" attributeName="cx" values="6;4.7128906;6" calcMode="spline" keyTimes="0;0.5;1" keySplines="0 0 1 1;0 0 1 1" dur="1s" begin="0s" repeatCount="indefinite" additive="replace" accumulate="none" fill="freeze" id="animate8845"></animate><animate attributeType="auto" attributeName="cy" values="291.5;289.71213;291.5" calcMode="spline" keyTimes="0;0.5;1" keySplines="0 0 1 1;0 0 1 1" dur="1s" begin="0s" repeatCount="indefinite" additive="replace" accumulate="none" fill="freeze" id="animate5387"></animate></circle>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 4.2 KiB |
14
index.html
Normal file
@ -0,0 +1,14 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>Browser Pet</title>
|
||||
<link href="css/css.css" rel="stylesheet" />
|
||||
<script src="libs/bluecore.js"></script>
|
||||
<script src="libs/pet.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
<script>
|
||||
petGame.init();
|
||||
</script>
|
||||
</html>
|
87
libs/blueaudio.js
Normal file
@ -0,0 +1,87 @@
|
||||
/////////////////////// BlueAudio 1.0.4 \\\\\\\\\\\\\\\\\\\\\\\\\\
|
||||
// This requires BlueCore in order to run and assumes it is \\
|
||||
// already loaded. It will not work without BlueCore loaded \\
|
||||
// first. \\
|
||||
//////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
|
||||
|
||||
function getFrequency (note, octave) {
|
||||
// octaves double value
|
||||
// half steps are calculated using fn = f0*(2^(1/12))^n
|
||||
var base = 16.35; // bottom c
|
||||
var a = Math.pow(2,1/12); // Defining a
|
||||
// Check our inputs for sanity
|
||||
if ("number" != typeof note) { note = 1; }
|
||||
if ("number" != typeof octave) { octave = 4; }
|
||||
if (note < 0) { note = 0;}
|
||||
if (note > 11) { note = 11; }
|
||||
if (octave < 0) { octave = 0; }
|
||||
if (octave > 8) { octave = 8; }
|
||||
return (base*Math.pow(a,note))*Math.pow(2,octave);
|
||||
}
|
||||
|
||||
function parseNote (string) {
|
||||
if ("string" != typeof string) { string = "4c1/4"; }
|
||||
var noteReg = new RegExp(/^([1-8])([a-g][nb#]?)(\d)\/(\d{1,2})/i);
|
||||
var noteArray = string.match(noteReg);
|
||||
if (noteArray) { if (noteArray.length == 5) {
|
||||
var noteTranslationObject = {"cb":11,"cn":0,"c":0,"c#":1,"db":1,"dn":2,"d":2,"d#":3,"eb":3,"en":4,"e":4,"e#":5,"fb":4,"fn":5,"f":5,"f#":6,"gb":6,"gn":7,"g":7,"g#":8,"ab":8,"an":9,"a":9,"a#":10,"bb":10,"bn":11,"b":11,"b#":0};
|
||||
var octave = noteArray[1]-0;
|
||||
var length = (noteArray[3]/noteArray[4]);
|
||||
var step = noteTranslationObject[noteArray[2]];
|
||||
if ("cb" == noteArray[2]) { octave--; }
|
||||
if ("b#" == noteArray[2]) { octave++; }
|
||||
return {"note":step,"octave":octave,"length":length};
|
||||
} else {
|
||||
console.log("bad note: "+noteArray.join(" "));
|
||||
return {};
|
||||
}} else {
|
||||
console.log("bad note");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function parseSequence (string) {
|
||||
if ("string" != typeof string) { string = "4c1/4;"; }
|
||||
var notes = string.split(";");
|
||||
var sequence = [];
|
||||
notes.forEach( function (note) {
|
||||
sequence.push( parseNote(note) );
|
||||
});
|
||||
return sequence;
|
||||
}
|
||||
|
||||
function playNote (soundObject, note, octave, length, wave, delay) {
|
||||
if ("string" != typeof wave) { wave = "sine"; }
|
||||
if ("number" != typeof length) { length = 1; }
|
||||
if ("number" != typeof octave) { octave = 4; }
|
||||
if ("number" != typeof note) { note = 0; }
|
||||
if ("object" != typeof soundObject) { soundObject = new AudioContext(); }
|
||||
if ("number" != typeof delay) { delay = 0; }
|
||||
var waveform = soundObject.createOscillator();
|
||||
var gain = soundObject.createGain();
|
||||
waveform.connect(gain);
|
||||
gain.connect(soundObject.destination);
|
||||
|
||||
waveform.type = wave;
|
||||
waveform.frequency.setValueAtTime(getFrequency(note,octave), 0);
|
||||
gain.gain.setValueAtTime(1, soundObject.currentTime+delay);
|
||||
waveform.start(soundObject.currentTime+delay);
|
||||
gain.gain.exponentialRampToValueAtTime(0.00001,soundObject.currentTime+length+delay);
|
||||
waveform.stop(soundObject.currentTime+(length*1.5)+delay);
|
||||
}
|
||||
|
||||
function playSequence (soundObject, sequenceArray, defaultWave, tempo) {
|
||||
if ("object" != typeof soundObject) { soundObject = new AudioContext(); }
|
||||
if ("string" != typeof defaultWave) { defaultWave = "sine"; }
|
||||
if ("sine" != defaultWave && "square" != defaultWave && "triangle" != defaultWave && "sawtooth" != defaultWave) { defaultWave = "sine"; }
|
||||
if ("number" != typeof tempo) { tempo = 60; }
|
||||
if (0 >= tempo) { tempo = 1; }
|
||||
if ("object" != typeof sequenceArray) { sequenceArray = [{"note":0,"octave":4,"length":1,"type":"sine"}]; }
|
||||
var timing = 0;
|
||||
sequenceArray.forEach( function (thisNote) {
|
||||
var adjustedLength = (thisNote.length*(60/tempo))*4;
|
||||
if ("undefined" == typeof thisNote.type) { thisNote.type = defaultWave; }
|
||||
playNote(soundObject, thisNote.note, thisNote.octave, adjustedLength, thisNote.type, timing);
|
||||
timing += adjustedLength/4;
|
||||
});
|
||||
}
|
143
libs/bluecore.js
Normal file
@ -0,0 +1,143 @@
|
||||
"use strict";
|
||||
/////////////////////// BlueCore 1.8.2 \\\\\\\\\\\\\\\\\\\\\\\\\\
|
||||
|
||||
function getData(url,dothis,tothis,type,body) {
|
||||
var DataRequest = new XMLHttpRequest();
|
||||
if (undefined == type) { type = "GET"; }
|
||||
if (undefined == body) { body = ""; }
|
||||
DataRequest.open(type, url, true);
|
||||
DataRequest.onreadystatechange = function () {
|
||||
if ( (DataRequest.readyState === XMLHttpRequest.DONE) && (DataRequest.status === 200) ) {
|
||||
dothis(DataRequest.responseText,tothis);
|
||||
}
|
||||
};
|
||||
DataRequest.send(body);
|
||||
}
|
||||
|
||||
function isEmpty(object) {
|
||||
console.log(object);
|
||||
console.log(typeof object);
|
||||
if ( "object" == typeof object ) {
|
||||
for ( var propery in object ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function addJavascript(string,action) {
|
||||
try {
|
||||
window.eval(string);
|
||||
if ("function" == typeof action) { action(); }
|
||||
}
|
||||
catch (e) { console.log("Error with external script: "+e); }
|
||||
}
|
||||
|
||||
function getJavascript(url,action) {
|
||||
getData(url,addJavascript,action);
|
||||
}
|
||||
|
||||
function addHTMLfrag(string,target) {
|
||||
target.innerHTML = string;
|
||||
}
|
||||
|
||||
function getHTMLfrag(url,targetNode) {
|
||||
var target = document.querySelector(targetNode);
|
||||
target.innerHTML = "Loading...";
|
||||
getData(url,addHTMLfrag,target);
|
||||
}
|
||||
|
||||
function elementMake (ID,Class,element) { //new and improved, I can use more than just divs for things now.
|
||||
ID = "string" == typeof ID ? ID.replace(/ /g,"_") : ID;
|
||||
return (function (myElement) {
|
||||
if ("string" == typeof ID) { myElement.id = ID; }
|
||||
if ("string" == typeof Class) { myElement.className = Class; }
|
||||
return myElement;
|
||||
})(document.createElement(element));
|
||||
}
|
||||
|
||||
function elementPlace (parentID, ID, Class, element, position) {
|
||||
parentID = "string" == typeof parentID ? parentID.replace(/ /g,"_") : parentID;
|
||||
ID = "string" == typeof ID ? ID.replace(/ /g,"_") : ID;
|
||||
var newElement = elementMake(ID,Class,element);
|
||||
if ( (typeof document.querySelector(parentID).append && typeof document.querySelector(parentID).prepend) !== "undefined") { // Are we compliant?
|
||||
if ("before" == position) {
|
||||
document.querySelector(parentID).prepend(newElement);
|
||||
} else {
|
||||
document.querySelector(parentID).append(newElement);
|
||||
}
|
||||
} else { //No? Ok we will use the old way.
|
||||
if ("before" == position) {
|
||||
var p = document.querySelector(parentID);
|
||||
p.insertBefore(newElement,p.firstChild);
|
||||
} else {
|
||||
document.querySelector(parentID).appendChild(newElement);
|
||||
}
|
||||
}
|
||||
return newElement;
|
||||
}
|
||||
|
||||
function titledContainer (ParentID,ID,Class,Element,Position,Title) {
|
||||
var outer = elementPlace(ParentID,"outer_"+ID,"outer "+Class,"div",Position);
|
||||
outer.innerHTML = '<p class="title">'+Title+'</p>';
|
||||
return elementPlace("#outer_"+ID,ID,Class,Element);
|
||||
}
|
||||
|
||||
function numberShorten (Value) {
|
||||
var level = 0;
|
||||
var number = Value;
|
||||
var unit = ["","k","M","B","T","q","Q","s","S","O","N","d","Ud","Dd","Td","qd","Qd","sd","Sd","Od","Nd","v","Uv","Dv","Tv","qv","Qv","sv","Sv","Ov","Nv","t","Ut","Dt","Tt","qt","Qt","st","St","Ot","Nv","c","uc","dc","Tc","Dc","Uc","vc","Sc","Oc","Nc","STOP"];
|
||||
while (999<number) {
|
||||
level++;
|
||||
number = Math.round(number)/1000;
|
||||
}
|
||||
return number+unit[level];
|
||||
}
|
||||
|
||||
function buttonAdd (ParentID,ID,Label,Action,Class,Element) {
|
||||
if ( "undefined" == typeof Class ) { Class = ""; }
|
||||
if ( "undefined" == typeof Element) { Element = "div"; }
|
||||
(function (button) {
|
||||
button.innerHTML = Label;
|
||||
button.onclick = function () { Action(); }
|
||||
})(elementPlace(ParentID,ID,"button "+Class,Element));
|
||||
}
|
||||
|
||||
function inputDialog (dialogRoot,container,args,callback) {
|
||||
args = "object" == typeof args ? args : {"content":""};
|
||||
args.content = "string" == typeof args.content ? args.content : "";
|
||||
container.innerText += args.content;
|
||||
var inputArea = elementPlace("#"+container.id,null,"formInput","input");
|
||||
if ("string" == typeof args.inputType) { inputArea.type = args.inputType; }
|
||||
buttonAdd("#"+container.id,null,"Submit",function () {
|
||||
callback(inputArea.value);
|
||||
dialogRoot.parentNode.removeChild(dialogRoot);
|
||||
},"dialog_submit");
|
||||
}
|
||||
|
||||
function messageDialog (dialogRoot,container,args) {
|
||||
args = "object" == typeof args ? args : {"content":""};
|
||||
args.content = "string" == typeof args.content ? args.content : "";
|
||||
container.innerText += args.content;
|
||||
buttonAdd("#"+container.id,null,"Ok",function () {
|
||||
dialogRoot.parentNode.removeChild(dialogRoot);
|
||||
},"dialog_submit");
|
||||
}
|
||||
|
||||
function popupDialog (ID, title, closeable, contentGen, genArgs, callback) {
|
||||
if ("function" != typeof callback) { callback = function () { return 0; }; }
|
||||
var dialogBack = elementPlace("body",ID+"_back","dialog_back","div");
|
||||
var dialogWindow = elementPlace("#"+ID+"_back",ID,"dialog_window","div");
|
||||
var dialogTitle = elementPlace("#"+ID,ID+"_title","dialog_title","div");
|
||||
if ("string" == typeof title) { dialogTitle.innerText = title; }
|
||||
if (true == closeable) {buttonAdd("#"+ID+"_title",null,"X",function () {dialogBack.parentNode.removeChild(dialogBack);},"dialog_close");}
|
||||
var dialogContent = elementPlace("#"+ID,ID+"_content","dialog_content","div");
|
||||
if ("function" == typeof contentGen) {
|
||||
contentGen(dialogBack,dialogContent,genArgs,callback);
|
||||
} else {
|
||||
dialogContent.innerText = "string" == typeof contentGen ? contentGen : "Empty Dialog";
|
||||
buttonAdd("#"+ID+"_content",null,"Close",callback);
|
||||
}
|
||||
}
|
720
libs/pet.js
Normal file
@ -0,0 +1,720 @@
|
||||
// Define humanTime function
|
||||
function humanTime (time) {
|
||||
var days = (((Math.abs(time)/1000)/60)/60)/24;
|
||||
var hours = (days%1)*24;
|
||||
var minutes = (hours%1)*60;
|
||||
var seconds = (minutes%1)*60;
|
||||
return (1 < days ? Math.floor(days)+"D " : "") + (1 < hours ? Math.floor(hours).toString().padStart(2,"0")+":": "") + ( 1 < minutes ? Math.floor(minutes).toString().padStart(2,"0")+":" : "")+ Math.floor(seconds).toString().padStart(2,"0") ;
|
||||
}
|
||||
// Define RNA validator function
|
||||
function validateRna (rna) {
|
||||
rna = "object" == typeof rna ? rna : {};
|
||||
rna.healthMax = "number" == typeof rna.healthMax ? rna.healthMax : Math.floor(Math.random()*25)+75;
|
||||
rna.stomachMax = "number" == typeof rna.stomachMax ? rna.stomachMax : Math.floor(Math.random()*25)+25;
|
||||
rna.hydrationMax = "number" == typeof rna.hydrationMax ? rna.hydrationMax : Math.floor(Math.random()*90)+10;
|
||||
rna.nurishmentMax = "number" == typeof rna.nurishmentMax ? rna.nurishmentMax : Math.floor(Math.random()*90)+10;
|
||||
rna.thirstRate = "number" == typeof rna.thirstRate ? rna.thirstRate : 300000;
|
||||
rna.hungerRate = "number" == typeof rna.hungerRate ? rna.hungerRate : 300000;
|
||||
return rna;
|
||||
}
|
||||
// Define RNA to DNA function
|
||||
function rna2dna (motherRna,fatherRna) {
|
||||
return dna = [validateRna(motherRna),validateRna(fatherRna)];
|
||||
}
|
||||
// Define DNA to RNA function
|
||||
function dna2rna (dna) {
|
||||
var rna = validateRna({
|
||||
"healthMax":dna[Math.floor(Math.random())].healthMax,
|
||||
"stomachMax":dna[Math.floor(Math.random())].stomachMax,
|
||||
"hydrationMax":dna[Math.floor(Math.random())].hydrationMax,
|
||||
"nurishmentMax":dna[Math.floor(Math.random())].nurishmentMax,
|
||||
"thirstRate":dna[Math.floor(Math.random())].thirstRate,
|
||||
"hungerRate":dna[Math.floor(Math.random())].hungerRate
|
||||
});
|
||||
return rna;
|
||||
}
|
||||
// Define item class
|
||||
class item {
|
||||
constructor (itemDef) {
|
||||
this.id = -1;
|
||||
this.name = "Azathoth";
|
||||
this.desc = "Unknowable";
|
||||
this.countInc = 1;
|
||||
this.action = function () { return 0; };
|
||||
if ("object" == typeof itemDef) {
|
||||
if ("number" == typeof itemDef.id) { this.id = itemDef.id; }
|
||||
if ("string" == typeof itemDef.name) { this.name = itemDef.name; }
|
||||
if ("string" == typeof itemDef.desc) { this.desc = itemDef.desc; }
|
||||
if ("number" == typeof itemDef.countInc) { this.countInc = itemDef.countInc; }
|
||||
if ("function" == typeof itemDef.action) { this.action = itemDef.action; }
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
// Define inventory class
|
||||
class inventory {
|
||||
constructor () {
|
||||
var me = this;
|
||||
this.update = false;
|
||||
this.contents = [];
|
||||
this.addItem = function (itemID,amount,overrides) {
|
||||
if ("number" != typeof amount) { amount = 1;}
|
||||
var exsistingItem = me.contents.findIndex( function (item) { return item.id == itemID; });
|
||||
if (exsistingItem >= 0) {
|
||||
me.contents[exsistingItem].count += amount;
|
||||
} else {
|
||||
me.contents.push(new item(petGame.itemDB[itemID]));
|
||||
me.contents[me.contents.length-1].count = amount;
|
||||
if ("object" == typeof overrides) {
|
||||
if ("string" == typeof overrides.name) { me.contents[me.contents.length-1].name = overrides.name; }
|
||||
if ("string" == typeof overrides.desc) { me.contents[me.contents.length-1].desc = overrides.desc; }
|
||||
if ("number" == typeof overrides.countInc) { me.contents[me.contents.length-1].countInc = overrides.countInc; }
|
||||
if ("function" == typeof overrides.action) { me.contents[me.contents.length-1].action = overrides.action; }
|
||||
}
|
||||
}
|
||||
me.update = true;
|
||||
};
|
||||
|
||||
this.useItem = function (itemIndex,actionBool) {
|
||||
if (actionBool) { me.contents[itemIndex].action(); }
|
||||
me.contents[itemIndex].count -= me.contents[itemIndex].countInc;
|
||||
if (me.contents[itemIndex].count <= 0) {
|
||||
me.contents.splice(itemIndex,1);
|
||||
}
|
||||
me.update = true;
|
||||
};
|
||||
|
||||
this.getBasic = function (info) {
|
||||
return me.contents.map( function (item) { return item[info]; } );
|
||||
};
|
||||
|
||||
this.getEssentials = function () {
|
||||
return me.contents.map( function (item) { return {"id":item.id,"count":item.count}; });
|
||||
};
|
||||
|
||||
}
|
||||
};
|
||||
// Define Pet class
|
||||
class pet {
|
||||
constructor (mother,father) {
|
||||
var me = this;
|
||||
this.dna = rna2dna(mother,father);
|
||||
this.activeRna = dna2rna(this.dna);
|
||||
this.birth = performance.now();
|
||||
this.healthMax = this.activeRna.healthMax + (Math.floor(Math.random()*20)-10);
|
||||
this.stomachMax = this.activeRna.stomachMax + (Math.floor(Math.random()*10)-5);
|
||||
this.hydrationMax = this.activeRna.hydrationMax + (Math.floor(Math.random()*10)-5);
|
||||
this.thirstRate = this.activeRna.thirstRate + (Math.floor(Math.random()*120000)-60000);
|
||||
this.nurishmentMax = this.activeRna.nurishmentMax + (Math.floor(Math.random()*10)-5);
|
||||
this.hungerRate = this.activeRna.hungerRate + (Math.floor(Math.random()*120000)-60000);
|
||||
this.health = this.healthMax;
|
||||
this.stomach = 0;
|
||||
this.hydration = this.hydrationMax;
|
||||
this.nurishment = this.nurishmentMax;
|
||||
this.affection = 0;
|
||||
this.mood = 0;
|
||||
this.name = "pet"+Math.floor(this.birth);
|
||||
this.gender = Math.round(Math.random());
|
||||
this.ageStart = this.birth.valueOf();
|
||||
this.age = 0;
|
||||
this.dirty = 0;
|
||||
this.lastPoop = this.birth;
|
||||
this.busyUntil = this.birth;
|
||||
this.currentAction = null;
|
||||
this.dead = false;
|
||||
this.tick = function (deltaT) {
|
||||
var oldMood = me.mood;
|
||||
me.mood = 0;
|
||||
me.hydration -= deltaT/me.thirstRate;
|
||||
me.nurishment -= deltaT/me.hungerRate;
|
||||
|
||||
if (me.hydrationMax / 2 >= me.hydration) { //Attempt to drink
|
||||
me.takeAction(function () { return me.intake("water"); }, 5000, "drinking",true);
|
||||
}
|
||||
if (me.nurishmentMax / 2 >= me.nurishment) { //Attempt to eat
|
||||
me.takeAction(function () { return me.intake("food"); }, 5000, "eating",true);
|
||||
}
|
||||
|
||||
me.mood += me.hydration < 0 ? me.hydration : 0;
|
||||
me.health += me.hydration < 0 ? me.hydration : 0;
|
||||
me.hydration = me.hydration > 0 ? me.hydration : 0;
|
||||
|
||||
me.mood += me.nurishment < 0 ? me.nurishment : 0;
|
||||
me.health += me.nurishment < 0 ? me.nurishment : 0;
|
||||
me.nurishment = me.nurishment > 0 ? me.nurishment : 0;
|
||||
|
||||
var poops = Math.floor(me.stomach / 10);
|
||||
if (poops) {
|
||||
var time = Math.floor((performance.now() - me.lastPoop) / 25000);
|
||||
if (time > poops) {
|
||||
me.dirty += poops/10;
|
||||
me.stomach -= 10 * poops;
|
||||
me.lastPoop = performance.now();
|
||||
petGame.gui.player.pets.update = true;
|
||||
} else {
|
||||
me.dirty += time/10;
|
||||
me.stomach -= 10 * time;
|
||||
}
|
||||
}
|
||||
if (0 >= me.stomach) { me.stomach = 0; }
|
||||
|
||||
me.mood -= me.dirty*(deltaT/30000);
|
||||
|
||||
me.affection += ((oldMood + me.mood)/2)*(deltaT/30000);
|
||||
|
||||
if (performance.now() >= me.ageStart+(Math.pow(me.age+1,2)*1800000)) {
|
||||
me.age++;
|
||||
me.ageStart = performance.now();
|
||||
petGame.log.messageAdd(me.name+" has grown!",2);
|
||||
}
|
||||
|
||||
if (10 < me.age) { // Death from old age
|
||||
me.dead = true;
|
||||
me.tick = function () {return 0;};
|
||||
petGame.log.messageAdd(me.name+" has died of old age.",2);
|
||||
}
|
||||
|
||||
if (0 >= me.health) { //Death from health loss
|
||||
me.dead = true;
|
||||
me.tick = function () { return 0; };
|
||||
petGame.log.messageAdd(me.name+" has died from health loss", 2);
|
||||
}
|
||||
|
||||
if ((me.busyUntil <= performance.now()) && ("string" == typeof me.currentAction)) {
|
||||
petGame.log.messageAdd(me.name+" has finished "+me.currentAction);
|
||||
me.currentAction = null;
|
||||
petGame.gui.player.pets.update = true;
|
||||
if (true == me.selected) { petGame.player.actions.update = true; }
|
||||
}
|
||||
};
|
||||
|
||||
this.intake = function (type) {
|
||||
if (("string" != typeof type) || ("water" != type && "food" != type)) { console.error("intake: invalid type given to intake: "+type); return 0;}
|
||||
var max = "water" == type ? "hydrationMax" : "nurishmentMax";
|
||||
var current = "water" == type ? "hydration" : "nurishment";
|
||||
|
||||
var def = me[max] - Math.ceil(me[current]);
|
||||
var sdef = me.stomachMax - Math.ceil(me.stomach);
|
||||
var amount = def <= sdef ? def : def - (def - sdef);
|
||||
if (petGame.player[type] > 0) {
|
||||
if (petGame.player[type] >= amount) {
|
||||
petGame.player[type] -= amount;
|
||||
me[current] += amount;
|
||||
me.stomach += amount;
|
||||
return [2, amount];
|
||||
} else {
|
||||
me[current] += petGame.player[type];
|
||||
me.stomach += petGame.player[type];
|
||||
petGame.player[type] = 0;
|
||||
return 3;
|
||||
}
|
||||
} else {
|
||||
return 4;
|
||||
}
|
||||
};
|
||||
|
||||
this.takeAction = function (action, actionTime,actionString,silent) {
|
||||
if ("function" != typeof action) { console.error("given action is not a function"); return 0; }
|
||||
if ("number" != typeof actionTime) { actionTime = 10000; }
|
||||
if ("string" != typeof actionString) { actionString = "something"; }
|
||||
console.log(performance.now()+"-"+me.busyUntil);
|
||||
petGame.gui.player.pets.update = true;
|
||||
if (0 <= performance.now() - me.busyUntil){
|
||||
var result = action();
|
||||
if (0 == result) { return 0; }
|
||||
petGame.log.messageAdd(me.name+" began "+actionString);
|
||||
me.currentAction = actionString;
|
||||
me.busyUntil = performance.now()+actionTime;
|
||||
if (true == me.selected) { petGame.player.actions.update = true; }
|
||||
return result;
|
||||
} else {
|
||||
if (silent) {} else { petGame.log.messageAdd(me.name+" is busy right now."); }
|
||||
return 1;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.feed = function () {
|
||||
var result = me.takeAction(function () { return me.intake("food"); },10000,"eating");
|
||||
if ("number" == typeof result) {
|
||||
if (3 == result) { petGame.log.messageAdd("You fed "+me.name+" your remaining food."); }
|
||||
if (4 == result) { petGame.log.messageAdd("You have no food to give "+me.name, 1); }
|
||||
if (0 == result) { return console.error("Something went wrong");}
|
||||
}
|
||||
if ("object" == typeof result) {
|
||||
if (2 == result[0]) { petGame.log.messageAdd("You fed "+me.name+" "+result[1]+" food."); }
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
this.water = function () {
|
||||
var result = me.takeAction(function () { return me.intake("water"); },10000,"drinking");
|
||||
if ("number" == typeof result) {
|
||||
if (3 == result) { petGame.log.messageAdd("You gave "+me.name+" your remaining water."); }
|
||||
if (4 == result) { petGame.log.messageAdd("You have no water to give "+me.name, 1); }
|
||||
if (0 == result) { return console.error("Something went wrong");}
|
||||
}
|
||||
if ("object" == typeof result) {
|
||||
if (2 == result[0]) { petGame.log.messageAdd("You gave "+me.name+" "+result[1]+" water."); }
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
this.play = function () {
|
||||
var result = me.takeAction(function () {
|
||||
me.mood+=50*(1+(function (a) {return a.length > 0 ? a.reduce(function (a,b) { return a + b;}) : 0})(petGame.player.inventory.contents.filter(function (item) { return (item.id == 4 || item.id == 5)}).map(function (item) { return item.count})));
|
||||
return 2;
|
||||
}, 10000, "playing");
|
||||
return result;
|
||||
};
|
||||
|
||||
this.sleep = function () {
|
||||
var result = me.takeAction(function () {
|
||||
var dif = me.healthMax - me.health;
|
||||
if (20 <= dif) {
|
||||
me.health += 20;
|
||||
} else {
|
||||
me.mood += (me.health+20)-me.healthMax;
|
||||
me.health = me.healthMax;
|
||||
}
|
||||
return 2;
|
||||
},30000,"sleeping");
|
||||
return result;
|
||||
};
|
||||
|
||||
this.walk = function () {
|
||||
var result = me.takeAction(function () {
|
||||
me.mood+=20;
|
||||
me.health-=20;
|
||||
if(25 >= Math.floor(Math.random()*100)) {
|
||||
petGame.log.messageAdd("While out walking, "+me.name+" found something");
|
||||
petGame.player.giveItem(5);
|
||||
}
|
||||
return 2;
|
||||
},10000,"walking");
|
||||
return result;
|
||||
};
|
||||
|
||||
this.clean = function () {
|
||||
var result = me.takeAction(function () { me.dirty = 0; me.mood+=10; return 2; },10000,"bathing");
|
||||
return result;
|
||||
};
|
||||
|
||||
this.rename = function () { me.name = window.prompt("What would you like to change "+me.name+"'s name to?",me.name)};
|
||||
|
||||
petGame.gui.player.pets.update = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Define main game object and its imidiate children
|
||||
window.petGame = {};
|
||||
petGame.start = performance.now();
|
||||
petGame.current = petGame.start;
|
||||
petGame.player = {};
|
||||
petGame.log = {};
|
||||
petGame.market = {};
|
||||
petGame.eventDB = [];
|
||||
petGame.eventCountdown = 300000;
|
||||
petGame.itemDB = [];
|
||||
// Define player object and its children
|
||||
petGame.player.inventory = new inventory();
|
||||
petGame.player.pets = [];
|
||||
petGame.player.water = 0;
|
||||
petGame.player.food = 0;
|
||||
petGame.player.coins = 0;
|
||||
petGame.player.actions = {};
|
||||
petGame.player.give = function (type,amount) {
|
||||
if ("string" != typeof type) { return console.error("type must be string but was:"+(typeof type)); }
|
||||
if ("number" != typeof amount) { return console.error("amount must be number but was:"+(typeof amount)); }
|
||||
petGame.player[type] += amount;
|
||||
}
|
||||
petGame.player.giveItem = function (itemID,amount) {
|
||||
petGame.player.inventory.addItem(itemID,amount);
|
||||
}
|
||||
petGame.gui = {};
|
||||
// Define log object and its children
|
||||
petGame.log.queue = [];
|
||||
petGame.log.messageAdd = function (message, priority, life) {
|
||||
if (petGame.log.queue.length >= 50) { petGame.log.queue.shift(); }
|
||||
message = "string" == typeof message ? message : "No message proveded?";
|
||||
priority = "number" == typeof priority ? priority : 0;
|
||||
life = "number" == typeof life ? life : 600000;
|
||||
petGame.log.queue.push({"message":message, "priority":priority, "life":performance.now()+life});
|
||||
petGame.log.update = true;
|
||||
}
|
||||
petGame.log.clean = function () {
|
||||
petGame.log.queue.forEach( function (message, index, queue) {
|
||||
if (performance.now() > message.life) {
|
||||
queue.splice(index,1);
|
||||
petGame.log.update = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
// Define market object and its children
|
||||
petGame.market.exchangeRate = 1;
|
||||
petGame.market.inventory = new inventory();
|
||||
petGame.market.coins = 0;
|
||||
petGame.market.addItem = function (itemID,amount,override) {
|
||||
petGame.market.inventory.addItem(itemID,amount,override);
|
||||
}
|
||||
// Build eventDB database
|
||||
petGame.eventDB = [
|
||||
{"chance":90,"action":function () {
|
||||
petGame.log.messageAdd("A stranger gives you some money, weird...");
|
||||
petGame.player.give("coins",Math.floor(Math.random()*100));
|
||||
}},
|
||||
{"chance":3,"action":function () {
|
||||
petGame.log.messageAdd("A strange new egg appeared in the market.");
|
||||
petGame.market.addItem(3);;
|
||||
}},
|
||||
{"chance":10,"action":function () {
|
||||
petGame.log.messageAdd("The market has more eggs!");
|
||||
petGame.market.addItem(0,5);
|
||||
}},
|
||||
{"chance":40,"action":function () {
|
||||
petGame.log.messageAdd("You find a toy on the ground, maybe your pets will have more fun playing now.");
|
||||
petGame.player.giveItem(4);
|
||||
}},
|
||||
{"chance":30,"action":function () {
|
||||
petGame.log.messageAdd("The market has more food and water!");
|
||||
petGame.market.addItem(1,5);
|
||||
petGame.market.addItem(2,5);
|
||||
}},
|
||||
{"chance":3,"action":function () {
|
||||
petGame.log.messageAdd("The market has a Nexus for sale");
|
||||
petGame.market.addItem(6,1);
|
||||
}},
|
||||
];
|
||||
// Build itemDB database
|
||||
petGame.itemDB = [
|
||||
{"id":0,"name":"Egg","cost":300,"countInc":1,"desc":"This is a pet egg, when you use it, it will hatch into a new pet.","action": function () {
|
||||
return petGame.player.pets.push(new pet());
|
||||
}},
|
||||
{"id":1,"name":"Water","cost":50,"countInc":1,"desc":"A package of water, use this to add more water to your supply.","action": function () {
|
||||
return petGame.player.give("water",100);
|
||||
}},
|
||||
{"id":2,"name":"Food","cost":50,"countInc":1,"desc":"A package of food, use this to add more food to your supply.","action": function () {
|
||||
return petGame.player.give("food",100);
|
||||
}},
|
||||
{"id":3,"name":"SEgg","cost":50000,"countInc":1,"desc":"This pet egg seems different than others, it seems stronger.","action": function () {
|
||||
return petGame.player.pets.push(new pet({
|
||||
"healthMax":200,
|
||||
"stomachMax":200,
|
||||
"nutritionMax":200,
|
||||
"hydrationMax":200,
|
||||
"hungerRate":12000000,
|
||||
"thirstRate":12000000
|
||||
},{
|
||||
|
||||
}));;
|
||||
}},
|
||||
{"id":4,"name":"Toy","cost":100,"countInc":0,"desc":"This is a pet toy, the more of them you have for your pets to play with, the more affection you will gain each time you play with your pets.","action": function () {
|
||||
return petGame.log.messageAdd("It doesnt seem all that fun to you, but your pets sure enjoy it.");
|
||||
}},
|
||||
{"id":5,"name":"Treasure","cost":500,"countInc":1,"desc":"A buried treasure, sell it for more coins or keep it for more bonus affection from your pets when you play with them.","action": function () {
|
||||
petGame.player.give("coins",500);
|
||||
petGame.market.addItem(5);
|
||||
return petGame.log.messageAdd("You have sold the treasure");
|
||||
}},
|
||||
{"id":6,"name":"Nexus","cost":1000,"countInc":1,"desc":"A nexus allows you to breed two pets of the opposite gender that are at least age 5.","action": function () {
|
||||
if ((1 <= petGame.player.pets.filter(function (pet) {if ((1 == pet.gender) && (5 <= pet.age)) { return {"name":pet.name,"dna":pet.dna}; } else { return false; }}).length) && (1 <= petGame.player.pets.filter(function (pet) {if ((0 == pet.gender) && (5 <= pet.age)) { return {"name":pet.name,"dna":pet.dna}; } else { return false; }}).length)) {
|
||||
popupDialog("breed","New Egg cross Unity System (N.E.X.U.S)",false,function (dialogRoot,container,args) {
|
||||
container.innerHTML = args.content;
|
||||
var father = elementPlace("#"+container.id, null, "nexus_father", "select");
|
||||
args.malesOfAge.forEach(function (pet,index) {father.innerHTML += '<option value="'+index+'">'+pet.name+'</option>';});
|
||||
var mother = elementPlace("#"+container.id,null, "nexus_mother", "select");
|
||||
args.femalesOfAge.forEach(function (pet,index) {mother.innerHTML += '<option value="'+index+'">'+pet.name+'</option>';});
|
||||
buttonAdd("#"+container.id,null,"Breed",function () {
|
||||
if (("number" != typeof parseInt(father.value)) || ("number" != typeof parseInt(mother.value))) {
|
||||
petGame.player.giveItem(6);
|
||||
petGame.log.messageAdd("Your Nexus was not provided good information, try again or wait till later");
|
||||
} else {
|
||||
petGame.player.pets.push(new pet(dna2rna(args.malesOfAge[parseInt(father.value)].dna),dna2rna(args.femalesOfAge[parseInt(mother.value)].dna)));
|
||||
}
|
||||
dialogRoot.parentNode.removeChild(dialogRoot);
|
||||
},"dialog_button","div");
|
||||
buttonAdd("#"+container.id,null,"Cancel",function () {
|
||||
petGame.player.giveItem(6);
|
||||
dialogRoot.parentNode.removeChild(dialogRoot);
|
||||
},"dialog_button","div");
|
||||
},{
|
||||
"content":"Please select the pets you wish to breed:",
|
||||
"malesOfAge":petGame.player.pets.filter(function (pet) {if ((1 == pet.gender) && (5 <= pet.age)) { return {"name":pet.name,"dna":pet.dna}; } else { return false; }}),
|
||||
"femalesOfAge":petGame.player.pets.filter(function (pet) {if ((0 == pet.gender) && (5 <= pet.age)) { return {"name":pet.name,"dna":pet.dna}; } else { return false; }})
|
||||
});
|
||||
} else {
|
||||
petGame.log.messageAdd("You don't have enough pets of the right age or gender to use this...");
|
||||
petGame.player.giveItem(6);
|
||||
}
|
||||
}},
|
||||
];
|
||||
// Define petGame.gui init function
|
||||
petGame.gui.init = function () {
|
||||
window.document.body.innerHTML = null;
|
||||
petGame.gui.player = titledContainer("body","player",null,"div",null,"Player:");
|
||||
petGame.gui.player.stats = titledContainer("#player","playerStats",null,"ul",null,"Stats:");
|
||||
petGame.gui.player.stats.water = elementPlace("#playerStats",null,"playerStat water","li");
|
||||
petGame.gui.player.stats.food = elementPlace("#playerStats",null,"playerStat food","li");
|
||||
petGame.gui.player.stats.coins = elementPlace("#playerStats",null,"playerStat coins","li");
|
||||
petGame.gui.player.inventory = titledContainer("#player","playerInv","inventory","ul",null,"Inventory:");
|
||||
petGame.gui.player.actions = titledContainer("#player","playerActions","actions","ul",null,"Actions:");
|
||||
petGame.gui.player.pets = titledContainer("#player","playerPets",null,"div",null,"Pets:");
|
||||
petGame.gui.player.pets.update = true;
|
||||
petGame.gui.info = elementPlace("body","info",null,"div");
|
||||
petGame.gui.info.log = titledContainer("#info","infoLog",null,"ul",null,"Event Log:");
|
||||
petGame.gui.info.market = titledContainer("#info","infoMarket","inventory","ul",null,"Market:");
|
||||
}
|
||||
// Define gui update function
|
||||
petGame.gui.update = function () {
|
||||
petGame.gui.player.stats.water.innerText = "Water: "+numberShorten(petGame.player.water);
|
||||
petGame.gui.player.stats.food.innerText = "Food: "+numberShorten(petGame.player.food);
|
||||
petGame.gui.player.stats.coins.innerText = "Coins: "+numberShorten(petGame.player.coins);
|
||||
if (petGame.player.inventory.update) {
|
||||
petGame.gui.player.inventory.innerHTML = null;
|
||||
petGame.player.inventory.contents.forEach(function (item,itemIndex) {
|
||||
var itemGui = elementPlace("#playerInv",null,"item item"+item.name,"li");
|
||||
itemGui.innerHTML ='<span class="itemName">'+ item.name+'</span><span class="itemCount">'+numberShorten(item.count)+'</span><span class="itemDesc">'+item.desc+'</span>';
|
||||
itemGui.onclick = function () { petGame.player.inventory.useItem(itemIndex,true); };
|
||||
});
|
||||
petGame.player.inventory.update = false;
|
||||
}
|
||||
if (true == petGame.gui.player.pets.update) {
|
||||
petGame.gui.player.pets.innerHTML = null;
|
||||
petGame.player.pets.forEach(function (pet,index) {
|
||||
petGame.gui.player.pets["pet_"+index] = elementPlace("#playerPets","pet_"+pet.name, "pet gender"+pet.gender, "div");
|
||||
var petGUI = petGame.gui.player.pets["pet_"+index];
|
||||
petGUI.name = elementPlace("#pet_"+pet.name, null, "petName", "span");
|
||||
petGUI.name.innerText = pet.name;
|
||||
if (false == pet.dead) {
|
||||
petGUI.age = elementPlace("#pet_"+pet.name, null, "petAge", "span");
|
||||
petGUI.age.innerText = "Age: "+pet.age;
|
||||
petGUI.affection = elementPlace("#pet_"+pet.name, null, "petAffection", "span");
|
||||
petGUI.affection.innerText = "Love: "+(Math.sign(pet.affection)*Math.floor(Math.pow(Math.abs(pet.affection),1/7)));
|
||||
petGUI.health = elementPlace("#pet_"+pet.name, null, "petHealth", "span");
|
||||
petGUI.health.innerText = "health: "+Math.ceil(pet.health)+"/"+pet.healthMax;
|
||||
petGUI.hydration = elementPlace("#pet_"+pet.name, null, "petHydration", "span");
|
||||
petGUI.hydration.innerText = "Hydration: "+Math.ceil(pet.hydration)+"/"+pet.hydrationMax;
|
||||
petGUI.nurishment = elementPlace("#pet_"+pet.name, null, "petNurishment", "span");
|
||||
petGUI.nurishment.innerText = "Nurishment: "+Math.ceil(pet.nurishment)+"/"+pet.nurishmentMax;
|
||||
petGUI.stomach = elementPlace("#pet_"+pet.name, null, "petStomach", "span");
|
||||
petGUI.stomach.innerText = "Stomach: "+Math.ceil(pet.stomach)+"/"+pet.stomachMax;
|
||||
if ("string" == typeof pet.currentAction) {
|
||||
petGUI.action = elementPlace("#pet_"+pet.name, null, "petAction", "span");
|
||||
petGUI.action.innerText = humanTime(pet.busyUntil - performance.now());
|
||||
petGUI.action.classList.add(pet.currentAction);
|
||||
}
|
||||
if (0 < pet.dirty) {
|
||||
petGUI.poop = elementPlace("#pet_"+pet.name, null, "petPoop", "span");
|
||||
petGUI.poop.innerText = "Poop: "+Math.ceil(pet.dirty);
|
||||
}
|
||||
if (pet.selected) {
|
||||
petGUI.classList.add("selected");
|
||||
} else {
|
||||
petGUI.onclick = function () {
|
||||
petGame.player.pets.forEach(function (p) { p.selected = false;});
|
||||
petGame.player.actions.available = [
|
||||
{ "name":"Rename", "action":pet.rename, "petPointer": pet },
|
||||
{ "name":"Feed", "action":pet.feed, "petPointer": pet },
|
||||
{ "name":"Water", "action":pet.water, "petPointer": pet },
|
||||
{ "name":"Play", "action":pet.play, "petPointer": pet },
|
||||
{ "name":"Walk", "action":pet.walk, "petPointer": pet },
|
||||
{ "name":"Sleep", "action":pet.sleep, "petPointer": pet },
|
||||
{ "name":"Clean", "action":pet.clean, "petPointer": pet },
|
||||
];
|
||||
petGame.player.actions.update = true;
|
||||
petGame.gui.player.pets.update = true;
|
||||
pet.selected = true;
|
||||
};
|
||||
}
|
||||
} else {
|
||||
petGUI.name.innerHTML += '<p class="dead">RIP</p>';
|
||||
petGUI.classList.add("dead");
|
||||
}
|
||||
});
|
||||
petGame.gui.player.pets.update = false;
|
||||
} else {
|
||||
petGame.player.pets.forEach(function (pet,index) {
|
||||
var petGUI = petGame.gui.player.pets["pet_"+index];
|
||||
petGUI.name.innerText = pet.name;
|
||||
if (false == pet.dead) {
|
||||
petGUI.age.innerText = "Age: "+pet.age;
|
||||
petGUI.affection.innerText = "Love: "+(Math.sign(pet.affection)*Math.floor(Math.pow(Math.abs(pet.affection),1/7)));
|
||||
petGUI.health.innerText = "health: "+Math.ceil(pet.health)+"/"+pet.healthMax;
|
||||
petGUI.hydration.innerText = "Hydration: "+Math.ceil(pet.hydration)+"/"+pet.hydrationMax;
|
||||
petGUI.nurishment.innerText = "Nurishment: "+Math.ceil(pet.nurishment)+"/"+pet.nurishmentMax;
|
||||
petGUI.stomach.innerText = "Stomach: "+Math.ceil(pet.stomach)+"/"+pet.stomachMax;
|
||||
if ("string" == typeof pet.currentAction) {
|
||||
petGUI.action.innerText = humanTime(pet.busyUntil - performance.now());
|
||||
petGUI.action.classList.add(pet.currentAction);
|
||||
}
|
||||
if (0 < pet.dirty) {
|
||||
petGUI.poop.innerText = "Poop: "+Math.ceil(pet.dirty);
|
||||
}
|
||||
} else {
|
||||
petGUI.name.innerHTML += '<p class="dead">RIP</p>';
|
||||
petGUI.classList.add("dead");
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
if (true == petGame.player.actions.update) {
|
||||
petGame.gui.player.actions.innerHTML = null;
|
||||
petGame.player.actions.available.forEach(function (action) {
|
||||
var enabled = action.petPointer.currentAction ? "disabled" : "enabled";
|
||||
var thisAction = elementPlace("#playerActions",null,"actionButton "+enabled,"span");
|
||||
thisAction.innerText = action.name;
|
||||
thisAction.onclick = action.action;
|
||||
});
|
||||
petGame.player.actions.update = false;
|
||||
}
|
||||
if (true == petGame.log.update) {
|
||||
petGame.gui.info.log.innerHTML = null;
|
||||
petGame.log.queue.forEach(function (message) {
|
||||
petGame.gui.info.log.innerHTML += '<p class="'+message.priority+'">'+message.message+"</p>";
|
||||
});
|
||||
petGame.gui.info.log.scrollTop = petGame.gui.info.log.scrollHeight;
|
||||
petGame.log.update = false;
|
||||
}
|
||||
if(petGame.market.inventory.update) {
|
||||
petGame.gui.info.market.innerHTML = null;
|
||||
petGame.market.inventory.contents.forEach(function (item,itemIndex) {
|
||||
var itemGui = elementPlace("#infoMarket",null,"item item"+item.name,"li");
|
||||
var cost = petGame.itemDB[item.id].cost;
|
||||
itemGui.innerHTML ='<span class="itemName">'+ item.name+'</span><span class="itemCost">'+numberShorten(cost)+'</span><span class="itemCount">'+numberShorten(item.count)+'</span><span class="itemDesc">'+item.desc+'</span>';
|
||||
itemGui.onclick = function () {
|
||||
if (cost <= petGame.player.coins) {
|
||||
petGame.market.coins += cost;
|
||||
petGame.player.coins -= cost;
|
||||
petGame.player.giveItem(item.id);
|
||||
petGame.market.inventory.useItem(itemIndex,false);
|
||||
} else {
|
||||
petGame.log.messageAdd("You don't have enough coins for "+item.name,2,10000);
|
||||
}
|
||||
};
|
||||
});
|
||||
petGame.market.inventory.update = false;
|
||||
}
|
||||
|
||||
}
|
||||
// Define random events function
|
||||
petGame.randomEvent = function () {
|
||||
var dice = Math.floor(Math.random()*100);
|
||||
var potentialEvents = petGame.eventDB.filter(anEvent => anEvent.chance > dice);
|
||||
if (potentialEvents.length > 0) {
|
||||
potentialEvents[Math.floor(Math.random()*potentialEvents.length)].action();
|
||||
}
|
||||
}
|
||||
// Define Save function
|
||||
petGame.save = function () {
|
||||
var save = {};
|
||||
save.sessionDate = performance.timeOrigin + performance.now();
|
||||
save.sessionTime = performance.now();
|
||||
save.current = petGame.current;
|
||||
save.eventCountdown = petGame.eventCountdown;
|
||||
save.market = {"exchangeRate":petGame.market.exchangeRate,"coins":petGame.market.coins,"inventory":petGame.market.inventory.getEssentials()};
|
||||
save.player = {"water":petGame.player.water,"food":petGame.player.food,"coins":petGame.player.coins,"inventory":petGame.player.inventory.getEssentials(),"pets":[]};
|
||||
petGame.player.pets.forEach(function (pet,index) {
|
||||
save.player.pets[index] = {
|
||||
"affection":pet.affection,
|
||||
"age":pet.age,
|
||||
"ageStart":pet.ageStart,
|
||||
"birth":pet.birth,
|
||||
"busyUntil":pet.busyUntil,
|
||||
"currentAction":pet.currentAction,
|
||||
"dead":pet.dead,
|
||||
"dirty":pet.dirty,
|
||||
"dna":pet.dna,
|
||||
"activeRna":pet.activeRna,
|
||||
"gender":pet.gender,
|
||||
"health":pet.health,
|
||||
"healthMax":pet.healthMax,
|
||||
"hungerRate":pet.hungerRate,
|
||||
"hydration":pet.hydration,
|
||||
"hydrationMax":pet.hydrationMax,
|
||||
"lastPoop":pet.lastPoop,
|
||||
"mood":pet.mood,
|
||||
"name":pet.name,
|
||||
"nurishment":pet.nurishment,
|
||||
"nurishmentMax":pet.nurishmentMax,
|
||||
"stomach":pet.stomach,
|
||||
"stomachMax":pet.stomachMax,
|
||||
"thirstRate":pet.thirstRate,
|
||||
};
|
||||
});
|
||||
localStorage.setItem("petGameSave",JSON.stringify(save));
|
||||
}
|
||||
// Define Load function
|
||||
petGame.load = function () {
|
||||
var load = JSON.parse(localStorage.getItem("petGameSave"));
|
||||
var sessionStartDif = (load.sessionDate - load.sessionTime) - performance.timeOrigin;
|
||||
var offlineDeltaT = performance.timeOrigin - load.sessionDate;
|
||||
console.log("deltaT = "+offlineDeltaT);
|
||||
console.log("time between last start and this start: "+sessionStartDif);
|
||||
petGame.current = load.current + sessionStartDif + offlineDeltaT;
|
||||
petGame.eventCountdown = load.eventCountdown + offlineDeltaT + sessionStartDif;
|
||||
petGame.market.exchangeRate = load.market.exchangeRate;
|
||||
petGame.market.coins = load.market.coins;
|
||||
petGame.market.inventory.contents = [];
|
||||
load.market.inventory.forEach(function (item) {petGame.market.addItem(item.id,item.count);});
|
||||
petGame.player.water = load.player.water;
|
||||
petGame.player.food = load.player.food;
|
||||
petGame.player.coins = load.player.coins;
|
||||
petGame.player.inventory.contents = [];
|
||||
load.player.inventory.forEach(function (item) {petGame.player.giveItem(item.id,item.count);});
|
||||
load.player.pets.forEach(function (oldPet) {
|
||||
var index = (petGame.player.pets.push(new pet()) - 1);
|
||||
petGame.player.pets[index].affection = oldPet.affection;
|
||||
petGame.player.pets[index].age = oldPet.age,
|
||||
petGame.player.pets[index].ageStart = oldPet.ageStart + sessionStartDif + offlineDeltaT,
|
||||
petGame.player.pets[index].birth = oldPet.birth + sessionStartDif + offlineDeltaT,
|
||||
petGame.player.pets[index].busyUntil = oldPet.busyUntil + sessionStartDif + offlineDeltaT,
|
||||
petGame.player.pets[index].currentAction = oldPet.currentAction,
|
||||
petGame.player.pets[index].dead = oldPet.dead,
|
||||
petGame.player.pets[index].dirty = oldPet.dirty,
|
||||
petGame.player.pets[index].dna = oldPet.dna,
|
||||
petGame.player.pets[index].activeRna = oldPet.activeRna,
|
||||
petGame.player.pets[index].gender = oldPet.gender,
|
||||
petGame.player.pets[index].health = oldPet.health,
|
||||
petGame.player.pets[index].healthMax = oldPet.healthMax,
|
||||
petGame.player.pets[index].hungerRate = oldPet.hungerRate,
|
||||
petGame.player.pets[index].hydration = oldPet.hydration,
|
||||
petGame.player.pets[index].hydrationMax = oldPet.hydrationMax,
|
||||
petGame.player.pets[index].lastPoop = oldPet.lastPoop + offlineDeltaT + sessionStartDif,
|
||||
petGame.player.pets[index].mood = oldPet.mood,
|
||||
petGame.player.pets[index].name = oldPet.name,
|
||||
petGame.player.pets[index].nurishment = oldPet.nurishment,
|
||||
petGame.player.pets[index].nurishmentMax = oldPet.nurishmentMax,
|
||||
petGame.player.pets[index].stomach = oldPet.stomach,
|
||||
petGame.player.pets[index].stomachMax = oldPet.stomachMax,
|
||||
petGame.player.pets[index].thirstRate = oldPet.thirstRate
|
||||
});
|
||||
}
|
||||
// Define games ticker function
|
||||
petGame.tickerFunction = function () {
|
||||
var deltaT = performance.now() - petGame.current;
|
||||
petGame.current += deltaT;
|
||||
petGame.eventCountdown -= deltaT;
|
||||
petGame.player.pets.forEach( function (pet) { pet.tick(deltaT); });
|
||||
if (petGame.eventCountdown <= 0) {
|
||||
petGame.eventCountdown += Math.floor(Math.random()*1800000);
|
||||
petGame.randomEvent();
|
||||
}
|
||||
// non time sensitive ticking functions
|
||||
petGame.save();
|
||||
petGame.log.clean();
|
||||
petGame.gui.update();
|
||||
}
|
||||
// Define petGame init function
|
||||
petGame.init = function () {
|
||||
petGame.gui.init();
|
||||
petGame.gui.update();
|
||||
petGame.ticker = setInterval(petGame.tickerFunction, 250);
|
||||
if (localStorage.getItem("petGameSave")) {
|
||||
petGame.load();
|
||||
} else {
|
||||
petGame.player.give("coins",500);
|
||||
petGame.market.addItem(0);
|
||||
petGame.market.addItem(1,10);
|
||||
petGame.market.addItem(2,10);
|
||||
}
|
||||
}
|
386
old/css/css.css
Normal file
@ -0,0 +1,386 @@
|
||||
*|* {
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
justify-content:space-evenly;
|
||||
align-items:center;
|
||||
flex-direction:column;
|
||||
background:#000;
|
||||
width:100vw;
|
||||
height:100vh;
|
||||
}
|
||||
|
||||
#petPin, #infoex, .player {
|
||||
display: flex;
|
||||
flex-wrap:wrap;
|
||||
justify-content:space-around;
|
||||
background: rgba(0,0,0,0);
|
||||
border: solid 5px rgba(200,100,50,0.5);
|
||||
border-radius:10px;
|
||||
padding:10px;
|
||||
overflow:auto;
|
||||
max-height:60vh;
|
||||
width: 90vw;
|
||||
}
|
||||
|
||||
#infoex {
|
||||
display:flex;
|
||||
position:relative;
|
||||
justify-content:space-between;
|
||||
max-height:30vh;
|
||||
}
|
||||
|
||||
.log {
|
||||
display:flex;
|
||||
flex-direction:column;
|
||||
width:45%;
|
||||
height:10em;
|
||||
border:solid 1px rgba(100,100,100,0.7);
|
||||
padding:0.5em;
|
||||
overflow-y:auto;
|
||||
}
|
||||
|
||||
.market {
|
||||
display:flex;
|
||||
justify-content:center;
|
||||
align-items:center;
|
||||
width:45%;
|
||||
}
|
||||
|
||||
.urgency_0 {
|
||||
color:rgba(150,150,150,0.9);
|
||||
}
|
||||
|
||||
.urgency_1 {
|
||||
color:rgba(250,250,250,1);
|
||||
}
|
||||
|
||||
.urgency_2 {
|
||||
color:rgba(250,250,0,1);
|
||||
}
|
||||
|
||||
.urgency_3 {
|
||||
color:rgba(250,0,0,1);
|
||||
}
|
||||
|
||||
.urgency_0, .urgency_1, .urgency_2, .urgency_3 {
|
||||
margin-bottom:0.5em;
|
||||
width:100%;
|
||||
}
|
||||
|
||||
.waterSupply {
|
||||
color:rgba(0,100,200,1);
|
||||
}
|
||||
|
||||
.foodSupply {
|
||||
color:rgba(200,100,0,1);
|
||||
}
|
||||
|
||||
.coins {
|
||||
color:rgba(200,200,50,1);
|
||||
}
|
||||
|
||||
.waterSupply, .foodSupply, .coins {
|
||||
font-size:1.5em;
|
||||
}
|
||||
|
||||
.statbar_back {
|
||||
width:100%;
|
||||
border:solid 1px rgba(100,100,100,0.5);
|
||||
}
|
||||
|
||||
.statbar_fill {
|
||||
height: 1em;
|
||||
color: rgba(128,128,128,0.8);
|
||||
white-space:nowrap;
|
||||
transition:250ms;
|
||||
}
|
||||
|
||||
.health {
|
||||
background:rgba(100,0,0,0.9);
|
||||
}
|
||||
|
||||
.hunger {
|
||||
background:rgba(100,50,0,0.9);
|
||||
}
|
||||
|
||||
.thurst {
|
||||
background:rgba(0,50,100,0.9);
|
||||
}
|
||||
|
||||
.energy {
|
||||
background:rgba(100,100,0,0.9);
|
||||
}
|
||||
|
||||
.mood {
|
||||
background:rgba(100,0,100,0.9);
|
||||
}
|
||||
|
||||
.age {
|
||||
color: rgba(100,100,100,0.9);
|
||||
width:100%;
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
.petContainer {
|
||||
display:flex;
|
||||
flex-direction:column;
|
||||
align-items:stretch;
|
||||
padding: 5px;
|
||||
border:solid 1px rgba(100,100,100,0);
|
||||
border-radius:3px;
|
||||
transition:250ms
|
||||
}
|
||||
|
||||
.petContainer:hover {
|
||||
border:solid 1px rgba(100,100,100,1);
|
||||
transition:250ms;
|
||||
}
|
||||
|
||||
.egg {
|
||||
height:20vh;
|
||||
width:15vh;
|
||||
margin:auto;
|
||||
border:solid 1vh rgba(200,200,200,0.7);
|
||||
border-radius: 7.5vh/12vh 12vh 8vh 8vh;
|
||||
transition:1s;
|
||||
}
|
||||
|
||||
.baby {
|
||||
height:20vh;
|
||||
width:20vh;
|
||||
margin:auto;
|
||||
border:solid 0.1vh rgba(150,150,150,0.5);
|
||||
border-radius: 10vh;
|
||||
transition:10s;
|
||||
}
|
||||
|
||||
.toddler {
|
||||
height:20vh;
|
||||
width:20vh;
|
||||
margin:auto;
|
||||
border:solid 1px rgba(200,200,200,0.3);
|
||||
border-radius: 10vh/ 18vh 18vh 2vh 2vh;
|
||||
transition:10s;
|
||||
}
|
||||
|
||||
.kid {
|
||||
height:25vh;
|
||||
width:20vh;
|
||||
margin:auto;
|
||||
border:none;
|
||||
border-radius: 10vh/ 21vh 21vh 4vh 4vh;
|
||||
transition:10s;
|
||||
}
|
||||
|
||||
.teen {
|
||||
height:30vh;
|
||||
width:16vh;
|
||||
margin:auto;
|
||||
border:none;
|
||||
border-radius: 8vh/ 26vh 26vh 4vh 4vh;
|
||||
transition:10s;
|
||||
}
|
||||
|
||||
.adult{
|
||||
height:40vh;
|
||||
width:20vh;
|
||||
margin:auto;
|
||||
border:none;
|
||||
border-radius: 10vh/ 35vh 35vh 5vh 5vh;
|
||||
transition:10s;
|
||||
}
|
||||
|
||||
.midaged {
|
||||
height:35vh;
|
||||
width:25vh;
|
||||
margin:auto;
|
||||
border:none;
|
||||
border-radius: 12.5vh/ 30vh 30vh 5vh 5vh;
|
||||
transition:10s;
|
||||
}
|
||||
|
||||
.old {
|
||||
height:20vh;
|
||||
width:30vh;
|
||||
margin:auto;
|
||||
border:none;
|
||||
border-radius: 15vh/ 15vh 15vh 3vh 3vh;
|
||||
transition:10s;
|
||||
}
|
||||
|
||||
.gender_0 {
|
||||
background: rgba(255,100,100,1);
|
||||
}
|
||||
|
||||
.gender_1 {
|
||||
background: rgba(100,100,255,1);
|
||||
}
|
||||
|
||||
.dead_pet {
|
||||
height: 10vh;
|
||||
width: 10vh;
|
||||
border-radius:5vh 5vh 0 0;
|
||||
background: rgba(90,90,90,0.9);
|
||||
text-align:center;
|
||||
margin:auto;
|
||||
transition:1s;
|
||||
}
|
||||
|
||||
.actionCurrent {
|
||||
color: rgba(200,200,200,0.9);
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
.actionQueue {}
|
||||
|
||||
.actionMenu {
|
||||
opacity:0;
|
||||
width:100%;
|
||||
display:flex;
|
||||
justify-content:space-around;
|
||||
}
|
||||
|
||||
.itemContainer {
|
||||
display:flex;
|
||||
flex-direction:column;
|
||||
justify-content:space-around;
|
||||
align-items:center;
|
||||
height:4em;
|
||||
width:4em;
|
||||
margin:0.25em;
|
||||
padding:0.25em;
|
||||
overflow:hidden;
|
||||
border:solid 1px rgba(50,50,50,1);
|
||||
cursor:pointer;
|
||||
transition:250ms;
|
||||
}
|
||||
|
||||
.itemContainer:hover {
|
||||
height:4.25em;
|
||||
width:4.25em;
|
||||
margin:0em;
|
||||
transition:250ms;
|
||||
}
|
||||
|
||||
.itemContainer:hover .itemDesc {
|
||||
display:block;
|
||||
position:absolute;
|
||||
right:0;
|
||||
bottom:0;
|
||||
}
|
||||
|
||||
.itemCount {
|
||||
display:none;
|
||||
}
|
||||
|
||||
.itemName {
|
||||
color:rgba(255,255,255,1);
|
||||
}
|
||||
|
||||
.itemValue {
|
||||
color:rgba(200,200,50,1);
|
||||
font-size:1em;
|
||||
}
|
||||
|
||||
.itemDesc {
|
||||
display:none;
|
||||
text-align:center;
|
||||
border-top:solid 1px rgba(100,100,100,1);
|
||||
background:rgba(0,0,0,1);
|
||||
width:100%;
|
||||
color:rgba(200,200,200,1);
|
||||
font-size:1em;
|
||||
}
|
||||
|
||||
.player .market .itemContainer {
|
||||
height:unset;
|
||||
width:unset;
|
||||
}
|
||||
.player .market .itemCount { display: none;}
|
||||
.player .market .itemValue { display: none;}
|
||||
|
||||
.bowl_tray {
|
||||
opacity:0.2;
|
||||
width:100%;
|
||||
display:flex;
|
||||
justify-content:space-around;
|
||||
}
|
||||
|
||||
.bowl_tray .statbar_back {
|
||||
transform:rotate(-0.25turn);
|
||||
height:3em;
|
||||
width:2em;
|
||||
border:solid 0.3em rgba(100,100,100,1);
|
||||
border-right:none;
|
||||
border-radius: 2em 0 0 2em;
|
||||
overflow:hidden;
|
||||
background: rgba(50,50,50,1);
|
||||
}
|
||||
|
||||
.bowl_tray .statbar_fill {
|
||||
height:3em;
|
||||
line-height:3em;
|
||||
color: rgba(100,100,100,0);
|
||||
}
|
||||
|
||||
.statsContainer {
|
||||
margin:10px 0 0 0;
|
||||
border: solid 1px rgba(100,100,100,1);
|
||||
border-radius:3px;
|
||||
overflow:hidden;
|
||||
opacity:0.2;
|
||||
transition:250ms;
|
||||
}
|
||||
|
||||
.petContainer:hover .statsContainer, .petContainer:hover .actionMenu, .petContainer:hover .bowl_tray {
|
||||
opacity:1;
|
||||
transition:250ms;
|
||||
}
|
||||
|
||||
.water {
|
||||
color: rgba(100,200,250,1);
|
||||
background: rgba(0,50,200,1);
|
||||
border-right:solid 0.2em rgba(50,100,250,0.8);
|
||||
box-shadow:0 0 0.4em rgba(50,100,250,0.8);
|
||||
}
|
||||
|
||||
.feed, .food {
|
||||
color: rgba(250,200,100,1);
|
||||
background: rgba(100,50,0,1);
|
||||
border-right:solid 0.2em rgba(250,100,50,0.8);
|
||||
box-shadow:0 0 0.4em rgba(250,100,50,0.8);
|
||||
}
|
||||
|
||||
.play {
|
||||
color: rgba(250,250,100,1);
|
||||
background: rgba(100,100,0,1);
|
||||
border-right:solid 0.2em rgba(150,150,50,0.8);
|
||||
box-shadow:0 0 0.4em rgba(150,150,50,0.8);
|
||||
}
|
||||
|
||||
.button {
|
||||
display: inline-block;
|
||||
user-select: none;
|
||||
text-align:center;
|
||||
width:1em;
|
||||
height:1em;
|
||||
margin:1px;
|
||||
padding:2px;
|
||||
border:solid 1px rgba(90,90,90,0.5);
|
||||
border-radius:5px;
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
margin:0px;
|
||||
padding:3px;
|
||||
transition:0.2s;
|
||||
}
|
||||
|
||||
.disabled {
|
||||
opacity:0.7;
|
||||
}
|
13
old/index.html
Normal file
@ -0,0 +1,13 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Browser Pet</title>
|
||||
<link href="css/css.css" rel="stylesheet" />
|
||||
<script src="libs/bluecore.js"></script>
|
||||
<script src="libs/pet.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
<script>
|
||||
new game;
|
||||
</script>
|
||||
</html>
|
87
old/libs/blueaudio.js
Normal file
@ -0,0 +1,87 @@
|
||||
/////////////////////// BlueAudio 1.0.4 \\\\\\\\\\\\\\\\\\\\\\\\\\
|
||||
// This requires BlueCore in order to run and assumes it is \\
|
||||
// already loaded. It will not work without BlueCore loaded \\
|
||||
// first. \\
|
||||
//////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
|
||||
|
||||
function getFrequency (note, octave) {
|
||||
// octaves double value
|
||||
// half steps are calculated using fn = f0*(2^(1/12))^n
|
||||
var base = 16.35; // bottom c
|
||||
var a = Math.pow(2,1/12); // Defining a
|
||||
// Check our inputs for sanity
|
||||
if ("number" != typeof note) { note = 1; }
|
||||
if ("number" != typeof octave) { octave = 4; }
|
||||
if (note < 0) { note = 0;}
|
||||
if (note > 11) { note = 11; }
|
||||
if (octave < 0) { octave = 0; }
|
||||
if (octave > 8) { octave = 8; }
|
||||
return (base*Math.pow(a,note))*Math.pow(2,octave);
|
||||
}
|
||||
|
||||
function parseNote (string) {
|
||||
if ("string" != typeof string) { string = "4c1/4"; }
|
||||
var noteReg = new RegExp(/^([1-8])([a-g][nb#]?)(\d)\/(\d{1,2})/i);
|
||||
var noteArray = string.match(noteReg);
|
||||
if (noteArray) { if (noteArray.length == 5) {
|
||||
var noteTranslationObject = {"cb":11,"cn":0,"c":0,"c#":1,"db":1,"dn":2,"d":2,"d#":3,"eb":3,"en":4,"e":4,"e#":5,"fb":4,"fn":5,"f":5,"f#":6,"gb":6,"gn":7,"g":7,"g#":8,"ab":8,"an":9,"a":9,"a#":10,"bb":10,"bn":11,"b":11,"b#":0};
|
||||
var octave = noteArray[1]-0;
|
||||
var length = (noteArray[3]/noteArray[4]);
|
||||
var step = noteTranslationObject[noteArray[2]];
|
||||
if ("cb" == noteArray[2]) { octave--; }
|
||||
if ("b#" == noteArray[2]) { octave++; }
|
||||
return {"note":step,"octave":octave,"length":length};
|
||||
} else {
|
||||
console.log("bad note: "+noteArray.join(" "));
|
||||
return {};
|
||||
}} else {
|
||||
console.log("bad note");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function parseSequence (string) {
|
||||
if ("string" != typeof string) { string = "4c1/4;"; }
|
||||
var notes = string.split(";");
|
||||
var sequence = [];
|
||||
notes.forEach( function (note) {
|
||||
sequence.push( parseNote(note) );
|
||||
});
|
||||
return sequence;
|
||||
}
|
||||
|
||||
function playNote (soundObject, note, octave, length, wave, delay) {
|
||||
if ("string" != typeof wave) { wave = "sine"; }
|
||||
if ("number" != typeof length) { length = 1; }
|
||||
if ("number" != typeof octave) { octave = 4; }
|
||||
if ("number" != typeof note) { note = 0; }
|
||||
if ("object" != typeof soundObject) { soundObject = new AudioContext(); }
|
||||
if ("number" != typeof delay) { delay = 0; }
|
||||
var waveform = soundObject.createOscillator();
|
||||
var gain = soundObject.createGain();
|
||||
waveform.connect(gain);
|
||||
gain.connect(soundObject.destination);
|
||||
|
||||
waveform.type = wave;
|
||||
waveform.frequency.setValueAtTime(getFrequency(note,octave), 0);
|
||||
gain.gain.setValueAtTime(1, soundObject.currentTime+delay);
|
||||
waveform.start(soundObject.currentTime+delay);
|
||||
gain.gain.exponentialRampToValueAtTime(0.00001,soundObject.currentTime+length+delay);
|
||||
waveform.stop(soundObject.currentTime+(length*1.5)+delay);
|
||||
}
|
||||
|
||||
function playSequence (soundObject, sequenceArray, defaultWave, tempo) {
|
||||
if ("object" != typeof soundObject) { soundObject = new AudioContext(); }
|
||||
if ("string" != typeof defaultWave) { defaultWave = "sine"; }
|
||||
if ("sine" != defaultWave && "square" != defaultWave && "triangle" != defaultWave && "sawtooth" != defaultWave) { defaultWave = "sine"; }
|
||||
if ("number" != typeof tempo) { tempo = 60; }
|
||||
if (0 >= tempo) { tempo = 1; }
|
||||
if ("object" != typeof sequenceArray) { sequenceArray = [{"note":0,"octave":4,"length":1,"type":"sine"}]; }
|
||||
var timing = 0;
|
||||
sequenceArray.forEach( function (thisNote) {
|
||||
var adjustedLength = (thisNote.length*(60/tempo))*4;
|
||||
if ("undefined" == typeof thisNote.type) { thisNote.type = defaultWave; }
|
||||
playNote(soundObject, thisNote.note, thisNote.octave, adjustedLength, thisNote.type, timing);
|
||||
timing += adjustedLength/4;
|
||||
});
|
||||
}
|
127
old/libs/bluecore.js
Normal file
@ -0,0 +1,127 @@
|
||||
"use strict";
|
||||
/////////////////////// BlueCore 1.7.2 \\\\\\\\\\\\\\\\\\\\\\\\\\
|
||||
|
||||
function getData(url,dothis,tothis,type,body) {
|
||||
var DataRequest = new XMLHttpRequest();
|
||||
if (undefined == type) { type = "GET"; }
|
||||
if (undefined == body) { body = ""; }
|
||||
DataRequest.open(type, url, true);
|
||||
DataRequest.onreadystatechange = function () {
|
||||
if ( (DataRequest.readyState === XMLHttpRequest.DONE) && (DataRequest.status === 200) ) {
|
||||
dothis(DataRequest.responseText,tothis);
|
||||
}
|
||||
};
|
||||
DataRequest.send(body);
|
||||
}
|
||||
|
||||
function isEmpty(object) {
|
||||
console.log(object);
|
||||
console.log(typeof object);
|
||||
if ( "object" == typeof object ) {
|
||||
for ( var propery in object ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function addJavascript(string,action) {
|
||||
try {
|
||||
window.eval(string);
|
||||
if ("function" == typeof action) { action(); }
|
||||
}
|
||||
catch (e) { console.log("Error with external script: "+e); }
|
||||
}
|
||||
|
||||
function getJavascript(url,action) {
|
||||
getData(url,addJavascript,action);
|
||||
}
|
||||
|
||||
function addHTMLfrag(string,target) {
|
||||
target.innerHTML = string;
|
||||
}
|
||||
|
||||
function getHTMLfrag(url,targetNode) {
|
||||
var target = document.querySelector(targetNode);
|
||||
target.innerHTML = "Loading...";
|
||||
getData(url,addHTMLfrag,target);
|
||||
}
|
||||
|
||||
function elementMake (ID,Class,element) { //new and improved, I can use more than just divs for things now.
|
||||
return (function (myElement) {
|
||||
if ("string" == typeof ID) { myElement.id = ID; }
|
||||
if ("string" == typeof Class) { myElement.className = Class; }
|
||||
return myElement;
|
||||
})(document.createElement(element));
|
||||
}
|
||||
|
||||
function elementPlace (parentID, ID, Class, element, position) {
|
||||
var newElement = elementMake(ID,Class,element);
|
||||
if ( (typeof document.querySelector(parentID).append && typeof document.querySelector(parentID).prepend) !== "undefined") { // Are we compliant?
|
||||
if ("before" == position) {
|
||||
document.querySelector(parentID).prepend(newElement);
|
||||
} else {
|
||||
document.querySelector(parentID).append(newElement);
|
||||
}
|
||||
} else { //No? Ok we will use the old way.
|
||||
if ("before" == position) {
|
||||
var p = document.querySelector(parentID);
|
||||
p.insertBefore(newElement,p.firstChild);
|
||||
} else {
|
||||
document.querySelector(parentID).appendChild(newElement);
|
||||
}
|
||||
}
|
||||
return newElement;
|
||||
}
|
||||
|
||||
function buttonAdd (ParentID,ID,Label,Action,Class,Element) {
|
||||
if ( "undefined" == typeof Class ) { Class = ""; }
|
||||
if ( "undefined" == typeof Element) { Element = "div"; }
|
||||
(function (button) {
|
||||
button.innerHTML = Label;
|
||||
button.onclick = function () { Action(); }
|
||||
})(elementPlace(ParentID,ID,"button "+Class,Element));
|
||||
}
|
||||
|
||||
function dialogControlsGen(parentDialog,DialogBack,type,returnVar) { //I need to refactor this, these if statments are too similar.
|
||||
if ( "sub_window" == type ) {
|
||||
var closeButton = elementPlace(parentDialog,"closeButton",null,"div"); //Also need to change this, to help standardize the look and feel of the UI
|
||||
closeButton.innerHTML = "X";
|
||||
closeButton.onclick = function () { document.getElementById("body").removeChild(DialogBack); }
|
||||
//More controls will go here probably as I flesh out the sub window design
|
||||
}
|
||||
if ( "input" == type ) {
|
||||
var inputArea = elementPlace(parentDialog,"listID","inputField","input",null);
|
||||
var submitButton = buttonAdd(parentDialog,"SubmitButton","Submit",function () {
|
||||
returnVar.value = inputArea.value;
|
||||
document.getElementById("body").removeChild(DialogBack);
|
||||
},"UI UIbutton");
|
||||
}
|
||||
if ( "input_password" == type ) {
|
||||
var inputArea = elementPlace(parentDialog,"listID","inputField","input",null);
|
||||
inputArea.type = "password";
|
||||
var submitButton = buttonAdd(parentDialog,"SubmitButton","Submit",function () {
|
||||
returnVar.value = inputArea.value;
|
||||
document.getElementById("body").removeChild(DialogBack);
|
||||
},"UI UIbutton");
|
||||
}
|
||||
if ( "info" == type ) {
|
||||
var closeButton = elementPlace(parentDialog,"closeButton",null,"div");
|
||||
closeButton.innerHTML = "Close";
|
||||
closeButton.onclick = function () { document.getElementById("body").removeChild(DialogBack); }
|
||||
}
|
||||
if ( "end" == type ) {
|
||||
var closeButton = elementPlace(parentDialog,"closeButton",null,"div");
|
||||
closeButton.innerHTML = "Play Again";
|
||||
closeButton.onclick = function () { document.getElementById("body").removeChild(DialogBack); gameInit(); }
|
||||
}
|
||||
}
|
||||
|
||||
function dialogMessage (content,type,returnVar) {
|
||||
var message = elementPlace("#body","app_message_back","app_Message_Back","div");
|
||||
var dialog = elementPlace("#app_message_back","app_message","app_Message","div");
|
||||
dialog.innerHTML = content;
|
||||
dialogControlsGen("#app_message",message, type, returnVar);
|
||||
}
|
569
old/libs/pet.js
Normal file
@ -0,0 +1,569 @@
|
||||
function hours (hours, tick) {
|
||||
if (tick == undefined) { tick = 1; }
|
||||
return (hours*60*60*1000)/tick;
|
||||
}
|
||||
|
||||
class petStat {
|
||||
constructor(value,min,max) {
|
||||
var myValue;
|
||||
var myMin = Number.NEGATIVE_INFINITY;
|
||||
var myMax = Number.POSITIVE_INFINITY;
|
||||
|
||||
function checkBounds(value) {
|
||||
if (value > myMax) { return [myMax, value - myMax]; }
|
||||
if (value < myMin) { return [myMin, value - myMin];}
|
||||
return [value,0];
|
||||
}
|
||||
|
||||
if (typeof min == "number") { myMin = min; }
|
||||
if ((typeof max == "number" ) && ( max >= min )) { myMax = max; }
|
||||
myValue = checkBounds(value)[0];
|
||||
// Public Methods
|
||||
this.setValue = function (newVal) {
|
||||
var bounded = checkBounds(newVal);
|
||||
myValue = bounded[0];
|
||||
return bounded[1];
|
||||
};
|
||||
|
||||
this.setBounds = function (lower,upper) {
|
||||
if ((typeof lower == "number") && (typeof upper == "number") && (lower < upper)) {
|
||||
myMin = lower;
|
||||
myMax = upper;
|
||||
checkBounds();
|
||||
}
|
||||
return [myMin,myMax];
|
||||
};
|
||||
|
||||
this.getValue = function () {
|
||||
return myValue;
|
||||
};
|
||||
|
||||
this.modValue = function (mod) {
|
||||
var bounded = checkBounds(myValue+mod);
|
||||
myValue = bounded[0];
|
||||
return bounded[1];
|
||||
};
|
||||
|
||||
this.percent = function () {
|
||||
return myValue/myMax;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
class statBar {
|
||||
constructor(parentID,type,value) {
|
||||
var myParent = "body";
|
||||
var myType = "StatBar";
|
||||
var myValue = 0.5;
|
||||
var mySel = "";
|
||||
if (typeof value == "number") { myValue = value; }
|
||||
if (typeof parentID == "string") { myParent = parentID; mySel="#"; }
|
||||
if (typeof type == "string") { myType = type; }
|
||||
var current = new petStat(myValue,0,1);
|
||||
var myBack = elementPlace(mySel+myParent, myParent+"_"+myType, "statbar_back", "div");
|
||||
var myFill = elementPlace("#"+myParent+"_"+myType, null, "statbar_fill "+myType, "div");
|
||||
|
||||
this.update = function (newVal) {
|
||||
current.setValue(newVal);
|
||||
myFill.style.width = (current.getValue()*100)+"%";
|
||||
myFill.innerText = myType+" "+Math.floor(current.getValue()*100)+"%";
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
class pet {
|
||||
constructor(dna) {
|
||||
var me = this;
|
||||
//Initialise Private values
|
||||
var myDNA = {
|
||||
"gender":Math.round(Math.random()),
|
||||
"health":(Math.round(Math.random()*20)+80),
|
||||
"endurance":(Math.round(Math.random()*50)+50),
|
||||
"heartiness":(Math.random()*100)
|
||||
};
|
||||
if (typeof dna == "object") {
|
||||
if (typeof dna["gender"] == "object") { myDNA["gender"] = dna["gender"][Math.round(Math.random())]; }
|
||||
if (typeof dna["health"] == "object") { myDNA["health"] = dna["health"][Math.round(Math.random())]; }
|
||||
if (typeof dna["endurance"] == "object") { myDNA["endurance"] = dna["endurance"][Math.round(Math.random())]; }
|
||||
if (typeof dna["heartiness"] == "object") { myDNA["heartiness"] = dna["heartiness"][Math.round(Math.random())]; }
|
||||
}
|
||||
var birth = new Date();
|
||||
var petID = "pet_"+birth.valueOf();
|
||||
var name = petID;
|
||||
var tickTime = 50;
|
||||
var lifeStageIndex = ["egg","baby","toddler","kid","teen","adult","midaged","old"];
|
||||
var lifeStage = 0;
|
||||
var lifeMax = hours(168,tickTime); //168 hours *should* be 7 days
|
||||
var lifeStageTime = hours(0.5,tickTime);
|
||||
var lifeTimeCurrent = 0;
|
||||
var statHp = new petStat(myDNA["health"],0,myDNA["health"]);
|
||||
var statGender = new petStat(myDNA["gender"],0,1);
|
||||
var statHunger = new petStat(1,0,myDNA["endurance"]);
|
||||
var statThurst = new petStat(1,0,myDNA["endurance"]);
|
||||
var statMood = new petStat(0,-100,100);
|
||||
var statHeart = new petStat(myDNA["heartiness"],50,200);
|
||||
var statActive = new petStat(Math.random()*(myDNA["heartiness"]+myDNA["endurance"]),0,(myDNA["heartiness"]+myDNA["endurance"]));
|
||||
var statEnergy = new petStat(1,0,statActive.getValue());
|
||||
var foodBowl = new petStat(75000,0,250000);
|
||||
var waterBowl = new petStat(75000,0,250000);
|
||||
var guiPetID = elementPlace("#petPin", petID, "petContainer","div");
|
||||
var guiPetIconID = elementPlace("#"+petID,null,"gender_"+statGender.getValue()+" egg","div");
|
||||
guiPetIconID.onclick = function () { me.nameChange(); };
|
||||
var guiActionQueueID = elementPlace("#"+petID,null,"actionQueue","div");
|
||||
var guiActionCurrentID = elementPlace("#"+petID,null,"actionCurrent","div");
|
||||
var guiBowlID = elementPlace("#"+petID,petID+"_bowl_tray","bowl_tray","div");
|
||||
var guiBowlFood = new statBar(petID+"_bowl_tray","food");
|
||||
var guiBowlWater = new statBar(petID+"_bowl_tray","water");
|
||||
var guiActionMenuID = elementPlace("#"+petID,petID+"_actions","actionMenu","div");
|
||||
var guiActionFeedID = elementPlace("#"+petID+"_actions",null,"button feed disabled", "div");
|
||||
guiActionFeedID.innerText = "F";
|
||||
guiActionFeedID.onclick = function () { me.actionAdd("feed"); };
|
||||
var guiActionWaterID = elementPlace("#"+petID+"_actions",null,"button water disabled", "div");
|
||||
guiActionWaterID.innerText = "W";
|
||||
guiActionWaterID.onclick = function () { me.actionAdd("water"); };
|
||||
var guiStatsID = elementPlace("#"+petID,petID+"_stats","statsContainer","div");
|
||||
var guiStatAge = elementPlace("#"+petID,null,"age", "div");
|
||||
var guiStatHp = new statBar(petID+"_stats","health");
|
||||
var guiStatHunger = new statBar(petID+"_stats","hunger");
|
||||
var guiStatThurst = new statBar(petID+"_stats","thirst");
|
||||
var guiStatEnergy = new statBar(petID+"_stats","energy");
|
||||
var guiStatMood = new statBar(petID+"_stats","mood");
|
||||
var actionQueue = [];
|
||||
var actionCurrent = "";
|
||||
|
||||
//Private Methods
|
||||
function tickToTime (ticks) {
|
||||
var days = ((((Math.abs(ticks)*tickTime)/1000)/60)/60)/24;
|
||||
var hours = (days%1)*24;
|
||||
var minutes = (hours%1)*60;
|
||||
var seconds = (minutes%1)*60;
|
||||
return Math.floor(days)+"D "+Math.floor(hours).toString().padStart(2,"0")+":"+Math.floor(minutes).toString().padStart(2,"0")+":"+Math.floor(seconds).toString().padStart(2,"0");
|
||||
}
|
||||
|
||||
function updateGui() {
|
||||
guiActionCurrentID.innerText = actionCurrent+"ing";
|
||||
guiStatHp.update(statHp.percent());
|
||||
guiStatHunger.update(statHunger.percent());
|
||||
guiStatThurst.update(statThurst.percent());
|
||||
guiStatEnergy.update(statEnergy.percent());
|
||||
guiStatMood.update((statMood.percent()/2)+0.5);
|
||||
guiBowlFood.update(foodBowl.percent());
|
||||
guiBowlWater.update(waterBowl.percent());
|
||||
guiStatAge.innerText = tickToTime(lifeTimeCurrent - hours(0.5,tickTime));
|
||||
}
|
||||
|
||||
function tickMe() {
|
||||
var elapsedMS = ((new Date - birth.getTime()) - (lifeTimeCurrent*tickTime))/tickTime;
|
||||
for (;elapsedMS > 0;elapsedMS--) {
|
||||
lifeTimeCurrent++;
|
||||
lifeStageTime--;
|
||||
if (lifeStageTime <= 0) { age(); }
|
||||
if (lifeStage > 0) { // Eggs don't need food or water.
|
||||
actionDo();
|
||||
if (statEnergy.getValue() < 5 && actionQueue.includes("rest") == false) {
|
||||
"rest,".repeat(9).split(",").forEach(function (e) { actionQueue.push(e);});
|
||||
}
|
||||
if (statThurst.getValue() > 5 && actionQueue.includes("drink") == false) {
|
||||
"drink,".repeat(4).split(",").forEach(function (e) { actionQueue.push(e);});
|
||||
}
|
||||
if (statHunger.getValue() > 5 && actionQueue.includes("eat") == false) {
|
||||
"eat,".repeat(4).split(",").forEach(function (e) { actionQueue.push(e);});
|
||||
}
|
||||
} else { // Do this while its an egg
|
||||
actionCurrent = "Incubat";
|
||||
statHp.setValue((statHp.setBounds()[1]+1)-((lifeStageTime/hours(0.5,tickTime))*statHp.setBounds()[1]));
|
||||
}
|
||||
}
|
||||
updateGui();
|
||||
}
|
||||
|
||||
function hurt (amount) {
|
||||
window.gameDB.message(name+" is taking damage!",2,tickTime );
|
||||
var pain = statHp.modValue(-amount);
|
||||
if (pain < 0) {
|
||||
return die();
|
||||
} else {
|
||||
return emotion(-pain); // This kind of doesn't do anything...
|
||||
}
|
||||
}
|
||||
|
||||
function drink (amount) {
|
||||
if ((statEnergy.getValue() >= amount) && (waterBowl.getValue() >= amount)) {
|
||||
hurt(statHunger.modValue(amount*0.2));
|
||||
statEnergy.modValue(-amount);
|
||||
waterBowl.modValue(-amount);
|
||||
return statThurst.modValue(-amount);
|
||||
} else {
|
||||
actionQueue.push("drink");
|
||||
actionCurrent = "rest";
|
||||
var energyDef = statEnergy.modValue(-amount);
|
||||
var waterDef = waterBowl.modValue(-amount);
|
||||
if (energyDef < waterDef) { return statThurst.modValue(-(amount+energyDef));
|
||||
} else { return statThurst.modValue(-(amount+waterDef)); }
|
||||
}
|
||||
}
|
||||
|
||||
function eat (amount) {
|
||||
if ((statEnergy.getValue() >=amount) && (foodBowl.getValue() >= amount)) {
|
||||
hurt(statThurst.modValue(amount*0.2));
|
||||
statEnergy.modValue(-amount);
|
||||
foodBowl.modValue(-amount);
|
||||
return statHunger.modValue(-amount);
|
||||
} else {
|
||||
actionQueue.push("eat");
|
||||
actionCurrent = "rest";
|
||||
var energyDef = statEnergy.modValue(-amount);
|
||||
var foodDef = foodBowl.modValue(-amount);
|
||||
if (energyDef < foodDef) { return statHunger.modValue(-(amount+energyDef));
|
||||
} else { return statHunger.modValue(-(amount+foodDef));}
|
||||
}
|
||||
}
|
||||
|
||||
function play (amount) {
|
||||
if (statEnergy.getValue() >= amount*3) {
|
||||
hurt(statHunger.modValue(amount));
|
||||
hurt(statThurst.modValue(amount));
|
||||
hurt(statEnergy.modValue(-amount*3));
|
||||
return emotion(amount);
|
||||
} else {
|
||||
actionQueue.push("play");
|
||||
actionCurrent = "rest";
|
||||
}
|
||||
}
|
||||
|
||||
function rest (amount) {
|
||||
hurt(statHunger.modValue(amount*0.3));
|
||||
hurt(statThurst.modValue(amount*0.3));
|
||||
return statHp.modValue(statEnergy.modValue((amount)*(statHp.percent()+statMood.percent())));
|
||||
}
|
||||
|
||||
function emotion (amount) {
|
||||
var adjustedAmount = amount - (amount * (statMood.getValue() / 100));
|
||||
statMood.modValue(adjustedAmount);
|
||||
// statMood.modValue(Math.sqrt( (statMood.getValue() + amount) / 200));
|
||||
}
|
||||
|
||||
function age () {
|
||||
lifeStage++;
|
||||
if (lifeStage > lifeStageIndex.length-1) { return die(); }
|
||||
guiPetIconID.classList.replace(lifeStageIndex[lifeStage - 1],lifeStageIndex[lifeStage]);
|
||||
//Change stats
|
||||
statHp.setBounds(0,statHp.setBounds()[1]*(1+statHeart.percent()));
|
||||
statHp.modValue(statHp.setBounds()[1]);
|
||||
statThurst.setBounds(0,statThurst.setBounds()[1]*(1+statHeart.percent()));
|
||||
statHunger.setBounds(0,statHunger.setBounds()[1]*(1+statHeart.percent()));
|
||||
statEnergy.setBounds(0,statEnergy.setBounds()[1]*(1+statHeart.percent()));
|
||||
lifeStageTime = (((lifeMax-lifeTimeCurrent)/(10-lifeStage))*(statHeart.getValue()/100));
|
||||
window.gameDB.message("Your pet has grown to the next stage if its life.");
|
||||
}
|
||||
|
||||
function die () {
|
||||
actionQueue = [];
|
||||
actionCurrent = "Decompos";
|
||||
clearInterval(myTicker);
|
||||
guiPetIconID.className = "dead_pet";
|
||||
guiPetIconID.innerText = "RIP<br />"+name;
|
||||
guiStatsID.innerHTML = "";
|
||||
window.gameDB.message(name+" has died, but all is not lost, you will never forget them, but it seems they left behind a new egg, you will need to pay to have it hatched. But it also looks like your pet was hording coins, theres just enough here to hatch the new egg.",3,30000);
|
||||
window.gameDB.player.giveReward(300);
|
||||
window.gameDB.infoexch.market.addItem(window.gameDB.itemDB[1]);
|
||||
}
|
||||
|
||||
function actionDo () {
|
||||
if (actionQueue.length) {
|
||||
actionCurrent = actionQueue.shift();
|
||||
// action logic here
|
||||
if (actionCurrent == "drink") { emotion(-(drink(1)*0.25)); }
|
||||
if (actionCurrent == "eat") { emotion(-(eat(1)*0.25)); }
|
||||
if (actionCurrent == "play") { play(1); }
|
||||
if (actionCurrent == "rest") { emotion(-(rest(1)*0.25)); }
|
||||
} else { // Nothing to do
|
||||
actionCurrent = "rest";
|
||||
emotion(-(rest(1)*0.25));
|
||||
}
|
||||
}
|
||||
|
||||
//Public Methods
|
||||
this.statGet = function () {
|
||||
return {"health":statHp.percent(),"hunger":statHunger.percent(),"thurst":statThurst.percent(),"energy":statEnergy.percent(),"mood":statMood.getValue()};
|
||||
};
|
||||
|
||||
this.nameChange = function () {
|
||||
name = window.prompt("What would you like to name this pet?", name);
|
||||
};
|
||||
|
||||
this.actionAdd = function (action) {
|
||||
if (typeof action != "string") { return false; }
|
||||
if (action == "water") {
|
||||
var neededWater = waterBowl.setBounds()[1]-waterBowl.getValue();
|
||||
var someWater = window.gameDB.player.spendWater(neededWater);
|
||||
if (someWater >= 0) {
|
||||
waterBowl.modValue(neededWater);
|
||||
window.gameDB.message("You fill "+name+"'s water bowl.");
|
||||
window.gameDB.player.giveWater(someWater);
|
||||
} else {
|
||||
window.gameDB.message("You give "+name+" the water you have.");
|
||||
waterBowl.modValue(neededWater+someWater);
|
||||
}
|
||||
}
|
||||
if (action == "feed") {
|
||||
var neededFood = foodBowl.setBounds()[1]-foodBowl.getValue();
|
||||
var someFood = window.gameDB.player.spendFood(neededFood);
|
||||
if (someFood >= 0) {
|
||||
foodBowl.modValue(neededFood);
|
||||
window.gameDB.message("You fill "+name+"'s food bowl.");
|
||||
window.gameDB.player.giveFood(someFood);
|
||||
} else {
|
||||
window.gameDB.message("You give "+name+" the food you have.");
|
||||
foodBowl.modValue(neededFood+someFood);
|
||||
}
|
||||
}
|
||||
if (action == "play") {
|
||||
window.gameDB.message("You play with "+name+" for a little while");
|
||||
"play,".repeat(9).split(",").forEach(function (e) { actionQueue.unshift(e);});
|
||||
}
|
||||
};
|
||||
|
||||
//Init
|
||||
var myTicker = setInterval(tickMe, tickTime);
|
||||
}
|
||||
};
|
||||
|
||||
class player {
|
||||
constructor() {
|
||||
var coins = new petStat(0,0,null);
|
||||
var food = new petStat(0,0,null);
|
||||
var water = new petStat(0,0,null);
|
||||
var playerName = "player_"+(new Date()).valueOf();
|
||||
var guiPlayerID = elementPlace("body", playerName, "player", "div");
|
||||
var guiPlayerFood = elementPlace("#"+playerName, null, "foodSupply", "div");
|
||||
var guiPlayerWater = elementPlace("#"+playerName, null, "waterSupply", "div");
|
||||
var guiPlayerCoins = elementPlace("#"+playerName, null, "coins", "div");
|
||||
|
||||
function guiUpdate () {
|
||||
guiPlayerFood.innerText = "Food:"+Math.round(food.getValue()/10000);
|
||||
guiPlayerWater.innerText = "Water:"+Math.round(water.getValue()/10000);
|
||||
guiPlayerCoins.innerText = "Coins:"+coins.getValue();
|
||||
}
|
||||
|
||||
this.makePurchase = function (value) {
|
||||
var def = coins.modValue(-value);
|
||||
if (def < 0) {
|
||||
coins.modValue((value+def));
|
||||
return false;
|
||||
} else { return true; }
|
||||
};
|
||||
|
||||
this.giveReward = function (value) {
|
||||
coins.modValue(value);
|
||||
};
|
||||
|
||||
this.giveFood = function (value) {
|
||||
food.modValue(value);
|
||||
};
|
||||
|
||||
this.giveWater = function (value) {
|
||||
water.modValue(value);
|
||||
};
|
||||
|
||||
this.spendFood = function (value) {
|
||||
return food.modValue(-value);
|
||||
};
|
||||
|
||||
this.spendWater = function (value) {
|
||||
return water.modValue(-value);
|
||||
};
|
||||
|
||||
this.playerInventory = new market(playerName);
|
||||
|
||||
var myTicker = setInterval(guiUpdate, 250);
|
||||
}
|
||||
};
|
||||
|
||||
class item {
|
||||
constructor(DOMParent, name, value, description, count, countUse, itemFunction) {
|
||||
var myName = name;
|
||||
var myValue = value;
|
||||
var myDesc = description;
|
||||
var myCount = count;
|
||||
var myCountUse = countUse;
|
||||
var myFunction = itemFunction;
|
||||
var itemID = myName+"_"+(new Date).valueOf();
|
||||
var myParent = "body";
|
||||
if (DOMParent != "body") { myParent = "#"+DOMParent; }
|
||||
var guiItemContainerID = elementPlace(myParent,itemID,"itemContainer","div");
|
||||
var guiItemCountID = elementPlace("#"+itemID,null, "itemCount", "div");
|
||||
guiItemCountID.innerText = myCount;
|
||||
var guiItemNameID = elementPlace("#"+itemID,null, "itemName", "div");
|
||||
guiItemNameID.innerText = myName;
|
||||
var guiItemValueID = elementPlace("#"+itemID,null, "itemValue", "div");
|
||||
guiItemValueID.innerText = myValue;
|
||||
var guiItemDescID = elementPlace("#"+itemID,null, "itemDesc", "div");
|
||||
guiItemDescID.innerText = myDesc;
|
||||
guiItemContainerID.onclick = function () {
|
||||
if (window.gameDB.player.makePurchase(value)) {
|
||||
itemFunction();
|
||||
myCount -= myCountUse;
|
||||
if (myCount <= 0) { guiItemContainerID.parentNode.removeChild(guiItemContainerID); }
|
||||
} else { window.gameDB.message("You don't have enough coins for that!", 2); }
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class market {
|
||||
constructor(DOMParent) {
|
||||
var me = this;
|
||||
var myParent = "body";
|
||||
var marketID = "market_"+(new Date).valueOf();
|
||||
if (DOMParent != "body") { myParent = "#"+DOMParent; marketID += "_"+DOMParent; }
|
||||
var guiMarketID = elementPlace(myParent,marketID,"market","div");
|
||||
var inventory = [];
|
||||
|
||||
this.addItem = function (itemObject, name, value, discription, count, countUse, itemFunction) {
|
||||
var itemIndex = inventory.length;
|
||||
if (typeof itemObject == "object") {
|
||||
name = itemObject.name;
|
||||
value = itemObject.value;
|
||||
discription = itemObject.desc;
|
||||
count = itemObject.count;
|
||||
countUse = itemObject.countUse;
|
||||
itemFunction = itemObject.myFunction;
|
||||
}
|
||||
inventory.push(new item(marketID, name, value, discription,count, countUse, function () {
|
||||
var myIndex = itemIndex;
|
||||
inventory.splice(myIndex,1);
|
||||
itemFunction();
|
||||
}));
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class messageCenter {
|
||||
constructor (DOMParent) {
|
||||
var myParent = "body";
|
||||
var logID = "log_"+(new Date).valueOf();
|
||||
if (DOMParent != "body") { myParent = "#"+DOMParent; }
|
||||
var guiLogID = elementPlace(myParent,logID,"log","div");
|
||||
var MaxMessageQueue = 50;
|
||||
var messageQueue = [];
|
||||
|
||||
function cullOldMessages () {
|
||||
var curTime = new Date();
|
||||
messageQueue.forEach( function (message,index,queue) {
|
||||
if ((message.birth.valueOf()+message.life) < curTime.valueOf()) {
|
||||
queue.splice(index,1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function guiUpdate () {
|
||||
guiLogID.innerHTML = "";
|
||||
cullOldMessages();
|
||||
messageQueue.forEach( function (message,index) {
|
||||
if (index < 50) {
|
||||
guiLogID.innerHTML = '<p class="urgency_'+message.urgency+'">'+message.content+"</p>"+guiLogID.innerHTML;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.addMessage = function (message, urgency, life) {
|
||||
var myMessage = "";
|
||||
var myUrgency = 0;
|
||||
var myLife = 10000;
|
||||
if (typeof message == "string") { myMessage = message; }
|
||||
if (typeof urgency == "number") { myUrgency = urgency; }
|
||||
if (typeof life == "number") { myLife = life; }
|
||||
messageQueue.unshift({"birth": new Date(),"content":myMessage,"urgency":myUrgency,"life":myLife});
|
||||
guiUpdate();
|
||||
guiLogID.scrollTop = guiLogID.scrollHeight;
|
||||
}
|
||||
|
||||
var myTicker = setInterval(guiUpdate, 250);
|
||||
}
|
||||
}
|
||||
|
||||
class game {
|
||||
constructor() {
|
||||
window.gameDB = this;
|
||||
window.gameDB.initTime = new Date();
|
||||
window.gameDB.gameID = "game_"+window.gameDB.initTime.valueOf();
|
||||
window.gameDB = {};
|
||||
window.gameDB.player = new player;
|
||||
window.gameDB.player.pets = [];
|
||||
window.gameDB.petpen = elementPlace("body","petPin",null,"div");
|
||||
window.gameDB.infoexch = elementPlace("body","infoex",null,"div");
|
||||
window.gameDB.infoexch.messages = new messageCenter("infoex");
|
||||
window.gameDB.infoexch.market = new market("infoex");
|
||||
window.gameDB.itemDB = [
|
||||
{"name":"Egg","value":300,"desc":"Your first pet egg, take care of it!","count":1,"countUse":1, "myFunction": function () {
|
||||
window.gameDB.player.pets.push(new pet());
|
||||
window.gameDB.message("Great! Now you have your own little pet egg, in time it will hatch and you'll need to make sure its well fed and watered. But to do that you'll need to buy some water so you can put it in their bowl. And don't forget, you can rename your pet at any time by clicking on its avitar.",1,60000);
|
||||
window.gameDB.infoexch.market.addItem(window.gameDB.itemDB[3]);
|
||||
}},
|
||||
{"name":"Egg","value":300,"desc":"Another pet egg","count":1,"countUse":1, "myFunction": function () { window.gameDB.player.pets.push(new pet()); }},
|
||||
{"name":"SEgg","value":3000,"desc":"Another pet egg, it almost looks like a rock.","count":1,"countUse":1, "myFunction": function () { window.gameDB.player.pets.push(new pet({"gender":[1,0],"health":[200,300],"endurance":[200,300],"heartiness":[100,130]})); }},
|
||||
{"name":"Food","value":50,"desc":"Food for your pet, don't forget to put it in their bowl.","count":1,"countUse":1, "myFunction": function () {
|
||||
window.gameDB.player.giveFood(1000000);
|
||||
window.gameDB.message("Good, now don't forget to put it in their bowl by clicking the <span class="+'"food">F</span> button, now lets buy some water so you can water your pet.',1,60000);
|
||||
window.gameDB.infoexch.market.addItem(window.gameDB.itemDB[4]); }},
|
||||
{"name":"Water","value":50,"desc":"Water for your pet, don't forget to put it in their bowl.","count":1,"countUse":1, "myFunction": function () {
|
||||
window.gameDB.player.giveWater(1000000);
|
||||
window.gameDB.message("Alright, now that you have some water, lets fill up your pets water bowl, you can do that by clicking the <span class="+'"water">W</span> button. The next thing you will need is a toy to play with your pet, you should have just enough money for that now.',1,60000);
|
||||
window.gameDB.infoexch.market.addItem(window.gameDB.itemDB[5]);
|
||||
}},
|
||||
{"name":"Toy","value":100,"desc":"A toy to keep your pet happy.","count":1,"countUse":1, "myFunction": function () {
|
||||
window.gameDB.player.playerInventory.addItem(window.gameDB.itemDB[6]);
|
||||
window.gameDB.infoexch.market.addItem(window.gameDB.itemDB[7]);
|
||||
window.gameDB.infoexch.market.addItem(window.gameDB.itemDB[8]);
|
||||
}},
|
||||
{"name":"Toy","value":0,"desc":"A toy to keep your pet happy.","count":1,"countUse":0, "myFunction": function () { window.gameDB.player.pets.forEach(function (thisPet) { thisPet.actionAdd("play"); }); }},
|
||||
{"name":"Food","value":50,"desc":"Food for your pet, don't forget to put it in their bowl.","count":1,"countUse":0, "myFunction": function () { window.gameDB.player.giveFood(1000000); }},
|
||||
{"name":"Water","value":50,"desc":"Water for your pet, don't forget to put it in their bowl.","count":1,"countUse":0, "myFunction": function () { window.gameDB.player.giveWater(1000000); }},
|
||||
{"name":"Aid Kit (5)","value":100,"desc":"Emergency First Aid kit, heals 100% of all pets health.","count":1,"countUse":0, "myFunction": function () { window.gameDB.player.playerInventory.addItem(window.gameDB.itemDB[10]); }},
|
||||
{"name":"Aid Kit (5)","value":100,"desc":"Emergency First Aid kit, heals 100% of all pets health.","count":5,"countUse":1, "myFunction": function () { }}
|
||||
];
|
||||
|
||||
window.gameDB.encounterDB = [
|
||||
{"chance":75, "myFunction": function () {
|
||||
window.gameDB.player.pets.forEach( function (pet) {
|
||||
window.gameDB.player.giveReward(Math.round(((Math.random()*50)+1)*(1+(pet.statGet()["mood"]/100))));
|
||||
});
|
||||
window.gameDB.message("A stranger smiles at your pet, and gives you a few coins.");
|
||||
}},
|
||||
{"chance":15, "myFunction": function () { window.gameDB.infoexch.market.addItem(window.gameDB.itemDB[2]); window.gameDB.message("Huh, whats that on the ground, it looks like another egg, you can pay a hatchery to hatch it for you."); }}
|
||||
];
|
||||
|
||||
window.gameDB.randomEncounter = function () {
|
||||
console.log("Checking Encounter Table");
|
||||
var dice = Math.round(Math.random()*100);
|
||||
console.log("rolled a "+dice);
|
||||
var myEncounters = window.gameDB.encounterDB.filter( function (e) { return e.chance >= dice; });
|
||||
if (myEncounters.length > 0) {
|
||||
console.log("randomly choosing from "+myEncounters.length);
|
||||
myEncounters[Math.floor(Math.random()*myEncounters.length)].myFunction();
|
||||
} else {
|
||||
window.gameDB.message("Something happened somewhere, just not here.");
|
||||
}
|
||||
};
|
||||
|
||||
window.gameDB.save = function () {
|
||||
var saveingString = window.gameDB.ti
|
||||
};
|
||||
|
||||
window.gameDB.load = function () {};
|
||||
|
||||
// init finished
|
||||
|
||||
window.gameDB.message = function (message,urgency,life) {
|
||||
window.gameDB.infoexch.messages.addMessage(message,urgency,life);
|
||||
}
|
||||
window.gameDB.infoexch.market.addItem(window.gameDB.itemDB[0]);
|
||||
var myEncounterTicker = setInterval(window.gameDB.randomEncounter, hours(1/60));
|
||||
window.gameDB.player.giveReward(500);
|
||||
window.gameDB.message("Welcome to Pets: To get started you'll want to buy a new egg from the market",1,60*1000);
|
||||
window.gameDB.message("You have been given 500 coins. Use them well.");
|
||||
}
|
||||
}
|