Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature fun #2

Open
wants to merge 7 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions public/js/modules/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,26 @@ class Net {
app.nodes.push(this.initial)
this.node = app.getNode(this.initial.id)
}
}

// Sound Class
class Sound {
constructor(src,loop) {
this.sound = document.createElement("audio");
this.sound.src = src;
this.sound.setAttribute("preload", "auto");
this.sound.setAttribute("controls", "none");
this.sound.setAttribute("loop", loop)
this.sound.style.display = "none";
document.body.appendChild(this.sound);
}

play() {
this.sound.play()
}

pause() {
this.sound.pause()
this.sound.currentTime = 0
}
}
16 changes: 14 additions & 2 deletions public/js/modules/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ var pauseInst = new Text('pauseInst',app.width/2 + (secondText/2), app.height -

var state = 'START'

/**
* Add Game Music Level1.wav
* Created by https://juhanijunkala.com/
*/
var music = new Sound('sounds/level1.wav', true)

// Init
app.onInit = function(){

document.addEventListener('keydown', (event) => {
Expand Down Expand Up @@ -54,13 +61,16 @@ app.onInit = function(){
PlayerTwo.moveDown(false)

if(keyName == 'Enter'){
if(state == 'START')
if(state == 'START'){
music.play() // Start Game Music
state = 'GAME'
}
}

if(keyName == ' '){
if(state == 'GAME' || state == 'PAUSE')
if(state == 'GAME' || state == 'PAUSE'){
Copy link
Collaborator

@demiculus demiculus Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a typo and the game breaks
maybe you shouldn't use strings huh?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know how to use enum?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, I haven´t use enum before but I can change it and not use strings

this.pause()
}
}

if(keyName == 'r'){
Expand Down Expand Up @@ -90,11 +100,13 @@ app.onUpdate = function(time){

app.pause = function(){
if(state == 'GAME'){
music.pause() // Pause Game Music
Copy link
Collaborator

@demiculus demiculus Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

music.pause() isn't descriptive enough so you added // Pause Game Music to make sure the code reader understands right? :D

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, yes I define the "music" object and added some comments when I invoke the methods

state = 'PAUSE'
pauseText.setText("Pause")
pauseInst.setText("press 'R' for reset")
}
else{
music.play() // Resume Game Music
state = 'GAME'
pauseText.setText("")
pauseInst.setText("")
Expand Down
Binary file added public/sounds/level1.wav
Binary file not shown.