Giter VIP home page Giter VIP logo

stylus-snake-game's Introduction

Stylus Snake Game


In this project, the Classic Snake Game (which uses a keypad-control) has been recreated to a Stylus-controlled Snake Game, where the movement of the snake is controlled by a Stylus in front of the computer camera.

Results:-

Capturing the Stylus:

Stylus Snake Game:

Methodology:-

The Stylus Snake Game was constructed using the concepts of Computer Vision from OpenCV and the game environment from Pygame.

Structure of the Code:-

Capturing the Stylus:

  • Created a window where the user will place the Stylus within a rectangular region to capture it.
  • Take the average of the HSV values of the pixels in that Region of Interest.

Object Tracking using HSV Colour Thresholding:

  • Take each frame captured by the computer camera.
  • Convert it from BGR to HSV.
  • Thresholded the HSV image within a range of the captured average.
  • Reduced considerable amount of noise by using Morphological Transformations of Closing and Opening.
  • Applied Gaussian Blur.
  • Using Contour features, we obtained the coordinates of the centroid of the object.

Detecting the movement of the Stylus:

  • The camera window is divided into 4 triangles- marking the region of UP, DOWN, LEFT, RIGHT.
  • Used a function to find out if the centroid coordinates of the Stylus lies within these regions, using the area of triangles concept.

Creating the game environment using Pygame:

  • Created the main game window, along with the snake body and also added fruits at random positions.
  • Used a function to add 5 different obstacle layouts randomly to the game screen.
  • Directed the motion of the snake according to the movements of the Stylus.
  • Added the following 'Game Over' constraints:
    • Getting out-of-bounds of the game window.
    • Touching the snake body.
    • Touching the obstacles.
  • Used a Game Over function to display the final score and end the game.

View Project:-

Click here to view the demonstration of the Stylus Snake Game.

stylus-snake-game's People

Contributors

tabithasneha avatar hackmd-deploy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.