Add: BigMole, KeyboardMole

This commit is contained in:
2018-10-05 15:32:34 +09:00
parent 88fb1552ba
commit de26c72441
11 changed files with 193 additions and 317 deletions
+35 -18
View File
@@ -1,4 +1,4 @@
function Keyboard(keyMapper, language) {
function Keyboard(keyMapper, language, offsetY) {
this.keyMapper = keyMapper;
this.language = language;
@@ -29,7 +29,7 @@ function Keyboard(keyMapper, language) {
for(var i = 0; i < this.keyDataList.length; i++) {
this.keyList[i] = new KeyButton(
this.keyDataList[i].x,
this.keyDataList[i].y,
this.keyDataList[i].y + offsetY,
this.keyDataList[i].width,
this.keyDataList[i].height,
this.keyDataList[i].normalText,
@@ -219,6 +219,19 @@ Keyboard.prototype.addNextNormalKeyData = function(keyID, handSide, fingerType)
this.normalKeyHash[keyID] = newKey;
}
Keyboard.prototype.getKeyPosX = function(text) {
var keyID = this.keyMapper.getKeyIDOfText(text);
var key = this.allKeyHash[keyID];
if(key !== undefined)
return key.setting.x;
}
Keyboard.prototype.getKeyPosY = function(text) {
var keyID = this.keyMapper.getKeyIDOfText(text);
var key = this.allKeyHash[keyID];
if(key !== undefined)
return key.setting.y;
}
Keyboard.prototype.initKeyData = function(keyMapper) {
@@ -228,8 +241,8 @@ Keyboard.prototype.initKeyData = function(keyMapper) {
KeyButton.LEFT_HAND,
Keyboard.ROW_1,
KeyButton.LITTLE_FINGER,
Keyboard.KEYBOARD_OFFSET_POX_X,
Keyboard.ROW_1_POX_Y,
Keyboard.KEYBOARD_OFFSET_POS_X,
Keyboard.ROW_1_POS_Y,
Keyboard.DEFAULT_KEY_SIZE_PX,
Keyboard.DEFAULT_KEY_SIZE_PX,
KeyButton.NORMAL_FUNCTION_KEY
@@ -261,8 +274,8 @@ Keyboard.prototype.initKeyData = function(keyMapper) {
KeyButton.LEFT_HAND,
Keyboard.ROW_2,
KeyButton.NONE_FINGER,
Keyboard.KEYBOARD_OFFSET_POX_X,
Keyboard.ROW_2_POX_Y,
Keyboard.KEYBOARD_OFFSET_POS_X,
Keyboard.ROW_2_POS_Y,
Keyboard.TAB_KEY_WIDTH_PX,
Keyboard.DEFAULT_KEY_SIZE_PX,
KeyButton.LEFT_FUNCTION_KEY
@@ -287,8 +300,8 @@ Keyboard.prototype.initKeyData = function(keyMapper) {
KeyButton.LEFT_HAND,
Keyboard.ROW_3,
KeyButton.NONE_FINGER,
Keyboard.KEYBOARD_OFFSET_POX_X,
Keyboard.ROW_3_POX_Y,
Keyboard.KEYBOARD_OFFSET_POS_X,
Keyboard.ROW_3_POS_Y,
Keyboard.CAPS_LOCK_KEY_WIDTH_PX,
Keyboard.DEFAULT_KEY_SIZE_PX,
KeyButton.LEFT_FUNCTION_KEY
@@ -319,8 +332,8 @@ Keyboard.prototype.initKeyData = function(keyMapper) {
KeyButton.LEFT_HAND,
Keyboard.ROW_4,
KeyButton.LITTLE_FINGER,
Keyboard.KEYBOARD_OFFSET_POX_X,
Keyboard.ROW_4_POX_Y,
Keyboard.KEYBOARD_OFFSET_POS_X,
Keyboard.ROW_4_POS_Y,
Keyboard.SHIFT_KEY_WIDTH_PX,
Keyboard.DEFAULT_KEY_SIZE_PX,
KeyButton.LEFT_FUNCTION_KEY
@@ -350,8 +363,8 @@ Keyboard.prototype.initKeyData = function(keyMapper) {
KeyButton.LEFT_HAND,
Keyboard.ROW_5,
KeyButton.NONE_FINGER,
Keyboard.KEYBOARD_OFFSET_POX_X,
Keyboard.ROW_5_POX_Y,
Keyboard.KEYBOARD_OFFSET_POS_X,
Keyboard.ROW_5_POS_Y,
Keyboard.CTRL_KEY_WIDTH_PX,
Keyboard.DEFAULT_KEY_SIZE_PX,
KeyButton.LEFT_FUNCTION_KEY
@@ -433,12 +446,16 @@ Keyboard.KOREAN_ENGLISH_KEY_WIDTH_PX = Keyboard.DEFAULT_KEY_SIZE_PX;
Keyboard.KEY_GAP_PX = 6;
Keyboard.KEYBOARD_OFFSET_POX_X = 150;
Keyboard.ROW_1_POX_Y = 320;
Keyboard.ROW_2_POX_Y = Keyboard.ROW_1_POX_Y + Keyboard.DEFAULT_KEY_SIZE_PX + Keyboard.KEY_GAP_PX;
Keyboard.ROW_3_POX_Y = Keyboard.ROW_2_POX_Y + Keyboard.DEFAULT_KEY_SIZE_PX + Keyboard.KEY_GAP_PX;
Keyboard.ROW_4_POX_Y = Keyboard.ROW_3_POX_Y + Keyboard.DEFAULT_KEY_SIZE_PX + Keyboard.KEY_GAP_PX;
Keyboard.ROW_5_POX_Y = Keyboard.ROW_4_POX_Y + Keyboard.DEFAULT_KEY_SIZE_PX + Keyboard.KEY_GAP_PX;
Keyboard.NO_OFFSET_POS_Y = 0;
Keyboard.WHAC_A_MOLE_OFFSET_POS_Y = 70;
Keyboard.KEYBOARD_OFFSET_POS_X = 150;
Keyboard.ROW_1_POS_Y = 320;
Keyboard.ROW_2_POS_Y = Keyboard.ROW_1_POS_Y + Keyboard.DEFAULT_KEY_SIZE_PX + Keyboard.KEY_GAP_PX;
Keyboard.ROW_3_POS_Y = Keyboard.ROW_2_POS_Y + Keyboard.DEFAULT_KEY_SIZE_PX + Keyboard.KEY_GAP_PX;
Keyboard.ROW_4_POS_Y = Keyboard.ROW_3_POS_Y + Keyboard.DEFAULT_KEY_SIZE_PX + Keyboard.KEY_GAP_PX;
Keyboard.ROW_5_POS_Y = Keyboard.ROW_4_POS_Y + Keyboard.DEFAULT_KEY_SIZE_PX + Keyboard.KEY_GAP_PX;
Keyboard.ROW_1 = 1;
+17
View File
@@ -44,6 +44,23 @@ TypingContentBG.prototype.makeTestContentBG = function() {
}
}
TypingContentBG.prototype.makeWhacAMoleContentBG = function() {
var CONTENT_Y = 200;
var bar = game.add.graphics();
if(isKoreanTypingApp()) {
bar.beginFill(TypingContentBG.COLOR_CONTENT_BG, 1);
bar.drawRect(0, CONTENT_Y, GAME_SCREEN_SIZE.x, 120);
} else {
bar.beginFill(TypingContentBG.COLOR_CONTENT_BG, 1);
bar.drawRect(0, CONTENT_Y, GAME_SCREEN_SIZE.x, 40);
bar.beginFill(TypingContentBG.COLOR_CONTENT_ALPHABET_BG, 1);
bar.drawRect(0, CONTENT_Y + 40, GAME_SCREEN_SIZE.x, 50);
bar.beginFill(TypingContentBG.COLOR_CONTENT_BG, 1);
bar.drawRect(0, CONTENT_Y + 90, GAME_SCREEN_SIZE.x, 30);
}
}
TypingContentBG.COLOR_CONTENT_BG = 0x444444;
TypingContentBG.COLOR_CONTENT_ALPHABET_BG = 0x3d3d3d;
+2 -2
View File
@@ -93,9 +93,9 @@ var TypingPractice = {
this.keyMapper = new KeyMapper();
this.keyboard = null;
if(sessionStorageManager.getPlayingAppName().indexOf("korean") > 0)
this.keyboard = new Keyboard(this.keyMapper, Keyboard.KOREAN);
this.keyboard = new Keyboard(this.keyMapper, Keyboard.KOREAN, Keyboard.NO_OFFSET_POS_Y);
else
this.keyboard = new Keyboard(this.keyMapper, Keyboard.ENGLISH);
this.keyboard = new Keyboard(this.keyMapper, Keyboard.ENGLISH, Keyboard.NO_OFFSET_POS_Y);
game.input.keyboard.processKeyPress = (function() {
if(self.isOnStage === false)
+37 -26
View File
@@ -1,4 +1,4 @@
var TypingPractice = {
var WhacAMole = {
create: function() {
var self = this;
@@ -44,7 +44,7 @@ var TypingPractice = {
// var heartManager = new HeartManager();
this.stageTimer = new StageTimer( TypingPractice.STAGE_TIMER_SEC, (function() {
this.stageTimer = new StageTimer( WhacAMole.STAGE_TIMER_SEC, (function() {
self.isOnStage = false;
// self.goResult();
@@ -52,21 +52,23 @@ var TypingPractice = {
}));
this.bigMole = new BigMole(game.world.centerX, BigMole.START_POS_Y);
// typing content
var typingContentBG = new TypingContentBG();
typingContentBG.makePracticeContentBG();
typingContentBG.makeWhacAMoleContentBG();
var TYPING_CONTENT_Y = 200;
var TYPING_CONTENT_Y = 260;
textStyleBasic.font = "bold 84px Times New Roman";
this.textTypingContent = game.add.text(game.world.centerX, TYPING_CONTENT_Y, "", textStyleBasic)
.setShadow(3, 3, 'rgba(0, 0, 0, 1)', 2)
.addColor(TypingPractice.COLOR_CONTENT_INPUT, 0);
.addColor(WhacAMole.COLOR_CONTENT_INPUT, 0);
this.textTypingContent.anchor.set(0.5);
this.textTypingBracket = game.add.text(game.world.centerX, TYPING_CONTENT_Y, "[ ]", textStyleBasic)
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2)
.addColor(TypingPractice.COLOR_BRACKET, 0);
.addColor(WhacAMole.COLOR_BRACKET, 0);
this.textTypingBracket.anchor.set(0.5);
@@ -75,7 +77,7 @@ var TypingPractice = {
var textDoneColor = [ '#99994d', '#77774d', '#66664d' ];
this.textTypingContentsDone = [];
for(var i = 0; i < TypingPractice.TYPING_CONTENT_DONE_COUNT; i++) {
for(var i = 0; i < WhacAMole.TYPING_CONTENT_DONE_COUNT; i++) {
this.textTypingContentsDone[i] = game.add.text(
game.world.centerX - 200 - i * OFFSET_WORD_X, TYPING_CONTENT_Y,
"", textStyleBasic
@@ -86,7 +88,7 @@ var TypingPractice = {
var textPreviewColor = [ '#666666', '#888888', '#777777' ];
this.textTypingContentPreview = [];
for(var i = 0; i < TypingPractice.TYPING_CONTENT_PREVIEW_COUNT; i++) {
for(var i = 0; i < WhacAMole.TYPING_CONTENT_PREVIEW_COUNT; i++) {
this.textTypingContentPreview[i] = game.add.text(
game.world.centerX + 200 + i * OFFSET_WORD_X,
TYPING_CONTENT_Y, "", textStyleBasic
@@ -99,9 +101,9 @@ var TypingPractice = {
this.keyMapper = new KeyMapper();
this.keyboard = null;
if(sessionStorageManager.getPlayingAppName().indexOf("korean") > 0)
this.keyboard = new Keyboard(this.keyMapper, Keyboard.KOREAN);
this.keyboard = new Keyboard(this.keyMapper, Keyboard.KOREAN, Keyboard.WHAC_A_MOLE_OFFSET_POS_Y);
else
this.keyboard = new Keyboard(this.keyMapper, Keyboard.ENGLISH);
this.keyboard = new Keyboard(this.keyMapper, Keyboard.ENGLISH, Keyboard.WHAC_A_MOLE_OFFSET_POS_Y);
game.input.keyboard.processKeyPress = (function() {
if(self.isOnStage === false)
@@ -112,6 +114,8 @@ var TypingPractice = {
this.shiftKey = game.input.keyboard.addKey(Phaser.Keyboard.SHIFT);
this.keyboardMole = new KeyboardMole(this.keyboard);
// bottom ui
this.screenBottomUI = new ScreenBottomUI();
// screenBottomUI.printBottomUILeftText("");
@@ -127,24 +131,24 @@ var TypingPractice = {
this.isOnStage = true;
this.stageTimer.start();
this.showTypingPracticeContents();
this.showWhacAMoleContents();
this.showHighlightKey();
},
gameOver: function() {
this.isOnStage = false;
for(var i = 0; i < TypingPractice.TYPING_CONTENT_DONE_COUNT; i++) {
for(var i = 0; i < WhacAMole.TYPING_CONTENT_DONE_COUNT; i++) {
this.textTypingContentsDone[i].text = "";
}
this.textTypingBracket.text = "";
this.textTypingContent.clearColors();
this.textTypingContent.addColor(TypingPractice.COLOR_CONTENT_RIGHT, 0);
this.textTypingContent.addColor(WhacAMole.COLOR_CONTENT_RIGHT, 0);
this.textTypingContent.text = "= 연습 끝 =";
for(var i = 0; i < TypingPractice.TYPING_CONTENT_PREVIEW_COUNT; i++) {
for(var i = 0; i < WhacAMole.TYPING_CONTENT_PREVIEW_COUNT; i++) {
this.textTypingContentPreview[i].text = "";
}
@@ -317,8 +321,8 @@ var TypingPractice = {
return letters;
},
showTypingPracticeContents: function() {
for(var i = 0; i < TypingPractice.TYPING_CONTENT_DONE_COUNT; i++) {
showWhacAMoleContents: function() {
for(var i = 0; i < WhacAMole.TYPING_CONTENT_DONE_COUNT; i++) {
var doneIndex = this.typingIndex - i - 1;
if(doneIndex < 0) {
this.textTypingContentsDone[i].text = "";
@@ -333,8 +337,15 @@ var TypingPractice = {
}
this.textTypingContent.text = this.typingRandomLetters[this.typingIndex];
// var keyID = this.keyboard.keyMapper.getKeyIDOfText(this.typingRandomLetters[this.typingIndex]);
for(var i = 0; i < TypingPractice.TYPING_CONTENT_PREVIEW_COUNT; i++) {
this.bigMole.showUp();
this.keyboardMole.show();
this.keyboardMole.moveToKey(this.typingRandomLetters[this.typingIndex]);
for(var i = 0; i < WhacAMole.TYPING_CONTENT_PREVIEW_COUNT; i++) {
var previewIndex = this.typingIndex + i + 1;
if(previewIndex < this.typingRandomLetters.length)
this.textTypingContentPreview[i].text = this.typingRandomLetters[previewIndex];
@@ -401,20 +412,20 @@ var TypingPractice = {
this.hideHighlightKey();
this.typingIndex++;
this.showTypingPracticeContents();
this.showWhacAMoleContents();
this.showHighlightKey();
}
}
TypingPractice.TYPING_CONTENT_PREVIEW_COUNT = 3;
TypingPractice.TYPING_CONTENT_DONE_COUNT = 3;
// TypingPractice.TYPING_COUNT_PLUS_ENTER = 1;
WhacAMole.TYPING_CONTENT_PREVIEW_COUNT = 3;
WhacAMole.TYPING_CONTENT_DONE_COUNT = 3;
// WhacAMole.TYPING_COUNT_PLUS_ENTER = 1;
// TypingPractice.OFFSET_RIGHT_ALIGN = 10;
// WhacAMole.OFFSET_RIGHT_ALIGN = 10;
TypingPractice.STAGE_TIMER_SEC = 60;
WhacAMole.STAGE_TIMER_SEC = 60;
TypingPractice.COLOR_CONTENT_INPUT = "#dddddd";
TypingPractice.COLOR_BRACKET = "#dddd70";
TypingPractice.COLOR_CONTENT_RIGHT = "#ffff4d";
WhacAMole.COLOR_CONTENT_INPUT = "#dddddd";
WhacAMole.COLOR_BRACKET = "#dddd70";
WhacAMole.COLOR_CONTENT_RIGHT = "#ffff4d";
-263
View File
@@ -1,263 +0,0 @@
function Hand(keyMapper) {
this.keyMapper = keyMapper;
this.pressingFinger = KeyButton.NONE_FINGER;
this.prevFingerSprite = null;
this.hand = game.add.image(0, Hand.DEFAULT_Y_PX, "hand_palm");
this.hand.anchor.set(0.5);
this.hand.scale.set(2);
this.thumb = game.add.image(0, 0, "hand_thumb");
this.thumb.alpha = 0.5;
this.hand.addChild(this.thumb);
this.index_finger = game.add.image(0, 0, "hand_index_finger");
this.index_finger.alpha = 0.5;
this.hand.addChild(this.index_finger);
this.middle_finger = game.add.image(0, 0, "hand_middle_finger");
this.middle_finger.alpha = 0.5;
this.hand.addChild(this.middle_finger);
this.ring_filger = game.add.image(0, 0, "hand_little_finger");
this.ring_filger.alpha = 0.5;
this.hand.addChild(this.ring_filger);
this.little_finger = game.add.image(0, 0, "hand_ring_finger");
this.little_finger.alpha = 0.5;
this.hand.addChild(this.little_finger);
var mask = game.add.graphics();
mask.beginFill(0xffffff);
mask.drawRect(100, 300, 1028, 360);
this.hand.mask = mask;
}
Hand.prototype.move = function(sprite, x, y) {
sprite.x = x;
sprite.y = y;
}
Hand.prototype.moveTo = function(key) {
}
Hand.prototype.moveToDefaultPosition = function() {
this.moveRow(3, null);
this.unhighlightOffFinger(KeyButton.NONE_FINGER);
}
Hand.prototype.moveRow = function(rowNo, key) {
var rowIndex = rowNo - 1;
this.hand.y = Hand.DEFAULT_Y_PX + Keyboard.DEFAULT_KEY_SIZE_PX * rowIndex;
this.moveColumn(rowNo, key);
}
Hand.prototype.moveColumn = function(rowNo, key) {
}
Hand.prototype.getFingerSprite = function(fingerNo) {
var fingerSprite = null;
switch(fingerNo) {
case KeyButton.THUMB:
fingerSprite = this.thumb;
break;
case KeyButton.INDEX_FINGER:
case KeyButton.INDEX_FINGER_BASELINE:
fingerSprite = this.index_finger;
break;
case KeyButton.MIDDLE_FINGER:
fingerSprite = this.middle_finger;
break;
case KeyButton.RING_FINGER:
fingerSprite = this.ring_filger;
break;
case KeyButton.LITTLE_FINGER:
fingerSprite = this.little_finger;
break;
}
return fingerSprite;
}
Hand.prototype.highlightOnFinger = function(fingerNo) {
// console.log(fingerNo);
var pressingFingerSprite = this.getFingerSprite(fingerNo);
if(pressingFingerSprite === this.prevFingerSprite)
return;
if(this.prevFingerSprite !== null)
this.unhighlightOffFinger();
if(pressingFingerSprite !== null) {
// console.log(pressingFingerSprite);
pressingFingerSprite.tint = 0xffff00;
pressingFingerSprite.alpha = 1;
}
this.prevFingerSprite = pressingFingerSprite;
}
Hand.prototype.unhighlightOffFinger = function() {
if(this.prevFingerSprite === null)
return;
this.prevFingerSprite.tint = 0xffffff;
this.prevFingerSprite.alpha = 0.5;
this.prevFingerSprite = null;
}
Hand.DEFAULT_Y_PX = 540; // 680;
LeftHand.prototype = Object.create(Hand.prototype);
LeftHand.constructor = LeftHand;
function LeftHand(keyMapper) {
Hand.call(this, keyMapper);
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);
this.moveToDefaultPosition();
}
LeftHand.prototype.moveTo = function(key) {
if(key === undefined)
return;
// console.log(key);
var keyCode = this.keyMapper.getKeyIDOfText(key.normalText);
if(keyCode != "Space")
this.moveRow(key.row, key);
else
this.moveRow(3, key);
switch(key.keyCode) {
case "Key5":
case "KeyT":
case "KeyG":
case "KeyB":
this.moveColumn(5, key);
break;
}
this.highlightOnFinger(key.fingerType);
}
LeftHand.prototype.moveColumn = function(rowNo, key) {
var rowIndex = rowNo - 1;
this.hand.x = LeftHand.DEFAULT_X_PX + (Keyboard.DEFAULT_KEY_SIZE_PX / 2) * rowIndex;
if(key === null)
return;
var keyCode = this.keyMapper.getKeyIDOfText(key.normalText);
switch(keyCode) {
case "Key5":
case "KeyT":
case "KeyG":
case "KeyB":
this.hand.x += Keyboard.DEFAULT_KEY_SIZE_PX;
break;
case "ShiftLeft":
this.hand.x = LeftHand.DEFAULT_X_PX;
break;
}
}
LeftHand.DEFAULT_X_PX = 100;
RightHand.prototype = Object.create(Hand.prototype);
RightHand.constructor = RightHand;
function RightHand(keyMapper) {
Hand.call(this, keyMapper);
this.hand.scale.x *= -1;
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);
this.moveToDefaultPosition();
}
RightHand.prototype.moveTo = function(key) {
if(key === undefined)
return;
// console.log(key);
var keyCode = this.keyMapper.getKeyIDOfText(key.normalText);
if(keyCode != "Space")
this.moveRow(key.row, key);
else
this.moveRow(3, key);
switch(key.keyCode) {
case "Key5":
case "KeyT":
case "KeyG":
case "KeyB":
this.moveColumn(5, key);
break;
}
this.highlightOnFinger(key.fingerType);
}
RightHand.prototype.moveColumn = function(rowNo, key) {
var rowIndex = rowNo - 1;
this.hand.x = RightHand.DEFAULT_X_PX + (Keyboard.DEFAULT_KEY_SIZE_PX / 2) * rowIndex;
if(key === null)
return;
var keyCode = this.keyMapper.getKeyIDOfText(key.normalText);
switch(keyCode) {
case "Key6":
case "KeyY":
case "KeyH":
case "KeyN":
this.hand.x -= Keyboard.DEFAULT_KEY_SIZE_PX;
break;
case "Minus":
case "BracketLeft":
case "Quote":
this.hand.x += (Keyboard.DEFAULT_KEY_SIZE_PX / 2) * 3;
break;
case "Equal":
case "BracketRight":
this.hand.x += (Keyboard.DEFAULT_KEY_SIZE_PX / 2) * 5;
break;
case "Backslash":
this.hand.x += (Keyboard.DEFAULT_KEY_SIZE_PX / 2) * 7;
break;
case "Enter":
this.hand.x = RightHand.DEFAULT_X_PX + (Keyboard.DEFAULT_KEY_SIZE_PX / 2) * 6;
break;
case "ShiftRight":
this.hand.x = RightHand.DEFAULT_X_PX + (Keyboard.DEFAULT_KEY_SIZE_PX / 2) * 6;
break;
}
}
RightHand.DEFAULT_X_PX = 810;
+3 -4
View File
@@ -29,8 +29,7 @@ var Loading = {
startLoading: function() {
game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png');
// Hand.loadResources();
// Animal.loadResources();
game.load.image('mole', '../../../resources/image/character/mole.png');
// game.load.image('hand_left', '../../../resources/image/ui/hand_left.png');
@@ -82,11 +81,11 @@ var Loading = {
// this.preloadBar.alpha = 1;
if(isDebugMode()) {
this.state.start('TypingPractice');
this.state.start('WhacAMole');
return;
}
this.state.start('TypingPractice');
this.state.start('WhacAMole');
// this.startMenu();
// this.startTypingTestStage();
// this.startTypingTestResult();
+2 -2
View File
@@ -1,7 +1,7 @@
/////////////////////////////
// Main game
const CONTENT_ID = "Typing Practice";
const CONTENT_ID = "WhacAMole";
let game = new Phaser.Game(
GAME_SCREEN_SIZE.x, GAME_SCREEN_SIZE.y,
@@ -12,5 +12,5 @@ let game = new Phaser.Game(
game.state.add('Loading', Loading);
game.state.start('Loading');
game.state.add('TypingPractice', TypingPractice);
game.state.add('WhacAMole', WhacAMole);
// game.state.add('Menu', Menu);
+95
View File
@@ -0,0 +1,95 @@
function Mole(x, y, scale) {
this.mole = game.add.image(x, y, "mole");
this.mole.scale.set(scale);
// this.move(x, y);
// return this.mole;
}
Mole.prototype.alpha = function(value) {
this.mole.alpha = value;
}
Mole.prototype.move = function(x, y) {
this.mole.x = x;
this.mole.y = y;
this.posY = y;
}
Mole.prototype.anchor = function(x, y) {
this.mole.anchor.x = x;
this.mole.anchor.y = y;
}
Mole.prototype.showUpTween = function(showUpHeight) {
// if(this.tween != undefined && this.tween.isRunning) {
// this.tween.stop();
// // this.tween.pendingDelete = false;
// // this.mole.y = BigMole.START_POS_Y;
// }
// console.log(this.mole);
// console.log("this.posY : " + this.posY);
this.tween = game.add.tween(this.mole)
.from( { y: BigMole.START_POS_Y }, 10 )
.to( { y: BigMole.SHOW_UP_POS_Y }, BigMole.SHOW_UP_TIME_MS, "Quart.easeOut");
// .from( { y: this.posY }, 10 )
// .to( { y: (this.posY + showUpHeight) }, BigMole.SHOW_UP_TIME_MS, "Quart.easeOut");
this.tween.start();
}
// big mole
BigMole.prototype = Object.create(Mole.prototype);
BigMole.constructor = BigMole;
function BigMole(x, y) {
Mole.call(this, x, y, BigMole.SCALE);
this.anchor(0.5, 0);
}
BigMole.prototype.showUp = function() {
this.showUpTween(100);
}
BigMole.SCALE = 1;
BigMole.START_POS_Y = 200;
BigMole.SHOW_UP_POS_Y = 100;
BigMole.SHOW_UP_TIME_MS = 200;
// keyboard mole
KeyboardMole.prototype = Object.create(Mole.prototype);
KeyboardMole.constructor = KeyboardMole;
function KeyboardMole(keyboard) {
this.keyboard = keyboard;
Mole.call(this, 0, 0, KeyboardMole.SCALE);
this.anchor(0, 0);
this.hide();
}
KeyboardMole.prototype.show = function() {
this.alpha(1);
}
KeyboardMole.prototype.hide = function() {
this.alpha(0);
}
KeyboardMole.prototype.moveToKey = function(text) {
var x = this.keyboard.getKeyPosX(text);
var y = this.keyboard.getKeyPosY(text);
this.move(x, y);
}
KeyboardMole.SCALE = 0.5;