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.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Back
Top