• Content Count

  • Joined

  • Last visited

About mla

  • Rank
    Advanced Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Is there also a way to factor in the timing it takes to make updates on the server side? For example, 3 players click on one player, but only one ball can be sent to that one player. The sending player will send that he clicked first and update the receiving player to state he is in a move. This would mean the other two players who clicked at the same time, would then receive a message stating that that player is in play.
  2. @b10b to pass the ball from one player to another, you click on the player. The structure is set up that the client will listen for a mousedown event. When a mousedown occurs, it will capture the coordinates to know where the receiving player is standing to pass the Ball over. Then the ball will be removed from the sending players hands and will animate over to the receiving player. //Listen for player passing a ball BALLS.onmousedown = function(e) { var mouseX = e.pageX - this.offsetLeft; //get clicked x coordinate var mouseY = e.pageY - this.offsetTop; //get clicked y coordinate socket.emit('player-click', {remotePlayers: remotePlayers, mouseX:mouseX, mouseY:mouseY, remoteRole:remoteRole, myID:}, function(responseData){ console.log(responseData); playerClicked(mouseX, mouseY, timesup, responseData.myID); }); } //The player would like to pass a ball function playerClicked(mouseX, mouseY, timesup, myID) { senderPlayer = myID; var mouseX = mouseX ; var mouseY = mouseY; getPlayerDetails(senderPlayer); myChain = senderChain; passBall(); animateBall(); } //Ball must be removed from the sender and passed to the receiver function passBall(){ socket.emit('update-ballmove', {senderBall:senderBall, senderPlayer:senderPlayer}, function(responseData){ console.log('Callback called with data:', responseData); }); } //Animate the Ball movement function animateBall() { var getXCords = 'getp'+receiverPlayerNumber+'x'; var getYCords = 'getp'+receiverPlayerNumber+'y'; for (var i = 0; i < remotePlayers.length; i++) { console.log("id: " + senderPlayer); if(remotePlayers[i].id == senderPlayer) { Xcords = remotePlayers[i][getXCords]; Ycords = remotePlayers[i][getYCords]; } } var lastX = Xcords[4]; var lastY = Ycords[4]; socket.emit('show-animation', {Xcords:Xcords, Ycords:Ycords, senderChainURL:senderChainURL, receiverID:receiverID}, function(animateData){ console.log(animateData); }); } Meanwhile on the Server side, we want to broadcast to all players that a pass has been made. I remove the ball by slicing the ball from the senderPlayer's array. I then animate the ball movement and save the ball to the receivingPlayer's array. //Remove Ball from senderPlayer socket.on ('update-ballmove', function (data, callback){ var players = data.remotePlayers; PLAYER_LIST = data.cPlayers; var senderPlayer = data.senderPlayer; var senderBall = data.senderBall; newBall = senderBall.slice(0, -1); for (var c = 0; c < players.length; c++){ if(senderPlayer == players[c].id){ players[c].getBall = newBall; } } for (var i in PLAYER_LIST) { if (PLAYER_LIST[i].id == senderPlayer){ PLAYER_LIST[i].getBall = newBall; } }'update-Ball', {totPlayers, players});'load-player', {Players:PLAYER_LIST}); var responseData; responseData = 'done'; callback(responseData); }); //Broadcast to all players that a player wants to pass a ball socket.on('player-click', function (data, callback) { var myID = data.myID; for (var i in PLAYER_LIST) { if (PLAYER_LIST[i].id == myID){ myroom = PLAYER_LIST[i].roomID; gameID = PLAYER_LIST[i].gameID; } } var responseData = {myID:myID}; callback(responseData); }); //Update animation of Ball movements socket.on ('show-animation', function (data, animCallback){'animateBalls', data); var animateData = 'drawn'; animCallback(animateData); }); While this works great if one player passes to another while all other players wait, it won't if players are passing simultaneously. What does work is if two players try to pass the same ball to the one same player, the fastest player will be able to pass the ball, while the slower player will receive a message stating that that player is currently in the middle of a play.
  3. Hi, I have a multiplayer game that works, except when two players click at the exact same time. For example 6 players are in a game. The game consists of balls being sent from one player to another. The ball is animated from sender player to receiving player. Which means when the sender sends the ball, it is no longer in his/her hands. The ball is now is the hands of the receiving player. This works perfectly except if a move is made by another sending player at the exact same time. For example, 6 players are in a game. Player1 passes Player2 the ball at the same time, Player3 passes Player4 the ball. Player1 and Player2 will work correctly, however in the case of the other two players, what happens is Player3 sends the ball to Player4 who receives it but Player3 is still holding the ball even after he/she passed the ball over to Player4. Does this issue mean I should be using a Callback? Thanks, MLA
  4. Hi, I am looking to hire a html5 game developer for a freelance project who has experience with, express and node. It would be to take an already developed game to the next level with animations and to adjust any current glitches. if interested please connect with me and provide me with your price rate and portfolio. Thank you!
  5. Hi, I'm wondering how to avoid simultaneous mousedown events. I have a canvas drawn on screen. When a player clicks events take place based on where the player clicked on the screen. If two players click the canvas at the exact same time, they should both be alerted with a message that no simultaneous moves are allowed. I used an array to capture the move, however it seems to only register the move after the check and not before. Is there a simple way to capture which clients clicked at the same time? //Listen for player click event chainlinks.onmousedown = function(event) { var totCT; //update current player turn on client for (var i = 0; i < remotePlayers.length; i++) { if (remotePlayers[i].id == { remotePlayers[i].currentTurn = true; } } //update current player turn on server for (var i in cPlayers) { if (cPlayers[i].id =={ cPlayers[i].currentTurn = true; } } socket.emit('update-currentTurn', {remotePlayers: remotePlayers, cPlayers:cPlayers}); if (totCT > 1) { //Simultaneous move happened - show invalid message } else { //All good to go ahead with the click event } } Thanks!
  6. FIXED!!! I got it working with IIS 8, Windows 2012 server. The issue was my web.config file needed the proper rewrites. For anyone facing this issue, ensure you update the web.config correctly. It's all working now.
  7. Decided to try out the pm2. Seems the issue is that app.js is not found. A nice 404 Error!
  8. Thanks. I managed to get the iis and nodejs working and a simple test page launches great. I'm more faced with a content-security-policy issue and adjustments to my headers don't seem to make a difference. I may give your pm2 a try if I can't get past this error.
  9. Hi, I have a nodjs application that is currently saved in Windows 2012 R2 server using IISnode with IIS 8.5. I am getting a 404 File or directory not found error, however nothing is being recorded in the error logs. When I run this locally I have no issues and the game runs well. Thinking it could be a permissions issue, I decided to provide temporary read/write access, however that didn't seem to make a difference. I also confirmed that the links are all correct in terms of where files are sitting. Here is my server side code: var PORT = process.env.PORT || 8080; var express = require('express'); var app = express(); var http = require('http'); var path = require('path'); var util = require("util"); var server = require('http').createServer(app); var compression = require('compression'); //Get required classes xyLocation = require("./xyLocation").xyLocation; app.use(compression()); //Compress all routes app.use('/client', express.static(__dirname + '/client')); app.use('/js', express.static(__dirname + '/js')); app.use('/css', express.static(__dirname + '/css')); app.use('/sounds', express.static(__dirname + '/sounds')); app.use('/images', express.static(__dirname + '/images')); // Routing app.get('/', function(request, response) { response.sendFile(path.join(__dirname, 'index.html')); }); server.listen(PORT); console.log('Starting server on port '+ PORT); var io = require('')(server,{}); io.sockets.on('connection', function(socket) { ... Thanks MLA
  10. mla

    Images disappearing

    Worked like a charm!! Pre-loaded images, created gameloop on client and no flickering. Gameloop updates and draws images perfectly! Great help!! Thanks!!
  11. mla

    Images disappearing

    Each person who joins the game, is represented by a specific avatar that is placed on the screen at specific x, y coordinates. I am attaching the screen shot that will hopefully provide a better explanation. The game works, just that the images are flickering.
  12. mla

    Images disappearing

    I have re-coded the game and now the players connect and disconnect correctly. I save the disconnected player details in an array before the disconnect to allow him/her to comeback. The issue I seem to now face, is why my avatars are flickering on screen. They work great, but the image flickers. I have an interval to loop through the players{} and draw them out. My assumption is that the requestAnimFrame function is needed here. In Server: //show all logged players setInterval(function(){ io.sockets.emit('state', PLAYER_LIST); } },1000/25); In Client: socket.on('state', function(players){ context.clearRect(0, 0, canvas.width, canvas.height); context.font = '12pt Arial'; context.fillStyle = 'white'; context.textAlign="center"; for (var id in players) { var player = players[id]; var rectHeight = 50; var rectWidth = 100; var rectX = player.getX; var rectY = player.getY+200; context.fillText(, rectX+(rectWidth/2),rectY+(rectHeight/2)); var img = new Image(); img.onload = function () { context.drawImage(img, x, y, 85, 201); } img.src = imgFile; } });
  13. Thank you chriswa! After your first reply and then hearing from mattstyles, I decided to go forward with localStorage and not with the database. Since I'm utilizing local storage currently, I am re-coding the game entry part to recall the player id if it exists and show their last known information if the game is still in play. Since I already am using random ids, there is no worry about conflicting player logins or hijacking spots. I have a better understanding now of when to use a DB. Thanks All!!
  14. The minimum is 6 simultaneous players to a maximum of 12 simultaneous players. The game is pretty simple, and briefly explained below. Host logs in and received a gameID Between 6 - 12 players access the game using the gameID Each player is represented by a static non-moving image. When host starts the game, each player has 4 colored balls and a card showing the sequence of colored balls to complete. Each player passes balls around until the player completes their card showing the colored sequence of balls. This means that each player has 4 colored balls that are being tracked, and between 1-4 of each ball that matches their card. (When they get a ball matching their card, they will add it on the actual card. So I am saving, for each player (min 6, max 12), 4 balls / player, plus the 4 balls appearing on each of their cards. Totaling 8 balls / player. Game ends when each player completes their card or time runs out. What I am storing is the player id, name, 4 balls on hand, 4 balls on card, player status, x coordinate, y coordinate and static image. (The x and y, are where each player should appear on screen. They cannot appear randomly on the screen.) The only movement happening in this game is the balls being passed simultaneously around. (Player 1 can pass ball to player 2, while player 3 passes to player 4 at the same time, etc.) My worry is not if the server crashes, but if one player loses internet connect during the game, example power outage at his home, then he will be booted out of the game. My aim is to allow that player to be able to come back, provided game is still in play, and continue from where he left off.
  15. Hi, I'm creating a node js game, using javascript and socket io. I originally was not going to add a mongo DB, but now I'm thinking I should for anyone who may accidentally be disconnected from the game. What would the best game option be? To use a database or not, and the reasons behind it. Many thanks, MLA