Skip to content

Commit

Permalink
Merge pull request #3 from jgss-gabriel-sousa/new-version
Browse files Browse the repository at this point in the history
v0.14 (Nakajima version)
  • Loading branch information
jgss-gabriel-sousa authored May 26, 2024
2 parents d2c055e + d13b001 commit 93a16da
Show file tree
Hide file tree
Showing 12 changed files with 305 additions and 235 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ <h1>GP Tycoon</h1>
<button id="start-game" class="main-menu-btn"><span>Novo Jogo</span></button>
<button id="load-game" class="main-menu-btn"><span>Carregar Jogo</span></button>
</div>
<small>Copyright © <a href="https://jgss-gabriel-sousa.github.io/" target="_blank">JGSS</a> - v0.12</small>
<small>Copyright © <a href="https://jgss-gabriel-sousa.github.io/" target="_blank">JGSS</a> - version 0.14 (Nakajima)</small>
</div>

<div id="players-menu"></div>
Expand Down
4 changes: 4 additions & 0 deletions localization/base_PT.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"gender_male_PT": "Homem",
"gender_female_PT": "Mulher"
}
36 changes: 33 additions & 3 deletions scripts/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export let audio = new Audio();
const NUMBER_OF_SONGS = 7;

const stylesNotSelected = [];
let lastPlayedSong = "";
const songs = {
"Soundtrack": [
"Stronger - Savfk"
Expand All @@ -25,15 +26,44 @@ export function SoundStart(){
window.setTimeout(soundtrack, rand(1500,5000));
}

function selectSong(){
const SONGS_PATH = "../audio/songs/";
const SONGS_EXT = ".mp3";
let song_name;

if(stylesNotSelected.length == Object.keys(songs).length)
return; //All music styles were deselected

let themeID;
let theme;
do {
themeID = rand(0, Object.keys(songs).length);
theme = Object.keys(songs)[themeID];

} while (stylesNotSelected.includes(theme));


let songID;
do { //Not repeat song
songID = rand(0, songs[theme].length);
song_name = songs[theme][songID];

} while (songs[theme].length > 1 && song_name == lastPlayedSong);

console.log(SONGS_PATH+song_name+SONGS_EXT)
lastPlayedSong = song_name;
audio = new Audio(SONGS_PATH+song_name+SONGS_EXT);
}

export function soundtrack(){
if(audio.paused){
const SongID = rand(0,NUMBER_OF_SONGS);
//audio = new Audio("../audio/songs/"+SongID+".mp3");

selectSong();

audio.volume = game.settings.volume;

const tryToPlay = setInterval(() => {
console.log(SongID)

audio.play()
.then(() => {
clearInterval(tryToPlay);
Expand Down
Loading

0 comments on commit 93a16da

Please sign in to comment.