Viper is a QGIS snake clone made entirely from Qgs objects, utilizing QGIS geometry manipulation methods in order to create a working game.
It is a little project suitable for workshops teaching GIS and QGIS (or programming in general).
Concepts such as R-Tree (spatial index) and geometry objects and methods (points, polygons, centroids...) can be taught from it, as well as general work and programming for QGIS.
Game creates a group at the top of the layer tree called Viper in which 3 layers are stored:
- Snake
- Food
- Area
Area holds a single geometry (polygon) which serves as the play area: a rectangle of width x height as specified in the GUI, or it uses a copy of a selected geometry (must be a polygon, the selected geometry is not modified in any way).
Food holds a single geometry (polygon) at any time. If snake eats the food, the geometry is deleted and new is created which is within the play area, but is not contained within the snake.
Snake holds snake parts. Each snake part is a geometry object, same size and shape as food geometry. Geometry at the first index is always its tail and geometry at the last index, its head. Moves every N seconds, as set by the player.
Unless a time limit is specified, the game is finished once a snake bites itself or if it exists the play area.
At any time, the game can be paused and resumed, or it can be stopped completely, by canceling the task from the bottom task manager in QGIS.
Keyboard shortcuts for actions must be set and must be unique. Buttons for moving and pausing the game are also clickable, but unless a very slow speed is set, it might be a bit hard to play that way.
prepare food is a game optimization: instead of randomly generating a food point every time it is needed, the option instructs the game to generate and store all possible food points within the play area. Using the option, once a snake eats the food, new food is created without a visible hiccup, but starting the game could take longer if a HUGE play area is set (containing a million or more possible food locations). Also, the speed depends on the system it runs on.
remove added layers on game end removes the group containing the game layers when game ends.
When a game finishes, the result is logged in the QGIS Log Messages panel.
It is possible to define styles for game layers. Simply put your .qml styles in /styles/ directory within the plugin directory, name them snake.qml, food.qml and area.qml to set the style for the appropriate layer.
Default values are green polygons for snake, red for food and white for the play area.


