From 854d1c9a8d24f7af829dcc482d1f9d86836c5dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Thu, 3 Jan 2019 16:02:14 +0900 Subject: [PATCH] Add: flyingsaucer image --- resources/image/character/alien/cockpit.png | Bin 0 -> 528 bytes resources/image/character/alien/jet.png | Bin 0 -> 264 bytes resources/image/character/alien/ship.png | Bin 0 -> 585 bytes .../typing/word_flyingsaucer/flyingsaucer.js | 157 +++++++++++++++++- src/game/typing/word_flyingsaucer/game.js | 61 ++++--- src/game/typing/word_flyingsaucer/loading.js | 2 +- 6 files changed, 184 insertions(+), 36 deletions(-) create mode 100644 resources/image/character/alien/cockpit.png create mode 100644 resources/image/character/alien/jet.png create mode 100644 resources/image/character/alien/ship.png diff --git a/resources/image/character/alien/cockpit.png b/resources/image/character/alien/cockpit.png new file mode 100644 index 0000000000000000000000000000000000000000..96ce3e97f9a8e65dea01f5f940573778c865a674 GIT binary patch literal 528 zcmV+r0`L8aP)001Zm1^@s6c`Wgm0005jNklSO34?wymnIkwB&e_yimhS(UKEm!IIw3^EnKZ|EXmdy4cM z%4`_v0hZ7)fxClQ0+|6LCBPBTl~88GNCof;UZ$kGOTzQ#R~Xq+kpkcu-pJ^lCL;^P z&;SLmHWR1moQlyQh6E^h_3-Y>b5w|-0193^JT{1703Pw_9?uqHq%?E~sMNz_W7?>= z0#xet!*{&Waiij$hAse=dOq+<2tV(8LF^7tsppR`QW|yzD15Q-?Y;3V$=v`7Urc=7 z2)h6jzS#IY5t;)OJ`Q|d2u%SB9~V9kgk}JRj}u>SgeCxmj~ic4gr)#>rppg;e?(*T zpc)QvPe0+~$9GOb3xrUBD!qBo^*Svv0jTuL2hpk&!vL!E=0jKdb1SkGLjbDu=EwIL zp~aao6rf6Peu(H&EP(mVKt~u3pzi&k>r2rX5@B-!3Lu3UXeYw})aC=at~8AyHzQ36 zsPv;T1Mes*1qBekG-EUBhtl2MfOyAc7L$jdAd%wn4Yb~B0ZX80`H96-Dh&u*x zVuEz`Y&z2UgJ-wPI`V}&NkK&2r(&NV*<@%JpmtS2p))5RcLdyaW zv@OAvcR96Ez1N#C8VJ!50D}JO4Hzwi3WTOv4|^cv{445bR;3N#{6YLTLVa5-<( zWxm!#pu{5LfM5?(Z+N)_0woqv2LyX`&}o)XOh9W90#b~c7b6m=5)h785l4YFrwC|| zSt5h*(=Nj{5&?}xE(3x+Mj8$FvJ=o)L>v$<=M2|K1f&)rAR~31y@(081cc+2m^Tjw zBOpCyWevjRJXqIRu8M%fBBuet9xB#69FTy-B9{T-avrerELlw8$|A{tU=J~09t=+4 z$|Bi-V2|M4XZa!mIg1bw5kejsnSd%F9Ir+m1@@LAkUM658HAs98KOH9IJ3w{K(NOh zM}s}@1kNmy3<#HVhUSh0QWhZ~cbo+FoFtG92!F!K)Ii{$!14EOFM|*e#sdQ10r>+S XW(+u&hVktH0000 GAME_SCREEN_SIZE.y - 200) this.moveInitialPos(); } else { @@ -48,11 +105,92 @@ FlyingSaucer.prototype.stop = function() { FlyingSaucer.prototype.setActive = function(isActivated) { this.isActivated = isActivated; + + if(this.isActivated) { + this.alpha = 1; + } else { + this.alpha = 0; + this.wordText.text = ""; + } } FlyingSaucer.prototype.moveInitialPos = function() { - this.x = 50 + this.lineIndex * 100; + console.log("moveInitialPos"); + this.x = 100 + this.lineIndex * 200; this.y = 100; + + this.wordText.x = this.x; + this.wordText.y = this.y + FlyingSaucer.WORD_TEXT_OFFSET_Y; + + this.explodeEmitter = game.add.emitter( + this.x, + this.y, + 10 + ); + this.explodeEmitter.makeParticles('star'); + this.explodeEmitter.minParticleScale = 1; + this.explodeEmitter.maxParticleScale = 3; + this.explodeEmitter.forEach( + function(particle) { + particle.tint = 0xadff2f; + } + ); + this.explodeEmitter.gravity = 0; +} + +FlyingSaucer.prototype.reset = function() { + this.moveInitialPos(); + this.wordText.text = "text"; + this.setActive(true); +} + +FlyingSaucer.prototype.checkInputText = function(inputText) { + // console.log("inputText : " + inputText); + // console.log("this.wordText : " + this.wordText); + + this.wordText.clearColors(); + this.wordText.addColor(FlyingSaucer.TEXT_COLOR_NORMAL, 0); + + if(inputText == null || inputText.length == 0) + return; + + var word = this.wordText.text; + var inputTextLength = inputText.length; + var index = 0; + for(; index < inputTextLength; index++) { + // console.log("i : " + index); + // console.log("inputTextLength : " + inputTextLength); + // console.log("inputText.charAt(i) : " + inputText.charAt(index)); + // console.log("this.wordText.text.charAt(i) : " + this.wordText.text.charAt(index)); + + if(index == 0 && word.charAt(index) == inputText.charAt(index)) { + this.wordText.addColor(FlyingSaucer.TEXT_COLOR_CORRECT, index); + } else if(word.charAt(index) != inputText.charAt(index)) { + this.wordText.addColor(FlyingSaucer.TEXT_COLOR_NORMAL, index); + return; + } + } + this.wordText.addColor(FlyingSaucer.TEXT_COLOR_NORMAL, index); +} + +FlyingSaucer.prototype.attack = function(inputText) { + // console.log("inputText : " + inputText); + // console.log("this.wordText : " + this.wordText); + + var word = this.wordText.text; + + if(word == inputText) { + this.explode(); + return; + } +} + +FlyingSaucer.prototype.explode = function(inputText) { + this.setActive(false); + + this.explodeEmitter.start(true, 1000, null, 100); + + this.timerEvent = game.time.events.add(Phaser.Timer.SECOND, this.reset, this); } @@ -60,9 +198,22 @@ FlyingSaucer.prototype.moveInitialPos = function() { FlyingSaucer.loadResource = function() { if(!game.cache.checkImageKey('alien_normal')) game.load.image('alien_normal', '../../../resources/image/character/alien/green_alien.png'); + + if(!game.cache.checkImageKey('ship_cockpit')) + game.load.image('ship_cockpit', '../../../resources/image/character/alien/cockpit.png'); + + if(!game.cache.checkImageKey('ship_body')) + game.load.image('ship_body', '../../../resources/image/character/alien/ship.png'); + + if(!game.cache.checkImageKey('ship_jet')) + game.load.image('ship_jet', '../../../resources/image/character/alien/jet.png'); } FlyingSaucer.DEFAULT_SPEED = 10; // dot per sec +FlyingSaucer.WORD_TEXT_OFFSET_Y = 30; // px + +FlyingSaucer.TEXT_COLOR_NORMAL = "#000000"; +FlyingSaucer.TEXT_COLOR_CORRECT = "#ffff4d"; \ No newline at end of file diff --git a/src/game/typing/word_flyingsaucer/game.js b/src/game/typing/word_flyingsaucer/game.js index e24d9f1..45bfe5d 100644 --- a/src/game/typing/word_flyingsaucer/game.js +++ b/src/game/typing/word_flyingsaucer/game.js @@ -11,7 +11,26 @@ var WordFlyingSaucer = { (function() { this.timeOver(); }).bind(this) ); - game.stage.backgroundColor = '#4d4d4d'; + this.initVariables(); + + + + // game stage + this.game.stage.backgroundColor = "#000000"; // '#4d4d4d'; + var stars = game.add.group(); + for (var i = 0; i < 128; i++) { + var randomY = game.rnd.integerInRange(60, GAME_SCREEN_SIZE.y - 80); + stars.create(game.world.randomX, randomY, 'star'); + } + + this.flyingsaucers = []; + for(var i = 0; i < 2; i++) { + this.flyingsaucers[i] = new FlyingSaucer(i); + this.flyingsaucers[i].setup(this.wordLevel, this.speedLevel); + this.flyingsaucers[i].setActive(true); + } + + // top ui var screenTopUI = new ScreenTopUI(); @@ -44,14 +63,6 @@ var WordFlyingSaucer = { heartGauge.start(); - this.initVariables(); - - for(var i = 0; i < 10; i++) { - var flyingsaucer = new FlyingSaucer(i); - flyingsaucer.setup(this.wordLevel, this.speedLevel); - flyingsaucer.setActive(true); - } - // input text @@ -124,32 +135,18 @@ var WordFlyingSaucer = { checkTypingContents: function(event) { + var count = this.flyingsaucers.length; if(event.keyCode == Phaser.Keyboard.ENTER) { - // console.log("### enter ###"); - var inputContent = this.inputText.canvasInput.value(); - /* - var typingContent = this.typingRandomContents[this.typingIndex]; - - if(inputContent === typingContent) { - this.calculateTypingRecord(typingContent); - this.playNextContent(); - - if(this.typingIndex == this.typingContentLength) - this.gameOver(); - // this.goResult(); - // this.state.start('TypingTestResult'); - } - */ - } - else { - /* - if(this.isTyping == false) { - // console.log(event); - this.setTimeTypingStart(); + for(var i = 0; i < count; i++) { + this.flyingsaucers[i].attack(this.inputText.canvasInput.value()); } - this.showTypingContentHighlight(); - */ + this.inputText.canvasInput.value(""); + } else { + + for(var i = 0; i < count; i++) { + this.flyingsaucers[i].checkInputText(this.inputText.canvasInput.value()); + } } }, diff --git a/src/game/typing/word_flyingsaucer/loading.js b/src/game/typing/word_flyingsaucer/loading.js index 76a46ad..4c47c52 100644 --- a/src/game/typing/word_flyingsaucer/loading.js +++ b/src/game/typing/word_flyingsaucer/loading.js @@ -29,7 +29,7 @@ var Loading = { startLoading: function() { game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png'); - game.load.image('star', '../../../resources/image/ui/star_particle.png'); + game.load.image('star', '../../../resources/image/background/star_7x7.png'); HeartGauge.loadResources(); FlyingSaucer.loadResource();