用FLASH做了个贪吃蛇游戏,有很多bug

      FLASH 2005-5-10 22:51

Flash 动画

code:
onClipEvent (load) {
    attachegg = 1;\\snake's direction
    _root.score = 0;\\score
    this._x = 0;
    this._y = 360;
    next_x = 0;
    next_y = 0;
    to_x = 0;
    to_y = 0;
    flag = 0;
    _root.d = 0;
}
onClipEvent (enterFrame) {
    if (attachegg) {
        _root.attachMovie("egg", "egg0", 0, {_x:random(29)*20, _y:random(13)*20});
        attachegg = 0;
    }\\随机复制蛋
    for (i=0; i<=_root.score; i++) {
        mc = _root["snake"+i];
        next_x = mc._x;
        next_y = mc._y;
        if (i != 0) {
            mc._x = to_x;
            mc._y = to_y;
        } else {
            switch (_root.d) {
            case 1 :
                _root.snake0._x -=20;
                break;
            case 2 :
                _root.snake0._x +=20;
                break;
            case 3 :
                _root.snake0._y -=20;
                break;
            case 4 :
                _root.snake0._y +=20;
                break;
            }
        }
        to_x = next_x;
        to_y = next_y;\\我认为是这个游戏的关键,记录蛇每一节的坐标.
    }
    if (this._x == _root.egg0._x && this._y == _root.egg0._y) {
        attachegg = 1;
        _root.score += 1;
        _root.attachMovie("snake", "snake"+_root.score, _root.score, {_x:next_x, _y:next_y});
    }
    for (i=1; i<=_root.score; i++) {
        if (this._x == _root["snake"+i]._x && this._y == _root["snake"+i]._y) {
            flag = 1;
        }
    }
    if (this._y>360 || this._y<0 || this._x<0 || this._x>580 || flag) {
        //game over
        for (i=1; i<=_root.score; ++i) {
            removeMovieClip(_root["snake"+i]);
        }
        removeMovieClip(_root.egg0);
        _root.gotoAndStop(3);
    }
}
做到11:00,去睡觉,明天还的上班.
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}