Business Outfitted Bob - Exercise 20 "Going Further" - Speed Increase

I was hoping to get assistance with the “going further” of exercise 20 on the CREATE VIDEO GAMES WITH PHASER.JS tutorial - Business Outfitted Bob. I have tried several methods for incrementing the speed of Bob. I imagine it has to be something incredible small that I’m missing, but having tried several solutions and watched a million Code your own Snake game in JS videos, none of those implementations seem to work. I’ve also tried the solutions in both create() and update() (which to an amateur like myself seems logical. and yes, speed is properly declared using let. Just looking for any additional guidance other than the current Hints provide so i can finally figure this out.

Thanks!

Link to exercise - https://www.codecademy.com/paths/create-video-games-with-phaser/tracks/game-dev-learn-javascript-basics/modules/game-dev-project-variables-and-conditionals/projects/business-outfitted-bob

1 Like

Hi @gray2263698514 :slight_smile:
Would you mind posting your code too so that we can see your progress so far?
Thanks!

1 Like

Sure thing! Thanks for getting back so quick. Since I’m a newish user, I can only include 2 links max and can’t upload Js files so I’ve settled for included just the part of code that I thought should have been the quickest way to do this which is: "speed += 0.1; " underneath the code for what happens after bob and the money sprite interact. i tried it with larger numbers thinking perhaps 0.1 isnt perceptible but that made no difference. so i reput 0.1 since it’s what the guidance wanted. Sorry this is such a miserable way to have to check code. I tried things like update.speed and many other solutions but realized there’s no way it was intended to be that complicated. I imagine it’s quite simple I’m just missing it. Also i have speed declared at the top of the program as “let speed = 1” and gameState.player.speed and gameState.speed but those typically broke the code.

Initialization code at top:

let score = 0;
const gameState = {
numCoordinates: {},
};
// Add a variable to multiply money
const moneyMultiplier = 100;
// Add a variable to control speed of Bob sprite
let speed = 1;
// Add a variable to keep count of Bob’s earnings
let randomCoord;

Code in question where speed is supposed to be updated:

this.physics.add.overlap(gameState.player, gameState.money, () => {
// Hide and deactivate the money sprite after Bob collides with it
gameState.money.disableBody();
// Move money somewhere else on the canvas
delete gameState.numCoordinates[x${gameState.money.x}y${gameState.money.y}];
randomCoord = assignCoords();
// Place the money sprite somewhere new, then show and activate it
gameState.money.enableBody(true, randomCoord.x, randomCoord.y);
// Increase the score randomly between 100 and 1000
score += (Math.round(Math.random() * 10) * moneyMultiplier);
// Update cash total text
scoreText.setText(Earnings: \$${score});
// Place paper sprite on canvas randomly
randomCoord = assignCoords();
gameState.enemies.create(randomCoord.x, randomCoord.y, ‘paper’).setScale(.6);
//Update speed and increment by 0.1
speed += 0.1;
});

Thanks @gray2263698514 :slight_smile:

One quick tip for formatting code is to use triple backticks like:
```
console.log(‘hello’);
```

That way your code gets formatted as code instead of plain text. I was having a bit of difficulty copying and pasting in your code because of the interpolated stings that use backticks, gets rendered as code. Like:
delete gameState.numCoordinates[ delete gameState.numCoordinates[x${gameState.money.x}y${gameState.money.y} ]; ]; ← you can see that the `s disappear and the x${gameState.money.x}y${gameState.money.y} portion looks like some in-line code snippet.

But formatting aside. I think you’re on the right path. I tried your speed += 0.1 and it did work for me, but it’s such a small increment that I needed to up the value from 0.1 to 4 and then I noticed that the speed visibly changed.

If you aren’t running into any syntax errors, if you try upping the value higher you should see the change take place. I think the guidance in step 20 is more of a suggestion than anything else. So while, increasing by 0.1 might be better in the long run (i.e. encourage players to play longer), at the end of the day it should also help you learn! So maybe the takeaway here is that you know what you’re doing, 0.1 isn’t the best value, you can use different values to check your code, and to try out things even if they’re not what’s being asked of you :slight_smile:

I hope that helps, please let me know if I can clarify anything!

1 Like

Absolute lifesaver brother. I tried 1 and 2 but with the average game lasting maybe 5 money piles due to the random placement, I must have not perceived it still. Really appreciate the tips as well. Have a wonderful rest of the week.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.