Creating the projectile class
Now that we have the enemies spawning, we want them to shoot bullets at certain intervals. The bullets will spawn wherever the enemy is currently located. Once they have spawned, they should start moving left and once they are out of the screen, they should be deleted. For this, we create a class named Projectile
and add the Projectile.h
and Projectile.cpp
files to the Classes
folder, as we did previously for the other classes.
In the Projectile.h
file, add the following lines of code:
#ifndef __wp8Game__Projectile__ #define __wp8Game__Projectile__ #pragma once #include "cocos2d.h" using namespace cocos2d; class Projectile : public CCSprite { public: Projectile(void); ~Projectile(void); int type; static Projectile* createProjectile(CCPoint p, int _type); bool initProjectile(CCPoint p, int _type); void update(); }; #endif
You will see that this is very similar to the enemy class in terms of structure, but there...