Skip to content
Permalink
Browse files

New Movement

Keep moving until stop is emit’d
Should fix issue of sending the same packet over and over!
  • Loading branch information...
LexTheGreat committed Mar 10, 2015
1 parent efccb35 commit 063c8d98785c51ee216cd50f63182ec01d6cb10c
Showing with 93 additions and 24 deletions.
  1. +13 −3 app.js
  2. +5 −0 nodemmo/objects/player.js
  3. +13 −17 public/game/game.js
  4. +6 −3 public/game/network.js
  5. +1 −1 public/game/typewrite.js
  6. +55 −0 server.js
16 app.js
@@ -72,20 +72,29 @@ Global.Server.sockets.on('connection', function(socket) {
GameServer.Network.onLogin(socket, data.Username, data.Password);
}
});
socket.on('onMovement', function(data) {
socket.on('onStartMovement', function(data) {
if(typeof data != 'number') {
socket.emit('popup', "Incorect Data. Kicked! (Stop Trying to Cheat!)");
NConsole.writeLine("[" + socket.id + ":AntiPacket]: Socket sent incorect Data! (" + data + ")");
GameServer.Network.kickPlayer(socket);
return;
}
if(data > 3 && data < -1) {
if(data > 3 && data < 0) {
socket.emit('popup', "Incorect Data. Kicked! (Stop Trying to Cheat!)");
NConsole.writeLine("[" + socket.id + ":AntiPacket]: Socket sent incorect Data! (" + data + ")");
GameServer.Network.kickPlayer(socket);
return;
}
GameServer.Network.onMovement(socket, data);
GameServer.Network.onStartMovement(socket, data);
});
socket.on('onStopMovement', function(data) {
if(typeof data != "boolean") {
socket.emit("onNotice", "Incorect Data. Kicked (Stop Trying to Cheat!)");
NConsole.writeLine("[" + socket.id + ":AntiPacket]: Socket sent incorect Data! (" + data + ")");
GameServer.Network.kickPlayer(socket);
return;
}
GameServer.Network.onStopMovement(socket, data);
});
socket.on('onMessage', function(data) {
if(typeof data != 'string') {
@@ -116,6 +125,7 @@ ServerLoop = function() {
if(SocketID != 'undefined') {
var Socket = ClientSocket[SocketID];
if(Socket != 'undefined') {
GameServer.loop.doMovement(Socket);
GameServer.pFunc.sendPlayers(Socket);
}
}
@@ -8,6 +8,11 @@ var Player = function() {
this.Position = { x: 100, y: 100, dir: 3, ani: 0 };
this.isLoged = false; // Has loged in

this.end = false;
this.movY = 0;
this.movX = 0;
this.movDir = -1;

// Animation Variables
this.nextAniT = 5;
this.AniT = 0;
@@ -127,22 +127,13 @@ window.GameEngine = function() {

this.GameLoop = {
parent: this,
didsendReset: false,
shouldSendStop: false,
update: function() {
var self = this;

setTimeout(function() {
requestAnimationFrame(function() {self.update()})


if(isMoving) {
Network.sendMovement(Dir);
this.didsendReset = false;
} else if(!this.didsendReset) {
Network.sendReset();
this.didsendReset = true
}

self.parent.Render.draw();
}, 1000/60);
//setInterval(function() {
@@ -209,21 +200,24 @@ function onKeyDown(event) {

switch(code) {
case 83:
if(Dir == -1) Dir = 0;
if(!isMoving) Dir = 0;
break;
case 68:
if(Dir == -1) Dir = 2;
if(!isMoving) Dir = 2;
break;
case 87:
if(Dir == -1) Dir = 3;
if(!isMoving) Dir = 3;
break;
case 65:
if(Dir == -1) Dir = 1;
if(!isMoving) Dir = 1;
break;
}

if(code == 83 || code == 68 || code == 87 || code == 65) {
isMoving = true
if(!isMoving) {
Network.sendStartMovement(Dir);
isMoving = true;
}
}
}

@@ -235,8 +229,10 @@ function onKeyUp(event) {

// Movement Keys
if(code == 83 || code == 68 || code == 87 || code == 65) {
Dir = -1;
isMoving = false
if(isMoving) {
Network.sendStopMovement(true);
isMoving = false;
}
}
}

@@ -67,11 +67,14 @@ Network.prototype = {
console.log("[Socket:sendLogin] Username:",_Username,"Password:",_Password)
Socket.emit("onLogin", { Username:_Username, Password:_Password })
},
sendMovement: function(dir) {
if(dir <= 3 && dir >= -1) {
Socket.emit("onMovement", dir);
sendStartMovement: function(dir) {
if(dir <= 3 && dir >= 0) {
Socket.emit("onStartMovement", dir);
}
},
sendStopMovement: function(dataPass) {
Socket.emit("onStopMovement", dataPass);
},
sendReset: function() {
Socket.emit("onMovement", -1);
},
@@ -51,7 +51,7 @@ var _Console = function() {
}, speed * i);
});
setTimeout(function() {
$('#Notice').html($('#Notice').html() + "<br>");
$('#Notice').html($('#Notice').html());
if (message == ".c") {
$('#Notice').html("");
};
@@ -16,6 +16,22 @@ var Server = function() {
Maps: {},
};

this.loop = {
parent: this,
doMovement: function(Socket) {
var player = this.parent.GameObjects.Players[Socket.id];
if(player == 'undefined') { return; }

if(this.parent.pFunc.isPlaying(player)) {
if(player.end) {
player.endAni();
} else {
player.chgDir(player.movDir);player.moveX(player.movX*5);player.moveY(player.movY*5);player.nextAni();
}
}
}
};

this.pFunc = {
parent: this,
// Get Player
@@ -201,6 +217,45 @@ var Server = function() {
Database.savePlayer(this.parent.GameObjects.Players[Socket.id]);
delete this.parent.GameObjects.Players[Socket.id];
},
onStartMovement: function(Socket, dir) {
var player = this.parent.GameObjects.Players[Socket.id];
if(player == 'undefined') { return; }

var movY = 0;
var movX = 0;
switch(dir) {
case 0:
movY = 1
break;
case 1:
movX = -1
break;
case 2:
movX = 1
break;
case 3:
movY = -1
break;
}

console.log("Start Movement: ", dir);

player.end = false;
player.movDir = dir;
player.movY = movY;
player.movX = movX;
},
onStopMovement: function(Socket, dataCheck) {
var player = this.parent.GameObjects.Players[Socket.id];
if(player == 'undefined') { return; }
if(!dataCheck) { return; }

console.log("Stop Movement");
player.end = true;
player.movDir = false;
player.movY = 0;
player.movX = 0;
},
onMovement: function(Socket, dir) {
var player = this.parent.GameObjects.Players[Socket.id];
if(player == 'undefined') { return; }

0 comments on commit 063c8d9

Please sign in to comment.
You can’t perform that action at this time.