Software apps and online services
This project is an adventure in micro python for the bbc micro:bit board. The micro:bit has several interesting sensors built in. I wanted to make use of the communication capabilities first of all, and also some of the environment sensors. When elaborating on thoughts of distance measurement between two micro:bits within radio range, I came up with the micro mortar idea. In some way one might call it an augmented reality version of an old school artillery game.
The game connects two micro:bits to each other and negotiates a virtual distance between them. Then it's time to become trigger happy. Angle your micro:mortar choose projectile velocity and try to hit the opponents mortar (with virtual projectiles).
The game is written in micro python and make use of the micro:bits radio communication abilities and the accelerometer.
When a micromortar is powered on it will randomize a virtual distance suggestion and then listen for messages from another micromortar. It will also try to broadcast it's distance suggestion. The communication channel is hard-coded. More than two micromortars within radio distance is not intended in this version. The game will work in a way but all of the micromortars will be the same distance from each other. This is not tested. More than two mortars with different distances would be a nice upgrade for a future version. If more than one couple of micromortars want to play in pairs with each other, the channel must be varied in the code before compiling and downloading.
When a distance is negotiated both micromortars will broadcast a READY signal.The program will then:
A: Listen for messages from opponent.
B: Listen for user input by button press.
A: Two type of messages can be received. Either an 'H' which means the mortar has been hit by the opponent and the Alive-flag will be set to False. Or a 'WO' where the opponent has given up. Both messages means the game is over. However, the program is not threaded, therefore, if a button a is pressed and held, the game will not end untill it is released.
B: On button A pressed and held, the velocity variable will be set, or rather, a temporary velocity change will be added to the base velocity. On release of button A a calculation will be made using the Velocity, the current angle read from the micromortar accelerators y-axis, the gravity variable and the distance to the opponent. Resulting value is the y-distance the virtual projectile would have when it reaches the distance on the x-axis.
Above: If the calculated y at distance x (1000 in this battle) is less than negative 32 ( the "explosion radius"), the projectile did not reach the opponent. Too Short is displayed.
Above: The calculated y at x is more than 32, the shot was Too Long.
Above: The projectile is close enough to destroy the opponent. The micromortar will send an 'H' and claim victory.
When the game ends, the winner will see a happy face and the looser will se a sad face. A reset will start a new game. It is possible to forfeit the battle by pressing button B.
There's alot of development that could be made to improve this game. Besides the already mentioned, here's some suggestions:
Play several rounds, keep track of wins and losses.
Allow multiple hits, each one makes the opponent a little weaker (longer cooldown between shots, less effective projectiles...)
Get bonus shots (larger explosion radius) on occation.
Create a "server" version for one microbit connected via usb to a computer and play long distance battles (requres rewrite of the micro python code and a program for the computer).
Make use of more than one accelerator axis to play in "3D".
Implement real distance measurement between the micromortars.