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

단어 생성 방식 수정 및 instantiate 함수 각 클래스 별로 따로 구분지어놓음

parent 71d38ba3
...@@ -12,31 +12,15 @@ class WordObject ...@@ -12,31 +12,15 @@ class WordObject
this.isNameWord = isNameWord; this.isNameWord = isNameWord;
} }
instantiate(scene, lenRate) instantiate(scene, spriteName, textColor, lenRate)
{ {
let p = [{x : 3, y : 1.05}, {x : 20, y : 1.85}]; 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.scale = ((p[1].y - p[0].y) / (p[1].x - p[0].x)) * (this.wordWeight - p[0].x) + p[0].y;
this.fontScale = 25; this.fontScale = 25;
var random = WordSpace.getSpawnPoint(lenRate); var random = WordSpace.getSpawnPoint(lenRate);
if (!this.isNameWord) this.physicsObj = scene.physics.add.sprite(random.x, random.y, spriteName).setMass(this.wordWeight * 10).setScale(this.scale)
{ .setFrictionX(0).setFrictionY(0).setBounce(0.5);
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(this.scale)
.setFrictionX(0)
.setFrictionY(0)
.setBounce(0.5);
}
else
{
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)
.setFrictionY(0)
.setBounce(0.5);
}
this.physicsObj.wordCollider = null; 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);
...@@ -51,8 +35,7 @@ class WordObject ...@@ -51,8 +35,7 @@ class WordObject
fontFamily: '"궁서", 궁서체, serif', fontFamily: '"궁서", 궁서체, serif',
//fontStyle: (this.wordWeight > 5 ? 'bold' : '') //fontStyle: (this.wordWeight > 5 ? 'bold' : '')
}); });
if (!this.isNameWord) this.wordObj.setColor('#000000').setOrigin(0.5,0.5); this.wordObj.setColor(textColor).setOrigin(0.5,0.5);
else this.wordObj.setColor('#ffffff').setOrigin(0.45,0.5);
this.createdTime = WordSpace.gameTimer.now; this.createdTime = WordSpace.gameTimer.now;
WordSpace.totalWeight += this.wordWeight; WordSpace.totalWeight += this.wordWeight;
WordSpace.totalWordNum += 1; WordSpace.totalWordNum += 1;
...@@ -75,11 +58,6 @@ class WordObject ...@@ -75,11 +58,6 @@ class WordObject
setTimeout(function() { setTimeout(function() {
breakAnim.destroy(); breakAnim.destroy();
}, 200); }, 200);
if(!this.isNameWord)
{
this.wordObj.destroy();
this.physicsObj.destroy();
}
RoomData.myself.playerImage.play(WordSpace.pyeongminAnims[Enums.characterAnim.write]); RoomData.myself.playerImage.play(WordSpace.pyeongminAnims[Enums.characterAnim.write]);
} }
...@@ -121,17 +99,28 @@ class NormalWord extends WordObject ...@@ -121,17 +99,28 @@ class NormalWord extends WordObject
{ {
super(text); super(text);
} }
destroy() instantiate(scene, lenRate)
{
let spriteName = 'wordBgr' + this.wordGrade + '_' + Math.min(Math.max(2, this.wordText.length), 6);
let textColor = '#000000'
super.instantiate(scene, spriteName, textColor, lenRate);
}
destroy(isNormallyRemoved = true)
{ {
switch(this.wordGrade) super.destroy();
if(isNormallyRemoved)
{ {
case 0: WordSpace.attackGauge.add(2.5); break; switch(this.wordGrade)
case 1: WordSpace.attackGauge.add(1.5); break; {
case 2: WordSpace.attackGauge.add(0.9); break; case 0: WordSpace.attackGauge.add(2.5); break;
case 3: WordSpace.attackGauge.add(0.5); break; case 1: WordSpace.attackGauge.add(1.5); break;
default: console.log('[ERR] wrong grade of word'); break; case 2: WordSpace.attackGauge.add(0.9); break;
case 3: WordSpace.attackGauge.add(0.5); break;
default: console.log('[ERR] wrong grade of word'); break;
}
this.wordObj.destroy();
this.physicsObj.destroy();
} }
super.destroy();
} }
} }
...@@ -155,7 +144,9 @@ class AttackWord extends WordObject ...@@ -155,7 +144,9 @@ class AttackWord extends WordObject
} }
instantiate(scene, lenRate) instantiate(scene, lenRate)
{ {
super.instantiate(scene, lenRate); let spriteName = 'wordBgr' + this.wordGrade + '_' + Math.min(Math.max(2, this.wordText.length), 6);
let textColor = '#000000'
super.instantiate(scene, spriteName, textColor, 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)) 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); .setTint(Phaser.Display.Color.GetColor(120, 120, 120)).setScale(this.scale);
this.maskBackground.alpha = this.isDark ? 1 : 0.5; this.maskBackground.alpha = this.isDark ? 1 : 0.5;
...@@ -189,40 +180,45 @@ class AttackWord extends WordObject ...@@ -189,40 +180,45 @@ class AttackWord extends WordObject
else if(this.maskBackground != null) this.maskBackground.destroy(); else if(this.maskBackground != null) this.maskBackground.destroy();
} }
destroy() destroy(isNormallyRemoved = true)
{ {
switch(this.wordGrade) super.destroy();
{ if(isNormallyRemoved)
case 0: WordSpace.attackGauge.add(2.5); break;
case 1: WordSpace.attackGauge.add(1.5); break;
case 2: WordSpace.attackGauge.add(0.9); break;
case 3: WordSpace.attackGauge.add(0.5); break;
default: console.log('[ERR] wrong grade of word'); break;
}
if(WordSpace.gameTimer.now < this.counterTime)
{ {
let tempWord = WordSpace.generateWord.Name(ScenesData.gameScene, true, this.attacker); switch(this.wordGrade)
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, case 0: WordSpace.attackGauge.add(2.5); break;
attacker: RoomData.myself, case 1: WordSpace.attackGauge.add(1.5); break;
target: this.attacker.id, case 2: WordSpace.attackGauge.add(0.9); break;
text: this.wordText, case 3: WordSpace.attackGauge.add(0.5); break;
grade: Math.min(3, this.wordGrade + 1), default: console.log('[ERR] wrong grade of word'); break;
attackOption: { }
isStrong: false, if(WordSpace.gameTimer.now < this.counterTime)
isCountable: false, {
isHeavy: false, let tempWord = WordSpace.generateWord.Name(ScenesData.gameScene, true, this.attacker);
isDark: false 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),
attackOption: {
isStrong: false,
isCountable: false,
isHeavy: false,
isDark: false
},
}
socket.emit('attack', attackData);
} }
socket.emit('attack', attackData);
} }
if(this.maskBackground != null) this.maskBackground.destroy(); if(this.maskBackground != null) this.maskBackground.destroy();
super.destroy(); this.wordObj.destroy();
this.physicsObj.destroy();
} }
} }
...@@ -237,6 +233,13 @@ class NameWord extends WordObject ...@@ -237,6 +233,13 @@ class NameWord extends WordObject
this.isActive = true; this.isActive = true;
//console.log('Name : ' + player.nickname + ', Strong : ' + this.isStrong + ', Weight : ' + this.wordWeight); //console.log('Name : ' + player.nickname + ', Strong : ' + this.isStrong + ', Weight : ' + this.wordWeight);
} }
instantiate(scene, lenRate)
{
let spriteName = (this.isStrong ? 'strongBgr' : 'nameBgr') + Math.min(Math.max(2, this.wordText.length), 6)
let textColor = '#ffffff'
super.instantiate(scene, spriteName, textColor, lenRate);
this.wordObj.setOrigin(0.45,0.5);
}
attract() attract()
{ {
if(this.isActive) super.attract(); if(this.isActive) super.attract();
...@@ -258,40 +261,43 @@ class NameWord extends WordObject ...@@ -258,40 +261,43 @@ class NameWord extends WordObject
} }
} }
} }
destroy() destroy(isNormallyRemoved = true)
{ {
super.destroy(); super.destroy();
ScenesData.gameScene.physics.world.removeCollider(this.physicsObj.wordCollider); if(isNormallyRemoved)
WordSpace.wordGroup.forEach(function(element)
{ {
ScenesData.gameScene.physics.world.removeCollider(element.physicsObj.wordCollider); ScenesData.gameScene.physics.world.removeCollider(this.physicsObj.wordCollider);
element.physicsObj.wordCollider = ScenesData.gameScene.physics.add.collider(element.physicsObj, WordSpace.wordPhysicsGroup, function(object1) WordSpace.wordGroup.forEach(function(element)
{ {
object1.topObj.attract(); 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);
if(!this.isStrong) WordSpace.attackGauge.add(this.wordTyping * 0.1); WordSpace.nameGroup.push(this);
WordSpace.nameGroup.push(this); this.isActive = false;
this.isActive = false; this.physicsObj.setVelocity(0, 0).setDepth(20);
this.physicsObj.setVelocity(0, 0).setDepth(20); this.wordObj.setPosition(this.physicsObj.x, this.physicsObj.y).setDepth(20);
this.wordObj.setPosition(this.physicsObj.x, this.physicsObj.y).setDepth(20); this.follower = { t: 0, vec: new Phaser.Math.Vector2() };
this.follower = { t: 0, vec: new Phaser.Math.Vector2() }; this.path = new Phaser.Curves.Spline([
this.path = new Phaser.Curves.Spline([ this.physicsObj.x, this.physicsObj.y,
this.physicsObj.x, this.physicsObj.y, (this.physicsObj.x + game.config.width * (500 + WordSpace.nameGroup.length * 15) / 1280) / 2, this.physicsObj.y - game.config.height * 5 / 72,
(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
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({
ScenesData.gameScene.tweens.add({ targets: this.follower,
targets: this.follower, t: 1,
t: 1, ease: 'Sine',
ease: 'Sine', duration: 2000,
duration: 2000, repeat: 0
repeat: 0 });
}); //이동경로 디버그
//이동경로 디버그 /*var graphics = ScenesData.gameScene.add.graphics();
/*var graphics = ScenesData.gameScene.add.graphics(); graphics.lineStyle(2, 0xffffff, 1);
graphics.lineStyle(2, 0xffffff, 1); this.path.draw(graphics);*/
this.path.draw(graphics);*/ }
} }
} }
...@@ -299,54 +305,95 @@ class ItemWord extends WordObject ...@@ -299,54 +305,95 @@ class ItemWord extends WordObject
{ {
constructor(_itemType) constructor(_itemType)
{ {
super(_itemType, false); super(_itemType);
this.wordWeight = 2; this.wordWeight = 2;
this.itemType = _itemType this.itemType = _itemType
//console.log('Name : ' + player.nickname + ', Strong : ' + this.isStrong + ', Weight : ' + this.wordWeight); //console.log('Name : ' + player.nickname + ', Strong : ' + this.isStrong + ', Weight : ' + this.wordWeight);
} }
destroy() instantiate(scene, lenRate)
{ {
WordSpace.attackGauge.add(0.5); let spriteName = null;
super.destroy(); let textColor = null;
switch(this.itemType) switch(this.itemType)
{ {
case Enums.item.invincible: case Enums.item.invincible:
WordSpace.isInvincible = true; spriteName = 'item0';
setTimeout(() => { textColor = '#23D9B7'
WordSpace.isInvincible = false;
}, 5000);
break; break;
case Enums.item.nameList: case Enums.item.nameList:
let tempNames = []; spriteName = 'item1';
RoomData.players.forEach(function(element){ textColor = '#FFB28F'
if(element.id != RoomData.myself.id && element.isAlive) tempNames.push(element.index)
});
let length = Math.min(tempNames.length, 8);
tempNames = Phaser.Utils.Array.Shuffle(tempNames);
for(let i = 0; i < length; i++)
{
let tempWord = WordSpace.generateWord.Name(ScenesData.gameScene, true, RoomData.players[tempNames[i]]);
tempWord.physicsObj.setPosition(this.physicsObj.x, this.physicsObj.y);
tempWord.wordObj.setPosition(tempWord.physicsObj.x, tempWord.physicsObj.y);
tempWord.destroy();
}
break; break;
case Enums.item.charge: case Enums.item.charge:
WordSpace.attackGauge.add(11); spriteName = 'item2';
textColor = '#FF9515'
break; break;
case Enums.item.clean: case Enums.item.clean:
let tempLenth = WordSpace.wordGroup.length * 0.3; spriteName = 'item3';
for(let i = 0; i < tempLenth; i++) WordSpace.wordGroup[i].destroy(); textColor = '#263387'
break; break;
case Enums.item.heavy: case Enums.item.heavy:
Input.attackOption.isHeavy = true; spriteName = 'item4';
textColor = '#dddddd'
break; break;
case Enums.item.dark: case Enums.item.dark:
Input.attackOption.isDark = true; spriteName = 'item5';
textColor = '#dddd70'
break; break;
default: default:
console.log("Item type is inappropriate. Item type : " + this.itemType); console.log("Item type is inappropriate. Item type : " + this.itemType);
break; break;
} }
super.instantiate(scene, spriteName, textColor, lenRate);
}
destroy(isNormallyRemoved = true)
{
super.destroy();
if(isNormallyRemoved)
{
WordSpace.attackGauge.add(0.5);
switch(this.itemType)
{
case Enums.item.invincible:
WordSpace.isInvincible = true;
setTimeout(() => {
WordSpace.isInvincible = false;
}, 5000);
break;
case Enums.item.nameList:
let tempNames = [];
RoomData.players.forEach(function(element){
if(element.id != RoomData.myself.id && element.isAlive) tempNames.push(element.index)
});
let length = Math.min(tempNames.length, 8);
tempNames = Phaser.Utils.Array.Shuffle(tempNames);
for(let i = 0; i < length; i++)
{
let tempWord = WordSpace.generateWord.Name(ScenesData.gameScene, true, RoomData.players[tempNames[i]]);
tempWord.physicsObj.setPosition(this.physicsObj.x, this.physicsObj.y);
tempWord.wordObj.setPosition(tempWord.physicsObj.x, tempWord.physicsObj.y);
tempWord.destroy();
}
break;
case Enums.item.charge:
WordSpace.attackGauge.add(11);
break;
case Enums.item.clean:
let tempLenth = WordSpace.wordGroup.length * 0.3;
for(let i = 0; i < tempLenth; i++) WordSpace.wordGroup[i].destroy(false);
break;
case Enums.item.heavy:
Input.attackOption.isHeavy = true;
break;
case Enums.item.dark:
Input.attackOption.isDark = true;
break;
default:
console.log("Item type is inappropriate. Item type : " + this.itemType);
break;
}
}
this.wordObj.destroy();
this.physicsObj.destroy();
} }
} }
\ No newline at end of file
...@@ -181,6 +181,10 @@ WordSpace.loadImage = function(scene) ...@@ -181,6 +181,10 @@ WordSpace.loadImage = function(scene)
{ {
scene.load.image('attackAlert' + i, 'assets/placeholder/attackalert' + (i+1) + '.png'); scene.load.image('attackAlert' + i, 'assets/placeholder/attackalert' + (i+1) + '.png');
} }
for (let i = 0; i < 6; i++)
{
scene.load.image('item' + i, 'assets/placeholder/item' + i + '.png');
}
for (let i = 2; i < 7; i++) for (let i = 2; i < 7; i++)
{ {
scene.load.image('nameBgr' + i, 'assets/placeholder/name' + i + '.png'); scene.load.image('nameBgr' + i, 'assets/placeholder/name' + i + '.png');
......
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