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

Make soundtrack state configurable, closes #5 #6

Merged
merged 2 commits into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
Binary file added assets/images/keyboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 53 additions & 6 deletions src/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,68 @@
* DEFINITIONS
*/

// sound controller container
let soundOn = false;

// perlin noise terrain container
let terrain;

// soundtrack p5.SoundFile container
let soundtrack;

/**
* I draw this sketch sound indicator.
*
* Returns:
* undefined.
*/
function drawSoundIndicator()
{
// push transformation matrix
push();

// translate to bottom right corner
translate((WIDTH / 2) - 50, (HEIGHT / 2) - 50);

// set indicator transparency
soundOn ? tint(255, 100) : tint(255, 255);

// draw image
image(keyboard, 0, 0, 50, 50);

// pop transformation matrix
pop();
}

/**
* p5.js preload callback.
*
* Returns:
* undefined;
*/
function preload() {
// load soundtrack song
soundtrack = loadSound('assets/audio/da_beat-nr1.mp3');
function preload()
{
// load soundtrack song
soundtrack = loadSound('assets/audio/da_beat-nr1.mp3');

// load keyboard on image
keyboard = loadImage('assets/images/keyboard.png');
}

/**
* p5.js mouse clicked callback.
*
* Returns:
* undefined.
*/
function mouseClicked()
{
// soundtrack icon was clicked: update soundtrack state
if(mouseX > WIDTH - 50 && mouseX < WIDTH && mouseY > HEIGHT - 50 && mouseY < HEIGHT)
{
soundOn = !soundOn;
soundOn ? soundtrack.loop() : soundtrack.stop();
}
}

/**
Expand All @@ -33,9 +80,6 @@ function setup()
// create canvas and set renderer as WEBGL
createCanvas(WIDTH, HEIGHT, WEBGL);

// play soundtrack in a loop
soundtrack.loop();

// setup terrain
terrain = new Terrain(WIDTH + WIDTH_OFFSET, HEIGHT + HEIGHT, RESOLUTION);
terrain.setup();
Expand All @@ -57,4 +101,7 @@ function draw()

// draw terrain
terrain.render();

// draw soundtrack indicator
drawSoundIndicator();
}