|
Flash制作物体弹跳电脑游戏(2) level[12] = new Array(1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1); level[13] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1); level[14] = new Array(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); for (y=0; y<=14; y++) { for (x=0; x<=24; x++) { if (level[y][x] != 0) { place_brick = lev.attachMovie("block", "block_"+lev.getNextHighestDepth(), lev.getNextHighestDepth(), {_x:x*20+10, _y:y*20+10}); place_brick.gotoAndStop(level[y][x]); } } } _root.attachMovie("player", "player", _root.getNextHighestDepth(), {_x:40, _y:40}); player.onEnterFrame = function() { yspeed += gravity; if (yspeed>max_yspeed) { yspeed = max_yspeed; } if (Key.isDown(Key.LEFT)) { xspeed = -walk_speed; } if (Key.isDown(Key.RIGHT)) { xspeed = walk_speed; } while (_root.lev.hitTest(this._x, this._y+this._height/2-1+yspeed, true)) { yspeed--; } while (_root.lev.hitTest(this._x-this._width/2+1+xspeed, this._y, true)) { xspeed++; } while (_root.lev.hitTest(this._x+this._width/2-1+xspeed, this._y, true)) { xspeed--; } this._y += yspeed; this._x += xspeed; xspeed = 0; };
上面代码实现的效果是会出现一幅不动的背景。效果如下。
然后把弹跳的物体放进来。
yspeed = 0;
|