1 Star 1 Fork 1

shengtaii/鸟飞类游戏

forked from Micro/鸟飞类游戏 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Main.js 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
Micro 提交于 2020-10-24 21:48 . feat:小鸟运动轨迹
import {ResourceLoader} from "./js/base/ResourceLoader.js";
import {Background} from "./js/runtime/Background.js";
import {DataStore} from "./js/base/DataStore.js";
import {Director} from "./js/Director.js";
import {Land} from "./js/runtime/Land.js";
import Birds from "./js/player/Birds.js";
export class Main {
constructor() {
this.canvas = document.getElementById('game');
this.ctx = this.canvas.getContext('2d');
this.dataStore = DataStore.getInstance();
this.director = Director.getInstance();
const loader = ResourceLoader.create();
loader.onLoaded(map => this.onResourceFirstLoaded(map));
}
onResourceFirstLoaded(map) {
this.dataStore.ctx = this.ctx;
this.dataStore.res = map;
this.init();
}
init() {
// let background = new Background(this.dataStore.ctx, this.dataStore.res.get('background'));
this.dataStore
.put('pencils', [])
.put('background', Background)
.put('land', Land)
.put('birds', Birds)
this.director.isGameOver = false;
this.registerEvent();
this.director.createPencil();
this.director.run();
}
registerEvent() {
this.canvas.addEventListener('touchstart', e => {
e.preventDefault();
if (this.director.isGameOver) {
this.init();
} else {
this.director.birdsEvent();
}
})
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/shengtaii/flappy-bird-games.git
[email protected]:shengtaii/flappy-bird-games.git
shengtaii
flappy-bird-games
鸟飞类游戏
master

搜索帮助