Browse Source

bird -> main

master
wally 4 years ago
parent
commit
ffab9a61b9
  1. 10
      bird.js
  2. 2
      index.html
  3. 12
      js/classes/main.js
  4. 4
      js/custom.js
  5. 2
      js/test.js
  6. BIN
      鸟妈妈回家_HTML5 Canvas.fla

10
bird.js

File diff suppressed because one or more lines are too long

2
index.html

@ -25,7 +25,7 @@
<script src="bird.js"></script>
<script src="js/index.js"></script>
<script src="js/custom.js"></script>
<script src="js/classes/bird.js"></script>
<script src="js/classes/main.js"></script>
<script src="js/classes/count.js"></script>
<script src="js/classes/back.js"></script>
<script src="js/classes/time.js"></script>

12
js/classes/bird.js → js/classes/main.js

@ -10,7 +10,7 @@
* @property {number} times 当前运动次数 play依次+1
* @property {function} endCallback 结束后 调用的回调函数
*/
function Bird(endCallback, max) {
function Main(endCallback, max) {
this.lib = library;
this.element = null;
@ -26,15 +26,15 @@ function Bird(endCallback, max) {
* @param {function} endCallback 游戏结束的回调函数
* @param {number} max 最多运动次数
*/
Bird.of = function (endCallback, max = config.times) {
const instance = new Bird(endCallback, max);
Main.of = function (endCallback, max = config.times) {
const instance = new Main(endCallback, max);
instance.init();
return instance;
};
// 初始方法
Bird.prototype.init = function () {
const target = new this.lib.Bird();
Main.prototype.init = function () {
const target = new this.lib.Main();
this.element = target;
stage.addChild(target);
};
@ -43,7 +43,7 @@ Bird.prototype.init = function () {
// 限制了两次动作间隔时间不能少于2s
// 游戏状态在进行中才能触发
// play次数 >= 最多完成次数 调用结束的callback
Bird.prototype.play = function () {
Main.prototype.play = function () {
if (Date.now() - this.prevTime <= 2000 || state !== 1) return;
this.element.play();
this.times += 1;

4
js/custom.js

@ -12,7 +12,7 @@ let state = 0; // 游戏状态 0->未开始 1->进行中 2->结束
function initStage(lib) {
library = lib;
window.bird = Bird.of(gameOver); // 初始化鸟等
window.main = Main.of(gameOver); // 初始化鸟等
window.timeInstance = Time.of(gameOver); // 初始化游戏时间
// window.soundInstance = Sound.of(); // 初始化音频
Level.of(2); // 游戏难度级别
@ -22,7 +22,7 @@ function initStage(lib) {
// 游戏结束 显示结束得分面板
function gameOver() {
state = 2;
const times = bird.times;
const times = main.times;
const score = parseInt((config.total / config.times) * times);
End.of(score);
}

2
js/test.js

@ -1,6 +1,6 @@
function test() {
document.addEventListener('click', () => {
bird.play();
main.play();
});
}

BIN
鸟妈妈回家_HTML5 Canvas.fla

Binary file not shown.
Loading…
Cancel
Save