JavaScript Why is my snake not increasing after eating food?

  • Thread starter Thread starter shivajikobardan
  • Start date Start date
  • Tags Tags
    Food Increasing
AI Thread Summary
The discussion centers around a code snippet for a snake game, specifically addressing the functionality of increasing the snake's size upon colliding with food. The provided code successfully updates the snake's position and triggers sound effects when food is consumed, although sound may not function on CodePen. The main issue identified was the absence of a CSS class for the snake, which has since been resolved. The conversation emphasizes the importance of ensuring all necessary elements, including CSS, are in place for the game to function correctly.
shivajikobardan
Messages
637
Reaction score
54
TL;DR Summary
snake not increasing after eating food.

Here's the full code.
JavaScript:
snakeArr.unshift({ x: snakeArr[0].x + inputDir.x, y: snakeArr[0].y + inputDir.y })
This is the code to increase the size of snake once it collides with food.
The code above it and below it, sound play when food is eaten and changing food location when food is eaten are working(sound play won't work on codepen).
What's the problem. Please help to fix the issue and understand it as well.
 
Technology news on Phys.org
This issue has been fixed, I forgot to add CSS class to snake.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top