AS贪吃蛇简陋版
作者 佚名技术
来源 服务器技术
浏览
发布时间 2012-07-13
全部代码如下: /************2005.5**************/ /*********贪吃蛇简陋版************/ /***********寒冰(胡乱编写)********/ var s_x = 0; var s_y = 0; var dir = [[-1, 0], [0, -1], [1, 0], [0, 1]]; //四个方向 var _dir; var c_x = (Stage.width-256)/2; var c_y = (Stage.height-256)/2; var map; var speed; var level = 1; var child_num; var Child; var snake_arr; init(); function init() { speed = 15; child_num = 1; snake_arr = []; DrawOutRound(); //画外框 DrawMap(); //画地图 SnakeRun(); //蛇移动 MakeWall(); //创建障碍物 MakeChild(); //创建食物(后来变成蛇身) createTextField("info", getNextHighestDepth(), 30, 350, 400, 20); createTextField("status", getNextHighestDepth(), 320, 370, 100, 20); status.text = "状态:playing"; info.text = "[用方向键控制方向,dead后请点鼠标重新开始]____寒冰制造"; } function DrawBox(name, color, w, h) { //画方块 var _b = createEmptyMovieClip(name, getNextHighestDepth()); with (_b) { lineStyle(0); beginFill(color); lineTo(w, 0); lineTo(w, h); lineTo(0, h); endFill(); } return _b; } function DrawOutRound() { DrawBox("outround", 0xffffff, 400, 400); } function DrawMap() { var _box = DrawBox("box", 0xffffff, 16, 16); _box._visible = false; map = []; for (var i = 0; i<16; i++) { map[i] = []; for (var j = 0; j<16; j++) { map[i][j] = 0; _box.duplicateMovieClip("_map"+i+j, getNextHighestDepth(), {_x:c_x+j*16, _y:c_y+i*16}); } } //trace(map) } function MakeSnake() { var Snake = DrawBox("snake", 0x000000, 16, 16); snake_arr.push(snake); Snake.x = s_x; Snake.y = s_y; //map[Snake.y][Snake.x] = 1; Snake._x = c_x+s_x*16; Snake._y = c_y+s_y*16; return Snake; } function SnakeRun() { var S = MakeSnake(); var i = 0; _dir = dir[3]; SnakeControl(); S.onEnterFrame = function() { if (++i>100/speed) { ChildRun(); i = 0; if (map[this.y+_dir[1]][this.x+_dir[0]] == 0) { } else if (map[this.y+_dir[1]][this.x+_dir[0]] == 8) { speed++; map[this.y+_dir[1]][this.x+_dir[0]] == 0; snake.swapDepths(getNextHighestDepth()); Child._name = Child._name.substr(1); snake_arr.push(Child); MakeChild(); } else { status.text = "状态:over"; delete this.onEnterFrame; return; } this.x += _dir[0]; this.y += _dir[1]; this._x = c_x+16*this.x; this._y = c_y+16*this.y; } }; //trace(S); } function SnakeControl() { var obj = {}; obj.onKeyDown = function() { var key = Key.getCode(); switch (key) { case 37 : _dir = dir[0]; break; case 38 : _dir = dir[1]; break; case 39 : _dir = dir[2]; break; case 40 : _dir = dir[3]; } }; Key.addListener(obj); } function RndArr() { //随机乱数,为了取得随机的障碍物的位置,不过这里用随机是为了偷懒,应该固定位置的. var arr = []; for (var i = 1; i<256; i++) { arr[i-1] = i; } arr.sort(function () { return random(2) ? 1 : -1; }); return arr; } function MakeChild() { var rgb = 0x0000ff; Child = DrawBox("_child"+child_num, rgb, 16, 16); Ch |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: cool blur effect-模糊效果下一篇: 按钮中热区的疑惑
关于AS贪吃蛇简陋版的所有评论