Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: Fire/Fire.cpp
- Revision:
- 18:304700b5d8f8
- Parent:
- 16:331be5c7ed80
- Child:
- 21:20478f086bc2
diff -r f377df4ea7b1 -r 304700b5d8f8 Fire/Fire.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Fire/Fire.cpp Fri Apr 12 11:30:25 2019 +0000 @@ -0,0 +1,54 @@ +#include "Fire.h" + +// Define sprite arrays. +int fire_one[5][8] = { + { 1,0,1,0,0,1,0,0 }, + { 1,0,0,0,1,1,1,0 }, + { 0,0,0,1,1,1,1,1 }, + { 0,1,0,0,1,1,1,0 }, + { 1,0,0,1,0,1,0,0 }, +}; + +int fire_two[5][8] = { + { 0,0,1,0,0,1,0,0 }, + { 0,1,0,0,1,1,1,0 }, + { 1,0,1,0,1,1,1,0 }, + { 1,0,0,0,1,1,1,0 }, + { 0,1,0,1,1,0,0,0 }, +}; + +// Constructor and destructor. +Fire::Fire() {} + +Fire::~Fire() {} + +void Fire::init() { + // Initialise the fire ball + _x = -10; + _fire_counter = false; +} + +void Fire::update_fire() { + // On every iteration move the fire horizontally and toggle the fire counter. + // If the fire goes off the screen, restart it on the other side. + _x++; + _fire_counter = !_fire_counter; + if (_x == 90) _x = -10; +} + +int * Fire::get_fire_sprite() { + // Return a different fire sprite on each iteration. + if (_fire_counter) { + return *fire_one; + } else { + return *fire_two; + } +} + +int Fire::get_fire_x() { + return _x; +} + + + +