├── README.md
├── icons
├── Icon-App-29x29@1x.png
├── Icon-App-29x29@2x.png
├── Icon-App-29x29@3x.png
├── Icon-App-40x40@1x.png
├── Icon-App-40x40@2x.png
├── Icon-App-60x60@2x.png
├── Icon-App-60x60@3x.png
├── Icon-App-76x76@1x.png
└── Icon-App-76x76@2x.png
├── images
├── clouds.png
├── frog.png
├── ground.png
└── pipe.png
├── index.html
├── main.js
├── phaser.min.js
└── sounds
├── bgm.mp3
├── bgm.ogg
├── flap.mp3
├── flap.ogg
├── hurt1.mp3
├── hurt1.ogg
├── hurt2.mp3
├── hurt2.ogg
├── hurt3.mp3
├── hurt3.ogg
├── hurt4.mp3
├── hurt4.ogg
├── hurt5.mp3
├── hurt5.ogg
├── hurt6.mp3
├── hurt6.ogg
├── hurt7.mp3
├── hurt7.ogg
├── hurt8.mp3
├── hurt8.ogg
├── hurt9.mp3
├── hurt9.ogg
├── score1.mp3
├── score1.ogg
├── score10.mp3
├── score10.ogg
├── score2.mp3
├── score2.ogg
├── score3.mp3
├── score3.ogg
├── score4.mp3
├── score4.ogg
├── score5.mp3
├── score5.ogg
├── score6.mp3
├── score6.ogg
├── score7.mp3
├── score7.ogg
├── score8.mp3
├── score8.ogg
├── score9.mp3
└── score9.ogg
/README.md:
--------------------------------------------------------------------------------
1 | # FlappyFrog
2 | The violent **mo**dification of [Don't Touch My Birdie](https://github.com/marksteve/dtmb) by Mark Steve Samson
3 | licensed under [Creative Com**mo**ns Attribution-NonCommercial 4.0 International License](https://creativecommons.org/licenses/by-nc/4.0/).
4 |
5 | play: https://tusenpo.github.io/FlappyFrog/
6 |
7 | the weird frog image is **mo**dified from [another frog image](https://amphibian.com/)
8 |
--------------------------------------------------------------------------------
/icons/Icon-App-29x29@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/icons/Icon-App-29x29@1x.png
--------------------------------------------------------------------------------
/icons/Icon-App-29x29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/icons/Icon-App-29x29@2x.png
--------------------------------------------------------------------------------
/icons/Icon-App-29x29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/icons/Icon-App-29x29@3x.png
--------------------------------------------------------------------------------
/icons/Icon-App-40x40@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/icons/Icon-App-40x40@1x.png
--------------------------------------------------------------------------------
/icons/Icon-App-40x40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/icons/Icon-App-40x40@2x.png
--------------------------------------------------------------------------------
/icons/Icon-App-60x60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/icons/Icon-App-60x60@2x.png
--------------------------------------------------------------------------------
/icons/Icon-App-60x60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/icons/Icon-App-60x60@3x.png
--------------------------------------------------------------------------------
/icons/Icon-App-76x76@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/icons/Icon-App-76x76@1x.png
--------------------------------------------------------------------------------
/icons/Icon-App-76x76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/icons/Icon-App-76x76@2x.png
--------------------------------------------------------------------------------
/images/clouds.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/images/clouds.png
--------------------------------------------------------------------------------
/images/frog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/images/frog.png
--------------------------------------------------------------------------------
/images/ground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/images/ground.png
--------------------------------------------------------------------------------
/images/pipe.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/images/pipe.png
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Excited!
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
41 |
42 |
43 |
44 |
49 |
50 |
51 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/main.js:
--------------------------------------------------------------------------------
1 | (function(){
2 |
3 | var TEXT_LOADING = 'Loading...\n\n历史的行程: %s %';
4 | var TEXT_SCORE = '+ %s s';
5 | var TEXT_GAME_OVER = '我为长者续命%s秒\n志己的生命减少%s秒\n而且这个效率efficiency: %s%';
6 | var TEXT_TRY_AGAIN = '重新续';
7 | var TEXT_PLAY_BGM = '请州长夫人演唱';
8 | var TEXT_TIME_ELAPSED = '- %s s';
9 | var TEXT_TOTAL_TIME_ELAPSED = '累计被续 %s 秒';
10 | var TEXT_TINY_TIPS = '[微小的提示]\n为了获得坠好的游戏体验,请:\n打开音量\n穿上红色的衣服';
11 | var TEXT_FONT = '"Segoe UI", "Microsoft YaHei", 宋体, sans-serif'; // 插入宋体
12 |
13 | var _gravity = 40,
14 | _speed = 390,
15 | _flap = 620,
16 | _spawnRate = 1 / 1.2,
17 | _opening = 260;
18 |
19 | var _game;
20 |
21 | var _baseUrl = '';
22 |
23 | var _flapSound;
24 |
25 | var _numScoreSounds = 10,
26 | _numHurtSounds = 9;
27 |
28 | var _scoreSounds = [],
29 | _hurtSounds = [];
30 |
31 | var _currentScoreSound;
32 |
33 | var _bgColor = 0xDDEEFF,
34 | _background;
35 |
36 | var _pipes,
37 | _pipeInvisibleLines,
38 | _pipesTimer;
39 |
40 | var _frog;
41 |
42 | var _ground;
43 |
44 | var _clouds,
45 | _cloudsTimer;
46 |
47 | var _gameOver = false,
48 | _gameStarted = false;
49 |
50 | var _score = 0;
51 |
52 | var _scoreText,
53 | _gameOverText,
54 | _tryAgainText,
55 | _tryAgainSprite,
56 | _playBgmText,
57 | _playBgmSprite;
58 |
59 | var _bgm,
60 | _playBgm = false;
61 |
62 | var _bgmKeyCode = [
63 | Phaser.Keyboard.ZERO,
64 | Phaser.Keyboard.NUMPAD_0
65 | ];
66 |
67 | var _flapKeyCode = [
68 | Phaser.Keyboard.E,
69 | Phaser.Keyboard.SPACEBAR
70 | ];
71 |
72 | var _feedbackKeyCode = [
73 | Phaser.Keyboard.FIVE,
74 | Phaser.Keyboard.NUMPAD_5
75 | ];
76 |
77 | var _feedback,
78 | _feedbackFunc,
79 | _feedbackText,
80 | _feedbackSprite;
81 |
82 | var _loadingText,
83 | _tinyTipsText;
84 |
85 | var _timeElapsedText,
86 | _startTime,
87 | _timeElapsed;
88 |
89 | var _totalTimeElapsedText,
90 | _totalTimeElapsed = 0;
91 |
92 | var _debug = false;
93 |
94 | function showLoadingText(percent) {
95 | _loadingText.setText(TEXT_LOADING.replace('%s', percent));
96 | }
97 |
98 | function initLoadingText() {
99 | _tinyTipsText = _game.add.text(
100 | _game.world.width / 2,
101 | _game.world.height / 4,
102 | TEXT_TINY_TIPS,
103 | {
104 | font: '16px ' + TEXT_FONT,
105 | fill: '#fff',
106 | align: 'center'
107 | }
108 | );
109 | _tinyTipsText.anchor.setTo(0.5, 0.5);
110 |
111 | _loadingText = _game.add.text(
112 | _game.world.width / 2,
113 | _game.world.height / 2,
114 | '',
115 | {
116 | font: '24px ' + TEXT_FONT,
117 | fill: '#f00',
118 | align: 'center'
119 | }
120 | );
121 | _loadingText.anchor.setTo(0.5, 0.5);
122 | showLoadingText(0);
123 | }
124 |
125 | function loadAudio(key, path) {
126 | _game.load.audio(key, [path + '.ogg', path + '.mp3']);
127 | }
128 |
129 | function preload() {
130 | _game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
131 | _game.stage.scale.setScreenSize(true);
132 |
133 |
134 | initLoadingText();
135 | _game.load.onFileComplete.add(showLoadingText);
136 |
137 | _game.load.spritesheet('frog', _baseUrl + 'images/frog.png', 80, 64);
138 | _game.load.spritesheet('clouds', _baseUrl + 'images/clouds.png', 128, 64);
139 |
140 | _game.load.image('pipe', _baseUrl + 'images/pipe.png');
141 | _game.load.image('ground', _baseUrl + 'images/ground.png');
142 |
143 | loadAudio('bgm', _baseUrl + 'sounds/bgm');
144 | loadAudio('flap', _baseUrl + 'sounds/flap');
145 |
146 | var i;
147 | for (i = 1; i <= _numScoreSounds; i++) {
148 | loadAudio('score' + i, _baseUrl + 'sounds/score' + i);
149 | }
150 | for (i = 1; i <= _numHurtSounds; i++) {
151 | loadAudio('hurt' + i, _baseUrl + 'sounds/hurt' + i);
152 | }
153 | }
154 |
155 | function o() {
156 | return _opening + 60 * ((_score > 50 ? 50 : 50 - _score) / 50);
157 | }
158 |
159 | function spawnPipe(pipeY, flipped) {
160 | var pipe = _pipes.create(
161 | _game.width,
162 | pipeY + (flipped ? -o() : o()) / 2,
163 | 'pipe'
164 | );
165 | pipe.body.allowGravity = false;
166 |
167 | // Flip pipe! *GASP*
168 | pipe.scale.setTo(2, flipped ? -2 : 2);
169 | pipe.body.offset.y = flipped ? -pipe.body.height * 2 : 0;
170 |
171 | // Move to the left
172 | pipe.body.velocity.x = -_speed;
173 |
174 | return pipe;
175 | }
176 |
177 | function spawnPipes() {
178 | _pipesTimer.stop();
179 |
180 | var pipeY = ((_game.height - 16 - o() / 2) / 2) + (Math.random() > 0.5 ? -1 : 1) * Math.random() * _game.height / 6;
181 | // Bottom pipe
182 | var pipe = spawnPipe(pipeY);
183 | // Top pipe (flipped)
184 | spawnPipe(pipeY, true);
185 |
186 | // Add invisible thingy
187 | var inv = _pipeInvisibleLines.create(pipe.x + pipe.width, 0);
188 | inv.width = 2;
189 | inv.height = _game.world.height;
190 | inv.body.allowGravity = false;
191 | inv.body.velocity.x = -_speed;
192 |
193 | _pipesTimer.add(1 / _spawnRate);
194 | _pipesTimer.start();
195 | }
196 |
197 |
198 | function initPipes() {
199 | _pipes = _game.add.group();
200 | _pipeInvisibleLines = _game.add.group();
201 | }
202 |
203 | function resetPipes() {
204 | _pipes.removeAll();
205 | _pipeInvisibleLines.removeAll();
206 | }
207 |
208 | function startPipes() {
209 | _pipesTimer = new Phaser.Timer(_game);
210 | _pipesTimer.onEvent.add(spawnPipes);
211 | _pipesTimer.add(2);
212 | _pipesTimer.start();
213 | }
214 |
215 | function stopPipes() {
216 | _pipesTimer.stop();
217 |
218 | _pipes.forEachAlive(function(pipe) {
219 | pipe.body.velocity.x = 0;
220 | });
221 |
222 | _pipeInvisibleLines.forEach(function(inv) {
223 | inv.body.velocity.x = 0;
224 | });
225 | }
226 |
227 | function initBackground() {
228 | _background = _game.add.graphics(0, 0);
229 | _background.beginFill(_bgColor, 1);
230 | _background.drawRect(0, 0, _game.world.width, _game.world.height);
231 | _background.endFill();
232 | }
233 |
234 | function initFrog() {
235 | _frog = _game.add.sprite(0, 0, 'frog');
236 | _frog.anchor.setTo(0.5, 0.5);
237 | _frog.body.collideWorldBounds = true;
238 | _frog.body.gravity.y = _gravity;
239 | }
240 |
241 | function resetFrog() {
242 | _frog.body.allowGravity = false;
243 | _frog.angle = 0;
244 | _frog.scale.setTo(1, 1);
245 | _frog.reset(_game.world.width / 4, _game.world.height / 2);
246 | }
247 |
248 | function initGround() {
249 | _ground = _game.add.tileSprite(0, _game.world.height - 32, _game.world.width, 32, 'ground');
250 | _ground.tileScale.setTo(2, 2);
251 | }
252 |
253 | function spawnCloud() {
254 | _cloudsTimer.stop();
255 |
256 | var cloudY = Math.random() * _game.height / 2;
257 | var cloud = _clouds.create(
258 | _game.width,
259 | cloudY,
260 | 'clouds',
261 | Math.floor(4 * Math.random())
262 | );
263 | var cloudScale = 2 + 2 * Math.random();
264 | cloud.alpha = 2 / cloudScale;
265 | cloud.scale.setTo(cloudScale, cloudScale);
266 | cloud.body.allowGravity = false;
267 | cloud.body.velocity.x = -_speed / cloudScale;
268 | cloud.anchor.y = 0;
269 |
270 | _cloudsTimer.start();
271 | _cloudsTimer.add(4 * Math.random());
272 | }
273 |
274 | function initClouds() {
275 | _clouds = _game.add.group();
276 | _cloudsTimer = new Phaser.Timer(_game);
277 | _cloudsTimer.onEvent.add(spawnCloud);
278 | _cloudsTimer.add(Math.random());
279 | _cloudsTimer.start();
280 | }
281 |
282 |
283 | function doInitSounds(result, keyPrefix, l) {
284 | for (var i = 1; i <= l; i++) {
285 | result.push(_game.add.audio(keyPrefix + i));
286 | }
287 | }
288 |
289 |
290 | function initSounds() {
291 | doInitSounds(_scoreSounds, 'score', _numScoreSounds);
292 | doInitSounds(_hurtSounds, 'hurt', _numHurtSounds);
293 |
294 | _flapSound = _game.add.audio('flap', 0.5);
295 |
296 | _bgm = _game.add.audio('bgm', 0.5);
297 | _bgm.onStop.add(function() {
298 | if (_playBgm)
299 | _bgm.play();
300 | });
301 | }
302 |
303 | function randomPlaySound(list, count) {
304 | var sound;
305 | if (count == 1) {
306 | sound = list[0];
307 | sound.play();
308 | } else if (count > 1) {
309 | sound = list[Math.floor(Math.random() * count)];
310 | sound.play();
311 | }
312 | return sound;
313 | }
314 |
315 | function playScoreSound() {
316 | _currentScoreSound = randomPlaySound(_scoreSounds, _numScoreSounds);
317 | }
318 |
319 | function playHurtSound() {
320 | if (_currentScoreSound)
321 | _currentScoreSound.stop();
322 | randomPlaySound(_hurtSounds, _numHurtSounds);
323 | }
324 |
325 | function playFlapSound() {
326 | if (!_flapSound.isPlaying)
327 | _flapSound.play();
328 | }
329 |
330 | function playBgm() {
331 | if (_playBgm) {
332 | _playBgm = false;
333 | _bgm.stop()
334 | } else {
335 | _playBgm = true;
336 | _bgm.play();
337 | }
338 | }
339 |
340 | function removeOffscreenObjs(objs) {
341 | objs.forEachAlive(function(obj) {
342 | if (obj.x + obj.width < _game.world.bounds.left) {
343 | obj.kill();
344 | }
345 | });
346 | }
347 |
348 | function updateClouds() {
349 | removeOffscreenObjs(_clouds);
350 | _cloudsTimer.update();
351 | }
352 |
353 | function updatePipes() {
354 | removeOffscreenObjs(_pipes);
355 | _pipesTimer.update();
356 | }
357 |
358 | function updateGround() {
359 | _ground.tilePosition.x -= _game.time.physicsElapsed * _speed / 2;
360 | }
361 |
362 | function updateFrog() {
363 | // Make frog dive
364 | var dvy = _flap + _frog.body.velocity.y;
365 | _frog.angle = (90 * dvy / _flap) - 180;
366 | if (_frog.angle < 0) {
367 | _frog.angle = 0;
368 | }
369 |
370 | if (_gameOver) {
371 | _frog.scale.setTo(1, -1);
372 | _frog.angle = -20;
373 | }
374 | }
375 |
376 | function updateFrog2() {
377 | _frog.y = (_game.world.height / 2) + 8 * Math.cos(_game.time.now / 200);
378 | }
379 |
380 | function checkCollision() {
381 | if (_frog.body.bottom >= _game.world.bounds.bottom) {
382 | setGameOver();
383 | return;
384 | }
385 | if (_game.physics.overlap(_frog, _pipes)) {
386 | setGameOver();
387 | return;
388 | }
389 | // Add score
390 | _game.physics.overlap(_frog, _pipeInvisibleLines, addScore);
391 | }
392 |
393 | function addScore(_, inv) {
394 | _pipeInvisibleLines.remove(inv);
395 | _score += 1;
396 | showScore();
397 | playScoreSound();
398 | }
399 |
400 | function showScore() {
401 | _scoreText.setText(TEXT_SCORE.replace('%s', _score));
402 | }
403 |
404 | function setGameOver() {
405 | _gameOver = true;
406 | stopPipes();
407 | showGameOver();
408 | playHurtSound();
409 | }
410 |
411 | function showGameOver() {
412 | _totalTimeElapsed += _timeElapsed;
413 | _totalTimeElapsedText.setText(TEXT_TOTAL_TIME_ELAPSED.replace('%s', _totalTimeElapsed));
414 | _totalTimeElapsedText.renderable = true;
415 |
416 | var a = Math.floor(_score / _timeElapsed * 100);
417 | a = TEXT_GAME_OVER.replace('%s', _score).replace('%s', _timeElapsed).replace('%s', a);
418 | _gameOverText.setText(a);
419 | _gameOverText.renderable = true;
420 | _tryAgainText.renderable = true;
421 | _tryAgainSprite.events.onInputDown.addOnce(reset);
422 | }
423 |
424 | function hideGameOver() {
425 | _gameOverText.renderable = false;
426 | _tryAgainText.renderable = false;
427 | }
428 |
429 | function createTextSprite(t) {
430 | var s = _game.add.sprite(t.x, t.y);
431 | s.anchor.setTo(t.anchor.x, t.anchor.y);
432 | s.width = t.width;
433 | s.height = t.height;
434 | return s;
435 | }
436 |
437 | function initFeedback() {
438 | if (!_feedback)
439 | return;
440 | _feedbackText = _game.add.text(
441 | 0,
442 | 0,
443 | _feedback,
444 | {
445 | font: '14px ' + TEXT_FONT,
446 | fill: '#fff',
447 | stroke: '#430',
448 | strokeThickness: 4,
449 | align: 'center'
450 | }
451 | );
452 | if (!_feedbackFunc)
453 | return;
454 | _feedbackSprite = createTextSprite(_feedbackText);
455 | _feedbackSprite.inputEnabled = true;
456 | _feedbackSprite.events.onInputDown.add(_feedbackFunc);
457 | }
458 |
459 | function initTexts() {
460 | initFeedback();
461 |
462 | _playBgmText = _game.add.text(
463 | 0,
464 | 0,
465 | TEXT_PLAY_BGM,
466 | {
467 | font: '14px ' + TEXT_FONT,
468 | fill: '#fff',
469 | stroke: '#430',
470 | strokeThickness: 4,
471 | align: 'center'
472 | }
473 | );
474 | _playBgmText.x = _game.world.width - _playBgmText.width;
475 | _playBgmSprite = createTextSprite(_playBgmText);
476 | _playBgmSprite.inputEnabled = true;
477 | _playBgmSprite.events.onInputDown.add(playBgm);
478 |
479 | _scoreText = _game.add.text(
480 | _game.world.width / 2,
481 | _game.world.height / 4,
482 | '',
483 | {
484 | font: '14px ' + TEXT_FONT,
485 | fill: '#fff',
486 | stroke: '#430',
487 | strokeThickness: 4,
488 | align: 'center'
489 | }
490 | );
491 | _scoreText.anchor.setTo(0.5, 0.5);
492 |
493 | _timeElapsedText = _game.add.text(
494 | _game.world.width / 2,
495 | _scoreText.y + _scoreText.height,
496 | '',
497 | {
498 | font: '14px ' + TEXT_FONT,
499 | fill: '#f00',
500 | align: 'center'
501 | }
502 | );
503 | _timeElapsedText.anchor.setTo(0.5, 0.5);
504 |
505 | _totalTimeElapsedText = _game.add.text(
506 | _game.world.width / 2,
507 | 0,
508 | '',
509 | {
510 | font: '14px ' + TEXT_FONT,
511 | fill: '#f00',
512 | align: 'center'
513 | }
514 | );
515 | _totalTimeElapsedText.anchor.setTo(0.5, 0);
516 |
517 | _tryAgainText = _game.add.text(
518 | _game.world.width / 2,
519 | _game.world.height - _game.world.height / 6,
520 | TEXT_TRY_AGAIN,
521 | {
522 | font: '22px ' + TEXT_FONT,
523 | fill: '#fff',
524 | stroke: '#430',
525 | strokeThickness: 4,
526 | align: 'center'
527 | }
528 | );
529 | _tryAgainText.anchor.setTo(0.5, 0.5);
530 |
531 | _tryAgainSprite = createTextSprite(_tryAgainText);
532 | _tryAgainSprite.inputEnabled = true;
533 |
534 | _gameOverText = _game.add.text(
535 | _game.world.width / 2,
536 | _game.world.height / 2,
537 | '',
538 | {
539 | font: '18px ' + TEXT_FONT,
540 | fill: '#fff',
541 | stroke: '#430',
542 | strokeThickness: 4,
543 | align: 'center'
544 | }
545 | );
546 | _gameOverText.anchor.setTo(0.5, 0.5);
547 | }
548 |
549 | function start() {
550 | _totalTimeElapsedText.renderable = false;
551 |
552 | _frog.body.allowGravity = true;
553 | startPipes();
554 | _gameStarted = true;
555 |
556 | _startTime = _game.time.now;
557 | }
558 |
559 | function flap() {
560 | if (!_gameStarted) {
561 | start();
562 | }
563 | if (!_gameOver) {
564 | _frog.body.velocity.y = -_flap;
565 | playFlapSound();
566 | }
567 | }
568 |
569 | function checkKeyCode(input, a) {
570 | if (!input || !a)
571 | return;
572 | return input == a[0] || input == a[1];
573 | }
574 |
575 | function onKeyDown(e) { }
576 |
577 | function onKeyUp(e) {
578 | if (checkKeyCode(e.keyCode, _flapKeyCode)) {
579 | flap();
580 | } else if (checkKeyCode(e.keyCode, _bgmKeyCode)) {
581 | playBgm();
582 | } else if (_feedbackFunc && checkKeyCode(e.keyCode, _feedbackKeyCode)) {
583 | _feedbackFunc();
584 | }
585 | }
586 |
587 | function unlockAudio() {
588 | var context = _game.sound.context;
589 | if (context && context.state === 'suspended')
590 | context.resume();
591 | }
592 |
593 | function initControls() {
594 | _game.input.onUp.add(unlockAudio);
595 |
596 | _game.input.onDown.add(flap);
597 | _game.input.keyboard.addCallbacks(_game, onKeyDown, onKeyUp);
598 | }
599 |
600 |
601 | function reset() {
602 | _timeElapsedText.setText('');
603 |
604 | _score = 0;
605 | _gameOver = false;
606 | _gameStarted = false;
607 |
608 | hideGameOver();
609 |
610 | resetFrog();
611 | resetPipes();
612 |
613 | showScore();
614 | }
615 |
616 | function create() {
617 | initBackground();
618 | initPipes();
619 | initFrog();
620 | initGround();
621 | initTexts();
622 | initClouds();
623 | initSounds();
624 | initControls();
625 |
626 | reset();
627 | }
628 |
629 | function setTimeElapsed() {
630 | var a = Math.floor(_game.time.elapsedSecondsSince(_startTime)) + 1;
631 | if (_timeElapsed != a) {
632 | _timeElapsed = a;
633 | _timeElapsedText.setText(TEXT_TIME_ELAPSED.replace('%s', _timeElapsed));
634 | }
635 | }
636 |
637 | function update() {
638 | updateClouds();
639 | if (_gameStarted) {
640 | updateFrog();
641 | if (!_gameOver) {
642 | setTimeElapsed();
643 | checkCollision();
644 | }
645 | updatePipes();
646 | } else {
647 | updateFrog2();
648 | }
649 |
650 | if (!_gameOver) {
651 | updateGround();
652 | }
653 | }
654 |
655 | function render() {
656 | if (!_debug)
657 | return;
658 |
659 | _game.debug.renderSpriteBody(_tryAgainSprite);
660 | _game.debug.renderSpriteBody(_playBgmSprite);
661 | _game.debug.renderSpriteBody(_frog);
662 |
663 | _pipes.forEachAlive(function(pipe) {
664 | _game.debug.renderSpriteBody(pipe);
665 | });
666 | _pipeInvisibleLines.forEach(function(inv) {
667 | _game.debug.renderSpriteBody(inv);
668 | });
669 |
670 | }
671 |
672 | function init(options) {
673 | if (typeof options.debug !== 'undefined')
674 | _debug = options.debug;
675 |
676 | if (typeof options.gravity !== 'undefined')
677 | _gravity = options.gravity;
678 |
679 | if (typeof options.speed !== 'undefined')
680 | _speed = options.speed;
681 |
682 | if (typeof options.flap !== 'undefined')
683 | _flap = options.flap;
684 |
685 | if (typeof options.spawnRate !== 'undefined')
686 | _spawnRate = options.spawnRate;
687 |
688 | if (typeof options.opening !== 'undefined')
689 | _opening = options.opening;
690 |
691 | if (typeof options.flapKeyCode !== 'undefined')
692 | _flapKeyCode = options.flapKeyCode;
693 |
694 | if (typeof options.numScoreSounds !== 'undefined')
695 | _numScoreSounds = options.numScoreSounds;
696 |
697 | if (typeof options.numHurtSounds !== 'undefined')
698 | _numHurtSounds = options.numHurtSounds;
699 |
700 | if (typeof options.baseUrl !== 'undefined')
701 | _baseUrl = options.baseUrl;
702 |
703 | if (typeof options.feedback !== 'undefined')
704 | _feedback = options.feedback;
705 |
706 | if (typeof options.feedbackFunc !== 'undefined')
707 | _feedbackFunc = options.feedbackFunc;
708 |
709 | if (typeof options.bgmKeyCode !== 'undefined')
710 | _bgmKeyCode = options.bgmKeyCode;
711 |
712 | if (typeof options.feedbackKeyCode !== 'undefined')
713 | _feedbackKeyCode = options.feedbackKeyCode;
714 |
715 | _game = new Phaser.Game(
716 | 480,
717 | 700,
718 | Phaser.CANVAS,
719 | options.parent,
720 | {
721 | preload: preload,
722 | create: create,
723 | update: update,
724 | render: render
725 | },
726 | false,
727 | false
728 | );
729 | }
730 |
731 | initGame = init;
732 | })();
733 |
734 | var initGame;
735 |
--------------------------------------------------------------------------------
/sounds/bgm.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/bgm.mp3
--------------------------------------------------------------------------------
/sounds/bgm.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/bgm.ogg
--------------------------------------------------------------------------------
/sounds/flap.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/flap.mp3
--------------------------------------------------------------------------------
/sounds/flap.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/flap.ogg
--------------------------------------------------------------------------------
/sounds/hurt1.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt1.mp3
--------------------------------------------------------------------------------
/sounds/hurt1.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt1.ogg
--------------------------------------------------------------------------------
/sounds/hurt2.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt2.mp3
--------------------------------------------------------------------------------
/sounds/hurt2.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt2.ogg
--------------------------------------------------------------------------------
/sounds/hurt3.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt3.mp3
--------------------------------------------------------------------------------
/sounds/hurt3.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt3.ogg
--------------------------------------------------------------------------------
/sounds/hurt4.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt4.mp3
--------------------------------------------------------------------------------
/sounds/hurt4.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt4.ogg
--------------------------------------------------------------------------------
/sounds/hurt5.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt5.mp3
--------------------------------------------------------------------------------
/sounds/hurt5.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt5.ogg
--------------------------------------------------------------------------------
/sounds/hurt6.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt6.mp3
--------------------------------------------------------------------------------
/sounds/hurt6.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt6.ogg
--------------------------------------------------------------------------------
/sounds/hurt7.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt7.mp3
--------------------------------------------------------------------------------
/sounds/hurt7.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt7.ogg
--------------------------------------------------------------------------------
/sounds/hurt8.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt8.mp3
--------------------------------------------------------------------------------
/sounds/hurt8.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt8.ogg
--------------------------------------------------------------------------------
/sounds/hurt9.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt9.mp3
--------------------------------------------------------------------------------
/sounds/hurt9.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/hurt9.ogg
--------------------------------------------------------------------------------
/sounds/score1.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score1.mp3
--------------------------------------------------------------------------------
/sounds/score1.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score1.ogg
--------------------------------------------------------------------------------
/sounds/score10.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score10.mp3
--------------------------------------------------------------------------------
/sounds/score10.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score10.ogg
--------------------------------------------------------------------------------
/sounds/score2.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score2.mp3
--------------------------------------------------------------------------------
/sounds/score2.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score2.ogg
--------------------------------------------------------------------------------
/sounds/score3.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score3.mp3
--------------------------------------------------------------------------------
/sounds/score3.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score3.ogg
--------------------------------------------------------------------------------
/sounds/score4.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score4.mp3
--------------------------------------------------------------------------------
/sounds/score4.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score4.ogg
--------------------------------------------------------------------------------
/sounds/score5.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score5.mp3
--------------------------------------------------------------------------------
/sounds/score5.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score5.ogg
--------------------------------------------------------------------------------
/sounds/score6.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score6.mp3
--------------------------------------------------------------------------------
/sounds/score6.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score6.ogg
--------------------------------------------------------------------------------
/sounds/score7.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score7.mp3
--------------------------------------------------------------------------------
/sounds/score7.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score7.ogg
--------------------------------------------------------------------------------
/sounds/score8.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score8.mp3
--------------------------------------------------------------------------------
/sounds/score8.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score8.ogg
--------------------------------------------------------------------------------
/sounds/score9.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score9.mp3
--------------------------------------------------------------------------------
/sounds/score9.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tusenpo/FlappyFrog/f50fd4b1bead7719f69146f7604fc45c638e88a6/sounds/score9.ogg
--------------------------------------------------------------------------------