本文实例讲述了纯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.eoogi.com广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!华山资源网 Design By www.eoogi.com暂无评论...
更新日志
2024年10月04日
2024年10月04日
- 群星.2008-本色·百代音乐人创作专辑【EMI百代】【WAV+CUE】
- 群星.2001-同步过冬AVCD【环球】【WAV+CUE】
- 群星.2020-同步过冬2020冀待晴空【环球】【WAV+CUE】
- 沈雁.1986-四季(2012梦田复刻版)【白云唱片】【WAV+CUE】
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[FLAC/分轨][257.88MB]
- 《国语老歌 怀旧篇 3CD》[WAV/分轨][1.6GB]
- 班得瑞原装进口《第九张新世纪专辑:微风山谷》1CD[APE/CUE分轨][331MB]
- 陈慧琳.2008-Love.Fighters演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 米志宏.1994-HAPPY1994【波丽佳音】【WAV+CUE】
- 潘美辰.2006-最冷的夏天(引进版)【美梦辰真】【WAV+CUE】
- 班得瑞原装进口《第十张新世纪专辑:月光水岸》1CD[APE/CUE分轨][277.2MB]
- 班得瑞原装进口《第十一张新世纪专辑:雾色山脉》1CD[APE/CUE分轨][291.6MB]
- 班得瑞原装进口《第十二张新世纪专辑:翡翠谷》1CD[APE/CUE分轨][307.9MB]
- 高卿尘.2024-情绪商店【Hahahai】【FLAC分轨】
- 王恩喆.2024-黄沙【KOOD】【FLAC分轨】