void CGamePlay::HandleEvent(CEvent *pEvent)
{
	CSGD_ObjectFactory<string, CBase> *pOF		= CSGD_ObjectFactory<string, CBase>::GetInstance();
	CSGD_ObjectManager *pOM						= CSGD_ObjectManager::GetInstance();
 	CSGD_TextureManager *pTM = CSGD_TextureManager::GetInstance();

	if (pEvent->GetEventID() == "spawn powerups")
	{
		CBase *tempPowerup;
		int nRandomPowerup = rand() % 100 + 1;

		if (nRandomPowerup <= 30)
			tempPowerup = pOF->CreateObject("CPowerupHealth");
		else if (nRandomPowerup > 30 && nRandomPowerup <= 60)
			tempPowerup = pOF->CreateObject("CPowerupRapidFire");
		else if (nRandomPowerup > 60 && nRandomPowerup <= 90)
			tempPowerup = pOF->CreateObject("CPowerupThreeWay");
		else if (nRandomPowerup > 90)
			tempPowerup = pOF->CreateObject("CPowerup1up");

		tempPowerup ->SetImageID(m_nImageID[3]);
		tempPowerup->SetPosX(CPlayerCharacter::GetInstance()->GetPosX() + 128);
		if (tempPowerup->GetPosX() > 640)
			tempPowerup->SetPosX(640);
		tempPowerup->SetPosY(CPlayerCharacter::GetInstance()->GetPosY() + 32);
		pOM->AddObject(tempPowerup );
		tempPowerup ->Release();
	}

	else if (pEvent->GetEventID() == "scroll right")
	{
		if (GetBridgeOffset() > -100)
		{
			SetBridgeOffset(GetBridgeOffset() - (5 * CGame::GetInstance()->GetSpeed()));
			SetSpaceOffset(GetSpaceOffset() - (15 * CGame::GetInstance()->GetSpeed()));
			for (int i = 0; i < enemies.size(); ++i)
			{
				enemies[i]->SetPosX(enemies[i]->GetPosX() - (5 * CGame::GetInstance()->GetSpeed()));
			}
		}
	}

	else if (pEvent->GetEventID() == "scroll left")
	{
		if (GetBridgeOffset() < 0)
		{
			SetBridgeOffset(GetBridgeOffset() + (5 * CGame::GetInstance()->GetSpeed()));
			SetSpaceOffset(GetSpaceOffset() + (15 * CGame::GetInstance()->GetSpeed()));
			for (int i = 0; i < enemies.size(); ++i)
			{
				enemies[i]->SetPosX(enemies[i]->GetPosX() + (5 * CGame::GetInstance()->GetSpeed()));
			}
		}
	}

	else if (pEvent->GetEventID() == "spawn enemies")
	{
		CBase *tempEnemy;
		if (GetLevel() == 1 && m_nRemainingEnemies > 0 && m_nTotalSpawns < 10)
		{
			m_nEnemyCounter += 1;
			m_nTotalSpawns += 1;

			if (m_nTotalSpawns % 2 == 1)
			{
				tempEnemy = pOF->CreateObject("CEnemyDemon");
				tempEnemy ->SetImageID(m_nImageID[1]);
				pOM->AddObject(tempEnemy );
				tempEnemy ->Release();
				enemies.push_back(tempEnemy);
			}
			else
			{
				tempEnemy = pOF->CreateObject("CEnemyBusiness");
				tempEnemy ->SetImageID(m_nImageID[1]);
				pOM->AddObject(tempEnemy );
				tempEnemy ->Release();
				enemies.push_back(tempEnemy);
			}
	   }
	if (GetLevel() == 2 && m_nRemainingEnemies > 0 && m_nTotalSpawns < 10)
	{
		m_nEnemyCounter += 1;
		m_nTotalSpawns += 1;

		if (m_nTotalSpawns % 2 == 1)
		{
			tempEnemy = pOF->CreateObject("CEnemyMeat");
			tempEnemy ->SetImageID(m_nImageID[2]);
			pOM->AddObject(tempEnemy );
			tempEnemy ->Release();
			enemies.push_back(tempEnemy);
		}
		else
		{
			tempEnemy = pOF->CreateObject("CEnemyBooger");
			tempEnemy ->SetImageID(m_nImageID[2]);
			pOM->AddObject(tempEnemy );
			tempEnemy ->Release();
			enemies.push_back(tempEnemy);
		}
	}
	if (GetLevel() == 3)
	{
		tempEnemy = pOF->CreateObject("CEnemyPsycrow");
		tempEnemy->SetImageID(m_nBGID);
		pOM->AddObject(tempEnemy);
		tempEnemy->Release();
		enemies.push_back(tempEnemy);
	}
	}
}
Пример #2
0
CBase* Factory::CreateWeapon(int type, POINT mapPoint, bool bAddtoMngr)
{
	CBase* weapon = new CBase();

	CBase* temp;
	
	switch(type)
	{
	case BOKKEN:
		temp = weapons[BOKKEN];
		temp->SetName("Bokken");
		temp->SetImageID(CAssets::GetInstance()->aSwordID);
		temp->SetNumType(0);
		break;
	case TACHI:
		temp = weapons[TACHI];
		temp->SetName("Tachi");
		temp->SetImageID(CAssets::GetInstance()->aSwordID);
		temp->SetNumType(1);

		break;
	case KATANA:
		temp = weapons[KATANA];
		temp->SetName("Katana");
		temp->SetImageID(CAssets::GetInstance()->aSwordID);
		temp->SetNumType(2);

		break;
	case NINJATO:
		temp = weapons[NINJATO];
		temp->SetName("Ninjato");
		temp->SetImageID(CAssets::GetInstance()->aSwordID);
		temp->SetNumType(3);

		break;
	case WOODNUN:
		temp = weapons[WOODNUN];
		temp->SetName("Wooden Nunchaku");
		temp->SetImageID(CAssets::GetInstance()->aNunchakuID);
		temp->SetNumType(4);

		break;
	case GLASSNUN:
		temp = weapons[GLASSNUN];
		temp->SetName("Glass Nunchaku");
		temp->SetImageID(CAssets::GetInstance()->aNunchakuID);
		temp->SetNumType(5);

		break;
	case STEELNUN:
		temp = weapons[STEELNUN];
		temp->SetName("Steel Nunchaku");
		temp->SetImageID(CAssets::GetInstance()->aNunchakuID);
		temp->SetNumType(6);

		break;
	case OAKSTAFF:
		temp = weapons[OAKSTAFF];
		temp->SetName("Oak Bo Staff");
		temp->SetImageID(CAssets::GetInstance()->aStaffID);
		temp->SetNumType(7);

		break;
	case BAMBOOSTAFF:
		temp = weapons[BAMBOOSTAFF];
		temp->SetName("Bamboo Staff");
		temp->SetImageID(CAssets::GetInstance()->aStaffID);
		temp->SetNumType(8);

		break;
	case STEELSTAFF:
		temp = weapons[STEELSTAFF];
		temp->SetName("Steel Staff");
		temp->SetImageID(CAssets::GetInstance()->aStaffID);
		temp->SetNumType(9);

		break;
	case RUSTYSAI:
		temp = weapons[RUSTYSAI];
		temp->SetName("Rusty Sais");
		temp->SetImageID(CAssets::GetInstance()->aSaiID);
		temp->SetNumType(10);

		break;
	case POLISHEDSAI:
		temp = weapons[POLISHEDSAI];
		temp->SetName("Polished Sais");
		temp->SetImageID(CAssets::GetInstance()->aSaiID);
		temp->SetNumType(11);

		break;
	}
	weapon->SetWeapon(temp->GetName(),temp->GetStrength(), temp->GetDefense(), temp->GetImageID(), temp->GetNumType());

	weapon->SetType(OBJECT_WEAPON);
	weapon->SetWidth(32);
	weapon->SetHeight(32);

	if (bAddtoMngr)
	{
		CBattleMap* pBM =  CBattleMap::GetInstance();
		weapon->SetCurrTile(mapPoint, pBM->GetOffsetX(),pBM->GetOffsetY(),pBM->GetTileWidth(), pBM->GetTileHeight(),pBM->GetNumCols(),false);
	
		ObjectManager::GetInstance()->Add(weapon);
	}

	return weapon;
}