Skip to content

Commit

Permalink
destructured code and cleaned functions, which now import from sepera…
Browse files Browse the repository at this point in the history
…te module
  • Loading branch information
Will Irving authored and Will Irving committed May 24, 2021
1 parent 58dba53 commit 8dab8fa
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 513 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ increase density of objects depending on screen size
density > over time

feedback ++ when you hit objects

++ create imports/exports for functions and write a test for some of them
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [["@babel/preset-env", { targets: { node: "current" } }]],
};
52 changes: 52 additions & 0 deletions functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
export const shuffleArr = (array) => {
const newArray = [...array];
var currentIndex = newArray.length,
temporaryValue,
randomIndex;

// While there remain elements to shuffleArr...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;

// And swap it with the current element.
temporaryValue = newArray[currentIndex];
newArray[currentIndex] = newArray[randomIndex];
newArray[randomIndex] = temporaryValue;
}

return newArray;
};

export const getRandom = (upperLimit) => {
const arrayNum = [...Array(upperLimit)].map((_, i) => i);

const ranNums = shuffleArr(arrayNum);

return ranNums;
};

export const loadSounds = (length) => {
const soundArray = new Array(length);

for (let i = 0; i < soundArray.length; i++) {
const relPath = "./sounds/";
const fileType = ".mp3";
const srcLink = `${relPath}${i}${fileType}`;
soundArray[i] = new Howl({
src: [`${srcLink}`],
});
}

return soundArray;
};

export const makeImg = (name) => {
const img = new Image();
const path = "./images/";
const fileType = ".png";
const imgStr = `${path}${name}${fileType}`;
img.src = imgStr;
return img;
};
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
<canvas id="c"></canvas>
</div>
<script src="./node_modules/howler/dist/howler.js"></script>
<script src="./main.js"></script>
<script src="./main.js" type="module"></script>
</body>
</html>
Loading

0 comments on commit 8dab8fa

Please sign in to comment.