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,17 +99,28 @@ 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)
{
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;
switch(this.wordGrade)
{
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;
}
this.wordObj.destroy();
this.physicsObj.destroy();
}
super.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,40 +180,45 @@ class AttackWord extends WordObject
else if(this.maskBackground != null) this.maskBackground.destroy();
}
destroy()
destroy(isNormallyRemoved = true)
{
switch(this.wordGrade)
{
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)
super.destroy();
if(isNormallyRemoved)
{
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 =
switch(this.wordGrade)
{
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
},
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);
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();
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,40 +261,43 @@ class NameWord extends WordObject
}
}
}
destroy()
destroy(isNormallyRemoved = true)
{
super.destroy();
ScenesData.gameScene.physics.world.removeCollider(this.physicsObj.wordCollider);
WordSpace.wordGroup.forEach(function(element)
if(isNormallyRemoved)
{
ScenesData.gameScene.physics.world.removeCollider(element.physicsObj.wordCollider);
element.physicsObj.wordCollider = ScenesData.gameScene.physics.add.collider(element.physicsObj, WordSpace.wordPhysicsGroup, function(object1)
ScenesData.gameScene.physics.world.removeCollider(this.physicsObj.wordCollider);
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);
WordSpace.nameGroup.push(this);
this.isActive = false;
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,
(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,
t: 1,
ease: 'Sine',
duration: 2000,
repeat: 0
});
//이동경로 디버그
/*var graphics = ScenesData.gameScene.add.graphics();
graphics.lineStyle(2, 0xffffff, 1);
this.path.draw(graphics);*/
if(!this.isStrong) WordSpace.attackGauge.add(this.wordTyping * 0.1);
WordSpace.nameGroup.push(this);
this.isActive = false;
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,
(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,
t: 1,
ease: 'Sine',
duration: 2000,
repeat: 0
});
//이동경로 디버그
/*var graphics = ScenesData.gameScene.add.graphics();
graphics.lineStyle(2, 0xffffff, 1);
this.path.draw(graphics);*/
}
}
}
......@@ -299,54 +305,95 @@ 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)
{
WordSpace.attackGauge.add(0.5);
super.destroy();
let spriteName = null;
let textColor = null;
switch(this.itemType)
{
case Enums.item.invincible:
WordSpace.isInvincible = true;
setTimeout(() => {
WordSpace.isInvincible = false;
}, 5000);
spriteName = 'item0';
textColor = '#23D9B7'
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();
}
spriteName = 'item1';
textColor = '#FFB28F'
break;
case Enums.item.charge:
WordSpace.attackGauge.add(11);
spriteName = 'item2';
textColor = '#FF9515'
break;
case Enums.item.clean:
let tempLenth = WordSpace.wordGroup.length * 0.3;
for(let i = 0; i < tempLenth; i++) WordSpace.wordGroup[i].destroy();
spriteName = 'item3';
textColor = '#263387'
break;
case Enums.item.heavy:
Input.attackOption.isHeavy = true;
spriteName = 'item4';
textColor = '#dddddd'
break;
case Enums.item.dark:
Input.attackOption.isDark = true;
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)
{
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)
{
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