I’ve completed the assessment and it basically works. However, there seem to be two small differences between the function of my game and the reference game.
The evilCircle picks up the balls and they disappear. But they actually seem like they are still moving about the Canvas, just hidden. I can tell this by the fact that when I get down to about 5 balls, I can watch one of the remaining balls randomly change color! Which must be from a collision with another hidden ball? Also, my balls seem to flicker more color wise upon collision than in the reference game.
I’ve compared my source code to the reference source code. While I choose to implement the objects using Class definitions with inheritance, the methods seems to be performing the same functions. So, I’m at a loss as to explain the behavior differences. Any help would be greatly appreciated.
I’m also curious as to why the setControls method for the EvilCircle class had to assign its “this” to a local let “_this”. Is this because it’s basically an event handler and method’s normal “this” could change from its load time closure?
for the hidden ball it can be fixed by removing it from the ball array or change the collision function to check if the ball exist or not
for _this
let for example
we call
evilcircle.setControl()
this here is refering to the object that call the function which in that case the evilcircle
so any using of this will be vaild and refere to the object that called it
but
window.onkeydown = function(e) {} is not called by the evilcircle so this is not refered to the evilecircle object but again to the object that called it which is window in that case
and i like the class syntax more but it does not supported in IE browser
you have extra w at the end of your js file which i am sure is miss type and you need to add ; after the end of this window.onkeydown = function(e) {};