Compile and run your app and place some turrets on your map! You will see how the turret immediately begins to attack when the enemy moves, such as the range of attack, and the enemy's blood strips will be reduced as the attacks continue to know that they are being humanely destroyed! The victory is coming!
Oh! Okay, here are just a few details that you can get a full feature of the Tower defense game now! Sound should be a good try. And despite being invincible and extremely wealthy, your base should have the ability to fight continuously-and you need to limit the player's gold supply.
Shining turret: Gotta Polish It all!
Start implementing fate that show the rest of the player-and what happens when the player fails!
Open HelloWorldLayer.h and add the following 3 instance variables:
int*ui_hp_lbl;BOOL gameEnded;
PLAYERHP determines how many lives the player has, and cclabelbmfont tags are used to display their number. Gameended is set at the end of the game! Also add the following method definitions:
-(void)doGameOver;
Now open the HELLOWORLDLAYER.M file and complete the following modifications:
At theEndOf Init, add the following lines of code://7-Player LIVESPLAYERHP =5; ui_hp_lbl = [Cclabelbmfont labelwithstring:[nsstring stringwithformat:@"HP:%d", PLAYERHP] fntfile:@"Font_red_14.fnt"]; [Self ADDCHILD:UI_HP_LBL z:Ten]; [Ui_hp_lbl SETPOSITION:CCP ( *, winsize.height- A)];//Add The following methods-(void) Gethpdamage {PLAYERHP--;[Ui_hp_lbl setstring:[nsstring stringwithformat:@"HP:%d", PLAYERHP]];if(PLAYERHP <=0) {[Self dogameover]; }}-(void) Dogameover {if(!gameended) {gameended = YES;[[Ccdirector shareddirector] Replacescene:[cctransitionrotozoom transitionwithduration:1 Scene:[helloworldlayer scene]]]; }}
This adds a way to reduce the player's life, update the label's display, and check if the player is running out of life. If so, the game is over.
COCOS2D: Tower Defense Game Making Tour (16)