The "Hack-the-games" competiton centered on developing a game and automating the gameplay of said game using template matching.
THE GAME AND IT'S FEATURES :
- The game involves you, the player (blue tank), who has to shoot down the enemy tanks (red tank, black tank, sandy tank, green tank).
- The gameplay revolves around securing the highest possible highscore, and surviving for a long time.
- The game also includes a shop menu which can be accessed once the player is eliminated, to improve various stats of the player.
- The game has been automated with the help of template matching, so the game plays by itself to secure a high score.
PREREQUSITES FOR RUNNING THE PROGRAM :
- PGZERO (can be installed with "pip install pgzero" in command prompt). The whole game is based on this module.
- CV2, Numpy,Matplotlib (used to run template matching on sample images)
- Pyautogui (used to automatically take screenshots at regular intervals)
- Random function (used to create elements of chance within the game)
- 5 empty text files in the same directory ("Highscore.txt", "HP.txt", "Speed.txt", "Bullet.txt","Wall.txt"). These are required for the shop function to work.
- All the images attached with the program extracted in the same directory as the program.
EXPLANATION OF THE WORKING CODE :
- The player, and the enemy tanks are spawned in the beginning of the game with the help of "Actors" from the pgzero module.
- The highscore, HP, Speed, Bullet, Wall values from the respective files are read and updated in the current instance of the game.
- A timer begins, counting the time elapsed since the start.
- If the timer reaches a multiple of 3, new enemies are spawned.
- At the same time, a screenshot is taken and template matching is run, with the template images as the four enemy images (green,red,dark,sand tanks).
- The start and end values of the x-axis of the matched images are taken, and the midpoint is calculated.
- The player is moved to the midpoint of the closest matched enemy, and shoots bullets.
- If the player gets eliminated, the various values of the text files (Highscore, HP, Bullet, Wall, Speed) are updated in the respective files.
- A shop screen opens, allowing the player to get different upgrades, so that they may secure a higher score the next time they run the game.