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

Merge branch 'physics' into release

parents ca123aba 79aad6ec
This diff is collapsed.
......@@ -8,11 +8,13 @@
<script src="js/Background.js"></script>
<script src="js/Input.js"></script>
<script src="js/WordSpace.js"></script>
<script src="js/GameCycle.js"></script>
<script src="js/WordObject.js"></script>
<script src="js/WordReader.js"></script>
<script src="js/CSVParsing.js"></script>
<script src="js/SelectWord.js"></script>
<script src="js/BGMsound.js"></script>
<script src="js/Enums.js"></script>
</head>
<body>
<script src="js/Client.js"></script>
......
var Audio = Audio || {}
var bgm;
Audio.loadSound = function(scene)
{
scene.load.audio('login', 'assets/sound/login.ogg');
......@@ -8,33 +9,31 @@ Audio.loadSound = function(scene)
Audio.playSound = function(scene, title) // 한 번만 재생할 때 사용
{
var bgm = scene.sound.add(title);
bgm = scene.sound.add(title);
bgm.play();
}
Audio.loopSound = function(scene, title) // 반복재생할 때 사용
{
var bgm = scene.sound.add(title);
bgm = scene.sound.add(title);
bgm.setLoop(true);
bgm.play();
}
Audio.pauseSound = function(scene, title)
{
var bgm = scene.sound.add(title);
bgm.pause();
}
Audio.resumeSound = function(scene, title)
{
var bgm = scene.sound.add(title);
bgm = scene.sound.resume();
}
Audio.stopSound = function(scene, title)
Audio.killSound = function(scene, title)
{
var bgm = scene.sound.add(title);
bgm.setLoop(false);
bgm.stop();
console.log('killSound');
}
var BackGround = BackGround || {}
BackGround.brainGroup = null;
BackGround.myCharacter = null;
BackGround.loadImage = function(scene)
{
scene.load.image('brainGround', 'assets/image/background/background_brain.png');
scene.load.image('menuBackground', 'assets/placeholder/menuBackground.png')
scene.load.image('menuBackground', 'assets/placeholder/menuBackground.png');
scene.load.image('roomBackground', 'assets/placeholder/roomBackground.png');
}
BackGround.drawCharacter = function(scene)
{
BackGround.myCharacter = scene.add.sprite(640, 615, 'pyeongminWrite').setScale(0.45).setDepth(2);
}
BackGround.drawBrain = function(scene)
......@@ -16,4 +23,9 @@ BackGround.drawBrain = function(scene)
BackGround.drawMenu = function(scene)
{
scene.add.sprite(640, 360, 'menuBackground').setDisplaySize(1282, 722).setDepth(1);
}
BackGround.drawRoom = function(scene)
{
scene.add.sprite(640, 360, 'roomBackground').setDisplaySize(1282, 722).setDepth(1);
}
\ No newline at end of file
......@@ -5,35 +5,99 @@ socket.emit('idRequest');
socket.on('alert', function(msg) // string errorcode
{
let toAlert = 'null alert';
if (msg === 'errNicknameOverlaped') toAlert = '이미 사용중인 닉네임입니다.';
if (msg === 'gameWin') toAlert = '승리!';
alert(toAlert);
//let toAlert = 'null alert';
if (msg === 'errNicknameOverlaped') alert('이미 사용중인 닉네임입니다.');
if (msg === 'gameWin')
{
//toAlert = '승리!';
ScenesData.gameScene.add.text(640, 360, '승리!!!!', {fontSize: '30pt'})
.setPadding(5,5,5,5).setOrigin(0.5, 0.5).setDepth(11)
.setColor('#000000').setBackgroundColor('#ffffff');
}
//alert(toAlert);
});
socket.on('setId', function(msg) // {str, num playerNum}
{
console.log(msg.str);
PlayerData.idNum = msg.num;
PlayerData.id = msg.num;
});
socket.on('enterRoom', function()
{
Audio.killSound(ScenesData.menuScene, 'login');
game.scene.remove('menuScene');
game.scene.start('roomScene');
});
socket.on('setCount', function(msg)
socket.on('syncRoomScene', function(msg)
{
ScenesData.roomScene.isCounting = msg.isEnable;
ScenesData.roomScene.endTime = msg.endTime;
setTimeout(function()
{
for (let i = 0; i < msg.length; i++)
{
let randX = Math.random() * 1120 + 80;
let randY = Math.random() * 380 + 100;
var playerSet =
{
sprite: ScenesData.roomScene.add.sprite(randX, randY, 'playerStand').setOrigin(0.5, 0.5).setScale(0.2, 0.2),
nickname: ScenesData.roomScene.add.text(randX-10, randY-60, msg[i].nickname).setOrigin(0.5,0.5).setColor('#000000').setPadding(0.5,0.5,0.5,0.5),
id: msg[i].id
}
ScenesData.roomScene.players.push(playerSet);
}
}, 100);
});
socket.on('setRoomCount', function(msg)
{
setTimeout(function()
{
ScenesData.roomScene.isCounting = msg.isEnable;
ScenesData.roomScene.endTime = msg.endTime;
ScenesData.roomScene.peopleCount = msg.playerCount;
if (msg.isEnter) // generate charactor
{
let randX = Math.random() * 1120 + 80;
let randY = Math.random() * 380 + 100;
var playerSet =
{
sprite: ScenesData.roomScene.add.sprite(randX, randY, 'playerStand').setOrigin(0.5, 0.5).setScale(0.2, 0.2),
nickname: ScenesData.roomScene.add.text(randX-10, randY-60, msg.player.nickname).setOrigin(0.5,0.5).setColor('#000000').setPadding(0.5,0.5,0.5,0.5),
id: msg.player.id
}
ScenesData.roomScene.players.push(playerSet);
}
else // remove charactor
{
let idx = ScenesData.roomScene.players.findIndex(function(element)
{
return element.id === msg.player.id;
});
if (idx != -1)
{
ScenesData.roomScene.players[idx].sprite.destroy();
ScenesData.roomScene.players[idx].nickname.destroy();
ScenesData.roomScene.players.splice(idx, 1);
}
}
}, 200);
});
// init game
socket.on('syncRoomData', function(msg) // {num roomNum, [] players}
{
console.log(msg);
RoomData.roomNum = msg.roomNum;
//console.log(msg);
RoomData.roomId = msg.roomId;
RoomData.players = msg.players;
RoomData.aliveCount = msg.players.length;
RoomData.players.forEach(function(element)
{
if(element.id === PlayerData.id)
{
RoomData.myself = element;
return;
}
});
});
socket.on('startGame', function()
{
......@@ -54,10 +118,12 @@ socket.on('setPlayerTypingRate', function(msg) // number playerTypingRate
});
socket.on('attacked', function(msg) // object attackData
{
setTimeout(function()
//console.log('attacked by ' + msg.attacker.nickname);
var timeout = setTimeout(function()
{
WordSpace.generateWord.Attack(ScenesData.gameScene, msg.text, msg.grade, msg.attacker, msg.isStrong);
WordSpace.generateWord.Attack(ScenesData.gameScene, msg.text, msg.grade, msg.attacker, msg.isStrong, msg.isCountable);
}, 4000);
console.log(timeout);
});
socket.on('defeat', function(msg) // object player
{
......@@ -81,6 +147,7 @@ socket.on('gameEnd', function(msg) // object player
socket.on('attackSucceed', function(msg)
{
console.log('client');
let tempWord = WordSpace.generateWord.Name(ScenesData.gameScene, true, msg.victim);
tempWord.destroy();
});
......
var Enums = Enums || {};
Enums.characterAnim = { write: 0, attackWrite: 1, throw: 2, hit: 3 }
\ No newline at end of file
WordSpace.startCycle = function(scene)
{
WordSpace.wordCycle.resetCycle(scene, 3000, 0, true);
WordSpace.nameCycle.resetCycle(scene, 3000, 0, true);
WordSpace.varAdjustCycle.resetCycle(scene, 100, 0, true);
WordSpace.playerTypingCycle = setInterval(function()
{
socket.emit('setPlayerTyping', WordSpace.playerTyping);
}, 500);
}
WordSpace.pauseCycle = function(isPause)
{
WordSpace.wordCycle.currentCycle.paused = isPause;
WordSpace.nameCycle.currentCycle.paused = isPause;
WordSpace.varAdjustCycle.currentCycle.paused = isPause;
WordSpace.attackGauge.pauseCycle(isPause);
if (isPause) clearInterval(WordSpace.playerTypingCycle);
else WordSpace.playerTypingCycle = setInterval(function()
{
socket.emit('setPlayerTyping', WordSpace.playerTyping);
}, 500);
}
class Cycle //앞으로 cycle은 이 클래스를 사용해서 구현할 것
{
constructor(_callback)
{
this.delay = 0;
this.currentCycle = null;
this.callbackFunction = _callback;
}
resetCycle(scene, _delay, _startAt, _loop)
{
this.delay = _delay;
var option =
{
startAt: _startAt,
delay: _delay,
callback: this.callbackFunction,
callbackScope: scene,
loop: _loop
};
if (this.currentCycle != null) this.currentCycle = this.currentCycle.reset(option);
else this.currentCycle = scene.time.addEvent(option);
}
}
//단어 생성 사이클
WordSpace.wordCycle = new Cycle(function()
{
WordSpace.genWordByProb(this);
});
//게임 오버 사이클
WordSpace.gameOverCycle = new Cycle(gameOver);
//호패 생성 사이클
WordSpace.nameCycle = new Cycle(function()
{
WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
});
//이건 뭐지
WordSpace.varAdjustCycle = new Cycle(function()
{
//나중에는 메세지 분석해서 Phase랑 playerTypingRate 받겠지만 일단 이렇게 해둠
//WordSpace.GetPhase();
//WordSpace.GetPlayerTypingRate();
WordSpace.AdjustVarByPhase(WordSpace.playerTypingRate, WordSpace.CurrentPhase);
});
\ No newline at end of file
var Input = Input || {};
Input.input = [];
Input.converted = '';
Input.convInput = ''; // converted input
Input.finalInput = '';
Input.isShifted = false;
Input.isEntered = false;
......@@ -16,19 +18,19 @@ Input.gameSceneEnterReaction = function()
{
if (!Input.isEntered)
{
if (Input.attackMode) WordSpace.attack(Input.removeConVow(Input.convInput), Input.attackOption.wordGrade);
else WordSpace.findWord(Input.convInput);
if (Input.attackMode) WordSpace.attack(Input.removeConVow(Input.finalInput), Input.attackOption.wordGrade);
else WordSpace.findWord(Input.finalInput);
Input.reset();
Input.isEntered = true;
}
}
Input.menuSceneEnterReaction = function()
{
Input.convInput = Input.removeConVow(Input.convInput);
if (Input.convInput.length > 1)
Input.finalInput = Input.removeConVow(Input.finalInput);
if (Input.finalInput.length > 1)
{
socket.emit('setNickname', Input.convInput);
PlayerData.nickname = Input.convInput;
socket.emit('setNickname', Input.finalInput);
PlayerData.nickname = Input.finalInput;
Input.reset();
}
else
......@@ -41,11 +43,13 @@ Input.menuSceneEnterReaction = function()
Input.reset = function()
{
Input.input = [];
Input.convInput = [];
Input.inputField.text.setText(Input.convInput);
Input.converted = '';
Input.convInput = '';
Input.finalInput = '';
Input.inputField.text.setText(Input.finalInput);
}
// convert input to convInput
// convert input to finalInput
Input.convert = function()
{
// input -> krInput with vowels
......@@ -95,7 +99,7 @@ Input.convert = function()
//console.log(vowels);
//console.log(krInput);
this.convInput = "";
this.convInput = '';
let vowelIdx = 0;
if (vowelIdx === vowels.length) this.convInput = krInput; // 모음이 없을때
else // 모음이 존재할때
......@@ -193,6 +197,14 @@ Input.convert = function()
}
}
}
if (this.convInput.length > 1)
{
if (this.convInput[1].charCodeAt(0) > ''.charCodeAt(0)) Input.input.splice(0, this.input.length - 2);
else Input.input.splice(0, this.input.length - 1);
this.converted += this.convInput.slice(0, 1);
this.convInput = this.convInput.slice(1, 2);
}
Input.finalInput = Input.converted + Input.convInput;
return true;
//console.log('_____end_convert_____');
}
......@@ -304,8 +316,8 @@ Input.inputField =
{
generate: function(scene, enterCallback)
{
this.background = scene.add.sprite(640, 550, 'inputfield').setDepth(10);
this.text = scene.add.text(640, 550, "안녕하세요", {font: '25pt 궁서'}).setOrigin(0.5, 0.5).setColor('#000000').setDepth(10);
this.background = scene.add.sprite(640, 500, 'inputfield').setDepth(10);
this.text = scene.add.text(640, 500, "", {font: '25pt 궁서'}).setOrigin(0.5, 0.5).setColor('#000000').setDepth(10);
scene.input.keyboard.on('keyup', function() {Input.pressCount--; Input.justPressed = ''})
scene.input.keyboard.on('keydown-SHIFT', function() {Input.isShifted = true});
......@@ -317,8 +329,15 @@ Input.inputField =
{
Input.input.pop();
Input.convert();
Input.inputField.text.setText(Input.convInput);
Input.inputField.text.setText(Input.finalInput);
}
else if (Input.converted.length > 0)
{
Input.converted = Input.converted.slice(0, Input.converted.length - 1);
Input.finalInput = Input.converted + Input.convInput;
Input.inputField.text.setText(Input.finalInput);
}
else Input.reset();
});
scene.input.keyboard.on('keydown-ENTER', enterCallback);
scene.input.keyboard.on('keyup-ENTER', function(){Input.isEntered = false;})
......@@ -381,11 +400,11 @@ Input.pushInput = function(inputKey)
else output = inputKey.charCodeAt(0);
this.input.push(output);
//console.log(Input.input);
if (!this.convert() || this.convInput.length > this.maxInput)
if (!this.convert() || this.finalInput.length > this.maxInput)
{
this.input.pop();
this.convert();
}
this.inputField.text.setText(Input.convInput);
this.inputField.text.setText(Input.finalInput);
}
}
\ No newline at end of file
......@@ -24,6 +24,7 @@ var menuScene = new Phaser.Class(
Audio.loopSound(this, 'login');
Input.inputField.generate(this, Input.menuSceneEnterReaction);
BackGround.drawMenu(this);
}
});
......@@ -41,26 +42,64 @@ var roomScene = new Phaser.Class(
preload: function()
{
ScenesData.roomScene = this;
BackGround.loadImage(this);
this.load.image('playerStand', 'assets/image/character/pyeongmin/pyeong_stand.png');
},
create: function()
{
BackGround.drawRoom(this);
this.players = [];
this.isCounting = false;
this.isCountEnd = false;
this.endTime = 0;
this.countText = this.add.text(640, 360, '사람들을 위해 대기중입니다...').setOrigin(0.5, 0.5).setColor('#000000');
this.peopleCount = 1;
this.countText = this.add.text(640, 360, '사람들을 위해 대기중입니다...').setOrigin(0.5, 0.5).setColor('#000000').setBackgroundColor('#ffffff').setDepth(10).setPadding(5,5,5,5);
this.peopleText = this.add.text(640, 80, '1 / 10').setOrigin(0.5, 0.5).setColor('#000000').setBackgroundColor('#ffffff').setDepth(10);
},
update: function()
{
this.peopleText.setText(this.peopleCount + ' / 10');
if (this.isCounting)
{
this.countText.setText((this.endTime - Date.now()) / 1000);
if (this.endTime - Date.now() < 0)
this.countText.setText(((this.endTime - Date.now()) / 1000).toFixed(1));
if (this.endTime < Date.now())
{
socket.emit('endCount');
//console.log('end Count');
setTimeout(() => {
socket.emit('endCount');
}, (Phaser.Math.Distance.Between(0, 0, 640, 800) * 3));
this.isCounting = false;
this.isCountEnd = true;
this.players.forEach(function(element){
element.follower = { t: 0, vec: new Phaser.Math.Vector2() };
element.path = new Phaser.Curves.Line([
element.sprite.x, element.sprite.y,
640, 800
]);
ScenesData.roomScene.tweens.add({
targets: element.follower,
t: 1,
ease: 'Linear',
duration: Phaser.Math.Distance.Between(element.sprite.x, element.sprite.y, 640, 800) * 3,
repeat: 0
});
});
}
}
else if (this.isCountEnd)
{
this.players.forEach(function(element){
element.path.getPoint(element.follower.t, element.follower.vec);
element.sprite.setPosition(element.follower.vec.x, element.follower.vec.y);
element.nickname.setPosition(element.sprite.x - 10, element.sprite.y - 60);
});
this.countText.setText('잠시만 기다려주세요...');
}
else
{
this.countText.setText('사람들을 위해 대기중입니다...');
......@@ -91,8 +130,12 @@ var gameScene = new Phaser.Class(
create: function()
{
WordSpace.gameTimer = new Phaser.Time.Clock(this);
WordSpace.gameTimer.start();
WordSpace.loadAnimation(this);
CSVParsing.CSVParse(this);
BackGround.drawBrain(this);
BackGround.drawCharacter(this);
Audio.playSound(this, 'startGame');
WordSpace.wordPhysicsGroup = this.physics.add.group();
......@@ -101,28 +144,15 @@ var gameScene = new Phaser.Class(
WordSpace.spaceInitiate(this);
WordSpace.attackGauge.resetCycle(this);
WordSpace.wordCycle.resetCycle(this, 3000, 0, true);
WordSpace.nameCycle.resetCycle(this, 3000, 0, true);
WordSpace.varAdjustCycle.resetCycle(this, 100, 0, true);
WordSpace.playerTypingCycle = setInterval(function()
{
socket.emit('setPlayerTyping', WordSpace.playerTyping);
}, 500);
WordSpace.startCycle(this);
WordSpace.setPlayerTyping.initiate(this);
WordSpace.nameWordTextForTest = ScenesData.gameScene.add.text(50,400,'현재 가진 호패들 : 없음').setDepth(10).setColor('#000000');
WordSpace.nameQueue.initiate();
RoomData.players.forEach(function(element)
{
if(element.nickname == PlayerData.nickname)
{
RoomData.myself = element;
return;
}
});
console.log(RoomData.myself);
WordSpace.test = WordSpace.generateWord.Name(this, false, null);
// for test
WordSpace.attackGauge.add(11);
},
update: function()
......@@ -139,6 +169,7 @@ var gameScene = new Phaser.Class(
let tempNames = '';
WordSpace.nameGroup.forEach(function(element)
{
//테스트용
tempNames += element.wordText + (element.isStrong?' [강]':'') + '\n';
});
......
class WordObject
{
constructor(text, isNameWord = false)
{
this.generationCode = WordSpace.nextWordCode++;
this.wordText = text;
this.wordTyping = WordReader.getWordTyping(this.wordText);
this.wordGrade = WordReader.getWordGrade(this.wordTyping);
this.wordWeight = WordReader.getWordWeight(this.wordGrade);
this.wordWeight = WordReader.normalWeight[3 - this.wordGrade];
//console.log("wordTyping : " + this.wordTyping + '\n' + "wordGrade : " + this.wordGrade + '\n' + "wordWeight : " + this.wordWeight + '\n');
this.wordSpeed = 0.5;
this.isNameWord = isNameWord;
......@@ -30,7 +31,7 @@ class WordObject
}
else
{
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, (this.isStrong ? 'strongBgr' : 'nameBgr') + Math.min(Math.max(2, this.wordText.length), 6))
.setMass(this.wordWeight * 10)
.setScale(this.scale)
.setFrictionX(0)
......@@ -49,10 +50,11 @@ class WordObject
{
fontSize: (this.scale * this.fontScale) +'pt',
fontFamily: '"궁서", 궁서체, serif',
fontStyle: (this.wordWeight > 5 ? 'bold' : '')
//fontStyle: (this.wordWeight > 5 ? 'bold' : '')
});
if (!this.isNameWord) this.wordObj.setColor('#000000').setOrigin(0.5,0.5);
else this.wordObj.setColor('#ffffff').setOrigin(0.45,0.5);
this.createdTime = WordSpace.gameTimer.now;
WordSpace.totalWeight += this.wordWeight;
WordSpace.totalWordNum += 1;
WordSpace.setGameOverTimer();
......@@ -70,14 +72,18 @@ class WordObject
const forceIdx = WordSpace.wordForcedGroup.findIndex(function(item) {return this.isEqualObject(item.generationCode)}, this);
if (forceIdx > -1) WordSpace.wordForcedGroup.splice(forceIdx, 1);
WordSpace.wordPhysicsGroup.remove(this.physicsObj);
let breakAnim = ScenesData.gameScene.add.sprite(this.physicsObj.x, this.physicsObj.y, 'wordBreak').setScale(0.5).setDepth(3).play('wordBreakAnim');
setTimeout(function() {
breakAnim.destroy();
}, 200);
if(!this.isNameWord)
{
this.wordObj.destroy();
this.physicsObj.destroy();
}
BackGround.myCharacter.play(WordSpace.pyeongminAnims[Enums.characterAnim.write]);
}
attract()
{
if(!this.moveStarted)
......@@ -132,20 +138,50 @@ class NormalWord extends WordObject
class AttackWord extends WordObject
{
constructor(text, _wordGrade, _playerData, isStrong)
constructor(text, _wordGrade, _playerData, _isStrong, _isCountable = true, lenRate)
{
super(text);
this.wordGrade = _wordGrade;
this.wordWeight = WordReader.getWordWeight(this.wordGrade);
this.wordWeight = _isStrong ? WordReader.strongAttackWeight[3 - this.wordGrade] : WordReader.attackWeight[3 - this.wordGrade];
if(WordReader.getWordTyping(_playerData.nickname) > 9)
this.wordWeight += this.wordWeight * 0.2 * (WordReader.getWordTyping(_playerData.nickname) - 9);
this.wordWeight *= isStrong ? 3 : 2;
this.attacker = _playerData;
this.counterTime = WordSpace.gameTimer.now + 1000 * (this.wordTyping <= (5 - _wordGrade) * 2.5 ? this.wordTyping / (Math.max(200, WordSpace.playerTyping) / 60) * 1.5 :
if(!_isCountable) this.counterTime = 0;
else this.counterTime = WordSpace.gameTimer.now + 1000 * (this.wordTyping <= (5 - _wordGrade) * 2.5 ? this.wordTyping / (Math.max(200, WordSpace.playerTyping) / 60) * 1.5 :
((5 - _wordGrade) * 3 + (this.wordTyping - (5 - _wordGrade) * 2.5) * 2.5) / (Math.max(200, WordSpace.playerTyping) / 60) * 1.5);
console.log('Attack text : ' + text + ', Attacker : ' + this.attacker.nickname + ', Weight : ' + this.wordWeight);
console.log('Counter time : ' + this.counterTime);
}
instantiate(scene, lenRate)
{
super.instantiate(scene, lenRate);
this.maskBackground = scene.physics.add.sprite(this.physicsObj.x, this.physicsObj.y, 'wordBgr' + this.wordGrade + '_' + Math.min(Math.max(2, this.wordText.length), 6))
.setTint(Phaser.Display.Color.GetColor(120, 120, 120)).setScale(this.scale);
this.maskBackground.alpha = 0.5;
this.shape = scene.make.graphics();
var rect = new Phaser.Geom.Rectangle(0, 0, this.maskBackground.width * this.scale, this.maskBackground.height * this.scale);
this.shape.fillStyle(0xffffff).fillRectShape(rect);
this.mask = this.shape.createGeometryMask();
this.maskBackground.setMask(this.mask);
this.maskStart = this.physicsObj.x;
this.maskEnd = this.physicsObj.x - this.physicsObj.width * this.scale;
}
attract()
{
super.attract();
if(WordSpace.gameTimer.now < this.counterTime)
{
this.maskBackground.setPosition(this.physicsObj.x, this.physicsObj.y);
this.shape.x = this.physicsObj.x + (this.maskEnd - this.maskStart) *
((WordSpace.gameTimer.now - this.createdTime) / (this.counterTime - this.createdTime)) - this.physicsObj.width * this.scale / 2;
this.shape.y = this.physicsObj.y - this.physicsObj.height * this.scale / 2;
}
else if(this.maskBackground != null) this.maskBackground.destroy();
}
destroy()
{
switch(this.wordGrade)
......@@ -159,9 +195,22 @@ class AttackWord extends WordObject
if(WordSpace.gameTimer.now < this.counterTime)
{
let tempWord = WordSpace.generateWord.Name(ScenesData.gameScene, true, this.attacker);
tempWord.physicsObj.setPosition(this.physicsObj.x, this.physicsObj.y);
tempWord.wordObj.setPosition(tempWord.physicsObj.x, tempWord.physicsObj.y);
tempWord.destroy();
let attackData =
{
roomNum: RoomData.roomId,
attacker: RoomData.myself,
target: this.attacker.id,
text: this.wordText,
grade: Math.min(3, this.wordGrade + 1),
isStrong: false,
isCountable: false
}
socket.emit('attack', attackData);
}
//WordSpace.nameGroup.push(new NameWord(this.attacker, true));
if(this.maskBackground != null) this.maskBackground.destroy();
super.destroy();
}
}
......@@ -180,7 +229,8 @@ class NameWord extends WordObject
attract()
{
if(this.isActive) super.attract();
else{
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);
......@@ -212,8 +262,8 @@ class NameWord extends WordObject
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.physicsObj.setVelocity(0, 0).setDepth(20);
this.wordObj.setPosition(this.physicsObj.x, this.physicsObj.y).setDepth(20);
this.follower = { t: 0, vec: new Phaser.Math.Vector2() };
this.path = new Phaser.Curves.Spline([
this.physicsObj.x, this.physicsObj.y,
......
......@@ -54,9 +54,6 @@ WordReader.getWordGrade = function(_wordTyping)
17 <= _wordTyping && _wordTyping < 26 ? 0 : -1;
}
WordReader.getWordWeight = function(_wordGrade)
{
return _wordGrade == 3 ? 3 :
_wordGrade == 2 ? 5 :
_wordGrade == 1 ? 7 : 10;
}
\ No newline at end of file
WordReader.normalWeight = [3, 5, 7, 10];
WordReader.attackWeight = [6, 8, 12, 15];
WordReader.strongAttackWeight = [10, 13, 16, 20];
\ No newline at end of file
var WordSpace = WordSpace || {};
WordSpace.test = null;
// for test
WordSpace.weightTextObjForTest = null;
WordSpace.nameWordTextForTest = null;
......@@ -14,6 +12,7 @@ WordSpace.totalWordNum = 0;
WordSpace.brainCapacity = 200; //수용 가능한 단어 무게 최대치
WordSpace.gameTimer = null; //현재 게임 플레이 시간 타이머
WordSpace.isTimerOn = false;
WordSpace.pyeongminAnims = [];
WordSpace.wordGroup = [];
WordSpace.nameGroup = [];
......@@ -35,56 +34,10 @@ WordSpace.delay =
GameOver: 5000,
}
WordSpace.playerTypingCycle = null;
WordSpace.NameSpawnReduce = 1000;
WordSpace.gravityPoint = {x: 640, y: 280};
class Cycle //앞으로 cycle은 이 클래스를 사용해서 구현할 것
{
constructor(_callback)
{
this.delay = 0;
this.currentCycle = null;
this.callbackFunction = _callback;
}
resetCycle(scene, _delay, _startAt, _loop)
{
this.delay = _delay;
var option =
{
startAt: _startAt,
delay: _delay,
callback: this.callbackFunction,
callbackScope: scene,
loop: _loop
};
if (this.currentCycle != null) this.currentCycle = this.currentCycle.reset(option);
else this.currentCycle = scene.time.addEvent(option);
}
}
//단어 생성 사이클
WordSpace.wordCycle = new Cycle(function()
{
WordSpace.genWordByProb(this);
});
//게임 오버 사이클
WordSpace.gameOverCycle = new Cycle(gameOver);
//호패 생성 사이클
WordSpace.nameCycle = new Cycle(function()
{
WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
});
//이건 뭐지
WordSpace.varAdjustCycle = new Cycle(function()
{
//나중에는 메세지 분석해서 Phase랑 playerTypingRate 받겠지만 일단 이렇게 해둠
//WordSpace.GetPhase();
//WordSpace.GetPlayerTypingRate();
WordSpace.AdjustVarByPhase(WordSpace.playerTypingRate, WordSpace.CurrentPhase);
});
WordSpace.getSpawnPoint = function(_lenRate)
{
let lenRate = 1;
......@@ -159,7 +112,7 @@ WordSpace.attackGauge =
setRect: function()
{
this.rectUI.setSize(20 * this.value, 11);
this.rectUI.setPosition(640 - 10 * this.value, 597);
this.rectUI.setPosition(640 - 10 * this.value, 547);
let tmp = this.getAttackOption();
this.rectUI.setFillStyle(Phaser.Display.Color.HexStringToColor(this.gradeColor[tmp.wordGrade + 1]).color);
},
......@@ -238,12 +191,48 @@ WordSpace.loadImage = function(scene)
for (let i = 2; i < 7; i++)
{
scene.load.image('nameBgr' + i, 'assets/placeholder/name' + i + '.png');
scene.load.image('strongBgr' + i, 'assets/placeholder/strong' + i + '.png');
}
scene.load.spritesheet('wordBreak', 'assets/image/word/wordbreak.png', { frameWidth: 180, frameHeight: 180 });
scene.load.spritesheet('pyeongminWrite', 'assets/image/character/pyeongmin/write/pyeong_write.png', { frameWidth: 490, frameHeight: 423 });
scene.load.spritesheet('pyeongminThrow', 'assets/image/character/pyeongmin/throw/pyeong_throw.png', { frameWidth: 490, frameHeight: 423 });
WordSpace.weightTextObjForTest = scene.add.text(100, 75, '뇌의 무게: (현재) 0 / 100 (전체)').setDepth(10).setColor('#000000');
WordSpace.weightTextObjForTest = scene.add.text(100, 75, '뇌의 무게: (현재) 0 / ' + this.brainCapacity + ' (전체)').setDepth(10).setColor('#000000');
WordSpace.killLogTextForTest = scene.add.text(1000, 50, WordSpace.killLogForTest).setDepth(10).setColor('#000000').setAlign('right');
}
WordSpace.loadAnimation = function(scene)
{
scene.anims.create({
key: 'wordBreakAnim',
frames: scene.anims.generateFrameNumbers('wordBreak'),
frameRate: 10,
repeat: 0,
hideOnComplete: false
});
WordSpace.pyeongminAnims[Enums.characterAnim.write] = scene.anims.create({
key: 'pyeongminWriteAnim',
frames: scene.anims.generateFrameNumbers('pyeongminWrite'),
frameRate: 10,
repeat: 0,
hideOnComplete: false
});
WordSpace.pyeongminAnims[Enums.characterAnim.attackWrite] = scene.anims.create({
key: 'pyeongminattackWriteAnim',
frames: scene.anims.generateFrameNumbers('pyeongminWrite'),
frameRate: 10,
repeat: -1,
hideOnComplete: false
});
WordSpace.pyeongminAnims[Enums.characterAnim.throw] = scene.anims.create({
key: 'pyeongminThrowAnim',
frames: scene.anims.generateFrameNumbers('pyeongminThrow'),
frameRate: 10,
repeat: 0,
hideOnComplete: false
});
}
WordSpace.generateWord =
{
Normal: function(scene, grade, lenRate)
......@@ -252,9 +241,9 @@ WordSpace.generateWord =
WordSpace.pushWord(scene, word, lenRate);
return word;
},
Attack: function(scene, wordText, grade, attacker, isStrong, lenRate)
Attack: function(scene, wordText, grade, attacker, isStrong, isCountable, lenRate)
{
word = new AttackWord(wordText, grade, attacker, isStrong);
word = new AttackWord(wordText, grade, attacker, isStrong, isCountable);
WordSpace.pushWord(scene, word, lenRate);
return word;
},
......@@ -284,14 +273,14 @@ WordSpace.pushWord = function(scene, word, lenRate)
function gameOver()
{
WordSpace.wordCycle.currentCycle.remove();
WordSpace.nameCycle.currentCycle.remove();
WordSpace.varAdjustCycle.currentCycle.remove();
clearInterval(WordSpace.playerTypingCycle);
//To Do
WordSpace.pauseCycle(true);
socket.emit('defeated');
console.log('defeat');
alert('defeat');
ScenesData.gameScene.add.text(640, 360, '패배', {fontSize: '30pt'})
.setPadding(5,5,5,5).setOrigin(0.5, 0.5).setDepth(10)
.setColor('#000000').setBackgroundColor('#ffffff');
//alert('defeat');
}
//게임 오버 판정을 위한 타이머
......@@ -337,7 +326,7 @@ WordSpace.findWord = function(wordText)
}
WordSpace.setPlayerTyping.add(wordText);
}
else if (wordText === '공격' && WordSpace.attackGauge.value >= 3) // 공격모드 진입.
else if (wordText === '공격' && WordSpace.attackGauge.value >= 3 && WordSpace.nameGroup.length > 0) // 공격모드 진입.
{
console.log('attack mode');
Input.attackOption = this.attackGauge.getAttackOption();
......@@ -345,6 +334,8 @@ WordSpace.findWord = function(wordText)
Input.attackMode = true;
WordSpace.attackGauge.pauseCycle(true);
WordSpace.setPlayerTyping.add(wordText);
BackGround.myCharacter.play(WordSpace.pyeongminAnims[Enums.characterAnim.attackWrite]);
BackGround.myCharacter.anims.msPerFrame /= (4 - WordSpace.attackGauge.getAttackOption().wordGrade);
}
else // 오타 체크
{
......@@ -366,9 +357,9 @@ WordSpace.findWord = function(wordText)
console.log('Attack word : ' + element.wordText + ' of ' + element.attacker.nickname + ' 오타임');
let victimData =
{
roomNum: RoomData.roomNum,
roomNum: RoomData.roomId,
victim: RoomData.myself,
target: element.attacker.idNum
target: element.attacker.id
}
socket.emit('defenseFailed', victimData);
return true;
......@@ -389,8 +380,6 @@ WordSpace.setPlayerTyping =
},
initiate: function(scene)
{
WordSpace.gameTimer = new Phaser.Time.Clock(scene);
WordSpace.gameTimer.start();
this.text = scene.add.text(100,200,'현재 타수 : ' + WordSpace.playerTyping.toFixed(1)).setDepth(10).setColor('#000000');
}
}
......@@ -403,10 +392,11 @@ WordSpace.attack = function(wordText, grade)
console.log('attack ' + wordText + ', grade: ' + grade);
WordSpace.nameGroup.forEach(function(element)
{
//console.log(RoomData.myself);
let attackData =
{
roomNum: RoomData.roomNum,
attacker: PlayerData,
roomNum: RoomData.roomId,
attacker: RoomData.myself,
target: element.ownerId,
text: wordText,
grade: grade,
......@@ -422,6 +412,7 @@ WordSpace.attack = function(wordText, grade)
WordSpace.attackGauge.resetValue();
WordSpace.setPlayerTyping.add(wordText);
BackGround.myCharacter.play(WordSpace.pyeongminAnims[Enums.characterAnim.throw]);
}
else WordSpace.attackGauge.cutValue(0.3);
Input.maxInput = 6;
......@@ -434,8 +425,10 @@ WordSpace.nameQueue =
queue: [],
shuffle: function()
{
let tempIdx, tempElement, tempLength;
let tempQueue = RoomData.players;
let tempIdx, tempElement, tempLength, tempQueue = [];
RoomData.players.forEach(function(element){
tempQueue.push(element.index)
})
for(tempLength = tempQueue.length; tempLength; tempLength -= 1)
{
tempIdx = Math.floor(Math.random() * tempLength);
......@@ -445,7 +438,7 @@ WordSpace.nameQueue =
}
tempQueue.forEach(function(element)
{
if(element.id != PlayerData.idNum && element.isAlive)
if(RoomData.players[element].id != PlayerData.id && RoomData.players[element].isAlive)
WordSpace.nameQueue.queue.push(element);
});
},
......@@ -453,7 +446,8 @@ WordSpace.nameQueue =
{
let tempElement = WordSpace.nameQueue.queue.shift();
if(WordSpace.nameQueue.queue.length <= RoomData.aliveCount) this.shuffle();
return tempElement;
if(!RoomData.players[tempElement].isAlive) return WordSpace.nameQueue.pop();
else return RoomData.players[tempElement];
},
initiate: function()
{
......
......@@ -23,13 +23,13 @@ var game = new Phaser.Game(config)
//테스트용이므로 차후 수정 요망
var PlayerData = PlayerData || {};
PlayerData.idNum = -1; //플레이어 아이디, 고유 번호
PlayerData.id = -1; //플레이어 아이디, 고유 번호
PlayerData.nickname = '홍길동'; //플레이어 닉네임
// 현재 들어가있는 Game Room의 정보
var RoomData = RoomData || {};
RoomData.roomNum = -1;
RoomData.roomId = -1;
RoomData.myself = null;
RoomData.players = null;
RoomData.aliveCount = -1;
\ No newline at end of file
......@@ -25,12 +25,11 @@ io.on('connection', function(socket)
{
id: GameServer.getPlayerNumber(),
nickname: '게스트',
socketId: socket,
currentRoom: null,
playingData: null,
isReceivable: false
};
GameServer.currentPlayer.push(socket.playerData);
GameServer.currentPlayer.push(socket);
console.log('['+socket.playerData.id+'] client request');
socket.emit('setId',
{
......@@ -44,32 +43,37 @@ io.on('connection', function(socket)
let isAlreadyHave = false;
GameServer.currentPlayer.forEach(function(element)
{
if (element.nickname === msg) isAlreadyHave = true;
if (element.playerData.nickname === msg) isAlreadyHave = true;
});
if (isAlreadyHave) socket.emit('alert' ,'errNicknameOverlaped');
else
{
socket.playerData.nickname = msg;
console.log('['+socket.playerData.id+'] nickname set to ' + msg);
GameServer.enterEmptyRoom(socket.playerData);
GameServer.enterEmptyRoom(socket);
}
});
socket.on('setPlayerTyping', function(msg) // number playerTyping
{
socket.playerData.playingData.playerTyping = msg;
if (socket.playerData.currentRoom.maxTypingPlayer.playerTyping < msg)
try
{
socket.playerData.currentRoom.maxTypingPlayer = socket.playerData.playingData;
socket.playerData.playingData.playerTyping = msg;
if (socket.playerData.currentRoom.maxTypingPlayer.playerTyping < msg)
{
socket.playerData.currentRoom.maxTypingPlayer = socket.playerData.playingData;
}
if (socket.playerData.currentRoom.minTypingPlayer.playerTyping > msg)
{
socket.playerData.currentRoom.minTypingPlayer = socket.playerData.playingData;
}
let playerTypingRate = (msg - (socket.playerData.currentRoom.minTypingPlayer.playerTyping - socket.playerData.currentRoom.rateArrangePoint)) /
(socket.playerData.currentRoom.maxTypingPlayer.playerTyping - socket.playerData.currentRoom.minTypingPlayer.playerTyping + socket.playerData.currentRoom.rateArrangePoint * 2);
socket.emit('setPlayerTypingRate', playerTypingRate);
}
if (socket.playerData.currentRoom.minTypingPlayer.playerTyping > msg)
catch (e)
{
socket.playerData.currentRoom.minTypingPlayer = socket.playerData.playingData;
}
let playerTypingRate = (msg - (socket.playerData.currentRoom.minTypingPlayer.playerTyping - socket.playerData.currentRoom.rateArrangePoint)) /
(socket.playerData.currentRoom.maxTypingPlayer.playerTyping - socket.playerData.currentRoom.minTypingPlayer.playerTyping + socket.playerData.currentRoom.rateArrangePoint * 2);
socket.emit('setPlayerTypingRate', playerTypingRate);
});
socket.on('endCount', function()
......@@ -77,42 +81,43 @@ io.on('connection', function(socket)
socket.playerData.currentRoom.aliveCount--;
if (socket.playerData.currentRoom.aliveCount === 0)
{
GameServer.startRoom(GameServer.findRoomIndex(socket.playerData.currentRoom.roomNum));
socket.playerData.currentRoom.startRoom();
}
});
socket.on('attack', function(msg)
{
GameServer.announceToTarget(GameServer.findRoomIndex(msg.roomNum), msg.target, 'attacked', msg);
let target = GameServer.findPlayer(msg.target);
socket.playerData.currentRoom.announceToTarget(msg.target, 'attacked', msg);
//console.log('attack ' + msg.target + ' by ' + msg.attacker.id + ' with ' + msg.text);
let target = GameServer.findPlayerSocket(msg.target);
if (target != null)
{
let dataToPush =
{
attackerId: msg.attacker.idNum,
attackerId: msg.attacker.id,
attacker: msg.attacker.nickname,
word: msg.text,
wordGrade: msg.grade,
time: Date.now()
}
if (target.playingData.lastAttacks.length < 5) target.playingData.lastAttacks.push(dataToPush);
if (target.playerData.playingData.lastAttacks.length < 5) target.playerData.playingData.lastAttacks.push(dataToPush);
else
{
target.playingData.lastAttacks.splice(0, 1);
target.playingData.lastAttacks.push(dataToPush);
target.playerData.playingData.lastAttacks.splice(0, 1);
target.playerData.playingData.lastAttacks.push(dataToPush);
}
}
});
socket.on('defeated', function()
{
GameServer.playerDefeat(socket.playerData);
socket.playerData.playingData.defeat();
});
socket.on('defenseFailed', function(msg)
{
GameServer.announceToTarget(GameServer.findRoomIndex(msg.roomNum), msg.target, 'attackSucceed', msg);
socket.playerData.currentRoom.announceToTarget(msg.target, 'attackSucceed', msg);
});
socket.on('disconnect', function(reason)
......@@ -128,25 +133,38 @@ io.on('connection', function(socket)
console.log('['+ data.id +'] client disconnected, reason: ' + reason);
let idxToDel = GameServer.currentPlayer.findIndex(function(element)
{
return element.id === data.id;
return element.playerData.id === data.id;
});
if (idxToDel != -1)
{
GameServer.currentPlayer.splice(idxToDel, 1);
// 룸에서도 제거
if (data.currentRoom != null)
{
if (data.currentRoom.currentPhase === GameServer.Phase.READY)
if (data.currentRoom.currentPhase === GameServer.Phase.READY || data.currentRoom.currentPhase === GameServer.Phase.COUNT)
{
data.currentRoom.currentPlayer[data.playingData.index] = null;
data.currentRoom.currentSocket[data.playingData.index] = null;
data.currentRoom.exitRoom(data.id);
if (data.currentRoom.aliveCount < data.currentRoom.startCount)
{
data.currentRoom.announceToRoom('setRoomCount',
{
isEnable: false, endTime: 0, playerCount: data.currentRoom.currentPlayer.length,
isEnter: false, player: data.playingData
});
data.currentRoom.currentPhase = GameServer.Phase.READY;
}
else data.currentRoom.announceToRoom('setRoomCount',
{
isEnable: true, endTime: data.currentRoom.endTime, playerCount: data.currentRoom.currentPlayer.length,
isEnter: false, player: data.playingData
});
}
else if (data.playingData.isAlive)
{
GameServer.playerDefeat(socket.playerData);
data.playingData.defeat();
data.currentRoom.announceToRoom('userDisconnect', data.playingData);
}
GameServer.announceToRoom(GameServer.findRoomIndex(data.currentRoom.roomNum), 'userDisconnect', data.playingData);
}
GameServer.currentPlayer.splice(idxToDel, 1);
}
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