Commit 0a7d9205 authored by 18손재민's avatar 18손재민

Merge branch 'physics' into release

parents b2b41594 3f1c3ef1
var GameServer = GameServer || {}; var GameServer = GameServer || {};
GameServer.Phase = {READY: 0, START: 1, MAIN: 2, MUSIC: 3}; GameServer.Phase = {READY: 0, COUNT: -1, START: 1, MAIN: 2, MUSIC: 3};
GameServer.startCount = 4; GameServer.startCount = 2;
GameServer.currentPlayer = []; GameServer.currentPlayer = [];
GameServer.playingRoom = []; GameServer.playingRoom = [];
...@@ -18,26 +18,29 @@ GameServer.findPlayer = function(playerId) ...@@ -18,26 +18,29 @@ GameServer.findPlayer = function(playerId)
{ {
var idx = this.currentPlayer.findIndex(function(element) var idx = this.currentPlayer.findIndex(function(element)
{ {
return element.id === socket; return element.id === playerId;
}); });
if (idx != -1) return this.currentPlayer[idx]; if (idx != -1) return this.currentPlayer[idx];
else else
{ {
console.log('[ERR] wrong playerId to find'); console.log('[ERR] wrong playerId('+ playerId +') to find');
return null; return null;
} }
} }
GameServer.nextRoomNumber = 0; GameServer.nextRoomNumber = 0;
GameServer.makeRoom = function() GameServer.makeRoom = function()
{ {
// 나중에 room 삭제시 생긴 null에 채워넣는식으로 만들것, 룸의 인덱스를 고정
var roomOption = var roomOption =
{ {
roomNum: GameServer.nextRoomNumber++, roomNum: GameServer.nextRoomNumber++,
maxPlayer: 5, maxPlayer: 100,
nextRank: 5, nextRank: 100,
currentPlayer: [], currentPlayer: [],
aliveCount: 0,
currentSocket: [], currentSocket: [],
currentPhase: GameServer.Phase.READY, currentPhase: GameServer.Phase.READY,
endTime: 0,
rateArrangePoint: 300, rateArrangePoint: 300,
maxTypingPlayer: null, maxTypingPlayer: null,
...@@ -80,10 +83,26 @@ GameServer.enterRoom = function(roomIdx, playerData) ...@@ -80,10 +83,26 @@ GameServer.enterRoom = function(roomIdx, playerData)
} }
playerData.playingData = player; playerData.playingData = player;
playerData.currentRoom = room; playerData.currentRoom = room;
room.aliveCount++;
console.log('[' + playerData.id + '] entered to room #' + room.roomNum); console.log('[' + playerData.id + '] entered to room #' + room.roomNum);
playerData.socketId.emit('enterRoom'); playerData.socketId.emit('enterRoom');
if (room.currentPlayer.length >= this.startCount) GameServer.startRoom(roomIdx); room.endTime = Date.now() + 6000; // 테스트로 6초로 남겨둠
if (room.currentPlayer.length >= this.startCount)
{
if (room.currentPhase === this.Phase.READY) // start count
{
this.announceToRoom(room.roomNum, 'setCount', {isEnable: true, endTime: room.endTime});
}
else if (room.currentPhase === this.Phase.COUNT) // countinue count
{
playerData.socketId.emit('setCount', {isEnable: true, endTime: room.endTime});
}
}
else // stop count
{
this.announceToRoom(room.roomNum, 'setCount', {isEnable: false, endTime: 0});
}
return room; return room;
} }
GameServer.enterEmptyRoom = function(playerData) GameServer.enterEmptyRoom = function(playerData)
...@@ -107,6 +126,8 @@ GameServer.startRoom = function(roomIdx) ...@@ -107,6 +126,8 @@ GameServer.startRoom = function(roomIdx)
{ {
let room = this.playingRoom[roomIdx]; let room = this.playingRoom[roomIdx];
room.currentPhase = this.Phase.START; room.currentPhase = this.Phase.START;
room.nextRank = room.currentPlayer.length;
room.aliveCount = room.currentPlayer.length;
room.maxTypingPlayer = room.currentPlayer[0]; room.maxTypingPlayer = room.currentPlayer[0];
room.minTypingPlayer = room.currentPlayer[0]; room.minTypingPlayer = room.currentPlayer[0];
room.currentSocket.forEach(function(element) room.currentSocket.forEach(function(element)
...@@ -127,6 +148,39 @@ GameServer.startRoom = function(roomIdx) ...@@ -127,6 +148,39 @@ GameServer.startRoom = function(roomIdx)
this.announceToRoom(roomIdx, 'changePhase', this.Phase.START); this.announceToRoom(roomIdx, 'changePhase', this.Phase.START);
this.announceToRoom(roomIdx, 'startGame'); this.announceToRoom(roomIdx, 'startGame');
} }
GameServer.playerDefeat = function(playerData)
{
playerData.playingData.isAlive = false;
playerData.playingData.rank = playerData.currentRoom.nextRank--;
playerData.isReceivable = false;
playerData.currentRoom.aliveCount--;
if (playerData.playingData.lastAttacks.length > 0)
{
playerData.playingData.lastAttack = playerData.playingData.lastAttacks[playerData.playingData.lastAttacks.length - 1];
if (Date.now() - playerData.playingData.lastAttack.time > 40000) playerData.playingData.lastAttack = null;
else
{
playerData.playingData.lastAttacks.forEach(function(element)
{
if (Date.now() - element.time < 40000 && element.wordGrade > playerData.playingData.lastAttack.wordGrade) playerData.playingData.lastAttack = element;
});
}
}
GameServer.announceToRoom(this.findRoomIndex(playerData.currentRoom.roomNum), 'defeat', playerData.playingData);
console.log('['+playerData.id+']'+ ' defeated, rank: ' + playerData.playingData.rank);
if (playerData.currentRoom.aliveCount === 1)
{
let winner = playerData.currentRoom.currentPlayer.find(function(element)
{
return element.isAlive;
});
GameServer.announceToRoom(this.findRoomIndex(playerData.currentRoom.roomNum), 'gameEnd', winner);
GameServer.announceToTarget(this.findRoomIndex(playerData.currentRoom.roomNum), winner.id, 'alert', 'gameWin');
console.log('['+winner.id+']' + ' winner! ' + winner.nickname);
}
}
GameServer.announceToRoom = function(roomIdx, _message, _data = null) GameServer.announceToRoom = function(roomIdx, _message, _data = null)
{ {
this.playingRoom[roomIdx].currentSocket.forEach(function(element) this.playingRoom[roomIdx].currentSocket.forEach(function(element)
...@@ -154,7 +208,10 @@ class Player ...@@ -154,7 +208,10 @@ class Player
this.nickname = playerData.nickname; this.nickname = playerData.nickname;
this.isAlive = true; this.isAlive = true;
this.rank = -1; this.rank = -1;
this.playerTyping = 0; this.playerTyping = 0;
this.lastAttacks = []; // { attackerId, word, wordGrade, time }
this.lastAttack = null;
} }
} }
......
...@@ -2,27 +2,34 @@ var Audio = Audio || {} ...@@ -2,27 +2,34 @@ var Audio = Audio || {}
Audio.loadSound = function(scene) Audio.loadSound = function(scene)
{ {
scene.load.audio('menuBackground', 'assets/sound/BGM_twochae.ogg') scene.load.audio('BGM', 'assets/sound/login.ogg');
} }
Audio.playSound = function(scene) Audio.playSound = function(scene)
{ {
bgm = scene.sound.play('menuBackground') var bgm = scene.sound.add('BGM');
bgm.setLoop(true);
bgm.play();
console.log('PlayMusic');
} }
Audio.pauseSound = function(scene) Audio.pauseSound = function(scene)
{ {
bgm = scene.sound.pause() var bgm = scene.sound.add('BGM');
bgm.pause();
} }
Audio.resumeSound = function(scene) Audio.resumeSound = function(scene)
{ {
bgm = scene.sound.resume() var bgm = scene.sound.add('BGM');
bgm = scene.sound.resume();
} }
Audio.stopSound = function(scene) Audio.stopSound = function(scene)
{ {
bgm = scene.sound.stop() var bgm = scene.sound.add('BGM');
bgm.stop();
console.log('StopMusic');
} }
// var Audio = new Audio('assets/sound/BGM_twochae.ogg');
// Audio.play();
\ No newline at end of file
...@@ -2,18 +2,29 @@ var socket = io.connect(); ...@@ -2,18 +2,29 @@ var socket = io.connect();
// init account // init account
socket.emit('idRequest'); socket.emit('idRequest');
socket.on('alert', function(msg) // string errorcode
{
let toAlert = 'null alert';
if (msg === 'errNicknameOverlaped') toAlert = '이미 사용중인 닉네임입니다.';
if (msg === 'gameWin') toAlert = '승리!';
alert(toAlert);
});
socket.on('setId', function(msg) // {str, num playerNum} socket.on('setId', function(msg) // {str, num playerNum}
{ {
console.log(msg.str); console.log(msg.str);
PlayerData.idNum = msg.num; PlayerData.idNum = msg.num;
}); });
socket.on('errNicknameOverlaped', function()
{
alert('이미 사용중인 닉네임입니다.');
});
socket.on('enterRoom', function() socket.on('enterRoom', function()
{ {
game.scene.remove('menuScene'); game.scene.remove('menuScene');
game.scene.start('roomScene');
});
socket.on('setCount', function(msg)
{
ScenesData.roomScene.isCounting = msg.isEnable;
ScenesData.roomScene.endTime = msg.endTime;
}); });
// init game // init game
...@@ -26,6 +37,7 @@ socket.on('syncRoomData', function(msg) // {num roomNum, [] players} ...@@ -26,6 +37,7 @@ socket.on('syncRoomData', function(msg) // {num roomNum, [] players}
}); });
socket.on('startGame', function() socket.on('startGame', function()
{ {
game.scene.remove('roomScene');
game.scene.start('gameScene'); game.scene.start('gameScene');
}); });
...@@ -42,18 +54,35 @@ socket.on('setPlayerTypingRate', function(msg) // number playerTypingRate ...@@ -42,18 +54,35 @@ socket.on('setPlayerTypingRate', function(msg) // number playerTypingRate
}); });
socket.on('attacked', function(msg) // object attackData socket.on('attacked', function(msg) // object attackData
{ {
WordSpace.generateWord.Attack(WordSpace.gameSceneForTest, msg.text, msg.grade, msg.attacker, msg.isStrong); setTimeout(function()
{
WordSpace.generateWord.Attack(ScenesData.gameScene, msg.text, msg.grade, msg.attacker, msg.isStrong);
}, 4000);
}); });
socket.on('defeat', function(msg) // object player socket.on('defeat', function(msg) // object player
{ {
RoomData.players[msg.index] = msg; RoomData.players[msg.index] = msg;
RoomData.aliveCount--; RoomData.aliveCount--;
if (msg.lastAttack != null)
{
console.log(RoomData.players[msg.index].nickname + ' defeated by ' + msg.lastAttack.attacker + ', with ' + msg.lastAttack.word);
WordSpace.killLogForTest += ('\n' + msg.lastAttack.attacker + ' --' + msg.lastAttack.word + '-> ' + RoomData.players[msg.index].nickname);
}
else
{
console.log(RoomData.players[msg.index].nickname + ' defeated'); console.log(RoomData.players[msg.index].nickname + ' defeated');
WordSpace.killLogForTest += ('\n--Suicide->' + RoomData.players[msg.index].nickname);
}
});
socket.on('gameEnd', function(msg) // object player
{
console.log(msg.nickname + ' Win!!!!!!');
}); });
socket.on('attackSucceed', function(msg) socket.on('attackSucceed', function(msg)
{ {
WordSpace.nameGroup.push(new NameWord(msg.victim, true)); let tempWord = WordSpace.generateWord.Name(ScenesData.gameScene, true, msg.victim);
tempWord.destroy();
}); });
// out game // out game
......
var ScenesData = ScenesData || {};
var menuScene = new Phaser.Class( var menuScene = new Phaser.Class(
{ {
Extends: Phaser.Scene, Extends: Phaser.Scene,
...@@ -11,6 +13,7 @@ var menuScene = new Phaser.Class( ...@@ -11,6 +13,7 @@ var menuScene = new Phaser.Class(
preload: function() preload: function()
{ {
ScenesData.menuScene = this;
Input.inputField.loadImage(this); Input.inputField.loadImage(this);
BackGround.loadImage(this); BackGround.loadImage(this);
Audio.loadSound(this); Audio.loadSound(this);
...@@ -18,12 +21,53 @@ var menuScene = new Phaser.Class( ...@@ -18,12 +21,53 @@ var menuScene = new Phaser.Class(
create: function() create: function()
{ {
Audio.playSound(this);
Input.inputField.generate(this, Input.menuSceneEnterReaction); Input.inputField.generate(this, Input.menuSceneEnterReaction);
BackGround.drawMenu(this); BackGround.drawMenu(this);
Audio.playSound(this);
} }
}); });
var roomScene = new Phaser.Class(
{
Extends: Phaser.Scene,
initialize:
function roomScene ()
{
Phaser.Scene.call(this, {key: 'roomScene'});
},
preload: function()
{
ScenesData.roomScene = this;
},
create: function()
{
this.isCounting = false;
this.endTime = 0;
this.countText = this.add.text(640, 360, '사람들을 위해 대기중입니다...').setOrigin(0.5, 0.5).setColor('#000000');
},
update: function()
{
if (this.isCounting)
{
this.countText.setText((this.endTime - Date.now()) / 1000);
if (this.endTime - Date.now() < 0)
{
socket.emit('endCount');
this.isCounting = false;
}
}
else
{
this.countText.setText('사람들을 위해 대기중입니다...');
}
}
})
var gameScene = new Phaser.Class( var gameScene = new Phaser.Class(
{ {
Extends: Phaser.Scene, Extends: Phaser.Scene,
...@@ -37,6 +81,7 @@ var gameScene = new Phaser.Class( ...@@ -37,6 +81,7 @@ var gameScene = new Phaser.Class(
preload: function() preload: function()
{ {
ScenesData.gameScene = this;
BackGround.loadImage(this); BackGround.loadImage(this);
WordSpace.loadImage(this); WordSpace.loadImage(this);
Input.inputField.loadImage(this); Input.inputField.loadImage(this);
...@@ -65,7 +110,7 @@ var gameScene = new Phaser.Class( ...@@ -65,7 +110,7 @@ var gameScene = new Phaser.Class(
WordSpace.setPlayerTyping.initiate(this); WordSpace.setPlayerTyping.initiate(this);
WordSpace.nameWordTextForTest = WordSpace.gameSceneForTest.add.text(50,400,'현재 가진 호패들 : 없음').setDepth(10).setColor('#000000'); WordSpace.nameWordTextForTest = ScenesData.gameScene.add.text(50,400,'현재 가진 호패들 : 없음').setDepth(10).setColor('#000000');
WordSpace.nameQueue.initiate(); WordSpace.nameQueue.initiate();
RoomData.players.forEach(function(element) RoomData.players.forEach(function(element)
{ {
...@@ -76,14 +121,20 @@ var gameScene = new Phaser.Class( ...@@ -76,14 +121,20 @@ var gameScene = new Phaser.Class(
} }
}); });
console.log(RoomData.myself); console.log(RoomData.myself);
WordSpace.test = WordSpace.generateWord.Name(this, false, null);
}, },
update: function() update: function()
{ {
WordSpace.deltaTime = this.sys.game.loop.delta;
WordSpace.wordForcedGroup.forEach(function(element) WordSpace.wordForcedGroup.forEach(function(element)
{ {
element.attract(); element.attract();
}); });
WordSpace.nameGroup.forEach(function(element)
{
element.attract();
})
let tempNames = ''; let tempNames = '';
WordSpace.nameGroup.forEach(function(element) WordSpace.nameGroup.forEach(function(element)
{ {
...@@ -92,6 +143,7 @@ var gameScene = new Phaser.Class( ...@@ -92,6 +143,7 @@ var gameScene = new Phaser.Class(
WordSpace.nameWordTextForTest.setText('현재 가진 호패들 : \n' + tempNames); WordSpace.nameWordTextForTest.setText('현재 가진 호패들 : \n' + tempNames);
WordSpace.weightTextObjForTest.setText('뇌의 무게: (현재) '+WordSpace.totalWeight+' / '+ WordSpace.brainCapacity+' (전체)'); WordSpace.weightTextObjForTest.setText('뇌의 무게: (현재) '+WordSpace.totalWeight+' / '+ WordSpace.brainCapacity+' (전체)');
WordSpace.killLogTextForTest.setText(WordSpace.killLogForTest);
WordSpace.setPlayerTyping.add(''); WordSpace.setPlayerTyping.add('');
} }
}); });
\ No newline at end of file
...@@ -15,15 +15,15 @@ class WordObject ...@@ -15,15 +15,15 @@ class WordObject
instantiate(scene, lenRate) instantiate(scene, lenRate)
{ {
let p = [{x : 3, y : 0.7}, {x : 20, y : 1.2}]; let p = [{x : 3, y : 0.7}, {x : 20, y : 1.2}];
let scale = ((p[1].y - p[0].y) / (p[1].x - p[0].x)) * (this.wordWeight - p[0].x) + p[0].y; this.scale = ((p[1].y - p[0].y) / (p[1].x - p[0].x)) * (this.wordWeight - p[0].x) + p[0].y;
let fontscale = 25; this.fontScale = 25;
var random = WordSpace.getSpawnPoint(lenRate); var random = WordSpace.getSpawnPoint(lenRate);
if (!this.isNameWord) if (!this.isNameWord)
{ {
this.physicsObj = scene.physics.add.sprite(random.x, random.y, 'wordBgr' + this.wordGrade + '_' + Math.min(Math.max(2, this.wordText.length), 6)) this.physicsObj = scene.physics.add.sprite(random.x, random.y, 'wordBgr' + this.wordGrade + '_' + Math.min(Math.max(2, this.wordText.length), 6))
.setMass(this.wordWeight * 10) .setMass(this.wordWeight * 10)
.setScale(scale) .setScale(this.scale)
.setFrictionX(0) .setFrictionX(0)
.setFrictionY(0) .setFrictionY(0)
.setBounce(0.5); .setBounce(0.5);
...@@ -32,13 +32,12 @@ class WordObject ...@@ -32,13 +32,12 @@ class WordObject
{ {
this.physicsObj = scene.physics.add.sprite(random.x, random.y, 'nameBgr' + Math.min(Math.max(2, this.wordText.length), 6)) this.physicsObj = scene.physics.add.sprite(random.x, random.y, 'nameBgr' + Math.min(Math.max(2, this.wordText.length), 6))
.setMass(this.wordWeight * 10) .setMass(this.wordWeight * 10)
.setScale(scale) .setScale(this.scale)
.setFrictionX(0) .setFrictionX(0)
.setFrictionY(0) .setFrictionY(0)
.setBounce(0.5); .setBounce(0.5);
} }
this.physicsObj.wordCollider = null;
let dist = Phaser.Math.Distance.Between(this.physicsObj.x, this.physicsObj.y, WordSpace.gravityPoint.x, WordSpace.gravityPoint.y); let dist = Phaser.Math.Distance.Between(this.physicsObj.x, this.physicsObj.y, WordSpace.gravityPoint.x, WordSpace.gravityPoint.y);
let angle = Phaser.Math.Angle.Between(this.physicsObj.x, this.physicsObj.y, WordSpace.gravityPoint.x, WordSpace.gravityPoint.y); let angle = Phaser.Math.Angle.Between(this.physicsObj.x, this.physicsObj.y, WordSpace.gravityPoint.x, WordSpace.gravityPoint.y);
...@@ -48,7 +47,7 @@ class WordObject ...@@ -48,7 +47,7 @@ class WordObject
this.wordObj = scene.add.text(random.x, random.y, this.wordText, this.wordObj = scene.add.text(random.x, random.y, this.wordText,
{ {
fontSize: (scale * fontscale) +'pt', fontSize: (this.scale * this.fontScale) +'pt',
fontFamily: '"궁서", 궁서체, serif', fontFamily: '"궁서", 궁서체, serif',
fontStyle: (this.wordWeight > 5 ? 'bold' : '') fontStyle: (this.wordWeight > 5 ? 'bold' : '')
}); });
...@@ -62,16 +61,20 @@ class WordObject ...@@ -62,16 +61,20 @@ class WordObject
destroy() destroy()
{ {
console.log(this.generationCode + ': ' + this.wordText + ' destroyed'); //console.log(this.generationCode + ': ' + this.wordText + ' destroyed');
WordSpace.totalWeight -= this.wordWeight; WordSpace.totalWeight -= this.wordWeight;
WordSpace.totalWordNum -= 1; WordSpace.totalWordNum -= 1;
WordSpace.resetGameOverTimer(); WordSpace.resetGameOverTimer();
this.wordObj.destroy();
const groupIdx = WordSpace.wordGroup.findIndex(function(item) {return this.isEqualObject(item.generationCode)}, this); const groupIdx = WordSpace.wordGroup.findIndex(function(item) {return this.isEqualObject(item.generationCode)}, this);
if (groupIdx > -1) WordSpace.wordGroup.splice(groupIdx, 1); if (groupIdx > -1) WordSpace.wordGroup.splice(groupIdx, 1);
const forceIdx = WordSpace.wordForcedGroup.findIndex(function(item) {return this.isEqualObject(item.generationCode)}, this); const forceIdx = WordSpace.wordForcedGroup.findIndex(function(item) {return this.isEqualObject(item.generationCode)}, this);
if (forceIdx > -1) WordSpace.wordForcedGroup.splice(forceIdx, 1); if (forceIdx > -1) WordSpace.wordForcedGroup.splice(forceIdx, 1);
WordSpace.wordPhysicsGroup.remove(this.physicsObj, true, true); WordSpace.wordPhysicsGroup.remove(this.physicsObj);
if(!this.isNameWord)
{
this.wordObj.destroy();
this.physicsObj.destroy();
}
} }
...@@ -101,8 +104,7 @@ class WordObject ...@@ -101,8 +104,7 @@ class WordObject
} }
this.physicsObj.setVelocity(accel.x, accel.y); this.physicsObj.setVelocity(accel.x, accel.y);
this.wordObj.setPosition(this.physicsObj.x, this.physicsObj.y); this.wordObj.setPosition(this.physicsObj.x + (accel.x / 1000 * WordSpace.deltaTime), this.physicsObj.y + (accel.y / 1000 * WordSpace.deltaTime));
} }
isEqualObject(_generationCode) { return _generationCode === this.generationCode; } isEqualObject(_generationCode) { return _generationCode === this.generationCode; }
...@@ -156,10 +158,10 @@ class AttackWord extends WordObject ...@@ -156,10 +158,10 @@ class AttackWord extends WordObject
} }
if(WordSpace.gameTimer.now < this.counterTime) if(WordSpace.gameTimer.now < this.counterTime)
{ {
WordSpace.nameGroup.push(new NameWord(this.attacker, true)); let tempWord = WordSpace.generateWord.Name(ScenesData.gameScene, true, this.attacker);
tempWord.destroy();
} }
//강호패 넣기 구현해야됨 //WordSpace.nameGroup.push(new NameWord(this.attacker, true));
//WordSpace.generateWord.Name(WordSpace.gameSceneForTest, true);
super.destroy(); super.destroy();
} }
} }
...@@ -172,12 +174,63 @@ class NameWord extends WordObject ...@@ -172,12 +174,63 @@ class NameWord extends WordObject
this.ownerId = player.id; this.ownerId = player.id;
this.wordWeight = 2; this.wordWeight = 2;
this.isStrong = _isStrong; this.isStrong = _isStrong;
console.log('Name : ' + player.nickname + ', Strong : ' + this.isStrong + ', Weight : ' + this.wordWeight); this.isActive = true;
//console.log('Name : ' + player.nickname + ', Strong : ' + this.isStrong + ', Weight : ' + this.wordWeight);
}
attract()
{
if(this.isActive) super.attract();
else{
this.path.getPoint(this.follower.t, this.follower.vec);
this.physicsObj.setPosition(this.follower.vec.x, this.follower.vec.y);
this.wordObj.setPosition(this.physicsObj.x, this.physicsObj.y);
this.physicsObj.angle = 90 * this.follower.t;
this.wordObj.angle = this.physicsObj.angle;
if(this.isStrong)
{
this.physicsObj.setScale(this.follower.t < 0.2 ? 0.2 : this.follower.t * this.scale);
this.wordObj.setFont({
fontSize: (this.follower.t < 0.2 ? 0.05 : this.follower.t * this.scale * this.fontScale) +'pt',
fontFamily: '"궁서", 궁서체, serif',
fontStyle: (this.wordWeight > 5 ? 'bold' : '')
});
}
}
} }
destroy() destroy()
{ {
WordSpace.attackGauge.add(this.wordTyping * 0.1);
WordSpace.nameGroup.push(this);
super.destroy(); super.destroy();
ScenesData.gameScene.physics.world.removeCollider(this.physicsObj.wordCollider);
WordSpace.wordGroup.forEach(function(element)
{
ScenesData.gameScene.physics.world.removeCollider(element.physicsObj.wordCollider);
element.physicsObj.wordCollider = ScenesData.gameScene.physics.add.collider(element.physicsObj, WordSpace.wordPhysicsGroup, function(object1)
{
object1.topObj.attract();
});
});
if(!this.isStrong) WordSpace.attackGauge.add(this.wordTyping * 0.1);
WordSpace.nameGroup.push(this);
this.isActive = false;
this.physicsObj.setVelocity(0, 0).setDepth(2);
this.wordObj.setPosition(this.physicsObj.x, this.physicsObj.y).setDepth(2);
this.follower = { t: 0, vec: new Phaser.Math.Vector2() };
this.path = new Phaser.Curves.Spline([
this.physicsObj.x, this.physicsObj.y,
(this.physicsObj.x + 500 + WordSpace.nameGroup.length * 15) / 2, this.physicsObj.y - 50,
500 + WordSpace.nameGroup.length * 15, 680 + this.wordText.length * 10 + (Math.random() * 20 - 10)
]);
ScenesData.gameScene.tweens.add({
targets: this.follower,
t: 1,
ease: 'Sine',
duration: 2000,
repeat: 0
});
//이동경로 디버그
/*var graphics = ScenesData.gameScene.add.graphics();
graphics.lineStyle(2, 0xffffff, 1);
this.path.draw(graphics);*/
} }
} }
var WordSpace = WordSpace || {}; var WordSpace = WordSpace || {};
WordSpace.test = null;
// for test // for test
WordSpace.gameSceneForTest = null;
WordSpace.weightTextObjForTest = null; WordSpace.weightTextObjForTest = null;
WordSpace.nameWordTextForTest = null; WordSpace.nameWordTextForTest = null;
WordSpace.killLogTextForTest = null;
WordSpace.killLogForTest = '';
WordSpace.nextWordCode = 0; WordSpace.nextWordCode = 0;
WordSpace.totalWeight = 0; //현재 단어 무게 총합 WordSpace.totalWeight = 0; //현재 단어 무게 총합
...@@ -23,6 +26,8 @@ WordSpace.CurrentPhase = WordSpace.Phase.READY; ...@@ -23,6 +26,8 @@ WordSpace.CurrentPhase = WordSpace.Phase.READY;
WordSpace.playerTyping = 0; WordSpace.playerTyping = 0;
WordSpace.playerTypingRate = 0; WordSpace.playerTypingRate = 0;
WordSpace.deltaTime = 10;
WordSpace.delay = WordSpace.delay =
{ {
WordSpawn: 3000, WordSpawn: 3000,
...@@ -33,7 +38,7 @@ WordSpace.delay = ...@@ -33,7 +38,7 @@ WordSpace.delay =
WordSpace.playerTypingCycle = null; WordSpace.playerTypingCycle = null;
WordSpace.NameSpawnReduce = 1000; WordSpace.NameSpawnReduce = 1000;
WordSpace.gravityPoint = {x: 640, y: 300}; WordSpace.gravityPoint = {x: 640, y: 280};
class Cycle //앞으로 cycle은 이 클래스를 사용해서 구현할 것 class Cycle //앞으로 cycle은 이 클래스를 사용해서 구현할 것
{ {
...@@ -69,7 +74,7 @@ WordSpace.gameOverCycle = new Cycle(gameOver); ...@@ -69,7 +74,7 @@ WordSpace.gameOverCycle = new Cycle(gameOver);
//호패 생성 사이클 //호패 생성 사이클
WordSpace.nameCycle = new Cycle(function() WordSpace.nameCycle = new Cycle(function()
{ {
WordSpace.generateWord.Name(WordSpace.gameSceneForTest, false); WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
}); });
//이건 뭐지 //이건 뭐지
WordSpace.varAdjustCycle = new Cycle(function() WordSpace.varAdjustCycle = new Cycle(function()
...@@ -143,8 +148,8 @@ WordSpace.AdjustVarByPhase = function(typingRate, phase) ...@@ -143,8 +148,8 @@ WordSpace.AdjustVarByPhase = function(typingRate, phase)
WordSpace.GradeProb[1] = 0.8 - 0.45 * typingRate; WordSpace.GradeProb[1] = 0.8 - 0.45 * typingRate;
WordSpace.GradeProb[2] = 0.9 - 0.15 * typingRate; WordSpace.GradeProb[2] = 0.9 - 0.15 * typingRate;
} }
WordSpace.wordCycle.resetCycle(WordSpace.gameSceneForTest, WordSpace.delay.WordSpawn, WordSpace.wordCycle.currentCycle.getElapsed(), true); WordSpace.wordCycle.resetCycle(ScenesData.gameScene, WordSpace.delay.WordSpawn, WordSpace.wordCycle.currentCycle.getElapsed(), true);
WordSpace.nameCycle.resetCycle(WordSpace.gameSceneForTest, WordSpace.delay.NameSpawn, WordSpace.nameCycle.currentCycle.getElapsed(), true); WordSpace.nameCycle.resetCycle(ScenesData.gameScene, WordSpace.delay.NameSpawn, WordSpace.nameCycle.currentCycle.getElapsed(), true);
} }
WordSpace.attackGauge = WordSpace.attackGauge =
...@@ -235,8 +240,8 @@ WordSpace.loadImage = function(scene) ...@@ -235,8 +240,8 @@ WordSpace.loadImage = function(scene)
scene.load.image('nameBgr' + i, 'assets/placeholder/name' + i + '.png'); scene.load.image('nameBgr' + i, 'assets/placeholder/name' + i + '.png');
} }
WordSpace.gameSceneForTest = scene; // for test
WordSpace.weightTextObjForTest = scene.add.text(100, 75, '뇌의 무게: (현재) 0 / 100 (전체)').setDepth(10).setColor('#000000'); WordSpace.weightTextObjForTest = scene.add.text(100, 75, '뇌의 무게: (현재) 0 / 100 (전체)').setDepth(10).setColor('#000000');
WordSpace.killLogTextForTest = scene.add.text(1000, 50, WordSpace.killLogForTest).setDepth(10).setColor('#000000').setAlign('right');
} }
WordSpace.generateWord = WordSpace.generateWord =
...@@ -245,17 +250,21 @@ WordSpace.generateWord = ...@@ -245,17 +250,21 @@ WordSpace.generateWord =
{ {
word = new NormalWord(SelectWord.selectWord(grade)); word = new NormalWord(SelectWord.selectWord(grade));
WordSpace.pushWord(scene, word, lenRate); WordSpace.pushWord(scene, word, lenRate);
return word;
}, },
Attack: function(scene, wordText, grade, attacker, isStrong, lenRate) Attack: function(scene, wordText, grade, attacker, isStrong, lenRate)
{ {
word = new AttackWord(wordText, grade, attacker, isStrong); word = new AttackWord(wordText, grade, attacker, isStrong);
WordSpace.pushWord(scene, word, lenRate); WordSpace.pushWord(scene, word, lenRate);
return word;
}, },
Name: function(scene, isStrong, lenRate) Name: function(scene, isStrong, newPlayerData, lenRate)
{ {
word = new NameWord(WordSpace.nameQueue.pop(), isStrong); if(newPlayerData == null) word = new NameWord(WordSpace.nameQueue.pop(), isStrong);
else word = new NameWord(newPlayerData, isStrong);
//word = new NameWord(RoomData.myself, false); //word = new NameWord(RoomData.myself, false);
WordSpace.pushWord(scene, word, lenRate); WordSpace.pushWord(scene, word, lenRate);
return word;
} }
} }
...@@ -265,7 +274,7 @@ WordSpace.pushWord = function(scene, word, lenRate) ...@@ -265,7 +274,7 @@ WordSpace.pushWord = function(scene, word, lenRate)
WordSpace.wordGroup.push(word); WordSpace.wordGroup.push(word);
WordSpace.wordForcedGroup.push(word); WordSpace.wordForcedGroup.push(word);
word.physicsObj.topObj = word; word.physicsObj.topObj = word;
scene.physics.add.collider(word.physicsObj, WordSpace.wordPhysicsGroup, function(object1) word.physicsObj.wordCollider = scene.physics.add.collider(word.physicsObj, WordSpace.wordPhysicsGroup, function(object1)
{ {
//object1.topObj.wordSpeed = 0.1; //object1.topObj.wordSpeed = 0.1;
object1.topObj.attract(); object1.topObj.attract();
...@@ -292,7 +301,7 @@ WordSpace.setGameOverTimer = function() ...@@ -292,7 +301,7 @@ WordSpace.setGameOverTimer = function()
if(this.brainCapacity < this.totalWeight && !this.isTimerOn) if(this.brainCapacity < this.totalWeight && !this.isTimerOn)
{ {
this.isTimerOn = true; this.isTimerOn = true;
WordSpace.gameOverCycle.resetCycle(WordSpace.gameSceneForTest, WordSpace.delay.GameOver, 0, false); WordSpace.gameOverCycle.resetCycle(ScenesData.gameScene, WordSpace.delay.GameOver, 0, false);
} }
} }
...@@ -319,12 +328,12 @@ WordSpace.findWord = function(wordText) ...@@ -319,12 +328,12 @@ WordSpace.findWord = function(wordText)
if (weightest.wordWeight < element.wordWeight) weightest = element; if (weightest.wordWeight < element.wordWeight) weightest = element;
}); });
weightest.destroy(); weightest.destroy();
WordSpace.nameCycle.resetCycle(WordSpace.gameSceneForTest, WordSpace.delay.NameSpawn, WordSpace.nameCycle.currentCycle.getElapsed() + WordSpace.NameSpawnReduce, true); WordSpace.nameCycle.resetCycle(ScenesData.gameScene, WordSpace.delay.NameSpawn, WordSpace.nameCycle.currentCycle.getElapsed() + WordSpace.NameSpawnReduce, true);
while(WordSpace.totalWordNum < 5) while(WordSpace.totalWordNum < 5)
{ {
WordSpace.genWordByProb(WordSpace.gameSceneForTest); WordSpace.genWordByProb(ScenesData.gameScene);
WordSpace.wordCycle.resetCycle(WordSpace.gameSceneForTest, WordSpace.delay.WordSpawn, 0); WordSpace.wordCycle.resetCycle(ScenesData.gameScene, WordSpace.delay.WordSpawn, 0);
} }
WordSpace.setPlayerTyping.add(wordText); WordSpace.setPlayerTyping.add(wordText);
} }
...@@ -350,7 +359,7 @@ WordSpace.findWord = function(wordText) ...@@ -350,7 +359,7 @@ WordSpace.findWord = function(wordText)
if(tempDist <= minDist) minDist = tempDist; if(tempDist <= minDist) minDist = tempDist;
} }
}); });
attackWords.forEach(function(element) attackWords.some(function(element)
{ {
if(WordSpace.getEditDistance(wordText, element.wordText) == minDist) if(WordSpace.getEditDistance(wordText, element.wordText) == minDist)
{ {
...@@ -362,6 +371,7 @@ WordSpace.findWord = function(wordText) ...@@ -362,6 +371,7 @@ WordSpace.findWord = function(wordText)
target: element.attacker.idNum target: element.attacker.idNum
} }
socket.emit('defenseFailed', victimData); socket.emit('defenseFailed', victimData);
return true;
} }
}); });
this.attackGauge.sub(2); this.attackGauge.sub(2);
...@@ -403,11 +413,11 @@ WordSpace.attack = function(wordText, grade) ...@@ -403,11 +413,11 @@ WordSpace.attack = function(wordText, grade)
isStrong: element.isStrong isStrong: element.isStrong
} }
socket.emit('attack', attackData); socket.emit('attack', attackData);
element.physicsObj.destroy();
element.wordObj.destroy();
}); });
//테스트용, 자기 자신에게 공격함 WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
//WordSpace.generateWord.Attack(WordSpace.gameSceneForTest, wordText, grade, PlayerData, false); WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
WordSpace.generateWord.Name(WordSpace.gameSceneForTest, false);
WordSpace.generateWord.Name(WordSpace.gameSceneForTest, false);
WordSpace.nameGroup = []; WordSpace.nameGroup = [];
WordSpace.attackGauge.resetValue(); WordSpace.attackGauge.resetValue();
......
...@@ -2,6 +2,11 @@ var config = { ...@@ -2,6 +2,11 @@ var config = {
type: Phaser.AUTO, type: Phaser.AUTO,
width: 1280, width: 1280,
height: 720, height: 720,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH
},
autoRound: false,
physics: { physics: {
default: 'arcade', default: 'arcade',
arcade: { arcade: {
...@@ -9,7 +14,7 @@ var config = { ...@@ -9,7 +14,7 @@ var config = {
} }
}, },
backgroundColor: Phaser.Display.Color.HexStringToColor('#F0CB85').color,//GetColor(245,208,138), backgroundColor: Phaser.Display.Color.HexStringToColor('#F0CB85').color,//GetColor(245,208,138),
scene: [ menuScene, gameScene ] scene: [ menuScene, roomScene, gameScene ]
}; };
var game = new Phaser.Game(config) var game = new Phaser.Game(config)
......
...@@ -46,7 +46,7 @@ io.on('connection', function(socket) ...@@ -46,7 +46,7 @@ io.on('connection', function(socket)
{ {
if (element.nickname === msg) isAlreadyHave = true; if (element.nickname === msg) isAlreadyHave = true;
}); });
if (isAlreadyHave) socket.emit('errNicknameOverlaped'); if (isAlreadyHave) socket.emit('alert' ,'errNicknameOverlaped');
else else
{ {
socket.playerData.nickname = msg; socket.playerData.nickname = msg;
...@@ -72,19 +72,42 @@ io.on('connection', function(socket) ...@@ -72,19 +72,42 @@ io.on('connection', function(socket)
socket.emit('setPlayerTypingRate', playerTypingRate); socket.emit('setPlayerTypingRate', playerTypingRate);
}); });
socket.on('endCount', function()
{
socket.playerData.currentRoom.aliveCount--;
if (socket.playerData.currentRoom.aliveCount === 0)
{
GameServer.startRoom(GameServer.findRoomIndex(socket.playerData.currentRoom.roomNum));
}
});
socket.on('attack', function(msg) socket.on('attack', function(msg)
{ {
GameServer.announceToTarget(GameServer.findRoomIndex(msg.roomNum), msg.target, 'attacked', msg); GameServer.announceToTarget(GameServer.findRoomIndex(msg.roomNum), msg.target, 'attacked', msg);
let target = GameServer.findPlayer(msg.target);
if (target != null)
{
let dataToPush =
{
attackerId: msg.attacker.idNum,
attacker: msg.attacker.nickname,
word: msg.text,
wordGrade: msg.grade,
time: Date.now()
}
if (target.playingData.lastAttacks.length < 5) target.playingData.lastAttacks.push(dataToPush);
else
{
target.playingData.lastAttacks.splice(0, 1);
target.playingData.lastAttacks.push(dataToPush);
}
}
}); });
socket.on('defeated', function() socket.on('defeated', function()
{ {
socket.playerData.playingData.isAlive = false; GameServer.playerDefeat(socket.playerData);
socket.playerData.playingData.rank = socket.playerData.currentRoom.nextRank--;
socket.playerData.isReceivable = false;
// 패배단어 체크
GameServer.announceToRoom(socket.playerData.currentRoom.roomNum, 'defeat', socket.playerData.playingData);
console.log('['+socket.playerData.id+']'+ ' defeated');
}); });
socket.on('defenseFailed', function(msg) socket.on('defenseFailed', function(msg)
...@@ -95,7 +118,6 @@ io.on('connection', function(socket) ...@@ -95,7 +118,6 @@ io.on('connection', function(socket)
socket.on('disconnect', function(reason) socket.on('disconnect', function(reason)
{ {
let data = socket.playerData; let data = socket.playerData;
console.log('['+ data.id +'] client disconnected, reason: ' + reason);
if (typeof data.id === undefined) if (typeof data.id === undefined)
{ {
console.log('[ERROR] data.id is undefined'); console.log('[ERROR] data.id is undefined');
...@@ -103,6 +125,7 @@ io.on('connection', function(socket) ...@@ -103,6 +125,7 @@ io.on('connection', function(socket)
} }
else // data.id is not undefined else // data.id is not undefined
{ {
console.log('['+ data.id +'] client disconnected, reason: ' + reason);
let idxToDel = GameServer.currentPlayer.findIndex(function(element) let idxToDel = GameServer.currentPlayer.findIndex(function(element)
{ {
return element.id === data.id; return element.id === data.id;
...@@ -118,13 +141,11 @@ io.on('connection', function(socket) ...@@ -118,13 +141,11 @@ io.on('connection', function(socket)
data.currentRoom.currentPlayer[data.playingData.index] = null; data.currentRoom.currentPlayer[data.playingData.index] = null;
data.currentRoom.currentSocket[data.playingData.index] = null; data.currentRoom.currentSocket[data.playingData.index] = null;
} }
else else if (data.playingData.isAlive)
{ {
data.playingData.isAlive = false; GameServer.playerDefeat(socket.playerData);
if (data.playingData.rank === -1) data.playingData.rank = data.currentRoom.nextRank--;
data.currentRoom.currentSocket[data.playingData.index].isReceivable = false;
GameServer.announceToRoom(GameServer.findRoomIndex(data.currentRoom.roomNum), 'userDisconnect', data.playingData);
} }
GameServer.announceToRoom(GameServer.findRoomIndex(data.currentRoom.roomNum), 'userDisconnect', data.playingData);
} }
} }
console.log('['+ data.id +'] disconnect complete'); console.log('['+ data.id +'] disconnect complete');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment