Skip to content

Commit

Permalink
split main.js into 3 files
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerin3 committed Jun 13, 2023
1 parent 449f06e commit 51a58e7
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 143 deletions.
4 changes: 2 additions & 2 deletions css/main.css

Large diffs are not rendered by default.

24 changes: 18 additions & 6 deletions css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
font-family: "PixelSGA";
src: local("SGA Pixies"), local("SgaPixies"), url("../fonts/SgaPixies.ttf") format("truetype");
}
@font-face {
font-family: "Galactico";
src: local("Galactico Basic"), local("GalacticoBasic"), url("../fonts/GalacticoBasic.otf") format("opentype");
}
@import "../scss/bootstrap.scss";

html {
user-select: none;
background: #7109aa;
background: linear-gradient(180deg, rgba(158,0,89,1) 0%, rgba(43,14,136,1) 100%);
background-color: rgba(114, 9, 170, 0.5);
background-image: url("../img/Aethereal_Planes_-_Cosmic_Rift_2500x2500.jpg");
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
//background: linear-gradient(180deg, rgba(158,0,89,1) 0%, rgba(43,14,136,1) 100%);
min-height: 100%;
> body {
font-family: 'Pixeloid';
Expand Down Expand Up @@ -95,4 +95,16 @@ html {
}
.glitch{
font-family: 'PixelSGA';
}
#canvas {
margin: 0;
padding: 0;
height:100%;
width:100%;
position:fixed;
display:block;
z-index: -50;
}
#canopy{
height: 5px;
}
Binary file added img/Aethereal_Planes_-_Cosmic_Rift_2500x2500.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/goddess.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 74 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
<title>Nameless CYOA</title>
<link href="css/main.css" rel="stylesheet">
</head>
<body class="py-2"><audio id="bgm" preload="auto" loop autoplay>
<body><audio id="bgm" preload="auto" loop autoplay>
<source src="audio/bgm1.ogg" type="audio/ogg"> BGM
</audio>
<div class="category category-bg container-xl mt-2 py-2 shadow-lg rounded" id="welcome">
<div class="m-0 p-0" id="canopy"><canvas id="canvas"></canvas></div>
<div class="category category-bg container-xl mt-2 pt-2 pe-0 shadow-lg rounded" id="welcome">
<h1 class="category-title text-center">Welcome Mortal</h2>
<div class="text-white container-xl rounded p-2">
<div class="text-white container-xl rounded pt-2 pb-0 pe-0">
<div class="row">
<div class="col overflow-hidden">
<div class="intro p-2 text-center fs-5 rounded bg-gradient"> Welcome, mortal, I am <span class='glitch'>Luxuria</span>, Goddess of Life</div>
<div class="grid rounded p-2 text-center">
<div class="btn-group" role="group" aria-label="Controls"><button type="button" onclick="previous()" id="previous" class="btn btn-lg btn-primary" disabled>Backtrack</button><button type="button" onclick="next()" id="next" class="btn btn-lg btn-primary">Proceed</button></div><button type="button" onclick="accept()" id="accept" class="mx-1 btn btn-primary btn-lg d-none">Accept the offer!</button>
</div>
</div>
<div class="col-5 text-end overflow-hidden"><img src="img/succ-vamp2 purpleish.webp" class="w-100" alt="White Goddess"></div>
<div class="col-5 text-end overflow-hidden mb-0 pb-0"><img src="img/goddess.png" class="w-100 rounded mb-0 pb-0" alt="White Goddess"></div>
</div>
</div>
</div>
Expand Down Expand Up @@ -160,7 +161,7 @@ <h4 class="category-title text-center">-20 Karma</h4>
</div>
</div>
</div>
<div class="category container-xl text-center mt-2 px-0 py-2 rounded d-none after-karma" data-reveals="arborea">
<div class="category container-xl text-center mt-2 px-0 py-2 rounded d-none after-karma" data-reveals="arborea" data-limit="0">
<div class= "category-header category-bg rounded-top mb-0 py-1 px-4">
<h1 class="category-title pt-2 px-5">Arborea Modifiers</h2>
<span class="text-white fs-5">Ah, I see you're drawn to the enchanting realm of Arborea. Allow me to present you with six distinct variations of this world, each offering its own unique flavor and opportunities.</span>
Expand Down Expand Up @@ -224,7 +225,7 @@ <h4 class="category-title text-center">0 Karma</h4>
</div>
</div>
</div>
<div class="category container-xl text-center mt-2 px-0 py-2 rounded d-none after-karma" data-reveals="earth">
<div class="category container-xl text-center mt-2 px-0 py-2 rounded d-none after-karma" data-reveals="earth" data-limit="0">
<div class= "category-header category-bg rounded-top mb-0 py-1 px-4">
<h1 class="category-title pt-2 px-5">Earth Modifiers</h2>
<span class="text-white fs-5">Before we proceed, allow me to present six alternative versions of this world. Each one carries its own unique characteristics and challenges. You may consider these options, but rest assured that you are under no obligation to choose any of them.</span>
Expand Down Expand Up @@ -288,12 +289,79 @@ <h4 class="category-title text-center">0 Karma</h4>
</div>
</div>
</div>
<div class="category container-xl text-center mt-2 px-0 py-2 rounded d-none after-karma" data-reveals="future" data-limit="0">
<div class= "category-header category-bg rounded-top mb-0 py-1 px-4">
<h1 class="category-title pt-2 px-5">Different Future</h2>
<span class="text-white fs-5">Ah, a daring choice! You've chosen a world where humanity has ventured beyond the confines of our home planet, unlocking the mysteries of the cosmos. But, dear soul, even within this realm of advanced technology and interstellar exploration, variations exist. Allow me to present six alternative versions of Futuristic Earth for your consideration.</span>
</div>
<div class="container-xl category-bg shadow-lg rounded p-4">
<div class="row row-cols-2 row-cols-lg-3 justify-content-center g-2">
<div class="col">
<div class="card choice" id="united" data-karma="0" data-requires="future">
<div class="card-header card-img-overlay">
<h2 class="category-title text-center">United</h2>
<h4 class="category-title text-center">0 Karma</h4>
</div><img src="https://placehold.co/300x400" class="card-img" alt="...">
<div class="card-body text-white p-2 text-center fs-6 bg-gradient"><span>In this version of the future, humanity has overcome its divisions, forming a unified government that fosters cooperation among the stars. The United Earth allows for peace and progress, but navigating its complex political landscape can prove challenging. Will you become a leader, guiding humanity to greater heights, or will the machinations of others thwart your ambitions?</span></div>
</div>
</div>
<div class="col">
<div class="card choice" id="empires" data-karma="0" data-requires="future">
<div class="card-header card-img-overlay">
<h2 class="category-title text-center">Empires</h2>
<h4 class="category-title text-center">0 Karma</h4>
</div><img src="https://placehold.co/300x400" class="card-img" alt="...">
<div class="card-body text-white p-2 text-center fs-6 bg-gradient"><span>Here, humanity has fractured into numerous interstellar empires, each vying for power and influence in the cosmos. Skirmishes and alliances are commonplace, as factions struggle for dominance. Can you rise to prominence, leading your empire to victory, or will you fall prey to the ever-shifting tides of conflict?</span></div>
</div>
</div>
<div class="col">
<div class="card choice" id="future-utopia" data-karma="0" data-requires="future">
<div class="card-header card-img-overlay">
<h2 class="category-title text-center">Future Utopie</h2>
<h4 class="category-title text-center">0 Karma</h4>
</div><img src="https://placehold.co/300x400" class="card-img" alt="...">
<div class="card-body text-white p-2 text-center fs-6 bg-gradient"><span>In this iteration, advanced technology has eliminated scarcity, allowing for a world where every need is met. However, with such abundance comes complacency and a search for deeper meaning. Will you find purpose in a world where traditional notions of success and competition have faded, or will you be adrift in a sea of plenty?</span></div>
</div>
</div>
<div class="col">
<div class="card choice" id="integration" data-karma="0" data-requires="future">
<div class="card-header card-img-overlay">
<h2 class="category-title text-center">Integration</h2>
<h4 class="category-title text-center">0 Karma</h4>
</div><img src="https://placehold.co/300x400" class="card-img" alt="...">
<div class="card-body text-white p-2 text-center fs-6 bg-gradient"><span>Imagine a world where the line between human and machine has blurred, and cybernetic enhancements are the norm. This realm offers immense power through technology, but also raises questions of identity and humanity. Will you embrace the fusion of flesh and machine, or will you struggle to maintain your sense of self amidst the convergence?</span></div>
</div>
</div>
<div class="col">
<div class="card choice" id="diplomatics" data-karma="0" data-requires="future">
<div class="card-header card-img-overlay">
<h2 class="category-title text-center">Diplomatics</h2>
<h4 class="category-title text-center">0 Karma</h4>
</div><img src="https://placehold.co/300x400" class="card-img" alt="...">
<div class="card-body text-white p-2 text-center fs-6 bg-gradient"><span>"In this future, humanity has forged alliances and rivalries with various alien races, leading to a complex tapestry of interstellar relations. Diplomacy, trade, and conflict intertwine, and your actions could have far-reaching consequences. Can you navigate the delicate balance of power and cement humanity's place in the galactic community?</span></div>
</div>
</div>
<div class="col">
<div class="card choice" id="uncharted" data-karma="0" data-requires="future">
<div class="card-header card-img-overlay">
<h2 class="category-title text-center">Uncharted</h2>
<h4 class="category-title text-center">0 Karma</h4>
</div><img src="https://placehold.co/300x400" class="card-img" alt="...">
<div class="card-body text-white p-2 text-center fs-6 bg-gradient"><span>Finally, we have a world where the vastness of space remains largely unexplored, with countless mysteries and untapped potential. As a pioneer on the fringes of known space, you'll encounter new civilizations, ancient relics, and untold dangers. Will you become a legend, unearthing the secrets of the cosmos, or will the void consume you?</span></div>
</div>
</div>
</div>
</div>
</div>
<div class="footer mx-5 g-2 row fixed-bottom justify-content-center" id="pointBar">
<div class="col-2 text-center text-white fs-5 d-none" data-reveals="changed-world, high-profile, impactful, average, uneventful"><span id="karma">Karma: 0</span></div>
<div class="col-2 text-center text-white fs-5"><label for="customRange1" class="form-label">BGM Volume</label><input type="range" class="form-range" id="customRange1" value="100" oninput="changeVolume(document.getElementById('bgm'), this.value)"></div>
</div>
<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/anime.min.js"></script>
<script src="js/main.js"></script>
<script src="js/matrix.js"></script>
<script src="js/scramble.js"></script>
</body>
</body>
</html>
132 changes: 3 additions & 129 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,134 +57,6 @@ const choices = document.getElementsByClassName("choice");
for (let choice of choices) {
choice.addEventListener("click", () => {setChoice(choice)}, false);
}
// Intro
class TextScramble {
constructor(el) {
this.el = el
this.last = 0;
this.update = this.update.bind(this)
}
setText(newText) {
const oldText = this.el.innerText
const length = Math.max(oldText.length, newText.length)
const promise = new Promise((resolve) => this.resolve = resolve)
this.queue = []
for (let i = 0; i < length; i++) {
const from = oldText[i] || ''
const to = newText[i] || ''
const start = Math.floor(Math.random() * 40)
const end = start + Math.floor(Math.random() * 40)
this.queue.push({
from,
to,
start,
end
})
}
cancelAnimationFrame(this.frameRequest)
this.frame = 0
this.update()
return promise
}
letterScramble(iterations) {
if (iterations >= 0) {
requestAnimationFrame(() => this.letterScramble(iterations));
}
}
update() {
let output = ''
let complete = 0
for (let i = 0, n = this.queue.length; i < n; i++) {
let {
from,
to,
start,
end,
char
} = this.queue[i]
if (this.frame >= end) {
complete++
output += to
} else if (this.frame >= start) {
if (!char || Math.random() < 0.28) {
char = this.randomChar()
this.queue[i].char = char
}
output += `<span class="glitch">${char}</span>`
} else {
output += from
}
}
this.el.innerHTML = output
if (complete === this.queue.length) {
this.resolve()
} else {
this.frameRequest = requestAnimationFrame(this.update)
this.frame++
}
}
randomChar() {
return String.fromCharCode(0x0041 + Math.random() * (0x005A - 0x0041 + 1));
}
}

// ——————————————————————————————————————————————————
// 1st scramble (and probably only one)
// ——————————————————————————————————————————————————
const luxuria = "<span class='glitch'>Luxuria</span>"
const phrases = [
`Welcome, mortal, I am ${luxuria}, Goddess of Life`,
`As you may have surmised, your mortal coil has been severed, and you now stand at the threshold between life and the great beyond. I have taken an interest in your soul and have decided to present you with a choice.`,
`You may choose to reincarnate into a new existence, or I can leave you to drift aimlessly through the void for all eternity. The choice is yours.`,
`For those who choose to reincarnate, I offer an array of worlds and circumstances. However, there is a balance that must be maintained. You see, I have devised a system I call 'Karma' to ensure that equilibrium.`,
`Each 'positive' aspect you choose for your new life must be offset by a 'negative' one. You may be born into wealth and power, but you must also bear the burden of a tragic curse. Or perhaps you desire great intelligence, but in exchange, you must endure a lifetime of crippling loneliness. In the end, your Karma must balance at zero or above, unless you wish to a risk life full of misfortunes.`
]

const el = document.querySelector('.intro');
const fx = new TextScramble(el);
document.getElementById("next")
document.getElementById("previous")

let counter = 0;
const next = () => {
playSE('audio/click1.ogg');
counter++;
fx.setText(phrases[counter]);
if (counter == 1) document.getElementById("previous").removeAttribute("disabled");
if (counter + 1 == phrases.length) {
document.getElementById("next").setAttribute("disabled", "");
document.getElementById("accept").classList.remove("d-none");
}
}
const previous = () => {
playSE('audio/click1.ogg');
if (counter == phrases.length - 1) {
document.getElementById("next").removeAttribute("disabled");
document.getElementById("accept").classList.add("d-none");
}
counter--
fx.setText(phrases[counter]);
if (counter == 0) document.getElementById("previous").setAttribute("disabled", "");
}

const accept = () => {
playSE('audio/click1.ogg');
changeAudio(document.getElementById("bgm"), 'audio/bgm2.ogg', document.getElementById('customRange1').value);
anime({
targets: '#welcome',
opacity: 0,
easing: 'easeInOutSine',
complete: () => {
document.getElementById("welcome").classList.add("d-none")
document.getElementById("unwelcome").classList.remove("d-none");
anime({
targets: '#unwelcome',
opacity: 1,
easing: 'easeInOutSine'
});
}
});
}

//Karma System

Expand Down Expand Up @@ -312,11 +184,13 @@ const conreq = (element) => {
//choice handler
const setChoice = (element) => {
let grandParent = element.parentElement.parentElement;
let container = grandParent.parentElement.parentElement;
let siblings = grandParent.children;
let count = 0;
let stop = false;
let value = 0;
const limit = element.dataset.limit ? parseInt(element.dataset.limit) : 1;
const limit = container.dataset.limit ? parseInt(container.dataset.limit) : 1;
if (limit != 0)
for (let sibling of siblings) {
if (sibling.firstElementChild.classList.contains("active-choice")) count++;
if (count == limit) {
Expand Down
49 changes: 49 additions & 0 deletions js/matrix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Get the canvas node and the drawing context
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');

// set the width and height of the canvas
const w = canvas.width = document.body.offsetWidth;
const h = canvas.height = document.body.offsetHeight;

// draw a black rectangle of width and height same as that of the canvas
ctx.fillStyle = '#0000';
ctx.fillRect(0, 0, w, h);

const cols = Math.floor(w / 10) + 1;
const ypos = Array(cols).fill(0);

function matrix () {
// Draw a semitransparent black rectangle on top of previous drawing
ctx.fillStyle = '#0001';
ctx.globalCompositeOperation = 'destination-out';
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = '#0005';
ctx.globalCompositeOperation = 'xor';
ctx.fillRect(0, 0, w, h);

// Set color to green and font to 15pt pixelSGA in the drawing context
ctx.fillStyle = '#8c5dca';
ctx.font = '10px PixelSGA';

// for each column put a random character at the end
ypos.forEach((y, ind) => {
// generate a random character
const text = String.fromCharCode(0x0041 + Math.random() * (0x005A - 0x0041 + 1));

// x coordinate of the column, y coordinate is already given
const x = ind * 10;
// render the character at (x, y)
ctx.globalCompositeOperation = 'source-over';
ctx.fillText(text, x, y);


// randomly reset the end of the column if it's at least 100px high
if (y > 300 + Math.random() * 10000) ypos[ind] = 0;
// otherwise just move the y coordinate for the column 20px down,
else ypos[ind] = y + 10;
});
}

// render the animation at 20 FPS.
setInterval(matrix, 50);
Loading

0 comments on commit 51a58e7

Please sign in to comment.