https://studio.code.org/projects/gamelab/io32yKS6wnVDexNSMruh_nznjSAGL4SRzwlChkUmVeQ <—Link to the project (hope it works)
(arrow keys to move)
Background:
I am developing a top-down SHMUP game to practice working with sprites (prior to now, I never used them, but I am familiar with objects). Currently, I am working on adding enemy types. Two enemy types are ‘implemented’: type 0, which moves in a line periodically and shoots, and type 1, which slowly approaches the player, preparing a pseudo-laser attack. I say implemented in quotes, since type 1 does not fully work.
Problem:
To see this problem, start the project, and with your mouse on the canvas, hold “o” and press “p”.
I managed to work around this problem once, but it comes back to haunt me. After some time (which would be roughly around when it attacks) this error appears within the “update” function:
TypeError: Cannot read properties of null (reading ‘copy’)
In context, lines 374 - 414 are miscellaneous frame updates like collision, hit detection and counters that would look messy in the draw function. 390 specifically is “enemy.collide(player);” which calls for the collide collision mode between the enemy group and the player group (the player controller). If I remove this line (which i intend to do) similar problems arise when it refers to either the enemy group or the “eprojectiles” group, which handles enemy projectiles.
I know that this means that one property of either the sprite summoned is undefined, but this is reusing code from the type 0 enemy, which works. If anyone could bother looking through the code, or tell me how better i could avoid this error, it would be greatly appreciated!