In the on-going quest to see how far the ESP8266 Series 12e modules can be stretched, I have devised a game code named "Staroids". The Game is by no way finished, and more will be added in time.
It was a programming exercise, to see if I could mix both a cheap TFT screen and Nintendo Nun-chuck positional controller.
I originally had it wired up to the Nintendo's motion+ accessory, a 3 axis gyro..... however I had a ping moment when I noticed the Nunchuck had extra controls up its sleeve.
Its written using the Arduino IDE and ported to the ESP8266.... The biggest advantage is the ESP is faster that the arduino's atmel chip, this is from my observation of the frame updates to the TFT screen.
My TFT Screen has the markings 2.4" TFT SPI 240*320 TJCTM2404-SPI with a price of £4.00
To get the ESP talking to the Nun-chuck & TFT screen I am using these libraries :-
The TFT does not have a buffer area where you can pre-load graphics (maybe that's the way the adafruit library works).
Also you can not seem to be able to read the screen memory locations (again maybe its a limitation of the adafruit library)
With the above two points in mind, I traveled the "store" everything in a 2D array route. It kinda made sense as objects were given a single xy coordinate and this makes it easier to kinda vector build the graphics around it.
To make sense of the playing field and plotting environment all of the objects are sent to screen using polar coordinate plotting, this makes it easy to scale and launch objects on the correct headings. i.e.
rx1=rockets[rocketid]+10*(rockets[rocketid])*(-sin(radians(rockets[rocketid]))) ; // x position
ry1=rockets[rocketid]+10*(rockets[rocketid])*(cos(radians(rockets[rocketid]))) ; // y position
For object hit object collisions a rectangular "Hit Box" detect was created, as you can see from the code many brackets are needed to && the virtual hitbox into shape.Its not exact, however in gameplay you don't notice small misshit errors.
if ((starmatrix[hittest]==1)&&((mothershipx<(starmatrix[hittest]+starmatrix[hittest]))&&((mothershipx>(starmatrix[hittest]-starmatrix[hittest]))))&& ((mothershipy<(starmatrix[hittest]+starmatrix[hittest])) && ((mothershipy>(starmatrix[hittest]-starmatrix[hittest])))))
The whole thing is controlled by using a Nintendo NunChuck controller . It has pitch&roll position sensors however strangely no Yaw sensor, the joystick and two buttons make up for this though.
Either single missiles can be launched or a salvo of 2 or 3 or 4 can also be loosened by deft Skywalkers.
Scoring is done purely by time (will change shortly).... ie low (millis) score for 5 stars = High score.
Below = 24716 milliseconds.
Current code only uses 1/2 of the ESP's memory so room for more game-play, the speed is impressive for the workload needed.
I would like to conduct a test using the same setup using an Arduino just to confirm the speed upgrade that the ESP offers.
I know that in this example does not use the WiFi ability of the ESP ... maybe if enough people cloned this project then thier Highscore could be uploaded to a dedicated web server for example, just for fun.