The Lightning class
The Lightning
class inherits from CCDrawNode
because we refrain from using a CCSprite
for something as electric and random as a bolt of lightning. Also, the length of the bolt of lightning might change over the course of time with the tower being upgraded.
Thus, the init
function of the Lightning
class looks like this, from the Lightning.cpp
file:
bool Lightning::init(CCPoint from, CCPoint to, ccColor4F color, bool is_animated) { if(!CCDrawNode::init()) { return false; } color_ = color; GenerateKeyPoints(from , to); if(!is_animated) { DrawSegments(); } else { schedule(schedule_selector(Lightning::DrawNextSegment)); } return true; }
The init
function takes four arguments: the start and end points for the lightning bolt, the color of the bolt, and another parameter named is_animated
. If this flag is true
, the lightning bolt will be shown shooting out from source to destination and the lightning bolt will appear whole if this flag is...