Note: We are now making only the game, will be linked to the original code later
The basic operations required while making the game is:
- Creating a game window for the game to play in.
- Defining a gameloop is suggested so to make the make code more systematic.
- Initializing a snk_list in which coordinates of the whole snake piece by piece will be appended.
- Generating random coodinates of food for the snake after each time food is eaten.
- It should be noted that food should not come over the hurdles, separate conditions are mentioned.
- Mentioning the conditions for the arrows key to move the snake in that perticular direction.
- Creating a list for head and appending every new coordinate of head in the list.
- Now appending the head into the snk_list.
- Checking for the collision conditions(with itself and also with boundary).
- We can set the frame rate according to our choice.
Now that we have created a simple snake game we can add moving images and hurdles to make it attractive.
Our aims will be to detect the direction in which stylus is moving and if we are able to get it then only we have to link it with the game.
Approch for detecting the stlyus and then its direction.
- To find the upper and lower ranges of HSV values to detect the object which is to be used as Stylus.
- To find the contours of the object and finally finding out its centroid which will be tracked.
- To detect the direction we will be making a list and appending 10 consecutive coordinates of stylus moving.
- Finding the maximum difference of consecutive say x coordinates in the list and if it is greater than 10(significant movement in that perticular direction) then the snake is assigned that direction.
All the rest necessary information is explained through comments in the code
Here is the output of the detection of direction
https://drive.google.com/file/d/175HGr6Fc3pZmrkzumxFuOJrOXI9RHKVB/view?usp=sharing
Lovesh Goyal