diff --git a/README.md b/README.md deleted file mode 100644 index a904476..0000000 --- a/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Pacman -Pacman. 吃豆游戏 - -building.... - -项目建造中…… diff --git a/game.js b/game.js deleted file mode 100644 index 62453e3..0000000 --- a/game.js +++ /dev/null @@ -1,307 +0,0 @@ -'use strict'; -/* -* 小型游戏引擎 -*/ -function Game(id,options){ - var _ = this; - options = options||{}; - var settings = { - width:960, //画布宽度 - height:640 //画布高度 - }; - for(var i in settings){ - this[i] = options[i]||settings[i]; - } - var $canvas = document.getElementById(id); - $canvas.width = _.width; - $canvas.height = _.height; - var _context = $canvas.getContext('2d'); //画布上下文环境 - var _stages = []; //布景对象队列 - var _events = {}; //事件集合 - var _index, //当前布景索引 - _hander; //帧动画控制 - //活动对象构造 - var Item = function(options){ - options = options||{}; - var settings = { - x:0, //横坐标 - y:0, //纵坐标 - width:20, //宽 - height:20, //高 - type:0, //对象类型,0表示普通对象(不与地图绑定),1表示玩家控制对象,2表示程序控制对象 - color:'#F00', //标识颜色 - status:1, //对象状态,1表示正常,0表示隐藏,2表示暂停 - orientation:0, //当前定位方向,0表示上,1表示右,2表示下,3表示左 - vector:{}, //目标坐标 - coord:{}, //如果对象与地图绑定,获得坐标值 - speed:0, //移动速度 - frames:1, //速度等级,内部计算器times多少帧变化一次 - times:0, //计数 - control:{}, //控制缓存,到达定位点时处理 - path:[], //NPC自动行走的路径 - index:0, //对象索引 - stage:null, //绑定对象与所属布景绑定 - update:function(){}, //更新参数信息 - draw:function(){} //绘制 - }; - for(var i in settings){ - this[i] = options[i]||settings[i]; - } - }; - Item.prototype.bind = function(eventType,callback){ - if(!_events[eventType]){ - _events[eventType] = {}; - $canvas.addEventListener(eventType,function(e){ - var position = _.getPosition(e); - _stages[_index].items.forEach(function(item){ - if(Math.abs(position.x-item.x) - - - - Pac-Man . 吃豆游戏 - - - - Canvas not supported - - - - \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 2c20a55..0000000 --- a/index.js +++ /dev/null @@ -1,482 +0,0 @@ -//主程序,业务逻辑 -(function(){ - var game = new Game('canvas'); - //启动页 - (function(){ - var stage = game.createStage(); - stage.bind('keydown',function(e){ - switch(e.keyCode){ - case 13: - case 32: - game.nextStage(); - break; - } - }); - //logo - stage.createItem({ - x:game.width/2, - y:game.height*.45, - width:100, - height:100, - frames:10, - draw:function(context){ - context.fillStyle = '#FC3'; - context.beginPath(); - if(this.times%2){ - context.arc(this.x,this.y,this.width/2,.20*Math.PI,1.80*Math.PI,false); - }else{ - context.arc(this.x,this.y,this.width/2,.01*Math.PI,1.99*Math.PI,false); - } - context.lineTo(this.x,this.y); - context.closePath(); - context.fill(); - context.fillStyle = '#000'; - context.beginPath(); - context.arc(this.x+5,this.y-27,7,0,2*Math.PI,false); - context.closePath(); - context.fill(); - } - }); - //游戏名 - stage.createItem({ - x:game.width/2, - y:game.height*.6, - draw:function(context){ - context.font = 'bold 42px Helvetica'; - context.textAlign = 'center'; - context.textBaseline = 'middle'; - context.fillStyle = '#FFF'; - context.fillText('Pac-Man',this.x,this.y); - } - }); - //版权信息 - stage.createItem({ - x:game.width-12, - y:game.height-5, - draw:function(context){ - context.font = '14px Helvetica'; - context.textAlign = 'right'; - context.textBaseline = 'bottom'; - context.fillStyle = '#AAA'; - context.fillText('© passer-by.com',this.x,this.y); - } - }); - })(); - //游戏主程序 - (function(){ - var MAP_ORIENTATION = { //地图方向 - '38':0, - '39':1, - '40':2, - '37':3 - }, - MAP_DATA = [ //地图数据 - [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], - [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], - [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], - [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], - [1,0,1,1,1,1,0,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0,1], - [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], - [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], - [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], - [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], - [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], - [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], - [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], - [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], - [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] - ], - MAP_SIZE = 20; //地图大小 - var stage = game.createStage(); - stage.bind('keydown',function(e){ - switch(e.keyCode){ - case 13: - case 32: - this.status = this.status==2?1:2; - break; - } - }); - //绘制地图 - var map = stage.createMap({ - x:50, - y:10, - data:MAP_DATA, - draw:function(context){ - var y_length = this.data.length; - var x_length = this.data[0].length; - for(var j=0; jthis.coord.x){ - this.orientation = 1; - }else if(this.vector.xthis.coord.y){ - this.orientation = 2; - }else if(this.vector.y