How to use the level/config.foodWidth function in level

To help you get started, we’ve selected a few level examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github devyumao / super-ginger / src / level / Stage.js View on Github external
Stage.prototype.addNext = function (cb) {
        var game = this.game;

        // next 大小、位置信息
        var nextWidth = game.rnd.between(this.minWidth, this.maxWidth);
        var nextMargin = [20, 10];
        // next 水平位置在 curr 和除去自身宽度的边界之间, 考虑边缘留空
        var nextX = game.rnd.between(this.currEdgeX + nextMargin[0], game.width - nextWidth - nextMargin[1]);

        // food 大小、位置信息
        var foodWidth = config.foodWidth;
        var foodMargin = 10;
        var food = null;
        var foodX = nextX;
        var hasFood = util.proba(this.foodProba) // 先验概率
            && nextX - this.currEdgeX >= foodWidth + foodMargin * 2; // 间距是否足够放

        if (hasFood) {
            // food 水平位置在两根柱子之间
            foodX = game.rnd.between(this.currEdgeX + foodMargin, nextX - foodMargin - foodWidth);
            food = this._createFood();

            // food 平移动画
            var moveFood = game.add.tween(food.getEl())
                .to({x: foodX}, 300, this.moveEasing);
            moveFood.start();
        }
github devyumao / super-ginger / src / level / Food.js View on Github external
Food.prototype._init = function (options) {
        var game = this.game;
        var imageName = 'food-with-halo';

        var padding = (game.cache.getImage(imageName).width - config.foodWidth) / 2;
        this.image = game.add.image(options.x - padding, options.y - padding, 'food-with-halo');
        this._shake();
    };