Exemple #1
0
void SpriteHolder::Add(Sprite* s){
	sprites[s->GetType()].push_back(s);

	SpriteList * list = new SpriteList();
	switch (s->GetType()){
	case spritetype_t::PLAYER:
		GetSprites(spritetype_t::ENEMY_BULLET, list);
		for (SpriteList::iterator it = list->begin(); it != list->end(); ++it){
			CollisionChecker::Get().Register(s, *it);
		}
		GetSprites(spritetype_t::ENEMY, list);
		for (SpriteList::iterator it = list->begin(); it != list->end(); ++it){
			CollisionChecker::Get().Register(s, *it);
		}
		break;
	case spritetype_t::PLAYER_BULLET:
		GetSprites(spritetype_t::ENEMY, list);
		for (SpriteList::iterator it = list->begin(); it != list->end(); ++it){
			CollisionChecker::Get().Register(s, *it);
		}
		break;
	case spritetype_t::ENEMY:
		GetSprites(spritetype_t::PLAYER, list);
		for (SpriteList::iterator it = list->begin(); it != list->end(); ++it){
			CollisionChecker::Get().Register(s, *it);
		}
		GetSprites(spritetype_t::PLAYER_BULLET, list);
		for (SpriteList::iterator it = list->begin(); it != list->end(); ++it){
			CollisionChecker::Get().Register(s, *it);
		}
		break;
	case spritetype_t::ENEMY_BULLET:
		GetSprites(spritetype_t::PLAYER, list);
		for (SpriteList::iterator it = list->begin(); it != list->end(); ++it){
			CollisionChecker::Get().Register(s, *it);
		}
		break;
	case spritetype_t::POWER_UP:
		GetSprites(spritetype_t::PLAYER, list);
		for (SpriteList::iterator it = list->begin(); it != list->end(); ++it) {
			CollisionChecker::Get().Register(s, *it);
		}
		break;
	default:
		break;
	}
	delete list;
}
    //---------------------------------------------------------------------
    void
    BackgroundFileSerializer::removeBuggySprites( SpriteList &sprites )
    {
        auto it = sprites.begin();
        while (it != sprites.end())
        {
            const SpriteData &sprite = (*it);

            if (std::abs(sprite.dst.x) > SPRITE_DST_MAX
                    || std::abs(sprite.dst.y) > SPRITE_DST_MAX)
            {
                it = sprites.erase(it);
            }
            else
            {
                ++it;
            }
        }
    }
Exemple #3
0
void SpriteHolder::DrawSprites(){
	SpriteList * result = new SpriteList();
	for (int i = 0; i <= spritetype_t::UI; i++){
		
		GetSprites((spritetype_t)i, result);
		for (std::list<Sprite *>::iterator it = result->begin(); it != result->end(); ++it){
			Sprite * s = (*it);
			spritestate_t state = s->GetState();

			if (state == spritestate_t::ALIVE){
				s->Draw();
			}
			else if (state == spritestate_t::DEAD) {
				if (s->GetType() != spritetype_t::PLAYER) LatelyDestroyable::Add(s);
				s->SetState(spritestate_t::WAIT);
			}
		}
	}
	delete result;
}