ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Fire.cpp Source File

Fire.cpp

00001 #include "Fire.h"
00002 
00003 // Define sprite arrays.
00004 int fire_one[5][8] = {
00005   { 1,0,1,0,0,1,0,0 },
00006   { 1,0,0,0,1,1,1,0 },
00007   { 0,0,0,1,1,1,1,1 },
00008   { 0,1,0,0,1,1,1,0 },
00009   { 1,0,0,1,0,1,0,0 },
00010 };
00011 
00012 int fire_two[5][8] = {
00013   { 0,0,1,0,0,1,0,0 },
00014   { 0,1,0,0,1,1,1,0 },
00015   { 1,0,1,0,1,1,1,0 },
00016   { 1,0,0,0,1,1,1,0 },
00017   { 0,1,0,1,1,0,0,0 },
00018 };
00019 
00020 // Constructor and destructor.
00021 Fire::Fire() {} 
00022 
00023 Fire::~Fire() {}
00024 
00025 void Fire::init() {
00026   // Starting position of the fire (Y coord is calculated externally).
00027   _x = -10;  // Start fire off screen.
00028   _fire_counter = false;
00029 }
00030 
00031 void Fire::generate_fire() {
00032   // Sets the X coord so it moves independently.
00033   _x++;  // Keep fire moving from L to R.
00034   _fire_counter = !_fire_counter;  // Toggle fire counter to generate different 
00035   // sprites each iteration.
00036   if (_x == 90) _x = -10;  // If the fire goes off the screen, restart it on the 
00037   // other side.
00038 }
00039 
00040 int * Fire::get_fire_sprite() {
00041   // Return different fire sprites for dynamic effect.
00042   if (_fire_counter) {
00043     return *fire_one;
00044   } else {
00045     return *fire_two;
00046   }
00047 }
00048   
00049 int Fire::get_fire_x() {
00050   return _x;
00051 }
00052 
00053 
00054 
00055 
00056