Commit d7bf6857 authored by 18신대성's avatar 18신대성

대기실 카운터 WIP

parent beeacbac
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 = 2;
GameServer.currentPlayer = [];
......@@ -35,9 +35,9 @@ GameServer.makeRoom = function()
{
roomNum: GameServer.nextRoomNumber++,
maxPlayer: 5,
nextRank: 5,
nextRank: 0,
currentPlayer: [],
aliveCount: -1,
aliveCount: 0,
currentSocket: [],
currentPhase: GameServer.Phase.READY,
......@@ -82,10 +82,26 @@ GameServer.enterRoom = function(roomIdx, playerData)
}
playerData.playingData = player;
playerData.currentRoom = room;
room.aliveCount++;
console.log('[' + playerData.id + '] entered to room #' + room.roomNum);
playerData.socketId.emit('enterRoom');
if (room.currentPlayer.length >= this.startCount) GameServer.startRoom(roomIdx);
let endTimeToAnnounce = Date.now() + 6000;
if (room.currentPlayer.length >= this.startCount)
{
if (room.currentPhase === this.Phase.READY) // start count
{
this.announceToRoom(room.roomNum, 'setCount', {isEnable: true, endTime: endTimeToAnnounce});
}
else if (room.currentPhase === this.Phase.COUNT) // countinue count
{
playerData.socketId.emit('setCount', {isEnable: true, endTime: endTimeToAnnounce});
}
}
else // stop count
{
this.announceToRoom(room.roomNum, 'setCount', {isEnable: false, endTime: 0});
}
return room;
}
GameServer.enterEmptyRoom = function(playerData)
......
......@@ -19,6 +19,12 @@ socket.on('setId', function(msg) // {str, num playerNum}
socket.on('enterRoom', function()
{
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
......@@ -31,6 +37,7 @@ socket.on('syncRoomData', function(msg) // {num roomNum, [] players}
});
socket.on('startGame', function()
{
game.scene.remove('roomScene');
game.scene.start('gameScene');
});
......
......@@ -27,6 +27,47 @@ var menuScene = new Phaser.Class(
}
});
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(
{
Extends: Phaser.Scene,
......
......@@ -9,7 +9,7 @@ var config = {
}
},
backgroundColor: Phaser.Display.Color.HexStringToColor('#F0CB85').color,//GetColor(245,208,138),
scene: [ menuScene, gameScene ]
scene: [ menuScene, roomScene, gameScene ]
};
var game = new Phaser.Game(config)
......
......@@ -72,6 +72,15 @@ io.on('connection', function(socket)
socket.emit('setPlayerTypingRate', playerTypingRate);
});
socket.on('endCount')
{
socket.currentRoom.aliveCount--;
if (socket.currentRoom.aliveCount === 0)
{
GameServer.startRoom(GameServer.findRoomIndex(socket.currentRoom.roomNum));
}
}
socket.on('attack', function(msg)
{
GameServer.announceToTarget(GameServer.findRoomIndex(msg.roomNum), msg.target, 'attacked', msg);
......
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