Esempio n. 1
0
	void ManagerModel::AddAsteroid(int type, int length, Vec2 scale, Vec2 startPosition) {
		for (int i = 0; i != length; ++i) {
			Asteroid *asteroid = DBG_NEW Asteroid();
			asteroid->OnInit(this);
			asteroid->mType = type;
			asteroid->SetType(type);
			asteroid->Cleavage(startPosition, scale);

			mEntities.push_back(asteroid);
			for (auto *view : mViews) {
				view->OnAsteroidSpawned((Asteroid*)asteroid);
			}
		}
	}
Esempio n. 2
0
	void ManagerModel::Init(Vec2 screen, int asteroidType1, int asteroidType2, int maxScore, int level) {
		this->maxScore = maxScore;

		SetPlayArea(screen);

		if (level > 0) {
			isHealthPackageRespawnActivated = true;
		}

		Player *player = DBG_NEW Player();
		mEntities.push_back(player);

		ScoreKeeper *scoreKeeper = DBG_NEW ScoreKeeper();
		scoreKeeper->mScore = 0;
		mEntities.push_back(scoreKeeper);

		HealthKeeper *healthKeeper = DBG_NEW HealthKeeper();
		healthKeeper->mHealth = player->defaultHealth;
		healthKeeper->mMaxHealth = player->defaultHealth;
		mEntities.push_back(healthKeeper);

		if (level == 0 || level == 1) {
			Asteroid *asteroid = DBG_NEW Asteroid();
			asteroid->SetType(asteroidType1);
			mEntities.push_back(asteroid);

			Asteroid *asteroid2 = DBG_NEW Asteroid();
			asteroid2->SetType(asteroidType2);
			mEntities.push_back(asteroid2);

		} else if (level == 2) {
			EnemieBoss *enemieBoss = DBG_NEW EnemieBoss();
			mEntities.push_back(enemieBoss);
		} else {
			//TODO! Add new game elements for levels > 2...
		}

		for (Entity *e : mEntities) {
			e->OnInit(this);
			switch (e->Type()) {
				case ENTITY_PLAYER:
					for (auto *view : mViews) {
						view->OnPlayerSpawned((Player*)e);
					}
					break;
					case ENTITY_ASTEROID:
						for (View::ManagerView *view : mViews) {
						view->OnAsteroidSpawned((Asteroid*)e);
						}
						break;
				case ENTITY_HP:
					for (View::ManagerView *view : mViews) {
						view->OnHPInit((HealthKeeper*)e);
					}
					break;
				case ENTITY_SCORE:
					for (View::ManagerView *view : mViews) {
						view->OnScoreInit((ScoreKeeper*)e);
					}
					break;
				case ENTITY_ENEMIEBOSS:
					for (auto *view : mViews) {
						view->OnEnemieBossSpawned((EnemieBoss*)e);
					}
					break;
			}
		}
	}