marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.03k stars 799 forks source link

CH. 16, A Platform Game 3rd, Ed. #346

Closed asg5704-deprecated closed 6 years ago

asg5704-deprecated commented 6 years ago

Description: Ran into issue while trying to create A Platform Game (Chapter 16) of Eloquent Javascript, 3rd Edition. TypeError in the State.prototype.update function.

Expected Behavior The platform game would be drawn to the DOM, the game would be able to be played.

Actual Behavior Issue: Uncaught TypeError: Cannot read property 'pos' of undefined pointing towards the State.prototype.update function.

Additional Information I typed it out the first time while reading through the book. The second time I copied all the code from the sandbox just in case I made a mistake typing it. Included is a screenshot as well as the .zip of the js/html/css

error

ch16.zip

marijnh commented 6 years ago

Does the same thing happen when you use the actual code for the chapter—http://eloquentjavascript.net/3rd_edition/code/chapter/16_game.js along with http://eloquentjavascript.net/3rd_edition/code/game_levels.js ?

asg5704-deprecated commented 6 years ago

No it does not. The runGame function did not have a fallback to use the simpleLevelPlan when not using game_levels.js.

marijnh commented 6 years ago

Since runGame takes an array of level plans, you can pass it [simpleLevelPlan] to run only that level (but it wouldn't be a very interesting game).