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

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

parent 71d38ba3
......@@ -12,31 +12,15 @@ class WordObject
this.isNameWord = isNameWord;
}
instantiate(scene, lenRate)
instantiate(scene, spriteName, textColor, lenRate)
{
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);
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(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 = 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.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);
......@@ -51,8 +35,7 @@ class WordObject
fontFamily: '"궁서", 궁서체, serif',
//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.wordObj.setColor(textColor).setOrigin(0.5,0.5);
this.createdTime = WordSpace.gameTimer.now;
WordSpace.totalWeight += this.wordWeight;
WordSpace.totalWordNum += 1;
......@@ -75,11 +58,6 @@ class WordObject
setTimeout(function() {
breakAnim.destroy();
}, 200);
if(!this.isNameWord)
{
this.wordObj.destroy();
this.physicsObj.destroy();
}
RoomData.myself.playerImage.play(WordSpace.pyeongminAnims[Enums.characterAnim.write]);
}
......@@ -121,7 +99,16 @@ class NormalWord extends WordObject
{
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)
{
super.destroy();
if(isNormallyRemoved)
{
switch(this.wordGrade)
{
......@@ -131,7 +118,9 @@ class NormalWord extends WordObject
case 3: WordSpace.attackGauge.add(0.5); break;
default: console.log('[ERR] wrong grade of word'); break;
}
super.destroy();
this.wordObj.destroy();
this.physicsObj.destroy();
}
}
}
......@@ -155,7 +144,9 @@ class AttackWord extends WordObject
}
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))
.setTint(Phaser.Display.Color.GetColor(120, 120, 120)).setScale(this.scale);
this.maskBackground.alpha = this.isDark ? 1 : 0.5;
......@@ -189,7 +180,10 @@ class AttackWord extends WordObject
else if(this.maskBackground != null) this.maskBackground.destroy();
}
destroy()
destroy(isNormallyRemoved = true)
{
super.destroy();
if(isNormallyRemoved)
{
switch(this.wordGrade)
{
......@@ -221,8 +215,10 @@ class AttackWord extends WordObject
}
socket.emit('attack', attackData);
}
}
if(this.maskBackground != null) this.maskBackground.destroy();
super.destroy();
this.wordObj.destroy();
this.physicsObj.destroy();
}
}
......@@ -237,6 +233,13 @@ class NameWord extends WordObject
this.isActive = true;
//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()
{
if(this.isActive) super.attract();
......@@ -258,9 +261,11 @@ class NameWord extends WordObject
}
}
}
destroy()
destroy(isNormallyRemoved = true)
{
super.destroy();
if(isNormallyRemoved)
{
ScenesData.gameScene.physics.world.removeCollider(this.physicsObj.wordCollider);
WordSpace.wordGroup.forEach(function(element)
{
......@@ -293,21 +298,60 @@ class NameWord extends WordObject
graphics.lineStyle(2, 0xffffff, 1);
this.path.draw(graphics);*/
}
}
}
class ItemWord extends WordObject
{
constructor(_itemType)
{
super(_itemType, false);
super(_itemType);
this.wordWeight = 2;
this.itemType = _itemType
//console.log('Name : ' + player.nickname + ', Strong : ' + this.isStrong + ', Weight : ' + this.wordWeight);
}
destroy()
instantiate(scene, lenRate)
{
let spriteName = null;
let textColor = null;
switch(this.itemType)
{
case Enums.item.invincible:
spriteName = 'item0';
textColor = '#23D9B7'
break;
case Enums.item.nameList:
spriteName = 'item1';
textColor = '#FFB28F'
break;
case Enums.item.charge:
spriteName = 'item2';
textColor = '#FF9515'
break;
case Enums.item.clean:
spriteName = 'item3';
textColor = '#263387'
break;
case Enums.item.heavy:
spriteName = 'item4';
textColor = '#dddddd'
break;
case Enums.item.dark:
spriteName = 'item5';
textColor = '#dddd70'
break;
default:
console.log("Item type is inappropriate. Item type : " + this.itemType);
break;
}
super.instantiate(scene, spriteName, textColor, lenRate);
}
destroy(isNormallyRemoved = true)
{
WordSpace.attackGauge.add(0.5);
super.destroy();
if(isNormallyRemoved)
{
WordSpace.attackGauge.add(0.5);
switch(this.itemType)
{
case Enums.item.invincible:
......@@ -336,7 +380,7 @@ class ItemWord extends WordObject
break;
case Enums.item.clean:
let tempLenth = WordSpace.wordGroup.length * 0.3;
for(let i = 0; i < tempLenth; i++) WordSpace.wordGroup[i].destroy();
for(let i = 0; i < tempLenth; i++) WordSpace.wordGroup[i].destroy(false);
break;
case Enums.item.heavy:
Input.attackOption.isHeavy = true;
......@@ -349,4 +393,7 @@ class ItemWord extends WordObject
break;
}
}
this.wordObj.destroy();
this.physicsObj.destroy();
}
}
\ No newline at end of file
......@@ -181,6 +181,10 @@ WordSpace.loadImage = function(scene)
{
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++)
{
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