bool Enemy::CheckHealth() { FlashClear(); if (mHealth <= 0) { if (mBombupSpawn) CPlayState::Instance()->item_list.push_back(new Bombup( mPos.x + mpInfo->width / 2, mPos.y + mpInfo->height / 2, 0)); else if (mPowerupSpawn) CPlayState::Instance()->item_list.push_back(new Powerup( mPos.x + mpInfo->width / 2, mPos.y + mpInfo->height / 2, 0)); else { for (int i = 0; i <= mMaxHealth; i += 25) CPlayState::Instance()->item_list.push_back( new Gem(mPos.x + rand() % mpInfo->width, mPos.y + mpInfo->height / 2, 25)); } Explosion::RequestExplosion(mId, mPos.x + mpInfo->width / 2, mPos.y + mpInfo->height / 2, 0, 10); SFX::PlaySoundResource("explode_light1"); mExplode = true; } return false; }
/************************************************************************************//** ** \brief Erases the flash sectors from first_sector up until last_sector. ** \param first_sector First flash sector number. ** \param last_sector Last flash sector number. ** \return BLT_TRUE if successful, BLT_FALSE otherwise. ** ****************************************************************************************/ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector) { blt_int16u nr_of_blocks; blt_int16u block_cnt; blt_addr start_addr; blt_addr end_addr; /* validate the sector numbers */ if (first_sector > last_sector) { return BLT_FALSE; } if ( (first_sector < flashLayout[0].sector_num) || \ (last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num) ) { return BLT_FALSE; } /* determine how many blocks need to be erased */ start_addr = FlashGetSectorBaseAddr(first_sector); end_addr = FlashGetSectorBaseAddr(last_sector) + FlashGetSectorSize(last_sector) - 1; nr_of_blocks = (end_addr - start_addr + 1) / FLASH_ERASE_BLOCK_SIZE; /* erase all blocks one by one */ for (block_cnt=0; block_cnt<nr_of_blocks; block_cnt++) { /* keep the watchdog happy */ CopService(); /* erase the flash page with size FLASH_ERASE_BLOCK_SIZE */ if (FlashClear(start_addr + (block_cnt * FLASH_ERASE_BLOCK_SIZE)) != 0) { return BLT_FALSE; } } /* still here so all went okay */ return BLT_TRUE; } /*** end of FlashEraseSectors ***/