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

Merge branch 'wordspace'

parents 2fdf73fd c770c811
var GameServer = GameServer || {};
GameServer.Phase = {READY: 0, START: 1, MAIN: 2, MUSIC: 3};
GameServer.startCount = 4;
GameServer.startCount = 2;
GameServer.currentPlayer = [];
GameServer.playingRoom = [];
......
......@@ -53,7 +53,8 @@ socket.on('defeat', function(msg) // object player
socket.on('attackSucceed', function(msg)
{
WordSpace.nameGroup.push(new NameWord(msg.victim, true));
let tempWord = WordSpace.generateWord.Name(WordSpace.gameSceneForTest, true, msg.victim);
tempWord.destroy();
});
// out game
......
......@@ -42,7 +42,7 @@ var gameScene = new Phaser.Class(
Input.inputField.loadImage(this);
CSVParsing.loadText(this);
},
create: function()
{
CSVParsing.CSVParse(this);
......@@ -76,6 +76,21 @@ var gameScene = new Phaser.Class(
}
});
console.log(RoomData.myself);
WordSpace.test = WordSpace.generateWord.Name(this, false, null);
console.log('1' + WordSpace.test.physicsObj.body.width);
WordSpace.generateWord.Name(this, false, null);
WordSpace.generateWord.Name(this, false, null);
WordSpace.generateWord.Name(this, false, null);
WordSpace.generateWord.Name(this, false, null);
WordSpace.generateWord.Name(this, false, null);
WordSpace.generateWord.Name(this, false, null);
WordSpace.generateWord.Name(this, false, null);
WordSpace.generateWord.Name(this, false, null);
WordSpace.generateWord.Name(this, false, null);
WordSpace.attackGauge.add(5);
},
update: function()
......@@ -84,6 +99,10 @@ var gameScene = new Phaser.Class(
{
element.attract();
});
WordSpace.nameGroup.forEach(function(element)
{
element.attract();
})
let tempNames = '';
WordSpace.nameGroup.forEach(function(element)
{
......
......@@ -15,15 +15,15 @@ class WordObject
instantiate(scene, lenRate)
{
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;
let fontscale = 25;
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);
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))
.setMass(this.wordWeight * 10)
.setScale(scale)
.setScale(this.scale)
.setFrictionX(0)
.setFrictionY(0)
.setBounce(0.5);
......@@ -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))
.setMass(this.wordWeight * 10)
.setScale(scale)
.setScale(this.scale)
.setFrictionX(0)
.setFrictionY(0)
.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 angle = Phaser.Math.Angle.Between(this.physicsObj.x, this.physicsObj.y, WordSpace.gravityPoint.x, WordSpace.gravityPoint.y);
......@@ -48,7 +47,7 @@ class WordObject
this.wordObj = scene.add.text(random.x, random.y, this.wordText,
{
fontSize: (scale * fontscale) +'pt',
fontSize: (this.scale * this.fontScale) +'pt',
fontFamily: '"궁서", 궁서체, serif',
fontStyle: (this.wordWeight > 5 ? 'bold' : '')
});
......@@ -62,16 +61,20 @@ class WordObject
destroy()
{
console.log(this.generationCode + ': ' + this.wordText + ' destroyed');
//console.log(this.generationCode + ': ' + this.wordText + ' destroyed');
WordSpace.totalWeight -= this.wordWeight;
WordSpace.totalWordNum -= 1;
WordSpace.resetGameOverTimer();
this.wordObj.destroy();
const groupIdx = WordSpace.wordGroup.findIndex(function(item) {return this.isEqualObject(item.generationCode)}, this);
if (groupIdx > -1) WordSpace.wordGroup.splice(groupIdx, 1);
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, true, true);
WordSpace.wordPhysicsGroup.remove(this.physicsObj);
if(!this.isNameWord)
{
this.wordObj.destroy();
this.physicsObj.destroy();
}
}
......@@ -154,12 +157,7 @@ class AttackWord extends WordObject
case 3: WordSpace.attackGauge.add(0.5); break;
default: console.log('[ERR] wrong grade of word'); break;
}
if(WordSpace.gameTimer.now < this.counterTime)
{
WordSpace.nameGroup.push(new NameWord(this.attacker, true));
}
//강호패 넣기 구현해야됨
//WordSpace.generateWord.Name(WordSpace.gameSceneForTest, true);
if(WordSpace.gameTimer.now < this.counterTime) WordSpace.nameGroup.push(new NameWord(this.attacker, true));
super.destroy();
}
}
......@@ -172,12 +170,63 @@ class NameWord extends WordObject
this.ownerId = player.id;
this.wordWeight = 2;
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()
{
WordSpace.attackGauge.add(this.wordTyping * 0.1);
WordSpace.nameGroup.push(this);
super.destroy();
WordSpace.gameSceneForTest.physics.world.removeCollider(this.physicsObj.wordCollider);
WordSpace.wordGroup.forEach(function(element)
{
WordSpace.gameSceneForTest.physics.world.removeCollider(element.physicsObj.wordCollider);
element.physicsObj.wordCollider = WordSpace.gameSceneForTest.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)
]);
WordSpace.gameSceneForTest.tweens.add({
targets: this.follower,
t: 1,
ease: 'Sine',
duration: 2000,
repeat: 0
});
//이동경로 디버그
/*var graphics = WordSpace.gameSceneForTest.add.graphics();
graphics.lineStyle(2, 0xffffff, 1);
this.path.draw(graphics);*/
}
}
var WordSpace = WordSpace || {};
WordSpace.test = null;
// for test
WordSpace.gameSceneForTest = null;
WordSpace.weightTextObjForTest = null;
......@@ -69,7 +71,7 @@ WordSpace.gameOverCycle = new Cycle(gameOver);
//호패 생성 사이클
WordSpace.nameCycle = new Cycle(function()
{
WordSpace.generateWord.Name(WordSpace.gameSceneForTest, false);
WordSpace.generateWord.Name(WordSpace.gameSceneForTest, false, null);
});
//이건 뭐지
WordSpace.varAdjustCycle = new Cycle(function()
......@@ -237,6 +239,8 @@ WordSpace.loadImage = function(scene)
WordSpace.gameSceneForTest = scene; // for test
WordSpace.weightTextObjForTest = scene.add.text(100, 75, '뇌의 무게: (현재) 0 / 100 (전체)').setDepth(10).setColor('#000000');
scene.load.image('test', 'assets/placeholder/attackalert1.png')
}
WordSpace.generateWord =
......@@ -245,17 +249,21 @@ WordSpace.generateWord =
{
word = new NormalWord(SelectWord.selectWord(grade));
WordSpace.pushWord(scene, word, lenRate);
return word;
},
Attack: function(scene, wordText, grade, attacker, isStrong, lenRate)
{
word = new AttackWord(wordText, grade, attacker, isStrong);
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);
WordSpace.pushWord(scene, word, lenRate);
return word;
}
}
......@@ -265,7 +273,7 @@ WordSpace.pushWord = function(scene, word, lenRate)
WordSpace.wordGroup.push(word);
WordSpace.wordForcedGroup.push(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.attract();
......@@ -350,7 +358,7 @@ WordSpace.findWord = function(wordText)
if(tempDist <= minDist) minDist = tempDist;
}
});
attackWords.forEach(function(element)
attackWords.some(function(element)
{
if(WordSpace.getEditDistance(wordText, element.wordText) == minDist)
{
......@@ -362,6 +370,7 @@ WordSpace.findWord = function(wordText)
target: element.attacker.idNum
}
socket.emit('defenseFailed', victimData);
return true;
}
});
this.attackGauge.sub(2);
......@@ -403,11 +412,13 @@ WordSpace.attack = function(wordText, grade)
isStrong: element.isStrong
}
socket.emit('attack', attackData);
element.physicsObj.destroy();
element.wordObj.destroy();
});
//테스트용, 자기 자신에게 공격함
//WordSpace.generateWord.Attack(WordSpace.gameSceneForTest, wordText, grade, PlayerData, false);
WordSpace.generateWord.Name(WordSpace.gameSceneForTest, false);
WordSpace.generateWord.Name(WordSpace.gameSceneForTest, false);
WordSpace.generateWord.Name(WordSpace.gameSceneForTest, false, null);
WordSpace.generateWord.Name(WordSpace.gameSceneForTest, false, null);
WordSpace.nameGroup = [];
WordSpace.attackGauge.resetValue();
......
......@@ -2,6 +2,11 @@ var config = {
type: Phaser.AUTO,
width: 1280,
height: 720,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH
},
autoRound: false,
physics: {
default: 'arcade',
arcade: {
......
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