Feature/vampire survivor movement#2
Conversation
Review completed. Found 3 issues that should be addressed:
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| // Fire projectile at nearest enemy | ||
| function fireProjectile() { | ||
| const nearestEnemy = findNearestEnemy(); | ||
| if (!nearestEnemy) return; | ||
|
|
||
| const startX = game.player.x + game.player.size / 2; | ||
| const startY = game.player.y + game.player.size / 2; | ||
| const targetX = nearestEnemy.x + nearestEnemy.size / 2; | ||
| const targetY = nearestEnemy.y + nearestEnemy.size / 2; | ||
|
|
||
| const projectile = new Projectile( | ||
| startX, | ||
| startY, | ||
| targetX, | ||
| targetY, | ||
| game.weaponSystem.projectileSpeed | ||
| ); | ||
|
|
||
| game.projectiles.push(projectile); | ||
| } |
There was a problem hiding this comment.
Projectiles use the enemy's position at fire time and continue in that direction, which causes them to miss moving targets. Since enemies are constantly moving toward the player, projectiles will often miss at medium to long range. Consider implementing homing projectiles that update their direction each frame, or use predictive targeting that aims at where the enemy will be.
Fix it with Roo Code or mention @roomote and request a fix.
| if (collided) { | ||
| // Enemy reached player - remove it and count as kill | ||
| game.enemies.splice(i, 1); | ||
| game.stats.kills++; | ||
| } |
There was a problem hiding this comment.
When an enemy collides with the player, it's removed and counted as a kill. This is semantically incorrect for a vampire survivor game where enemies touching the player should damage the player, not reward them with a kill. The kill counter should only increment when projectiles destroy enemies.
Fix it with Roo Code or mention @roomote and request a fix.
| // Check collision with enemies | ||
| for (let j = game.enemies.length - 1; j >= 0; j--) { | ||
| const enemy = game.enemies[j]; | ||
| if (projectile.checkCollision(enemy)) { | ||
| projectile.alive = false; | ||
| const died = enemy.takeDamage(game.weaponSystem.damage); | ||
| if (died) { | ||
| game.enemies.splice(j, 1); | ||
| game.stats.kills++; | ||
| } | ||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
Modifying the game.enemies array while iterating through projectiles can cause issues. If multiple projectiles hit the same enemy in a single frame, the first hit removes the enemy from the array (line 713), but subsequent projectiles may still try to check collision with it. While the current code uses break to exit the inner loop, this pattern is fragile. Consider marking enemies for removal and cleaning them up after both loops complete, or iterate backwards through the enemies array.
Fix it with Roo Code or mention @roomote and request a fix.
No description provided.