Commit c4c6438f authored by 18손재민's avatar 18손재민

Merge branch 'wordspace'

parents e2b52595 e180f83c
......@@ -288,6 +288,7 @@ class Player
this.gameRoomId = gameRoom.roomId;
this.index = gameRoom.currentPlayer.length;
this.nickname = playerData.nickname;
this.position = null;
this.isAlive = true;
this.rank = -1;
......
......@@ -2,6 +2,15 @@ var BackGround = BackGround || {}
BackGround.brainGroup = null;
BackGround.myCharacter = null;
BackGround.characterPos = [
new Phaser.Math.Vector2(100, 99), new Phaser.Math.Vector2(248, 198), new Phaser.Math.Vector2(412, 144), new Phaser.Math.Vector2(124, 393),
new Phaser.Math.Vector2(368, 336), new Phaser.Math.Vector2(272, 453), new Phaser.Math.Vector2(100, 595), new Phaser.Math.Vector2(284, 678),
new Phaser.Math.Vector2(444, 639), new Phaser.Math.Vector2(116, 799), new Phaser.Math.Vector2(413, 789), new Phaser.Math.Vector2(280, 916),
new Phaser.Math.Vector2(1437, 157), new Phaser.Math.Vector2(1672, 95), new Phaser.Math.Vector2(1832, 166), new Phaser.Math.Vector2(1581, 239),
new Phaser.Math.Vector2(1779, 311), new Phaser.Math.Vector2(1595, 414), new Phaser.Math.Vector2(1774, 480), new Phaser.Math.Vector2(1501, 563),
new Phaser.Math.Vector2(1736, 655), new Phaser.Math.Vector2(1446, 770), new Phaser.Math.Vector2(1656, 894), new Phaser.Math.Vector2(1826, 819),
]
BackGround.otherCharacters = [];
BackGround.loadImage = function(scene)
{
......@@ -12,20 +21,31 @@ BackGround.loadImage = function(scene)
BackGround.drawCharacter = function(scene)
{
BackGround.myCharacter = scene.add.sprite(640, 615, 'pyeongminWrite').setScale(0.45).setDepth(2);
BackGround.myCharacter = scene.add.sprite(game.config.width / 2, game.config.height * 41 / 48, 'pyeongminWrite').setScale(0.45).setDepth(2);
BackGround.characterPos = BackGround.characterPos.sort(function(){return 0.5-Math.random()});
RoomData.players.forEach(function(element){
if(element.id != RoomData.myself.id)
{
element.position = BackGround.characterPos.pop();
element.playerImage = scene.add.sprite(element.position.x, element.position.y, 'pyeongminWrite').setScale(0.45).setDepth(1);
element.playerImage.flipX = element.position.x < game.config.width / 2 ? true : false;
element.nicknameText = scene.add.text(element.position.x, element.position.y - 90, element.nickname)
.setOrigin(0.5,0.5).setColor('#000000').setPadding(0.5,0.5,0.5,0.5).setDepth(1);
6 }
});
}
BackGround.drawBrain = function(scene)
{
brains = scene.add.sprite(640, 360, 'brainGround').setDisplaySize(1282, 722).setDepth(1);
brains = scene.add.sprite(game.config.width / 2, game.config.height / 2, 'brainGround').setDisplaySize(game.config.width, game.config.height).setDepth(1);
}
BackGround.drawMenu = function(scene)
{
scene.add.sprite(640, 360, 'menuBackground').setDisplaySize(1282, 722).setDepth(1);
scene.add.sprite(game.config.width / 2, game.config.height / 2, 'menuBackground').setDisplaySize(game.config.width, game.config.height).setDepth(1);
}
BackGround.drawRoom = function(scene)
{
scene.add.sprite(640, 360, 'roomBackground').setDisplaySize(1282, 722).setDepth(1);
scene.add.sprite(game.config.width / 2, game.config.height / 2, 'roomBackground').setDisplaySize(game.config.width, game.config.height).setDepth(1);
}
\ No newline at end of file
......@@ -10,7 +10,7 @@ socket.on('alert', function(msg) // string errorcode
if (msg === 'gameWin')
{
//toAlert = '승리!';
ScenesData.gameScene.add.text(640, 360, '승리!!!!', {fontSize: '30pt'})
ScenesData.gameScene.add.text(game.config.width / 2, game.config.height / 2, '승리!!!!', {fontSize: '30pt'})
.setPadding(5,5,5,5).setOrigin(0.5, 0.5).setDepth(11)
.setColor('#000000').setBackgroundColor('#ffffff');
......
......@@ -316,8 +316,8 @@ Input.inputField =
{
generate: function(scene, enterCallback)
{
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);
this.background = scene.add.sprite(game.config.width / 2, game.config.height * 25 / 36, 'inputfield').setDepth(10);
this.text = scene.add.text(game.config.width / 2, game.config.height * 25 / 36, "", {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});
......
......@@ -56,8 +56,8 @@ var roomScene = new Phaser.Class(
this.isCountEnd = false;
this.endTime = 0;
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);
this.countText = this.add.text(game.config.width / 2, game.config.height / 2, '사람들을 위해 대기중입니다...').setOrigin(0.5, 0.5).setColor('#000000').setBackgroundColor('#ffffff').setDepth(10).setPadding(5,5,5,5);
this.peopleText = this.add.text(game.config.width / 2, game.config.height / 9, '1 / 10').setOrigin(0.5, 0.5).setColor('#000000').setBackgroundColor('#ffffff').setDepth(10);
},
update: function()
......@@ -72,20 +72,20 @@ var roomScene = new Phaser.Class(
//console.log('end Count');
setTimeout(() => {
socket.emit('endCount');
}, (Phaser.Math.Distance.Between(0, 0, 640, 800) * 3));
}, (Phaser.Math.Distance.Between(0, 0, game.config.width / 2, game.config.height * 10 / 9) * 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
game.config.width / 2, game.config.height * 10 / 9
]);
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,
duration: Phaser.Math.Distance.Between(element.sprite.x, element.sprite.y, game.config.width / 2, game.config.height * 10 / 9) * 3,
repeat: 0
});
});
......@@ -96,7 +96,7 @@ var roomScene = new Phaser.Class(
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);
element.nickname.setPosition(element.sprite.x - game.config.width / 128, element.sprite.y - game.config.height / 12);
});
this.countText.setText('잠시만 기다려주세요...');
}
......@@ -153,6 +153,17 @@ var gameScene = new Phaser.Class(
// for test
WordSpace.attackGauge.add(11);
WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
WordSpace.generateWord.Name(ScenesData.gameScene, false, null);
},
update: function()
......@@ -166,11 +177,8 @@ var gameScene = new Phaser.Class(
{
element.attract();
})
let tempNames = '';
WordSpace.nameGroup.forEach(function(element)
{
//테스트용
tempNames += element.wordText + (element.isStrong?' [강]':'') + '\n';
WordSpace.attackPaperGroup.forEach(function(element){
element.moveObject(element);
});
WordSpace.nameWordTextForTest.setText('현재 가진 호패들 : \n' + tempNames);
......
class WordObject
{
constructor(text, isNameWord = false)
{
this.generationCode = WordSpace.nextWordCode++;
......@@ -15,7 +14,7 @@ class WordObject
instantiate(scene, lenRate)
{
let p = [{x : 3, y : 0.7}, {x : 20, y : 1.2}];
let p = [{x : 3, y : 1.05}, {x : 20, y : 1.85}];
this.scale = ((p[1].y - p[0].y) / (p[1].x - p[0].x)) * (this.wordWeight - p[0].x) + p[0].y;
this.fontScale = 25;
var random = WordSpace.getSpawnPoint(lenRate);
......@@ -267,8 +266,8 @@ class NameWord extends WordObject
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)
(this.physicsObj.x + game.config.width * (500 + WordSpace.nameGroup.length * 15) / 1280) / 2, this.physicsObj.y - game.config.height * 5 / 72,
game.config.width * (500 + WordSpace.nameGroup.length * 15) / 1280, game.config.height * (680 + this.wordText.length * 10 + (Math.random() * 20 - 10)) / 720
]);
ScenesData.gameScene.tweens.add({
targets: this.follower,
......
var WordReader = WordReader || {};
WordReader.normalWeight = [3, 5, 7, 10];
WordReader.attackWeight = [6, 8, 12, 15];
WordReader.strongAttackWeight = [10, 13, 16, 20];
//초성의 타수를 반환함
WordReader.firstSound = function(charText)
{
......@@ -54,6 +58,32 @@ WordReader.getWordGrade = function(_wordTyping)
17 <= _wordTyping && _wordTyping < 26 ? 0 : -1;
}
WordReader.normalWeight = [3, 5, 7, 10];
WordReader.attackWeight = [6, 8, 12, 15];
WordReader.strongAttackWeight = [10, 13, 16, 20];
\ No newline at end of file
WordReader.getEditDistance = function(input, check) {
var inputWords = [], checkWords = []
for(let i = 0; i < input.length; i++)
{
inputWords.push(parseInt(((input[i].charCodeAt(0) - parseInt('0xac00',16)) /28) / 21) + parseInt('0x1100',16));
inputWords.push(parseInt(((input[i].charCodeAt(0)- parseInt('0xac00',16)) / 28) % 21) + parseInt('0x1161',16));
inputWords.push(parseInt((input[i].charCodeAt(0) - parseInt('0xac00',16)) % 28) + parseInt('0x11A8') -1);
}
for(let i = 0; i < check.length; i++)
{
checkWords.push(parseInt(((check[i].charCodeAt(0) - parseInt('0xac00',16)) /28) / 21) + parseInt('0x1100',16));
checkWords.push(parseInt(((check[i].charCodeAt(0)- parseInt('0xac00',16)) / 28) % 21) + parseInt('0x1161',16));
checkWords.push(parseInt((check[i].charCodeAt(0) - parseInt('0xac00',16)) % 28) + parseInt('0x11A8') -1);
}
var matrix = [];
var i, j;
for(i = 0; i <= checkWords.length; i++) // increment along the first column of each row
matrix[i] = [i];
for(j = 0; j <= inputWords.length; j++) // increment each column in the first row
matrix[0][j] = j;
for(i = 1; i <= checkWords.length; i++) // Fill in the rest of the matrix
for(j = 1; j <= inputWords.length; j++){
if(checkWords[i-1] == inputWords[j-1]) matrix[i][j] = matrix[i-1][j-1];
else matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, // substitution
Math.min(matrix[i][j-1] + 1, // insertion
matrix[i-1][j] + 1)); // deletion
}
return matrix[checkWords.length][inputWords.length];
}
\ No newline at end of file
......@@ -16,6 +16,7 @@ WordSpace.pyeongminAnims = [];
WordSpace.wordGroup = [];
WordSpace.nameGroup = [];
WordSpace.attackPaperGroup = [];
WordSpace.wordForcedGroup = [];
WordSpace.wordPhysicsGroup = null;
......@@ -36,7 +37,7 @@ WordSpace.delay =
WordSpace.NameSpawnReduce = 1000;
WordSpace.gravityPoint = {x: 640, y: 280};
WordSpace.gravityPoint = {x: 960, y: 420};
WordSpace.getSpawnPoint = function(_lenRate)
{
......@@ -102,15 +103,15 @@ WordSpace.attackGauge =
gradeColor: ['#111124','#EBB435','#A42FFF','#1D22EB','#83947F'],
setRect: function()
{
this.rectUI.setSize(20 * this.value, 11);
this.rectUI.setPosition(640 - 10 * this.value, 547);
this.rectUI.setSize(game.config.width / 64 * this.value, game.config.height * 11 / 720);
this.rectUI.setPosition(game.config.width * (640 - 10 * this.value) / 1280, game.config.height * 547 / 720);
let tmp = this.getAttackOption();
this.rectUI.setFillStyle(Phaser.Display.Color.HexStringToColor(this.gradeColor[tmp.wordGrade + 1]).color);
},
generate: function(scene)
{
//console.log("created");
this.rectUI = scene.add.rectangle(640,600,0,11).setDepth(11);
this.rectUI = scene.add.rectangle(game.config.width / 2, game.config.height * 5 / 6, 0, game.config.height * 11 / 720).setDepth(11);
},
add: function(plus)
{
......@@ -187,9 +188,10 @@ WordSpace.loadImage = function(scene)
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 });
scene.load.image('attackPapaer', 'assets/image/etc/paper_crumbled.png');
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.weightTextObjForTest = scene.add.text(game.config.width * 5 / 64, game.config.height * 5 / 48, '뇌의 무게: (현재) 0 / ' + this.brainCapacity + ' (전체)').setDepth(10).setColor('#000000');
WordSpace.killLogTextForTest = scene.add.text(game.config.width * 25 / 32, game.config.height * 5 / 72, WordSpace.killLogForTest).setDepth(10).setColor('#000000').setAlign('right');
}
WordSpace.loadAnimation = function(scene)
......@@ -268,7 +270,7 @@ function gameOver()
socket.emit('defeated');
console.log('defeat');
ScenesData.gameScene.add.text(640, 360, '패배', {fontSize: '30pt'})
ScenesData.gameScene.add.text(game.config.width / 2, game.config.height / 2, '패배', {fontSize: '30pt'})
.setPadding(5,5,5,5).setOrigin(0.5, 0.5).setDepth(10)
.setColor('#000000').setBackgroundColor('#ffffff');
//alert('defeat');
......@@ -336,14 +338,14 @@ WordSpace.findWord = function(wordText)
{
if(element instanceof AttackWord)
{
tempDist = WordSpace.getEditDistance(wordText, element.wordText);
tempDist = WordReader.getEditDistance(wordText, element.wordText);
attackWords.push(element);
if(tempDist <= minDist) minDist = tempDist;
}
});
attackWords.some(function(element)
{
if(WordSpace.getEditDistance(wordText, element.wordText) == minDist)
if(WordReader.getEditDistance(wordText, element.wordText) == minDist)
{
console.log('Attack word : ' + element.wordText + ' of ' + element.attacker.nickname + ' 오타임');
let victimData =
......@@ -412,6 +414,33 @@ WordSpace.attack = function(wordText, grade)
}
element.physicsObj.destroy();
element.wordObj.destroy();
var attackPaper = ScenesData.gameScene.add.sprite(BackGround.myCharacter.x, BackGround.myCharacter.y, 'attackPapaer').setScale(0.5).setDepth(3);
attackPaper.throwTarget = RoomData.players.find(function(_element) {
return _element.id == element.ownerId;
}).playerImage;
attackPaper.follower = { t: 0, vec: new Phaser.Math.Vector2() };
attackPaper.path = new Phaser.Curves.Spline([
BackGround.myCharacter.x, BackGround.myCharacter.y,
(BackGround.myCharacter.x + attackPaper.throwTarget.x) / 2, Math.min(BackGround.myCharacter.y, attackPaper.throwTarget.y) - 100,
attackPaper.throwTarget.x, attackPaper.throwTarget.y - 10
]);
ScenesData.gameScene.tweens.add({
targets: attackPaper.follower,
t: 1,
ease: 'Linear',
duration: 4000,
repeat: 0,
onComplete: function() {
attackPaper.destroy();
WordSpace.attackPaperGroup = [];
}
});
attackPaper.moveObject = function(obj)
{
obj.path.getPoint(obj.follower.t, obj.follower.vec);
obj.setPosition(obj.follower.vec.x, obj.follower.vec.y);
}
WordSpace.attackPaperGroup.push(attackPaper);
});
toSend.forEach(function(element)
{
......@@ -437,17 +466,11 @@ WordSpace.nameQueue =
queue: [],
shuffle: function()
{
let tempIdx, tempElement, tempLength, tempQueue = [];
let tempQueue = [];
RoomData.players.forEach(function(element){
tempQueue.push(element.index)
})
for(tempLength = tempQueue.length; tempLength; tempLength -= 1)
{
tempIdx = Math.floor(Math.random() * tempLength);
tempElement = tempQueue[tempLength - 1];
tempQueue[tempLength - 1] = tempQueue[tempIdx];
tempQueue[tempIdx] = tempElement;
}
tempQueue.sort(function(){return 0.5-Math.random()});
tempQueue.forEach(function(element)
{
if(RoomData.players[element].id != PlayerData.id && RoomData.players[element].isAlive)
......@@ -467,33 +490,3 @@ WordSpace.nameQueue =
this.shuffle();
}
}
WordSpace.getEditDistance = function(input, check) {
var inputWords = [], checkWords = []
for(let i = 0; i < input.length; i++)
{
inputWords.push(parseInt(((input[i].charCodeAt(0) - parseInt('0xac00',16)) /28) / 21) + parseInt('0x1100',16));
inputWords.push(parseInt(((input[i].charCodeAt(0)- parseInt('0xac00',16)) / 28) % 21) + parseInt('0x1161',16));
inputWords.push(parseInt((input[i].charCodeAt(0) - parseInt('0xac00',16)) % 28) + parseInt('0x11A8') -1);
}
for(let i = 0; i < check.length; i++)
{
checkWords.push(parseInt(((check[i].charCodeAt(0) - parseInt('0xac00',16)) /28) / 21) + parseInt('0x1100',16));
checkWords.push(parseInt(((check[i].charCodeAt(0)- parseInt('0xac00',16)) / 28) % 21) + parseInt('0x1161',16));
checkWords.push(parseInt((check[i].charCodeAt(0) - parseInt('0xac00',16)) % 28) + parseInt('0x11A8') -1);
}
var matrix = [];
var i, j;
for(i = 0; i <= checkWords.length; i++) // increment along the first column of each row
matrix[i] = [i];
for(j = 0; j <= inputWords.length; j++) // increment each column in the first row
matrix[0][j] = j;
for(i = 1; i <= checkWords.length; i++) // Fill in the rest of the matrix
for(j = 1; j <= inputWords.length; j++){
if(checkWords[i-1] == inputWords[j-1]) matrix[i][j] = matrix[i-1][j-1];
else matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, // substitution
Math.min(matrix[i][j-1] + 1, // insertion
matrix[i-1][j] + 1)); // deletion
}
return matrix[checkWords.length][inputWords.length];
}
\ No newline at end of file
var config = {
type: Phaser.AUTO,
width: 1280,
height: 720,
width: 1920,
height: 1080,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH
......
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