Add: hands

This commit is contained in:
2018-06-19 22:57:16 +09:00
parent e7ce9c2e10
commit 6a5a2db670
13 changed files with 259 additions and 26 deletions
+189
View File
@@ -0,0 +1,189 @@
class Hand {
constructor(keyMapper) {
this.keyMapper = keyMapper;
console.log(this.keyMapper);
this.pressingFinger = KeyButton.NONE_FINGER;
this.hand = game.add.image(0, Hand.DEFAULT_Y_PX, "hand_palm");
this.hand.anchor.set(0.5);
this.thumb = game.add.image(0, 0, "hand_thumb");
this.hand.addChild(this.thumb);
this.index_finger = game.add.image(0, 0, "hand_index_finger");
this.hand.addChild(this.index_finger);
this.middle_finger = game.add.image(0, 0, "hand_middle_finger");
this.hand.addChild(this.middle_finger);
this.ring_filger = game.add.image(0, 0, "hand_little_finger");
this.hand.addChild(this.ring_filger);
this.little_finger = game.add.image(0, 0, "hand_ring_finger");
this.hand.addChild(this.little_finger);
this.hand.scale.set(2);
// this.hand.anchor.set(0.5);
let mask = game.add.graphics();
mask.beginFill(0xffffff);
mask.drawRect(100, 300, 1028, 400);
this.hand.mask = mask;
}
move(sprite, x, y) {
sprite.x = x;
sprite.y = y;
}
moveTo(key) {
}
moveRow(no) {
let rowIndex = no - 1;
this.hand.y = Hand.DEFAULT_Y_PX + Keyboard.DEFAULT_KEY_SIZE_PX * rowIndex;
this.moveColumn(no);
}
moveColumn(no) {
}
pressFinger(finger) {
if(this.pressingFinger !== finger) {
unpressFinger(this.pressingFinger);
}
switch(finger) {
case KeyButton.THUMB:
prevFinger = this.thumb;
break;
case KeyButton.INDEX_FINGER:
prevFinger = this.thumb;
break;
case KeyButton.MIDDLE_FINGER:
prevFinger = this.thumb;
break;
case KeyButton.RING_FINGER:
prevFinger = this.thumb;
break;
case KeyButton.LITTLE_FINGER:
prevFinger = this.thumb;
break;
}
if(prevFinger !== null)
prevFinger.tint = 0x0000ff;
}
unpressFinger(finger) {
let prevFinger = null;
switch(finger) {
case KeyButton.THUMB:
prevFinger = this.thumb;
break;
case KeyButton.INDEX_FINGER:
prevFinger = this.thumb;
break;
case KeyButton.MIDDLE_FINGER:
prevFinger = this.thumb;
break;
case KeyButton.RING_FINGER:
prevFinger = this.thumb;
break;
case KeyButton.LITTLE_FINGER:
prevFinger = this.thumb;
break;
}
if(prevFinger !== null)
prevFinger.tint = 0xffffff;
}
}
Hand.DEFAULT_Y_PX = 580; // 680;
class LeftHand extends Hand {
constructor(keyMapper) {
super(keyMapper);
this.moveRow(3);
this.move(this.thumb, 126, -50);
this.move(this.index_finger, 96, -102);
this.move(this.middle_finger, 58, -116);
this.move(this.ring_filger, 32, -110);
this.move(this.little_finger, 4, -106);
}
moveTo(key) {
console.log(key);
let keyCode = this.keyMapper.getKeyIDOfText(key.normalText);
if(keyCode != "Space")
this.moveRow(key.row);
else
this.moveRow(3);
switch(key.keyCode) {
case "key5":
case "keyT":
case "keyG":
case "keyB":
this.moveColumn(5);
break;
}
}
moveColumn(no) {
let colIndex = no - 1;
this.hand.x = LeftHand.DEFAULT_X_PX + (Keyboard.DEFAULT_KEY_SIZE_PX / 2) * colIndex;
}
}
LeftHand.DEFAULT_X_PX = 100;
class RightHand extends Hand {
constructor(keyMapper) {
super(keyMapper);
this.hand.scale.x *= -1;
this.moveRow(3);
this.move(this.thumb, 126, -50);
this.move(this.index_finger, 96, -102);
this.move(this.middle_finger, 58, -116);
this.move(this.ring_filger, 32, -110);
this.move(this.little_finger, 4, -106);
}
moveTo(key) {
console.log(key);
let keyCode = this.keyMapper.getKeyIDOfText(key.normalText);
if(keyCode != "Space")
this.moveRow(key.row);
else
this.moveRow(3);
switch(key.keyCode) {
case "key5":
case "keyT":
case "keyG":
case "keyB":
this.moveColumn(5);
break;
}
}
moveColumn(no) {
let colIndex = no - 1;
this.hand.x = RightHand.DEFAULT_X_PX + (Keyboard.DEFAULT_KEY_SIZE_PX / 2) * colIndex;
}
}
RightHand.DEFAULT_X_PX = 810;