|
Flash制作物体弹跳电脑游戏(6) 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; };
效果(这时按键盘左右方向键你可以看到效果)
最后让物体能够蹦起来啊!
xspeed = 0;
|