11#include " GameScene.h"
2+ #include " HelloWorldScene.h"
23
34USING_NS_CC;
45
@@ -66,7 +67,7 @@ bool GameScene::init() {
6667 float x = spawnPoint[" x" ].asFloat ();
6768 float y = spawnPoint[" y" ].asFloat ();
6869 hero = Player::create ();
69- hero->setPosition (Vec2 (x+20 , y+70 ));
70+ hero->setPosition (Vec2 (x+20 , y+70 ));
7071 this ->addChild (hero, 100 , 200 );
7172
7273
@@ -158,6 +159,10 @@ bool GameScene::init() {
158159
159160void GameScene::update (float delta) {
160161
162+ if (!hero->is_alive ()) {
163+ game_over ();
164+ }
165+
161166 /* Following part updates the movement of player */
162167 float position_x = hero->getPositionX ();
163168 float position_y = hero->getPositionY ();
@@ -170,7 +175,7 @@ void GameScene::update(float delta) {
170175 makeMove (Vec2 (position_x, position_y), hero);
171176
172177 /* Bombs blow up destructable bricks */
173- while (!current_bombs.empty () && ! current_bombs.front ()->bombIsCounting ()) {
178+ while (!current_bombs.empty () && current_bombs.front ()->bombIsExploded ()) {
174179 Bomb * bomb = current_bombs.front ();
175180 bomb_explode (bomb);
176181 current_bombs.erase (0 );
@@ -190,7 +195,6 @@ void GameScene::bomb_explode(Bomb *bomb)
190195 int firstGid_of_brk = bricks->getTileSet ()->_firstGid ;
191196
192197 for (; l_range < power && bomb_tile_coord.x - l_range - 1 >= 0 ; l_range++) {
193-
194198 int GID_brk = bricks->getTileGIDAt (Vec2 (bomb_tile_coord.x - l_range - 1 , bomb_tile_coord.y ));
195199 if (GID_brk - firstGid_of_brk >= 0 ){
196200 int GID_des = destructable->getTileGIDAt (Vec2 (bomb_tile_coord.x - l_range - 1 , bomb_tile_coord.y ));
@@ -248,12 +252,59 @@ void GameScene::bomb_explode(Bomb *bomb)
248252 }
249253 }
250254
255+ hero->bomb_vs_man (bomb_tile_coord, l_range, r_range, u_range, d_range);
256+
251257 /* Now we have l_range, r_value, u_value, d_value, which indicate the explosion
252258 * range of the bomb in the four directions. What you need to do now is to
253259 * display the animation effect of bombs.
254260 * Please add your code here...
255261 */
256262
263+ SpriteFrameCache::getInstance ()->addSpriteFramesWithFile (" Explosion.plist" );
264+ Sprite *wave = Sprite::createWithSpriteFrameName (" ExplosionCenter_01.png" );
265+ bomb->addChild (wave);
266+ wave->setPosition (Vec2 (TILE_SIZE.width /2 , TILE_SIZE.height /2 ));
267+
268+ for (int i = 0 ; i < l_range; i++) {
269+ Sprite *l_wave;
270+ if (i = l_range - 1 ) {
271+ l_wave = Sprite::createWithSpriteFrameName (" ExplosionLEFT_01.png" );
272+ } else {
273+ l_wave = Sprite::createWithSpriteFrameName (" ExplosionLEFT_02.png" );
274+ }
275+ bomb->addChild (l_wave);
276+ l_wave->setPosition (Vec2 ((-i - 1 ) * TILE_SIZE.width + TILE_SIZE.width / 2 , TILE_SIZE.height / 2 ));
277+ }
278+ for (int i = 0 ; i < r_range; i++) {
279+ Sprite *r_wave;
280+ if (i = r_range - 1 ) {
281+ r_wave = Sprite::createWithSpriteFrameName (" ExplosionRIGHT_01.png" );
282+ } else {
283+ r_wave = Sprite::createWithSpriteFrameName (" ExplosionRIGHT_02.png" );
284+ }
285+ bomb->addChild (r_wave);
286+ r_wave->setPosition (Vec2 ((i + 1 ) * TILE_SIZE.width + TILE_SIZE.width / 2 , TILE_SIZE.height / 2 ));
287+ }
288+ for (int i = 0 ; i < d_range; i++) {
289+ Sprite *d_wave;
290+ if (i = d_range - 1 ) {
291+ d_wave = Sprite::createWithSpriteFrameName (" ExplosionDOWN_01.png" );
292+ } else {
293+ d_wave = Sprite::createWithSpriteFrameName (" ExplosionDOWN_02.png" );
294+ }
295+ bomb->addChild (d_wave);
296+ d_wave->setPosition (Vec2 (TILE_SIZE.width / 2 , (- i - 1 ) * TILE_SIZE.height + TILE_SIZE.height / 2 ));
297+ }
298+ for (int i = 0 ; i < u_range; i++) {
299+ Sprite *u_wave;
300+ if (i = u_range - 1 ) {
301+ u_wave = Sprite::createWithSpriteFrameName (" ExplosionUP_01.png" );
302+ } else {
303+ u_wave = Sprite::createWithSpriteFrameName (" ExplosionUP_02.png" );
304+ }
305+ u_wave->setPosition (Vec2 (TILE_SIZE.width / 2 , (i + 1 ) * TILE_SIZE.height + TILE_SIZE.height / 2 ));
306+ bomb->addChild (u_wave);
307+ }
257308}
258309
259310bool GameScene::isOutOfMap (Vec2 pos)
@@ -301,7 +352,7 @@ bool GameScene::collideWithBrick(cocos2d::Vec2 targetPos)
301352bool GameScene::collideWithBubble (Vec2 playerPos, Vec2 targetPos)
302353{
303354 Vec2 target_tileCoord = tileCoordFromPosition (targetPos);
304- Vec2 now_tileCoord = tileCoordFromPosition (playerPos);
355+ Vec2 now_tileCoord = tileCoordFromPosition (Vec2 ( playerPos. x , playerPos. y ) );
305356
306357 if (now_tileCoord == target_tileCoord) return false ;
307358
@@ -346,4 +397,9 @@ Vec2 GameScene::tileCoordFromPosition(Vec2 position)
346397 int x = position.x / map->getTileSize ().width ;
347398 int y = ((map->getMapSize ().height * map->getTileSize ().height ) - position.y ) / map->getTileSize ().height ;
348399 return Vec2 (x, y);
349- }
400+ }
401+
402+ void GameScene::game_over ()
403+ {
404+ Director::getInstance ()->replaceScene (CCTransitionMoveInR::create (0 .4f , HelloWorld::createScene ()));
405+ }
0 commit comments