11#include " GameScene.h"
2+ #include " HelloWorldScene.h"
23
34// using namespace std;
45USING_NS_CC;
@@ -78,7 +79,7 @@ bool GameScene::init() {
7879 float x = spawnPoint[" x" ].asFloat ();
7980 float y = spawnPoint[" y" ].asFloat ();
8081 hero = Player::create ();
81- hero->setPosition (Vec2 (x+20 , y+70 ));
82+ hero->setPosition (Vec2 (x+20 , y+70 ));
8283 this ->addChild (hero, 100 , 200 );
8384
8485
@@ -164,6 +165,10 @@ bool GameScene::init() {
164165
165166void GameScene::update (float delta) {
166167
168+ if (!hero->is_alive ()) {
169+ game_over ();
170+ }
171+
167172 /* Following part updates the movement of player */
168173 float position_x = hero->getPositionX ();
169174 float position_y = hero->getPositionY ();
@@ -176,7 +181,7 @@ void GameScene::update(float delta) {
176181 makeMove (Vec2 (position_x, position_y));
177182
178183 /* Bombs blow up destructable bricks */
179- while (!current_bombs.empty () && ! current_bombs.front ()->bombIsCounting ()) {
184+ while (!current_bombs.empty () && current_bombs.front ()->bombIsExploded ()) {
180185 Bomb * bomb = current_bombs.front ();
181186 bomb_explode (bomb);
182187 current_bombs.erase (0 );
@@ -207,7 +212,6 @@ void GameScene::bomb_explode(Bomb *bomb)
207212 int firstGid_of_brk = bricks->getTileSet ()->_firstGid ;
208213
209214 for (; l_range < power && bomb_tile_coord.x - l_range - 1 >= 0 ; l_range++) {
210-
211215 int GID_brk = bricks->getTileGIDAt (Vec2 (bomb_tile_coord.x - l_range - 1 , bomb_tile_coord.y ));
212216 if (GID_brk - firstGid_of_brk >= 0 ){
213217 int GID_des = destructable->getTileGIDAt (Vec2 (bomb_tile_coord.x - l_range - 1 , bomb_tile_coord.y ));
@@ -265,12 +269,59 @@ void GameScene::bomb_explode(Bomb *bomb)
265269 }
266270 }
267271
272+ hero->bomb_vs_man (bomb_tile_coord, l_range, r_range, u_range, d_range);
273+
268274 /* Now we have l_range, r_value, u_value, d_value, which indicate the explosion
269275 * range of the bomb in the four directions. What you need to do now is to
270276 * display the animation effect of bombs.
271277 * Please add your code here...
272278 */
273279
280+ SpriteFrameCache::getInstance ()->addSpriteFramesWithFile (" Explosion.plist" );
281+ Sprite *wave = Sprite::createWithSpriteFrameName (" ExplosionCenter_01.png" );
282+ bomb->addChild (wave);
283+ wave->setPosition (Vec2 (TILE_SIZE.width /2 , TILE_SIZE.height /2 ));
284+
285+ for (int i = 0 ; i < l_range; i++) {
286+ Sprite *l_wave;
287+ if (i = l_range - 1 ) {
288+ l_wave = Sprite::createWithSpriteFrameName (" ExplosionLEFT_01.png" );
289+ } else {
290+ l_wave = Sprite::createWithSpriteFrameName (" ExplosionLEFT_02.png" );
291+ }
292+ bomb->addChild (l_wave);
293+ l_wave->setPosition (Vec2 ((-i - 1 ) * TILE_SIZE.width + TILE_SIZE.width / 2 , TILE_SIZE.height / 2 ));
294+ }
295+ for (int i = 0 ; i < r_range; i++) {
296+ Sprite *r_wave;
297+ if (i = r_range - 1 ) {
298+ r_wave = Sprite::createWithSpriteFrameName (" ExplosionRIGHT_01.png" );
299+ } else {
300+ r_wave = Sprite::createWithSpriteFrameName (" ExplosionRIGHT_02.png" );
301+ }
302+ bomb->addChild (r_wave);
303+ r_wave->setPosition (Vec2 ((i + 1 ) * TILE_SIZE.width + TILE_SIZE.width / 2 , TILE_SIZE.height / 2 ));
304+ }
305+ for (int i = 0 ; i < d_range; i++) {
306+ Sprite *d_wave;
307+ if (i = d_range - 1 ) {
308+ d_wave = Sprite::createWithSpriteFrameName (" ExplosionDOWN_01.png" );
309+ } else {
310+ d_wave = Sprite::createWithSpriteFrameName (" ExplosionDOWN_02.png" );
311+ }
312+ bomb->addChild (d_wave);
313+ d_wave->setPosition (Vec2 (TILE_SIZE.width / 2 , (- i - 1 ) * TILE_SIZE.height + TILE_SIZE.height / 2 ));
314+ }
315+ for (int i = 0 ; i < u_range; i++) {
316+ Sprite *u_wave;
317+ if (i = u_range - 1 ) {
318+ u_wave = Sprite::createWithSpriteFrameName (" ExplosionUP_01.png" );
319+ } else {
320+ u_wave = Sprite::createWithSpriteFrameName (" ExplosionUP_02.png" );
321+ }
322+ u_wave->setPosition (Vec2 (TILE_SIZE.width / 2 , (i + 1 ) * TILE_SIZE.height + TILE_SIZE.height / 2 ));
323+ bomb->addChild (u_wave);
324+ }
274325}
275326
276327bool GameScene::isOutOfMap (Vec2 pos)
@@ -318,7 +369,7 @@ bool GameScene::collideWithBrick(cocos2d::Vec2 targetPos)
318369bool GameScene::collideWithBubble (Vec2 playerPos, Vec2 targetPos)
319370{
320371 Vec2 target_tileCoord = tileCoordFromPosition (targetPos);
321- Vec2 now_tileCoord = tileCoordFromPosition (playerPos);
372+ Vec2 now_tileCoord = tileCoordFromPosition (Vec2 ( playerPos. x , playerPos. y ) );
322373
323374 if (now_tileCoord == target_tileCoord) return false ;
324375
@@ -363,4 +414,9 @@ Vec2 GameScene::tileCoordFromPosition(Vec2 position)
363414 int x = position.x / map->getTileSize ().width ;
364415 int y = ((map->getMapSize ().height * map->getTileSize ().height ) - position.y ) / map->getTileSize ().height ;
365416 return Vec2 (x, y);
366- }
417+ }
418+
419+ void GameScene::game_over ()
420+ {
421+ Director::getInstance ()->replaceScene (CCTransitionMoveInR::create (0 .4f , HelloWorld::createScene ()));
422+ }
0 commit comments