Final Project Presentation
Over the last couple of days I made significant progress adding features and polishing up my final project. You can try it here and also in an embed at the bottom of this page.
Sound
During previous feedback Shawn pointed out that some unwanted noise from the P5 oscillator was likely due to needing to stop sounds before removing the variables controlling them.
// stop tone from planet i planets[i].osc.stop(2);
Using stop() was exactly what was needed as it allows a delay to the stop by a set number of seconds, permitting the sound to finish.
Visual Polish
Building out the environment further I added additional planets to the solar system that drift by; giving a better sense of scale and depth. Also the user’s cursor is replaced by a glowing light.
Game Rooms
The biggest update was made on the server side implementing rooms in Socket.io.
During testing in class I found the experience of several users in one space to be overwhelming, defeating the meditative intent of the app. Using rooms on the server side I organize users into pairs, allowing for a much calmer experience.
var users = []; var rooms = []; io.sockets.on('connection', // We are given a websocket object in our function function (socket) { console.log("We have a new client: " + socket.id); users.push(socket); // Room setup let roomId = 0; let roomNumber = 0; if(rooms.length > 0){ // Check for available rooms for(let i = 0; i < rooms.length; i++){ // Check for open room if(rooms[i][0] == 0){ // You are now the controller in this room roomId = socket.id; rooms[i][0] = socket.id; roomNumber = i + 1; } else if(rooms[i].length == 1){ // You are now the guest in this room roomId = rooms[i][0]; rooms[i][1] = socket.id; roomNumber = i + 1; } } } // If still no roomNumber if(roomNumber == 0){ // No available rooms... if(users.length%2 == 1){ // You are the room controller roomId = socket.id; let tempId = []; tempId[0] = roomId; rooms.push(tempId); roomNumber = rooms.length; } else if(users.length%2 == 0) { // You are a guest roomId = rooms[rooms.length - 1][0]; roomNumber = rooms.length; rooms[roomNumber-1][1] = socket.id; } } socket.join(roomNumber); console.log("Joining room number: " + roomNumber); console.log("Room ID: " + roomId); );