Juego de Snake hecho en javascript siguiendo el tutorial https://www.youtube.com/watch?v=Je0B3nHhKmM y añadiendo algunas funcionalidades más y bugfixing.
- Comida especial: Cada vez que se inicia el juego o se come una pieza normal, hay una probabilidad del 10% de que aparezca en el tablero una fruta especial que suma 5 puntos al score, sin aumentar el tamaño de la serpiente.
- Reset con el spaceBar: puedes resetear el juego sin pulsar manualmente el botón reset, con la barra espaciadora del teclado.
-
Migración de
event.keyCodeaevent.key: Se ha reemplazado el uso de keycodes numéricos (deprecated) por strings como"ArrowUp"o" "para mejorar la legibilidad y compatibilidad. -
Corrección del uso de
eventglobal (deprecated): Se ha eliminado el uso implícito dewindow.event, asegurando que el objetoeventse recibe correctamente como parámetro en los event listeners. -
Fix de movimiento diagonal al inicio: Se ha corregido la velocidad inicial estableciendo
yVelocity = 0, evitando que la serpiente se mueva en diagonal al comenzar el juego. -
Fix de múltiples loops al reiniciar (speed bug): Se ha evitado la creación de múltiples bucles de juego simultáneos añadiendo una comprobación:
if (running) return;
-
Añadido bordes a la comida con
const foodBorder = "black";yctx.strokeStyle = foodBorder;
Snake game made in JavaScript following the tutorial https://www.youtube.com/watch?v=Je0B3nHhKmM and adding some more functionalities and bugfixing.
- Special food: Each time the game starts or a normal piece is eaten, there is a 10% chance that a special fruit will appear on the board that adds 5 points to the score, without increasing the size of the snake.
- Reset with the spaceBar: you can reset the game without manually pressing the reset button, using the keyboard space bar.
-
Migration from
event.keyCodetoevent.key: The use of numeric keycodes (deprecated) has been replaced by strings like"ArrowUp"or" "to improve readability and compatibility. -
Correction of the use of global
event(deprecated): The implicit use ofwindow.eventhas been removed, ensuring that theeventobject is correctly received as a parameter in the event listeners. -
Fix for diagonal movement at the start: The initial speed has been corrected by setting
yVelocity = 0, preventing the snake from moving diagonally when starting the game. -
Fix for multiple loops on restart (speed bug): The creation of multiple simultaneous game loops has been prevented by adding a check:
if (running) return;
-
Added borders to the food with
const foodBorder = "black";andctx.strokeStyle = foodBorder;
// Transalted by https://openl.io/es/translate/markdown