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

Merge branch 'word' into wordspace

parents 9b13860d cccf35e2
...@@ -76,7 +76,7 @@ class GameRoom ...@@ -76,7 +76,7 @@ class GameRoom
{ {
this.roomId = GameServer.getRoomNumber(); this.roomId = GameServer.getRoomNumber();
this.roomIndex = -1; this.roomIndex = -1;
this.startCount = 2; this.startCount = 3;
this.maxPlayer = 100; this.maxPlayer = 100;
this.nextRank = 100; this.nextRank = 100;
...@@ -288,6 +288,7 @@ class Player ...@@ -288,6 +288,7 @@ class Player
this.gameRoomId = gameRoom.roomId; this.gameRoomId = gameRoom.roomId;
this.index = gameRoom.currentPlayer.length; this.index = gameRoom.currentPlayer.length;
this.nickname = playerData.nickname; this.nickname = playerData.nickname;
this.playerImage = null;
this.position = null; this.position = null;
this.isAlive = true; this.isAlive = true;
......
var BackGround = BackGround || {} var BackGround = BackGround || {}
BackGround.brainGroup = null; BackGround.brainGroup = null;
BackGround.myCharacter = null;
BackGround.characterPos = [ 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(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(368, 336), new Phaser.Math.Vector2(272, 453), new Phaser.Math.Vector2(100, 595), new Phaser.Math.Vector2(284, 678),
...@@ -21,13 +20,14 @@ BackGround.loadImage = function(scene) ...@@ -21,13 +20,14 @@ BackGround.loadImage = function(scene)
BackGround.drawCharacter = function(scene) BackGround.drawCharacter = function(scene)
{ {
BackGround.myCharacter = scene.add.sprite(game.config.width / 2, game.config.height * 41 / 48, 'pyeongminWrite').setScale(0.45).setDepth(2); RoomData.myself.playerImage = scene.add.sprite(game.config.width / 2, game.config.height * 41 / 48, 'pyeongminWrite').setScale(0.45).setDepth(2);
RoomData.myself.position = new Phaser.Math.Vector2(RoomData.myself.playerImage.x, RoomData.myself.playerImage.y);
BackGround.characterPos = BackGround.characterPos.sort(function(){return 0.5-Math.random()}); BackGround.characterPos = BackGround.characterPos.sort(function(){return 0.5-Math.random()});
RoomData.players.forEach(function(element){ RoomData.players.forEach(function(element){
if(element.id != RoomData.myself.id) if(element.id != RoomData.myself.id)
{ {
element.position = BackGround.characterPos.pop(); element.position = BackGround.characterPos.pop();
element.playerImage = scene.add.sprite(element.position.x, element.position.y, 'pyeongminWrite').setScale(0.45).setDepth(1); element.playerImage = scene.add.sprite(element.position.x, element.position.y, 'pyeongminWrite').setScale(0.315).setDepth(1);
element.playerImage.flipX = element.position.x < game.config.width / 2 ? true : false; 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) 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); .setOrigin(0.5,0.5).setColor('#000000').setPadding(0.5,0.5,0.5,0.5).setDepth(1);
......
...@@ -59,7 +59,7 @@ socket.on('setRoomCount', function(msg) ...@@ -59,7 +59,7 @@ socket.on('setRoomCount', function(msg)
ScenesData.roomScene.endTime = msg.endTime; ScenesData.roomScene.endTime = msg.endTime;
ScenesData.roomScene.peopleCount = msg.playerCount; ScenesData.roomScene.peopleCount = msg.playerCount;
if (msg.isEnter) // generate charactor if (msg.isEnter) // generate character
{ {
let randX = Math.random() * 1120 + 80; let randX = Math.random() * 1120 + 80;
let randY = Math.random() * 380 + 100; let randY = Math.random() * 380 + 100;
...@@ -71,7 +71,7 @@ socket.on('setRoomCount', function(msg) ...@@ -71,7 +71,7 @@ socket.on('setRoomCount', function(msg)
} }
ScenesData.roomScene.players.push(playerSet); ScenesData.roomScene.players.push(playerSet);
} }
else // remove charactor else // remove character
{ {
let idx = ScenesData.roomScene.players.findIndex(function(element) let idx = ScenesData.roomScene.players.findIndex(function(element)
{ {
...@@ -140,20 +140,23 @@ socket.on('attackMode', function(msg) // number playerId ...@@ -140,20 +140,23 @@ socket.on('attackMode', function(msg) // number playerId
console.log(msg + ' is on attack Mode'); console.log(msg + ' is on attack Mode');
// msg의 id를 가진 사람이 attack Mode이다. // msg의 id를 가진 사람이 attack Mode이다.
}); });
socket.on('attack', function(msg) // {number attackerId, number targetId} socket.on('someoneAttacked', function(msg) // {Player attacker, Player victim}
{ {
// 이때 위의 attack Mode인 사람(msg.attackerId)을 해제해주자. // 이때 위의 attack Mode인 사람(msg.attackerId)을 해제해주자.
console.log(msg.attackerId + ' attack to ' + msg.targetId); console.log(msg.attacker.id + ' attacked ' + msg.victim.id);
let attackerPos = RoomData.findPlayer(msg.attacker).position;
let victimPos = RoomData.findPlayer(msg.victim).position;
WordSpace.makeAttackPaper(ScenesData.gameScene, attackerPos, victimPos);
}); });
socket.on('attacked', function(msg) // object attackData socket.on('attacked', function(msg) // object attackData
{ {
//console.log('attacked by ' + msg.attacker.nickname); //console.log('attacked by ' + msg.attacker.nickname);
let attackedEvent = new Cycle(function() let attackedEvent = new Cycle(function()
{ {
for (let i = 0; i < msg.multiple; i++) WordSpace.generateWord.Attack(ScenesData.gameScene, msg.text, msg.grade, msg.attacker, msg.isStrong, msg.isCountable); if(!WordSpace.isInvincible)
for (let i = 0; i < msg.multiple; i++) WordSpace.generateWord.Attack(ScenesData.gameScene, msg.text, msg.grade, msg.attacker, msg.attackOption);
attackedEvent.currentCycle.destroy(); attackedEvent.currentCycle.destroy();
WordSpace.attackedEvents.splice(WordSpace.attackedEvents.findIndex(function(element) WordSpace.attackedEvents.splice(WordSpace.attackedEvents.findIndex(function(element) {
{
return element.cert === (msg.text + msg.attacker); return element.cert === (msg.text + msg.attacker);
}), 1); }), 1);
}); });
...@@ -171,6 +174,11 @@ socket.on('defeat', function(msg) // object player ...@@ -171,6 +174,11 @@ socket.on('defeat', function(msg) // object player
{ {
console.log(RoomData.players[msg.index].nickname + ' defeated by ' + msg.lastAttack.attacker + ', with ' + msg.lastAttack.word); console.log(RoomData.players[msg.index].nickname + ' defeated by ' + msg.lastAttack.attacker + ', with ' + msg.lastAttack.word);
WordSpace.killLogForTest += ('\n' + msg.lastAttack.attacker + ' --' + msg.lastAttack.word + '-> ' + RoomData.players[msg.index].nickname); WordSpace.killLogForTest += ('\n' + msg.lastAttack.attacker + ' --' + msg.lastAttack.word + '-> ' + RoomData.players[msg.index].nickname);
if(msg.lastAttack.attackerId == RoomData.myself.id)
{
var keys = Object.keys(Enums.item);
WordSpace.generateWord.Item(ScenesData.gameScene, Enums.item[keys[keys.length * Math.random() << 0]]);
}
} }
else else
{ {
...@@ -186,6 +194,9 @@ socket.on('attackSucceed', function(msg) ...@@ -186,6 +194,9 @@ socket.on('attackSucceed', function(msg)
{ {
//console.log('client'); //console.log('client');
let tempWord = WordSpace.generateWord.Name(ScenesData.gameScene, true, msg.victim); let tempWord = WordSpace.generateWord.Name(ScenesData.gameScene, true, msg.victim);
let victimPos = RoomData.findPlayer(msg.victim).position;
tempWord.physicsObj.setPosition(victimPos.x, victimPos.y);
tempWord.wordObj.setPosition(tempWord.physicsObj.x, tempWord.physicsObj.y);
tempWord.destroy(); tempWord.destroy();
}); });
......
var Enums = Enums || {}; var Enums = Enums || {};
Enums.characterAnim = { write: 0, attackWrite: 1, throw: 2, hit: 3 } Enums.characterAnim = { write: 0, attackWrite: 1, throw: 2, hit: 3 }
\ No newline at end of file Enums.item = {invincible: "무적", nameList: "명단", charge: "충전", clean: "청소", heavy: "중량", dark: "암흑"}
\ No newline at end of file
...@@ -12,7 +12,12 @@ Input.justPressed = ''; ...@@ -12,7 +12,12 @@ Input.justPressed = '';
Input.maxInput = 6; Input.maxInput = 6;
Input.attackMode = false; Input.attackMode = false;
Input.attackOption = null; Input.attackOption = {
wordCount: 0,
wordGrade: 0,
isHeavy: false,
isDark: false
};
Input.gameSceneEnterReaction = function() Input.gameSceneEnterReaction = function()
{ {
......
...@@ -150,9 +150,22 @@ var gameScene = new Phaser.Class( ...@@ -150,9 +150,22 @@ var gameScene = new Phaser.Class(
WordSpace.nameWordTextForTest = ScenesData.gameScene.add.text(50,400,'현재 가진 호패들 : 없음').setDepth(10).setColor('#000000'); WordSpace.nameWordTextForTest = ScenesData.gameScene.add.text(50,400,'현재 가진 호패들 : 없음').setDepth(10).setColor('#000000');
WordSpace.nameQueue.initiate(); WordSpace.nameQueue.initiate();
WordSpace.generateWord.Item(ScenesData.gameScene, Enums.item.nameList);
WordSpace.generateWord.Item(ScenesData.gameScene, Enums.item.nameList);
WordSpace.generateWord.Item(ScenesData.gameScene, Enums.item.invincible);
WordSpace.generateWord.Item(ScenesData.gameScene, Enums.item.invincible);
WordSpace.generateWord.Item(ScenesData.gameScene, Enums.item.charge);
WordSpace.generateWord.Item(ScenesData.gameScene, Enums.item.charge);
WordSpace.generateWord.Item(ScenesData.gameScene, Enums.item.clean);
WordSpace.generateWord.Item(ScenesData.gameScene, Enums.item.clean);
WordSpace.generateWord.Item(ScenesData.gameScene, Enums.item.heavy);
WordSpace.generateWord.Item(ScenesData.gameScene, Enums.item.heavy);
WordSpace.generateWord.Item(ScenesData.gameScene, Enums.item.dark);
WordSpace.generateWord.Item(ScenesData.gameScene, Enums.item.dark);
// for test // for test
WordSpace.attackGauge.add(11); 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);
...@@ -162,8 +175,7 @@ var gameScene = new Phaser.Class( ...@@ -162,8 +175,7 @@ var gameScene = new Phaser.Class(
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() update: function()
......
...@@ -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,12 +58,7 @@ class WordObject ...@@ -75,12 +58,7 @@ class WordObject
setTimeout(function() { setTimeout(function() {
breakAnim.destroy(); breakAnim.destroy();
}, 200); }, 200);
if(!this.isNameWord) RoomData.myself.playerImage.play(WordSpace.pyeongminAnims[Enums.characterAnim.write]);
{
this.wordObj.destroy();
this.physicsObj.destroy();
}
BackGround.myCharacter.play(WordSpace.pyeongminAnims[Enums.characterAnim.write]);
} }
attract() attract()
...@@ -121,51 +99,76 @@ class NormalWord extends WordObject ...@@ -121,51 +99,76 @@ class NormalWord extends WordObject
{ {
super(text); super(text);
} }
destroy() instantiate(scene, lenRate)
{ {
switch(this.wordGrade) 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)
{ {
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;
}
} }
super.destroy(); this.wordObj.destroy();
this.physicsObj.destroy();
} }
} }
class AttackWord extends WordObject class AttackWord extends WordObject
{ {
constructor(text, _wordGrade, _playerData, _isStrong, _isCountable = true, lenRate) constructor(text, _wordGrade, _playerData, _attackOption, lenRate)
{ {
super(text); super(text);
this.wordGrade = _wordGrade; this.wordGrade = _wordGrade;
this.wordWeight = _isStrong ? WordReader.strongAttackWeight[3 - this.wordGrade] : WordReader.attackWeight[3 - this.wordGrade]; this.wordWeight = _attackOption.isStrong ? WordReader.strongAttackWeight[3 - this.wordGrade] : WordReader.attackWeight[3 - this.wordGrade];
if(WordReader.getWordTyping(_playerData.nickname) > 9) if(WordReader.getWordTyping(_playerData.nickname) > 9)
this.wordWeight += this.wordWeight * 0.2 * (WordReader.getWordTyping(_playerData.nickname) - 9); this.wordWeight += this.wordWeight * 0.2 * (WordReader.getWordTyping(_playerData.nickname) - 9);
if(_attackOption.isHeavy) this.wordWeight *= 2;
this.attacker = _playerData; this.attacker = _playerData;
if(!_isCountable) this.counterTime = 0; if(!_attackOption.isCountable) this.counterTime = 0;
else this.counterTime = WordSpace.gameTimer.now + 1000 * (this.wordTyping <= (5 - _wordGrade) * 2.5 ? this.wordTyping / (Math.max(200, WordSpace.playerTyping) / 60) * 1.5 : else this.counterTime = WordSpace.gameTimer.now + 1000 * (this.wordTyping <= (5 - _wordGrade) * 2.5 ? this.wordTyping / (Math.max(200, WordSpace.playerTyping) / 60) * 1.5 :
((5 - _wordGrade) * 3 + (this.wordTyping - (5 - _wordGrade) * 2.5) * 2.5) / (Math.max(200, WordSpace.playerTyping) / 60) * 1.5); ((5 - _wordGrade) * 3 + (this.wordTyping - (5 - _wordGrade) * 2.5) * 2.5) / (Math.max(200, WordSpace.playerTyping) / 60) * 1.5);
this.isDark = _attackOption.isDark;
console.log('Attack text : ' + text + ', Attacker : ' + this.attacker.nickname + ', Weight : ' + this.wordWeight); console.log('Attack text : ' + text + ', Attacker : ' + this.attacker.nickname + ', Weight : ' + this.wordWeight);
console.log('Counter time : ' + this.counterTime); console.log('Counter time : ' + this.counterTime);
} }
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 = 0.5; this.maskBackground.alpha = this.isDark ? 1 : 0.5;
this.shape = scene.make.graphics(); this.shape = scene.make.graphics();
var rect = new Phaser.Geom.Rectangle(0, 0, this.maskBackground.width * this.scale, this.maskBackground.height * this.scale); var rect = new Phaser.Geom.Rectangle(0, 0, this.maskBackground.width * this.scale, this.maskBackground.height * this.scale);
this.shape.fillStyle(0xffffff).fillRectShape(rect); this.shape.fillStyle(0xffffff).fillRectShape(rect);
this.mask = this.shape.createGeometryMask(); this.mask = this.shape.createGeometryMask();
this.maskBackground.setMask(this.mask);
this.maskStart = this.physicsObj.x; this.maskStart = this.physicsObj.x;
this.maskEnd = this.physicsObj.x - this.physicsObj.width * this.scale; this.maskEnd = this.physicsObj.x - this.physicsObj.width * this.scale;
if(this.isDark)
{
setTimeout(() => {
if(this.maskBackground != null && this.mask != null)
{
this.maskBackground.setMask(this.mask);
this.maskBackground.alpha = 0.5;
}
}, 4000);
}
else this.maskBackground.setMask(this.mask);
} }
attract() attract()
...@@ -181,36 +184,45 @@ class AttackWord extends WordObject ...@@ -181,36 +184,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); case 0: WordSpace.attackGauge.add(2.5); break;
tempWord.destroy(); case 1: WordSpace.attackGauge.add(1.5); break;
let attackData = 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)
{ {
roomNum: RoomData.roomId, let tempWord = WordSpace.generateWord.Name(ScenesData.gameScene, true, this.attacker);
attacker: RoomData.myself, tempWord.physicsObj.setPosition(this.physicsObj.x, this.physicsObj.y);
target: this.attacker.id, tempWord.wordObj.setPosition(tempWord.physicsObj.x, tempWord.physicsObj.y);
text: this.wordText, tempWord.destroy();
grade: Math.min(3, this.wordGrade + 1), let attackData =
isStrong: false, {
isCountable: false 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();
} }
} }
...@@ -225,6 +237,13 @@ class NameWord extends WordObject ...@@ -225,6 +237,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();
...@@ -233,7 +252,7 @@ class NameWord extends WordObject ...@@ -233,7 +252,7 @@ class NameWord extends WordObject
this.path.getPoint(this.follower.t, this.follower.vec); this.path.getPoint(this.follower.t, this.follower.vec);
this.physicsObj.setPosition(this.follower.vec.x, this.follower.vec.y); this.physicsObj.setPosition(this.follower.vec.x, this.follower.vec.y);
this.wordObj.setPosition(this.physicsObj.x, this.physicsObj.y); this.wordObj.setPosition(this.physicsObj.x, this.physicsObj.y);
this.physicsObj.angle = 90 * this.follower.t; this.physicsObj.angle = (this.isStrong ? 450 : 90) * this.follower.t
this.wordObj.angle = this.physicsObj.angle; this.wordObj.angle = this.physicsObj.angle;
if(this.isStrong) if(this.isStrong)
{ {
...@@ -246,40 +265,139 @@ class NameWord extends WordObject ...@@ -246,40 +265,139 @@ 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();
//이동경로 디버그 graphics.lineStyle(2, 0xffffff, 1);
/*var graphics = ScenesData.gameScene.add.graphics(); this.path.draw(graphics);*/
graphics.lineStyle(2, 0xffffff, 1); }
this.path.draw(graphics);*/
} }
} }
class ItemWord extends WordObject
{
constructor(_itemType)
{
super(_itemType);
this.wordWeight = 2;
this.itemType = _itemType
//console.log('Name : ' + player.nickname + ', Strong : ' + this.isStrong + ', Weight : ' + this.wordWeight);
}
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)
{
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
...@@ -12,6 +12,7 @@ WordSpace.totalWordNum = 0; ...@@ -12,6 +12,7 @@ WordSpace.totalWordNum = 0;
WordSpace.brainCapacity = 200; //수용 가능한 단어 무게 최대치 WordSpace.brainCapacity = 200; //수용 가능한 단어 무게 최대치
WordSpace.gameTimer = null; //현재 게임 플레이 시간 타이머 WordSpace.gameTimer = null; //현재 게임 플레이 시간 타이머
WordSpace.isTimerOn = false; WordSpace.isTimerOn = false;
WordSpace.isInvincible = false;
WordSpace.pyeongminAnims = []; WordSpace.pyeongminAnims = [];
WordSpace.wordGroup = []; WordSpace.wordGroup = [];
...@@ -43,8 +44,8 @@ WordSpace.getSpawnPoint = function(_lenRate) ...@@ -43,8 +44,8 @@ WordSpace.getSpawnPoint = function(_lenRate)
{ {
let lenRate = 1; let lenRate = 1;
if(typeof _lenRate == 'number') lenRate = _lenRate; if(typeof _lenRate == 'number') lenRate = _lenRate;
let xLen = 550 * lenRate; let xLen = 650 * lenRate;
let yLen = 350 * lenRate; let yLen = 500 * lenRate;
const angle = Math.random() * Math.PI * 2; const angle = Math.random() * Math.PI * 2;
let _x = xLen * Math.cos(angle) + this.gravityPoint.x; let _x = xLen * Math.cos(angle) + this.gravityPoint.x;
let _y = yLen * Math.sin(angle) + this.gravityPoint.y; let _y = yLen * Math.sin(angle) + this.gravityPoint.y;
...@@ -180,6 +181,10 @@ WordSpace.loadImage = function(scene) ...@@ -180,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');
...@@ -234,17 +239,27 @@ WordSpace.generateWord = ...@@ -234,17 +239,27 @@ WordSpace.generateWord =
WordSpace.pushWord(scene, word, lenRate); WordSpace.pushWord(scene, word, lenRate);
return word; return word;
}, },
Attack: function(scene, wordText, grade, attacker, isStrong, isCountable, lenRate) Attack: function(scene, wordText, grade, attacker, attackOption, lenRate)
{ {
word = new AttackWord(wordText, grade, attacker, isStrong, isCountable); word = new AttackWord(wordText, grade, attacker, attackOption);
WordSpace.pushWord(scene, word, lenRate); WordSpace.pushWord(scene, word, lenRate);
return word; return word;
}, },
Name: function(scene, isStrong, newPlayerData, lenRate) Name: function(scene, isStrong, newPlayerData, lenRate)
{ {
if(newPlayerData == null) word = new NameWord(WordSpace.nameQueue.pop(), isStrong); if(newPlayerData == null)
{
if(WordSpace.nameQueue.queue.length == 1) return null;
let temp = WordSpace.nameQueue.pop();
word = new NameWord(temp, isStrong);
}
else word = new NameWord(newPlayerData, isStrong); else word = new NameWord(newPlayerData, isStrong);
//word = new NameWord(RoomData.myself, false); WordSpace.pushWord(scene, word, lenRate);
return word;
},
Item: function(scene, itemType, lenRate)
{
word = new ItemWord(itemType);
WordSpace.pushWord(scene, word, lenRate); WordSpace.pushWord(scene, word, lenRate);
return word; return word;
} }
...@@ -322,13 +337,15 @@ WordSpace.findWord = function(wordText) ...@@ -322,13 +337,15 @@ WordSpace.findWord = function(wordText)
else if (wordText === '공격' && WordSpace.attackGauge.value >= 3 && WordSpace.nameGroup.length > 0) // 공격모드 진입. else if (wordText === '공격' && WordSpace.attackGauge.value >= 3 && WordSpace.nameGroup.length > 0) // 공격모드 진입.
{ {
console.log('attack mode'); console.log('attack mode');
Input.attackOption = this.attackGauge.getAttackOption(); let tempAttackOption = this.attackGauge.getAttackOption();
Input.attackOption.wordCount = tempAttackOption.wordCount;
Input.attackOption.wordGrade = tempAttackOption.wordGrade;
Input.maxInput = Input.attackOption.wordCount; Input.maxInput = Input.attackOption.wordCount;
Input.attackMode = true; Input.attackMode = true;
WordSpace.attackGauge.pauseCycle(true); WordSpace.attackGauge.pauseCycle(true);
WordSpace.setPlayerTyping.add(wordText); WordSpace.setPlayerTyping.add(wordText);
BackGround.myCharacter.play(WordSpace.pyeongminAnims[Enums.characterAnim.attackWrite]); RoomData.myself.playerImage.play(WordSpace.pyeongminAnims[Enums.characterAnim.attackWrite]);
BackGround.myCharacter.anims.msPerFrame /= (4 - WordSpace.attackGauge.getAttackOption().wordGrade); RoomData.myself.playerImage.anims.msPerFrame /= (4 - Input.attackOption.wordGrade);
} }
else // 오타 체크 else // 오타 체크
{ {
...@@ -400,47 +417,29 @@ WordSpace.attack = function(wordText, grade) ...@@ -400,47 +417,29 @@ WordSpace.attack = function(wordText, grade)
} }
else else
{ {
let target = RoomData.players.find(function(_element) {
return _element.id == element.ownerId;
});
let attackData = let attackData =
{ {
roomNum: RoomData.roomId, roomNum: RoomData.roomId,
attacker: RoomData.myself, attacker: RoomData.myself,
target: element.ownerId, victim: target,
text: wordText, text: wordText,
grade: grade, grade: grade,
isStrong: element.isStrong, attackOption: {
isStrong: element.isStrong,
isCountable: true,
isHeavy: Input.attackOption.isHeavy,
isDark: Input.attackOption.isDark
},
multiple: 1 multiple: 1
} }
WordSpace.makeAttackPaper(ScenesData.gameScene, RoomData.myself.position, target.position);
toSend.push(attackData); toSend.push(attackData);
} }
element.physicsObj.destroy(); element.physicsObj.destroy();
element.wordObj.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) toSend.forEach(function(element)
{ {
...@@ -453,7 +452,9 @@ WordSpace.attack = function(wordText, grade) ...@@ -453,7 +452,9 @@ WordSpace.attack = function(wordText, grade)
WordSpace.attackGauge.resetValue(); WordSpace.attackGauge.resetValue();
WordSpace.setPlayerTyping.add(wordText); WordSpace.setPlayerTyping.add(wordText);
BackGround.myCharacter.play(WordSpace.pyeongminAnims[Enums.characterAnim.throw]); RoomData.myself.playerImage.play(WordSpace.pyeongminAnims[Enums.characterAnim.throw]);
Input.attackOption.isHeavy = false;
Input.attackOption.isDark = false;
} }
else WordSpace.attackGauge.cutValue(0.3); else WordSpace.attackGauge.cutValue(0.3);
Input.maxInput = 6; Input.maxInput = 6;
...@@ -461,6 +462,36 @@ WordSpace.attack = function(wordText, grade) ...@@ -461,6 +462,36 @@ WordSpace.attack = function(wordText, grade)
WordSpace.attackGauge.pauseCycle(false); WordSpace.attackGauge.pauseCycle(false);
} }
WordSpace.makeAttackPaper = function(scene, attackFrom, attackTo)
{
var attackPaper = scene.add.sprite(attackFrom.x, attackFrom.y, 'attackPapaer').setScale(0.5).setDepth(3);
attackPaper.throwTarget = attackTo;
attackPaper.follower = { t: 0, vec: new Phaser.Math.Vector2() };
attackPaper.path = new Phaser.Curves.Spline([
attackFrom.x, attackFrom.y,
(attackFrom.x + attackPaper.throwTarget.x) / 2, Math.min(attackFrom.y, attackPaper.throwTarget.y) - 100,
attackPaper.throwTarget.x, attackPaper.throwTarget.y - 10
]);
scene.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);
obj.angle = 720 * obj.follower.t;
}
WordSpace.attackPaperGroup.push(attackPaper);
}
WordSpace.nameQueue = WordSpace.nameQueue =
{ {
queue: [], queue: [],
...@@ -468,12 +499,12 @@ WordSpace.nameQueue = ...@@ -468,12 +499,12 @@ WordSpace.nameQueue =
{ {
let tempQueue = []; let tempQueue = [];
RoomData.players.forEach(function(element){ RoomData.players.forEach(function(element){
tempQueue.push(element.index) tempQueue.push(element.index);
}) })
tempQueue.sort(function(){return 0.5-Math.random()}); Phaser.Utils.Array.Shuffle(tempQueue);
tempQueue.forEach(function(element) tempQueue.forEach(function(element)
{ {
if(RoomData.players[element].id != PlayerData.id && RoomData.players[element].isAlive) if(RoomData.players[element].id != PlayerData.id && RoomData.players[element].isAlive && WordSpace.nameQueue.getCount(element) < 3)
WordSpace.nameQueue.queue.push(element); WordSpace.nameQueue.queue.push(element);
}); });
}, },
...@@ -481,9 +512,17 @@ WordSpace.nameQueue = ...@@ -481,9 +512,17 @@ WordSpace.nameQueue =
{ {
let tempElement = WordSpace.nameQueue.queue.shift(); let tempElement = WordSpace.nameQueue.queue.shift();
if(WordSpace.nameQueue.queue.length <= RoomData.aliveCount) this.shuffle(); if(WordSpace.nameQueue.queue.length <= RoomData.aliveCount) this.shuffle();
if(!RoomData.players[tempElement].isAlive) return WordSpace.nameQueue.pop(); if(!RoomData.players[tempElement].isAlive && WordSpace.nameQueue.getCount(tempElement) < 3) return WordSpace.nameQueue.pop();
else return RoomData.players[tempElement]; else return RoomData.players[tempElement];
}, },
getCount: function(player)
{
let i = 0;
WordSpace.nameGroup.forEach(function(element){
if(element.id == player.id) i++;
})
return i;
},
initiate: function() initiate: function()
{ {
this.shuffle(); this.shuffle();
......
...@@ -32,4 +32,8 @@ var RoomData = RoomData || {}; ...@@ -32,4 +32,8 @@ var RoomData = RoomData || {};
RoomData.roomId = -1; RoomData.roomId = -1;
RoomData.myself = null; RoomData.myself = null;
RoomData.players = null; RoomData.players = null;
RoomData.aliveCount = -1; RoomData.aliveCount = -1;
\ No newline at end of file RoomData.findPlayer = function(player)
{
return RoomData.players.find(function(element){ return element.id == player.id; });
}
\ No newline at end of file
...@@ -94,12 +94,12 @@ io.on('connection', function(socket) ...@@ -94,12 +94,12 @@ io.on('connection', function(socket)
socket.on('attack', function(msg) socket.on('attack', function(msg)
{ {
socket.playerData.currentRoom.announceToTarget(msg.target, 'attacked', msg); socket.playerData.currentRoom.announceToTarget(msg.victim.id, 'attacked', msg);
socket.playerData.currentRoom.announceToRoom('attack', {attackerId: msg.attacker.id, targetId: msg.target}); socket.playerData.currentRoom.announceToRoom('someoneAttacked', {attacker: msg.attacker, victim: msg.victim});
//console.log('attack ' + msg.target + ' by ' + msg.attacker.id + ' with ' + msg.text); //console.log('attack ' + msg.target + ' by ' + msg.attacker.id + ' with ' + msg.text);
setTimeout(function() setTimeout(function()
{ {
let target = GameServer.findPlayerSocket(msg.target); let target = GameServer.findPlayerSocket(msg.victim.id);
if (target != null) if (target != null)
{ {
let dataToPush = let dataToPush =
......
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