Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Explosion.cpp Source File

Explosion.cpp

00001 #include "Explosion.h"
00002 
00003 // Defining animation states for explosion FSM
00004 Animation animation_fsm[2] = {
00005     {false, true, FILL_WHITE, FILL_BLACK},
00006     {true, false, FILL_TRANSPARENT, FILL_WHITE},   
00007 };
00008 
00009 Explosion::Explosion() {
00010      
00011 }
00012  
00013 Explosion::~Explosion() { 
00014  
00015 }
00016 
00017 void Explosion::init(Vector2D destroyed_position) {
00018     // Assign values to variables
00019     position_x_ = destroyed_position.x + 3; 
00020     position_y_ = destroyed_position.y + 3; 
00021     fsm_counter_ = 0;  
00022     explosion_radius_ = 4;
00023     draw_counter = 0;
00024 }
00025 
00026 void Explosion::draw_explosion(N5110 &lcd) {
00027     // Draws each explosion frame depending on state 
00028     // Draw circle one
00029     if (animation_fsm[fsm_counter_].draw_circle_one) {
00030         lcd.drawCircle(position_x_, position_y_,explosion_radius_ + 1, 
00031         animation_fsm[fsm_counter_].circle_one);
00032     }
00033     // Draw circle two
00034     if (animation_fsm[fsm_counter_].draw_circle_two) {
00035         lcd.drawCircle(position_x_, position_y_,(explosion_radius_ - 2), 
00036         animation_fsm[fsm_counter_].circle_two);
00037     }
00038     
00039     // Slows down animation change time, so explosion animation is longer
00040     if (draw_counter%2 == 0) {
00041         explosion_radius_++;
00042         fsm_counter_ = !fsm_counter_;
00043     }
00044     draw_counter++;
00045 }
00046 
00047 int Explosion::get_explosion_radius() {
00048     return explosion_radius_;
00049 }