相思资源网 Design By www.200059.com
本文实例讲述了纯javascript实现的小游戏《Flappy Pig》。分享给大家供大家参考。具体如下:
Flappy Pig,是Pig,使用原生javascript写的网页版“Flappy Bird”。我也奇了个怪为什么搞这个东西出来,而且还花了一天宝贵的周末,但是既然写出来,就拿出来和大家分享一下。
option.js如下:
"top"></div><div class="bottom"></div>', //柱子宽度 pillarWidth: 45, //柱子上下间隔高度 pillarGapY: 108, //柱子左右间隔宽度 pillarGapX: 250, //上柱子的基础定位值(就是top值,和css写法有关) pillarTop: -550, //下柱子的基础定位值 pillarBottom: -500 }; return self; })(flappy || {})
util.js如下:
"htmlcode">"htmlcode">"htmlcode">"htmlcode">"htmlcode">/** * 原生javascript实现的《Flappy Pig》v0.1.0 * ======================================= * @author keenwon * Full source at http://keenwon.com */ var flappy = (function (self) { 'use strict'; var controller = self.controller, option = self.option, pig = self.pig, pillar = self.pillar, pos = self.position, util = self.util, $ = self.util.$; //主程序 self.game = { init: function () { var t = this; t._isStart = false; t._isEnd = false; t._timer = null; pig.init(t.fall, t); pillar.init(); pos.init(t.hit, t); t.addKeyListener(); }, addKeyListener: function () { var t = this; document.onkeydown = function (e) { var e = e || event; var currKey = e.keyCode || e.which || e.charCode; if (currKey == 32) { if (!t._isEnd) { t.jump(); } else { window.location.reload(); } util.preventDefaultEvent(e); } } }, jump: function () { var t = this; if (!t._isStart) { $('start').style.display = 'none'; t._createTimer(function () { pig.start(); pillar.move(); pos.judge(); $('score').innerHTML = pillar.currentId + 1; }); t._isStart = true; } else { pig.jump(); } }, hit: function () { var t = this; t.over(); pig.hit(); }, fall: function () { var t = this; t.over(); pig.fall(); }, over: function () { var t = this; clearInterval(t._timer); t._isEnd = true; $('end').style.display = 'block'; }, _createTimer: function (fn) { var t = this; t._timer = setInterval(fn, option.frequency); } }; flappy.init = function () { self.game.init(); } return self; })(flappy || {})希望本文所述对大家的javascript程序设计有所帮助。
相思资源网 Design By www.200059.com广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com相思资源网 Design By www.200059.com暂无纯javascript实现的小游戏《Flappy Pig》实例的评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。