Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Introducing JavaScript Let's Make a Game Modifying Values

how can i answer this question? would you like tell about this task?

i'm trying this task but this is may be gonna tuff. as what i did 24th coordinates copied to 100th coordinates after that i modified the number. for the ex;(300, 100) that is changed by (300, 200). that is also went wrong

game.js
var game;
var player;
var platforms;
var badges;
var coins;
var cursors;
var jumpButton;
var text;
var winningMessage;
var won = false;
var currentScore = 0;
var winningScore = 100;

function createCoins() {
    coins = game.add.physicsGroup();

    coinCreate(375, 100, 'coin');

}

function createPlatforms() {
    platforms = game.add.physicsGroup();

    platforms.create(300, 100, 'platform');
    platforms.create(400, 450, 'platform');
    platforms.create(100, 450, 'platform');

    platforms.setAll('body.immovable', true);
}

function createBadge() {
    badges = game.add.physicsGroup();

    var badge = badges.create(550, 450, 'badge');
    badge.animations.add('spin');
    badge.animations.play('spin', 10, true);
}

function coinCreate(left, top, coinImage) {
    var coin = coins.create(left, top, coinImage);
    coin.animations.add('spin');
    coin.animations.play('spin', 10, true);
}

function collectHandler(player, coin) {
    coin.kill();
    currentScore = currentScore + 10;
    if (currentScore === winningScore) {
        createBadge();
    }
}

function collectBadgeHandler(player, badge) {
    badge.kill();
    won = true;
}

window.onload = function () {

    game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });

    function preload() {

        game.stage.backgroundColor = '#5db1ad';
        //Load images
        game.load.image('platform', 'platform_1.png');
        game.load.image('platform2', 'platform_2.png');
        //Load spritesheets
        game.load.spritesheet('player', 'chalkers.png', 48, 62);
        game.load.spritesheet('coin', 'coin.png', 36, 44);
        game.load.spritesheet('badge', 'badge.png', 42, 54);
    }

    function create() {

        player = game.add.sprite(50, 600, 'player');
        player.animations.add('walk');
        player.anchor.setTo(0.5, 1);

        game.physics.arcade.enable(player);

        player.body.collideWorldBounds = true;
        player.body.gravity.y = 500;

        createCoins();
        createPlatforms();

        cursors = game.input.keyboard.createCursorKeys();
        jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);

        text = game.add.text(16, 16, "SCORE: " + currentScore, { font: "Press Start 2P", fontSize: 18, fill: "white" });
        winningMessage = game.add.text(game.world.centerX, 250, "", { font: "Press Start 2P", fontSize:"48px", fill: "white" });
        winningMessage.anchor.setTo(0.5, 1);

    }

    function update() {
        text.text = "SCORE: " + currentScore;
        game.physics.arcade.collide(player, platforms);
        platforms.create(300, 200, 'platform');
        game.physics.arcade.overlap(player, coins, collectHandler);
        game.physics.arcade.overlap(player, badges, collectBadgeHandler);

        player.body.velocity.x = 0;

        if (cursors.left.isDown) {
            player.animations.play('walk', 10, true);
            player.body.velocity.x = -300;
            player.scale.x = - 1;
        }
        else if (cursors.right.isDown) {
            player.animations.play('walk', 10, true);
            player.body.velocity.x = 300;
            player.scale.x = 1;
        }
        else {
            player.animations.stop();
        }

        if (jumpButton.isDown && (player.body.onFloor() || player.body.touching.down)) {
            player.body.velocity.y = -400;
        }
        if (won) {
            winningMessage.text = "YOU WIN!!!";
        }

    }

    function render() {

    }

};

2 Answers

Task 1 on Line #24 - just change 100 to 200

from

platforms.create(300, 100, 'platform');```

to
```javascript
platforms.create(300, 200, 'platform'); ```

Task #2 on Line #25 - just change 'platform' to 'platform2'

from
```javascript
platforms.create(400, 450, 'platform');```

to
```javascript
platforms.create(400, 450, 'platform2');```



```javascript
function createPlatforms() {
    platforms = game.add.physicsGroup();

    platforms.create(300, 200, 'platform');
    platforms.create(400, 450, 'platform2');
    platforms.create(100, 450, 'platform');

    platforms.setAll('body.immovable', true);
}

sorry bad formatting; let me try again

Task 1 on Line #24 - just change 100 to 200

from

platforms.create(300, 100, 'platform');

to

platforms.create(300, 200, 'platform');

Task #2 on Line #25 - just change 'platform' to 'platform2'

from

platforms.create(400, 450, 'platform');

to

platforms.create(400, 450, 'platform2');

together

function createPlatforms() {
    platforms = game.add.physicsGroup();

    platforms.create(300, 200, 'platform');
    platforms.create(400, 450, 'platform2');
    platforms.create(100, 450, 'platform');

    platforms.setAll('body.immovable', true);
}