/snakemovement

snake game based on kontra framework

Primary LanguageJavaScript

Snake game - movement implemented in Kontra

About game

Kontra.js is a mini JS game engine. Good to implement ideas. This program tries to implement snake game's movement logic.

Installation

Just clone this directory and serve it via server, no installation required

Game Logic

  1. Snake is a grid based movement i.e. if you move in slow motion it will move in box, This is evident when you take a turn. The whole first block will move then body will follow. Implmenet a virtual grid of XX boxes, your snake body should be XX as well for easy understanding
  2. Once game starts , check for direction in which snake needs to move, mark the movement in that direction, ( + for right and up, - for down and left etc. you can choose what is easy to understand)
  3. In the direction, move the tail infront of its head,
  4. Move position of head to 2, 2 to 3 etc. that way whole body will move back. I implemented this logic using different colors, this way you can see colors cycling back and moving in front.
  5. So grid by grid our snake will move in correct direction

have tried to add in comments, feel free to fork and play around.

Contact

📫 Feel free to drop me a line twitter @blackarck, blackarck@gmail.com ✉️ [github][https://github.com/blackarck]