├── LICENSE ├── README.md ├── favicon.png ├── game.js ├── index.html └── index.js /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Haole Zheng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pacman 吃豆游戏 2 | 3 | - 项目演示(DEMO)地址:https://passer-by.com/pacman/ 4 | 5 | ### 版权 6 | 本游戏由 [passer-by.com](https://passer-by.com/) 制作,请尊重作者,引用请注明来源。 7 | 8 | 功能 9 | 10 | - [x] 地图绘制 11 | - [x] 玩家控制 12 | - [x] NPC根据玩家坐标实时自动寻径 13 | - [x] 吃豆积分系统 14 | - [x] 能量豆功能 15 | - [x] 多关卡(共12关) 16 | - [ ] 特殊物品记分 17 | -------------------------------------------------------------------------------- /favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CleverProgrammer/pacman/e7d5cfac2978b9c24a42a7568dacd67cec07fae9/favicon.png -------------------------------------------------------------------------------- /game.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | * 小型游戏引擎 4 | */ 5 | 6 | // requestAnimationFrame polyfill 7 | if (!Date.now) 8 | Date.now = function() { return new Date().getTime(); }; 9 | (function() { 10 | 'use strict'; 11 | var vendors = ['webkit', 'moz']; 12 | for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) { 13 | var vp = vendors[i]; 14 | window.requestAnimationFrame = window[vp+'RequestAnimationFrame']; 15 | window.cancelAnimationFrame = (window[vp+'CancelAnimationFrame'] || window[vp+'CancelRequestAnimationFrame']); 16 | } 17 | if (/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) // iOS6 is buggy 18 | || !window.requestAnimationFrame || !window.cancelAnimationFrame) { 19 | var lastTime = 0; 20 | window.requestAnimationFrame = function(callback) { 21 | var now = Date.now(); 22 | var nextTime = Math.max(lastTime + 16, now); 23 | return setTimeout(function() { callback(lastTime = nextTime); }, 24 | nextTime - now); 25 | }; 26 | window.cancelAnimationFrame = clearTimeout; 27 | } 28 | }()); 29 | 30 | function Game(id,params){ 31 | var _ = this; 32 | var settings = { 33 | width:960, //画布宽度 34 | height:640 //画布高度 35 | }; 36 | Object.assign(_,settings,params); 37 | var $canvas = document.getElementById(id); 38 | $canvas.width = _.width; 39 | $canvas.height = _.height; 40 | var _context = $canvas.getContext('2d'); //画布上下文环境 41 | var _stages = []; //布景对象队列 42 | var _events = {}; //事件集合 43 | var _index=0, //当前布景索引 44 | _hander; //帧动画控制 45 | //活动对象构造 46 | var Item = function(params){ 47 | this._params = params||{}; 48 | this._id = 0; //标志符 49 | this._stage = null; //与所属布景绑定 50 | this._settings = { 51 | x:0, //位置坐标:横坐标 52 | y:0, //位置坐标:纵坐标 53 | width:20, //宽 54 | height:20, //高 55 | type:0, //对象类型,0表示普通对象(不与地图绑定),1表示玩家控制对象,2表示程序控制对象 56 | color:'#F00', //标识颜色 57 | status:1, //对象状态,0表示未激活/结束,1表示正常,2表示暂停,3表示临时,4表示异常 58 | orientation:0, //当前定位方向,0表示右,1表示下,2表示左,3表示上 59 | speed:0, //移动速度 60 | //地图相关 61 | location:null, //定位地图,Map对象 62 | coord:null, //如果对象与地图绑定,需设置地图坐标;若不绑定,则设置位置坐标 63 | path:[], //NPC自动行走的路径 64 | vector:null, //目标坐标 65 | //布局相关 66 | frames:1, //速度等级,内部计算器times多少帧变化一次 67 | times:0, //刷新画布计数(用于循环动画状态判断) 68 | timeout:0, //倒计时(用于过程动画状态判断) 69 | control:{}, //控制缓存,到达定位点时处理 70 | update:function(){}, //更新参数信息 71 | draw:function(){} //绘制 72 | }; 73 | Object.assign(this,this._settings,this._params); 74 | }; 75 | Item.prototype.bind = function(eventType,callback){ 76 | if(!_events[eventType]){ 77 | _events[eventType] = {}; 78 | $canvas.addEventListener(eventType,function(e){ 79 | var position = _.getPosition(e); 80 | _stages[_index].items.forEach(function(item){ 81 | if(Math.abs(position.x-item.x) 2 | 3 | 4 | Pac-Man . 吃豆人游戏 5 | 6 | 7 | 8 | 32 | 41 | 42 | 43 |
44 | 不支持画布 45 |
按[空格]暂停或继续
46 |

这款吃豆人游戏的开发是我在学习和探索HTML5游戏的一次尝试,也是对这款经典街机游戏的致敬。游戏大致还原了我印象中Pac-Man的样子,在移植关卡和玩法规则的同时,在游戏中加入了游戏角色动画管理和幽灵的智能寻址算法,实现了幽灵对玩家的围堵。希望能通过游戏和代码和你分享一些我对游戏开发的感悟。

47 |
48 | Follow @mumuy 49 | Star 50 |
51 |
52 | 53 | 54 | 55 |
56 | 57 |
58 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | //主程序,业务逻辑 2 | (function(){ 3 | var _COIGIG = [ //关卡 4 | { //第1关 5 | 'map':[ //地图数据 6 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], 7 | [1,0,0,0,0,0,0,0,0,0,0,0,0,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,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1], 25 | [1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1], 26 | [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1], 27 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 28 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 29 | [1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1], 30 | [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], 31 | [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], 32 | [1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1], 33 | [1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1], 34 | [1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1], 35 | [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], 36 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] 37 | ], 38 | 'wall_color':'#09f', 39 | 'goods':{ //能量豆 40 | '1,3':1, 41 | '26,3':1, 42 | '1,23':1, 43 | '26,23':1 44 | } 45 | }, 46 | { //第2关 47 | 'map':[ //地图数据 48 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], 49 | [1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1], 50 | [1,0,1,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1], 67 | [1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1], 68 | [1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1], 69 | [1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1], 70 | [1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1], 71 | [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], 72 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 73 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 74 | [1,0,1,1,1,1,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,1,1,1,1,0,1], 75 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 76 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 77 | [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], 78 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] 79 | ], 80 | 'wall_color':'#FF5983', 81 | 'goods':{ //能量豆 82 | '1,2':1, 83 | '26,2':1, 84 | '1,27':1, 85 | '26,27':1 86 | } 87 | }, 88 | { //第3关 89 | 'map':[ //地图数据 90 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], 91 | [1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1], 92 | [1,0,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,1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1,1,1,1,1,0,1,1,1,1,0,1], 110 | [1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1], 111 | [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], 112 | [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], 113 | [1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1], 114 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 115 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 116 | [1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1], 117 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 118 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 119 | [1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1], 120 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] 121 | ], 122 | 'wall_color':'#E08031', 123 | 'goods':{ //能量豆 124 | '1,2':1, 125 | '26,2':1, 126 | '1,23':1, 127 | '26,23':1 128 | } 129 | }, 130 | { //第4关 131 | 'map':[ //地图数据 132 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], 133 | [1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1], 134 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 135 | [1,0,1,1,1,1,0,1,1,0,1,1,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,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,1,1,0,1,1,1], 153 | [1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1], 154 | [1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1], 155 | [0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0], 156 | [1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1], 157 | [1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1], 158 | [1,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,1], 159 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 160 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 161 | [1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1], 162 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] 163 | ], 164 | 'wall_color':'#37C6C0', 165 | 'goods':{ //能量豆 166 | '1,3':1, 167 | '26,3':1, 168 | '1,28':1, 169 | '26,28':1 170 | } 171 | }, 172 | { //第5关 173 | 'map':[ //地图数据 174 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], 175 | [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1], 176 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 177 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 178 | [1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,1,0,1], 195 | [1,0,1,1,0,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,0,1,1,0,1], 196 | [1,0,1,1,0,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,0,1,1,0,1], 197 | [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], 198 | [1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1], 199 | [1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1], 200 | [1,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,1], 201 | [1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1], 202 | [1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1], 203 | [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1], 204 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] 205 | ], 206 | 'wall_color':'#5ED5D1', 207 | 'goods':{ //能量豆 208 | '1,3':1, 209 | '26,3':1, 210 | '1,27':1, 211 | '26,27':1 212 | } 213 | }, 214 | { //第6关 215 | 'map':[ //地图数据 216 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], 217 | [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1], 218 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 219 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 220 | [1,0,0,0,1,1,0,0,0,0,1,1,0,1,1,0,1,1,0,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,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], 238 | [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], 239 | [1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1], 240 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 241 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 242 | [1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1], 243 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 244 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 245 | [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], 246 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] 247 | ], 248 | 'wall_color':'#7E884F', 249 | 'goods':{ //能量豆 250 | '1,3':1, 251 | '26,3':1, 252 | '1,28':1, 253 | '26,28':1 254 | } 255 | }, 256 | { //第7关 257 | 'map':[ //地图数据 258 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], 259 | [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], 260 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 261 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 262 | [1,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,1], 263 | [1,1,1,0,1,1,1,1,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,1,1,0,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,0,1,1,0,1], 281 | [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], 282 | [1,0,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,0,1,1,0,1], 283 | [1,0,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,0,1,1,0,1], 284 | [1,0,1,1,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,1,1,0,1], 285 | [1,0,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,1,0,1], 286 | [1,0,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,1,0,1], 287 | [1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1], 288 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] 289 | ], 290 | 'wall_color':'#C9C', 291 | 'goods':{ //能量豆 292 | '1,3':1, 293 | '26,3':1, 294 | '1,24':1, 295 | '26,24':1 296 | } 297 | }, 298 | { //第8关 299 | 'map':[ //地图数据 300 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], 301 | [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], 302 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 303 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 304 | [1,0,1,1,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,1,1,0,1], 305 | [1,0,1,1,0,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1],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,1,1,0,1,1,1], 323 | [1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1], 324 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 325 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 326 | [1,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,1], 327 | [1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1], 328 | [1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1], 329 | [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], 330 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] 331 | ], 332 | 'wall_color':'#EB3F2F', 333 | 'goods':{ //能量豆 334 | '1,4':1, 335 | '26,4':1, 336 | '1,25':1, 337 | '26,25':1 338 | } 339 | }, 340 | { //第9关 341 | 'map':[ //地图数据 342 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], 343 | [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1], 344 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 345 | [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], 346 | [1,0,1,1,0,0,0,0,0,0,1,1,0,1,1,0,1,1,0,0,0,0,0,0,1,1,0,1], 347 | [1,0,1,1,0,1,1,1,1,0,1,1,0,0,0,0,1,1,0,1,1,1,1,0,1,1,0,1], 348 | [1,0,1,1,0,1,1,1,1,0,1,1,0,1,1,0,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,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0], 366 | [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], 367 | [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], 368 | [1,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,1], 369 | [1,0,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,0,1], 370 | [1,0,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,0,1], 371 | [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1], 372 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] 373 | ], 374 | 'wall_color':'#2E68AA', 375 | 'goods':{ //能量豆 376 | '1,6':1, 377 | '26,6':1, 378 | '1,27':1, 379 | '26,27':1 380 | } 381 | }, 382 | { //第10关 383 | 'map':[ //地图数据 384 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], 385 | [1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1], 386 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 387 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 388 | [1,0,1,1,1,1,0,1,1,0,1,1,0,0,0,0,1,1,0,1,1,0,1,1,1,1,0,1], 389 | [1,0,0,0,0,0,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,0,0,1], 390 | [1,0,1,1,0,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1], 391 | [1,0,1,1,0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408 | [1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1], 409 | [1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1], 410 | [1,0,0,0,1,1,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,1,1,0,0,0,1], 411 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 412 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 413 | [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], 414 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] 415 | ], 416 | 'wall_color':'#C1194E', 417 | 'goods':{ //能量豆 418 | '1,4':1, 419 | '26,4':1, 420 | '1,28':1, 421 | '26,28':1 422 | } 423 | }, 424 | { //第11关 425 | 'map':[ //地图数据 426 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], 427 | [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], 428 | [1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1], 429 | [1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1], 430 | [1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1], 431 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 432 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 433 | [1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,1,1,0,1,1,0,1,1,1], 451 | [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], 452 | [1,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,1], 453 | [1,0,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,0,1], 454 | [1,0,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,0,1], 455 | [1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1], 456 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] 457 | ], 458 | 'wall_color':'#56A36C', 459 | 'goods':{ //能量豆 460 | '1,3':1, 461 | '26,3':1, 462 | '1,28':1, 463 | '26,28':1 464 | } 465 | }, 466 | { //第12关 467 | 'map':[ //地图数据 468 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], 469 | [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1], 470 | [1,0,1,1,0,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,0,1,1,0,1], 471 | [1,0,1,1,0,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,0,1,1,0,1], 472 | [1,0,1,1,0,0,0,0,0,0,1,1,0,1,1,0,1,1,0,0,0,0,0,0,1,1,0,1], 473 | [1,0,1,1,1,1,0,1,1,0,1,1,0,0,0,0,1,1,0,1,1,0,1,1,1,1,0,1], 474 | [1,0,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,1,0,1], 475 | [1,0,0,0,0,0,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,0,0,1], 476 | [1,1,1,0,1,1,1,1,1,0,0,0,0,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,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1], 494 | [1,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,1], 495 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 496 | [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], 497 | [1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1], 498 | [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] 499 | ], 500 | 'wall_color':'#9966CC', 501 | 'goods':{ //能量豆 502 | '1,4':1, 503 | '26,4':1, 504 | '1,27':1, 505 | '26,27':1 506 | } 507 | } 508 | ]; 509 | _COLOR = ['#F00','#F93','#0CF','#F9C'], //NPC颜色 510 | _COS = [1,0,-1,0], 511 | _SIN = [0,1,0,-1], 512 | _LIFE = 5, //玩家生命值 513 | _SCORE = 0; //玩家得分 514 | 515 | var game = new Game('canvas'); 516 | //启动页 517 | (function(){ 518 | var stage = game.createStage(); 519 | //logo 520 | stage.createItem({ 521 | x:game.width/2, 522 | y:game.height*.45, 523 | width:100, 524 | height:100, 525 | frames:3, 526 | draw:function(context){ 527 | var t = Math.abs(5-this.times%10); 528 | context.fillStyle = '#FFE600'; 529 | context.beginPath(); 530 | context.arc(this.x,this.y,this.width/2,t*.04*Math.PI,(2-t*.04)*Math.PI,false); 531 | context.lineTo(this.x,this.y); 532 | context.closePath(); 533 | context.fill(); 534 | context.fillStyle = '#000'; 535 | context.beginPath(); 536 | context.arc(this.x+5,this.y-27,7,0,2*Math.PI,false); 537 | context.closePath(); 538 | context.fill(); 539 | } 540 | }); 541 | //游戏名 542 | stage.createItem({ 543 | x:game.width/2, 544 | y:game.height*.6, 545 | draw:function(context){ 546 | context.font = 'bold 42px Helvetica'; 547 | context.textAlign = 'center'; 548 | context.textBaseline = 'middle'; 549 | context.fillStyle = '#FFF'; 550 | context.fillText('Pac-Man',this.x,this.y); 551 | } 552 | }); 553 | //版权信息 554 | stage.createItem({ 555 | x:game.width-12, 556 | y:game.height-5, 557 | draw:function(context){ 558 | context.font = '14px Helvetica'; 559 | context.textAlign = 'right'; 560 | context.textBaseline = 'bottom'; 561 | context.fillStyle = '#AAA'; 562 | context.fillText('© passer-by.com',this.x,this.y); 563 | } 564 | }); 565 | //事件绑定 566 | stage.bind('keydown',function(e){ 567 | switch(e.keyCode){ 568 | case 13: 569 | case 32: 570 | game.nextStage(); 571 | break; 572 | } 573 | }); 574 | })(); 575 | //游戏主程序 576 | (function(){ 577 | _COIGIG.forEach(function(config,index){ 578 | var stage,map,beans,items,player,times; 579 | stage = game.createStage({ 580 | update:function(){ 581 | var stage = this; 582 | if(stage.status==1){ //场景正常运行 583 | items.forEach(function(item){ 584 | if(map&&!map.get(item.coord.x,item.coord.y)&&!map.get(player.coord.x,player.coord.y)){ 585 | var dx = item.x-player.x; 586 | var dy = item.y-player.y; 587 | if(dx*dx+dy*dy<750&&item.status!=4){ //物体检测 588 | if(item.status==3){ 589 | item.status = 4; 590 | _SCORE += 10; 591 | }else{ 592 | stage.status = 3; 593 | stage.timeout = 30; 594 | } 595 | } 596 | } 597 | }); 598 | if(JSON.stringify(beans.data).indexOf(0)<0){ //当没有物品的时候,进入下一关 599 | game.nextStage(); 600 | } 601 | }else if(stage.status==3){ //场景临时状态 602 | if(!stage.timeout){ 603 | _LIFE--; 604 | if(_LIFE){ 605 | stage.resetItems(); 606 | }else{ 607 | var stages = game.getStages(); 608 | game.setStage(stages.length-1); 609 | return false; 610 | } 611 | } 612 | } 613 | } 614 | }); 615 | //绘制地图 616 | map = stage.createMap({ 617 | x:60, 618 | y:10, 619 | data:config['map'], 620 | cache:true, 621 | draw:function(context){ 622 | context.lineWidth = 2; 623 | for(var j=0; j-1){ 641 | context.strokeStyle=value==2?"#FFF":config['wall_color']; 642 | var pos = this.coord2position(i,j); 643 | switch(code.join('')){ 644 | case '1100': 645 | context.beginPath(); 646 | context.arc(pos.x+this.size/2,pos.y+this.size/2,this.size/2,Math.PI,1.5*Math.PI,false); 647 | context.stroke(); 648 | context.closePath(); 649 | break; 650 | case '0110': 651 | context.beginPath(); 652 | context.arc(pos.x-this.size/2,pos.y+this.size/2,this.size/2,1.5*Math.PI,2*Math.PI,false); 653 | context.stroke(); 654 | context.closePath(); 655 | break; 656 | case '0011': 657 | context.beginPath(); 658 | context.arc(pos.x-this.size/2,pos.y-this.size/2,this.size/2,0,.5*Math.PI,false); 659 | context.stroke(); 660 | context.closePath(); 661 | break; 662 | case '1001': 663 | context.beginPath(); 664 | context.arc(pos.x+this.size/2,pos.y-this.size/2,this.size/2,.5*Math.PI,1*Math.PI,false); 665 | context.stroke(); 666 | context.closePath(); 667 | break; 668 | default: 669 | var dist = this.size/2; 670 | code.forEach(function(v,index){ 671 | if(v){ 672 | context.beginPath(); 673 | context.moveTo(pos.x,pos.y); 674 | context.lineTo(pos.x-_COS[index]*dist,pos.y-_SIN[index]*dist); 675 | context.stroke(); 676 | context.closePath(); 677 | } 678 | }); 679 | } 680 | } 681 | } 682 | } 683 | } 684 | } 685 | }); 686 | //物品地图 687 | beans = stage.createMap({ 688 | x:60, 689 | y:10, 690 | data:config['map'], 691 | frames:8, 692 | draw:function(context){ 693 | for(var j=0; jthis.coord.x){ 855 | this.orientation = 0; 856 | }else if(this.vector.xthis.coord.y){ 859 | this.orientation = 1; 860 | }else if(this.vector.y80||this.times%2?true:false; 871 | } 872 | if(this.status!=4){ 873 | context.fillStyle = isSick?'#BABABA':this.color; 874 | context.beginPath(); 875 | context.arc(this.x,this.y,this.width*.5,0,Math.PI,true); 876 | switch(this.times%2){ 877 | case 0: 878 | context.lineTo(this.x-this.width*.5,this.y+this.height*.4); 879 | context.quadraticCurveTo(this.x-this.width*.4,this.y+this.height*.5,this.x-this.width*.2,this.y+this.height*.3); 880 | context.quadraticCurveTo(this.x,this.y+this.height*.5,this.x+this.width*.2,this.y+this.height*.3); 881 | context.quadraticCurveTo(this.x+this.width*.4,this.y+this.height*.5,this.x+this.width*.5,this.y+this.height*.4); 882 | break; 883 | case 1: 884 | context.lineTo(this.x-this.width*.5,this.y+this.height*.3); 885 | context.quadraticCurveTo(this.x-this.width*.25,this.y+this.height*.5,this.x,this.y+this.height*.3); 886 | context.quadraticCurveTo(this.x+this.width*.25,this.y+this.height*.5,this.x+this.width*.5,this.y+this.height*.3); 887 | break; 888 | } 889 | context.fill(); 890 | context.closePath(); 891 | } 892 | context.fillStyle = '#FFF'; 893 | if(isSick){ 894 | context.beginPath(); 895 | context.arc(this.x-this.width*.15,this.y-this.height*.21,this.width*.08,0,2*Math.PI,false); 896 | context.arc(this.x+this.width*.15,this.y-this.height*.21,this.width*.08,0,2*Math.PI,false); 897 | context.fill(); 898 | context.closePath(); 899 | }else{ 900 | context.beginPath(); 901 | context.arc(this.x-this.width*.15,this.y-this.height*.21,this.width*.12,0,2*Math.PI,false); 902 | context.arc(this.x+this.width*.15,this.y-this.height*.21,this.width*.12,0,2*Math.PI,false); 903 | context.fill(); 904 | context.closePath(); 905 | context.fillStyle = '#000'; 906 | context.beginPath(); 907 | context.arc(this.x-this.width*(.15-.04*_COS[this.orientation]),this.y-this.height*(.21-.04*_SIN[this.orientation]),this.width*.07,0,2*Math.PI,false); 908 | context.arc(this.x+this.width*(.15+.04*_COS[this.orientation]),this.y-this.height*(.21-.04*_SIN[this.orientation]),this.width*.07,0,2*Math.PI,false); 909 | context.fill(); 910 | context.closePath(); 911 | } 912 | } 913 | }); 914 | } 915 | items = stage.getItemsByType(2); 916 | //主角 917 | player = stage.createItem({ 918 | width:30, 919 | height:30, 920 | type:1, 921 | location:map, 922 | coord:{x:13.5,y:23}, 923 | orientation:2, 924 | speed:2, 925 | frames:10, 926 | update:function(){ 927 | var coord = this.coord; 928 | if(!coord.offset){ 929 | if(this.control.orientation!='undefined'){ 930 | if(!map.get(coord.x+_COS[this.control.orientation],coord.y+_SIN[this.control.orientation])){ 931 | this.orientation = this.control.orientation; 932 | } 933 | } 934 | this.control = {}; 935 | var value = map.get(coord.x+_COS[this.orientation],coord.y+_SIN[this.orientation]); 936 | if(value==0){ 937 | this.x += this.speed*_COS[this.orientation]; 938 | this.y += this.speed*_SIN[this.orientation]; 939 | }else if(value<0){ 940 | this.x -= map.size*(map.x_length-1)*_COS[this.orientation]; 941 | this.y -= map.size*(map.y_length-1)*_SIN[this.orientation]; 942 | } 943 | }else{ 944 | if(!beans.get(this.coord.x,this.coord.y)){ //吃豆 945 | _SCORE++; 946 | beans.set(this.coord.x,this.coord.y,1); 947 | if(config['goods'][this.coord.x+','+this.coord.y]){ //吃到能量豆 948 | items.forEach(function(item){ 949 | if(item.status==1||item.status==3){ //如果NPC为正常状态,则置为临时状态 950 | item.timeout = 450; 951 | item.status = 3; 952 | } 953 | }); 954 | } 955 | } 956 | this.x += this.speed*_COS[this.orientation]; 957 | this.y += this.speed*_SIN[this.orientation]; 958 | } 959 | }, 960 | draw:function(context){ 961 | context.fillStyle = '#FFE600'; 962 | context.beginPath(); 963 | if(stage.status!=3){ //玩家正常状态 964 | if(this.times%2){ 965 | context.arc(this.x,this.y,this.width/2,(.5*this.orientation+.20)*Math.PI,(.5*this.orientation-.20)*Math.PI,false); 966 | }else{ 967 | context.arc(this.x,this.y,this.width/2,(.5*this.orientation+.01)*Math.PI,(.5*this.orientation-.01)*Math.PI,false); 968 | } 969 | }else{ //玩家被吃 970 | if(stage.timeout) { 971 | context.arc(this.x,this.y,this.width/2,(.5*this.orientation+1-.02*stage.timeout)*Math.PI,(.5*this.orientation-1+.02*stage.timeout)*Math.PI,false); 972 | } 973 | } 974 | context.lineTo(this.x,this.y); 975 | context.closePath(); 976 | context.fill(); 977 | } 978 | }); 979 | //事件绑定 980 | stage.bind('keydown',function(e){ 981 | switch(e.keyCode){ 982 | case 13: //回车 983 | case 32: //空格 984 | this.status = this.status==2?1:2; 985 | break; 986 | case 39: //右 987 | player.control = {orientation:0}; 988 | break; 989 | case 40: //下 990 | player.control = {orientation:1}; 991 | break; 992 | case 37: //左 993 | player.control = {orientation:2}; 994 | break; 995 | case 38: //上 996 | player.control = {orientation:3}; 997 | break; 998 | } 999 | }); 1000 | }); 1001 | })(); 1002 | //结束画面 1003 | (function(){ 1004 | var stage = game.createStage(); 1005 | //游戏结束 1006 | stage.createItem({ 1007 | x:game.width/2, 1008 | y:game.height*.35, 1009 | draw:function(context){ 1010 | context.fillStyle = '#FFF'; 1011 | context.font = 'bold 48px Helvetica'; 1012 | context.textAlign = 'center'; 1013 | context.textBaseline = 'middle'; 1014 | context.fillText(_LIFE?'YOU WIN!':'GAME OVER',this.x,this.y); 1015 | } 1016 | }); 1017 | //记分 1018 | stage.createItem({ 1019 | x:game.width/2, 1020 | y:game.height*.5, 1021 | draw:function(context){ 1022 | context.fillStyle = '#FFF'; 1023 | context.font = '20px Helvetica'; 1024 | context.textAlign = 'center'; 1025 | context.textBaseline = 'middle'; 1026 | context.fillText('FINAL SCORE: '+(_SCORE+50*Math.max(_LIFE-1,0)),this.x,this.y); 1027 | } 1028 | }); 1029 | //事件绑定 1030 | stage.bind('keydown',function(e){ 1031 | switch(e.keyCode){ 1032 | case 13: //回车 1033 | case 32: //空格 1034 | _SCORE = 0; 1035 | _LIFE = 5; 1036 | game.setStage(1); 1037 | break; 1038 | } 1039 | }); 1040 | })(); 1041 | game.init(); 1042 | })(); 1043 | --------------------------------------------------------------------------------