Exemplo n.º 1
0
int main()
{
	CBase lw;
	lw.run();

	return 0;
}
void CBulletPaper::Update(float fElapsedTime)
{
	CSGD_ObjectManager *pOM = CSGD_ObjectManager::GetInstance();
	CSGD_MessageSystem *pMS = CSGD_MessageSystem::GetInstance();
	CGamePlay *pGP = CGamePlay::GetInstance();

	SetPosX(GetPosX() + GetVelX() * fElapsedTime);
	SetPosY(GetPosY() + GetVelY() * fElapsedTime);

	rCollisionRect.top = GetPosY();
	rCollisionRect.left = GetPosX();
	rCollisionRect.bottom = GetPosY() + GetHeight();
	rCollisionRect.right = GetPosX() + GetWidth();

	CBase *player;
	player = CPlayerCharacter::GetInstance();

	RECT cross;

	if (IntersectRect(&cross,&rCollisionRect,&player->GetCollisionRect()))
		pMS->SendMsg(new CCollisionMessage(player,this));

	if (GetPosY() > 580 || GetPosY() < -100 || GetPosX() > 740 || GetPosX() < -100)
		pMS->SendMsg(new CDestroyMessage(this));

}
void CBulletHook::Update(float fElapsedTime)
{
	CSGD_ObjectManager *pOM = CSGD_ObjectManager::GetInstance();
	CSGD_MessageSystem *pMS = CSGD_MessageSystem::GetInstance();
	CGamePlay *pGP = CGamePlay::GetInstance();
	CPlayerCharacter *pPC = CPlayerCharacter::GetInstance();


	if (GetScoreValue() == 1.0f)
	{
		m_fLifeTime -= fElapsedTime;
		SetPosX(GetPosX() + GetVelX() * fElapsedTime);
		SetPosY(GetPosY() + GetVelY() * fElapsedTime);
	}
	else if (GetScoreValue() == 2.0f)
		m_fLifeTime -= fElapsedTime * 0.25f;
	else  if (GetScoreValue() == 3.0f)
	{
		m_fLifeTime -= fElapsedTime;
		SetPosX(GetPosX() + GetVelX() * fElapsedTime);
		SetPosY(GetPosY() + GetVelY() * fElapsedTime);
		if (GetPosX() < pPC->GetPosX())
			SetVelX(abs(GetVelX()));
		else if (GetPosX() >= pPC->GetPosX())
			SetVelX(-abs(GetVelX()));
		if (GetPosY() < pPC->GetPosY())
			SetVelY(abs(GetVelY()));
		else if (GetPosY() >= pPC->GetPosY())
			SetVelY(-abs(GetVelY()));
	}

	rCollisionRect.top = GetPosY();
	rCollisionRect.left = GetPosX();
	rCollisionRect.bottom = GetPosY() + GetHeight();
	rCollisionRect.right = GetPosX() + GetWidth();

	CBase *player;
	player = CPlayerCharacter::GetInstance();

	RECT cross;

	if (IntersectRect(&cross,&rCollisionRect,&player->GetCollisionRect()))
	{
		pMS->SendMsg(new CCollisionMessage(player,this));
		pMS->SendMsg(new CDestroyMessage(this));
	}

	if (m_fLifeTime <= 0)
		pMS->SendMsg(new CDestroyMessage(this));

}
Exemplo n.º 4
0
void test_transfer()
{
    BOOST_TEST_MESSAGE( "starting transfer test" );
    CDerived from;
    CBase    to;

    set_capacity<CDerived>()( from );
    set_capacity<CBase>()( to );

    from.push_back( new T );
    from.push_back( new T );
    to. BOOST_NESTED_TEMPLATE transfer<CDerived>( to.end(), from );
    BOOST_TEST_MESSAGE( "finished transfer test" );
}
Exemplo n.º 5
0
void CGate::HandleEvent(CEvent* pEvent)
{
	if( pEvent->GetEventID() == "generator.destroyed" )
	{
		CBase* generator = (CBase*)pEvent->GetParam();

		tVector2D toGenerator;

		toGenerator.fX = generator->GetPosX() - GetPosX();
		toGenerator.fY = generator->GetPosY() - GetPosY();

		if( Vector2DLength(toGenerator) < 700 )
		{
			CMessageSystem::GetInstance()->SendMsg( new CDestroyBase(this));
		}
	}
}
Exemplo n.º 6
0
 bool                        Del     ( const CBase & x ){
     for( unsigned int i = 0; i < col.data.size(); i++ )
         if( (*col.data[i]).Type() == x.Type() && (*col.data[i]).Cmp(&x) ){
             col.data.erase(col.data.begin() + i);
             return true;
         }
     return false;
 }
Exemplo n.º 7
0
    bool                        Add     ( const CBase & x ){

        for( unsigned int i = 0; i < col.data.size(); i++ )
            if( (*col.data[i]).Type() == x.Type() && (*col.data[i]).Cmp(&x) ) return false;

        if( x.Type() == "A" ){
            CRecA * a = new CRecA(dynamic_cast<const CRecA &>(x));
            col.data.push_back(a);
        }
        else if( x.Type() == "AAAA" ){
            CRecAAAA * a = new CRecAAAA(dynamic_cast<const CRecAAAA &>(x));
            col.data.push_back(a);
        }

        else if( x.Type() == "MX" ){
            CRecMX * a = new CRecMX(dynamic_cast<const CRecMX &>(x));
            col.data.push_back(a);
        }

        return true;
    }
Exemplo n.º 8
0
/////////////////////////////////////////////////////////////////
// CBase::ReleaseChildren
//
/////////////////////////////////////////////////////////////////
HRESULT CBase::ReleaseChildren()
{
	//Make our lives easier...
	CObjTree* pCObjTree = m_pCMainWindow->m_pCMDIObjects->m_pCObjTree;

	//No-op
	if(!m_hTreeItem || !pCObjTree->m_hWnd)
		return S_OK;
	BOOL bAllRemoved = TRUE;

	//Try to obtain the first child...
	HTREEITEM hChildItem = pCObjTree->GetChildItem(m_hTreeItem);
	while(hChildItem)
	{
		//NOTE: Before deleting this node of the tree, obtain the 
		//next sibling (if there is one...).  Since we can't do this after the node has been deleted!
		HTREEITEM hNextSibling = pCObjTree->GetNextItem(hChildItem);
		CBase* pCChild = (CBase*)pCObjTree->GetItemParam(hChildItem);
		
		if(pCChild)
		{
			//Make sure all its children are released (recurse)
			//If this child cannot be released, we still can continue on to the next child
			//(ie: release everything we can - not all or nothing...)
			if(SUCCEEDED(pCChild->ReleaseChildren()))
			{
				//Now we can release this child
				pCChild->ReleaseObject();
			}
		}
		
		//Go to the next sibling...
		hChildItem = hNextSibling;
	}

	return bAllRemoved ? S_OK : E_FAIL;
}
Exemplo n.º 9
0
void UpdateRollAway( float elapsedTime, CSkill* skill, CParticleSystem* ps )
{
	CPlayer* pPlayer		= CPlayer::GetInstance();
	CBattleMap* pBattleMap	= CBattleMap::GetInstance();
	CBase* character		= pBattleMap->GetCurrChar();
	CBase* target			= pBattleMap->GetCurrEnemyTarget();
	//	if the skill consists of more than one animation, this needs to happen when each one is finished
	if (skill->Trigger()) 
	{
		ps[NINJA_BLOOD].Emit(target->GetPosX(), target->GetPosY());
		ps[NINJA_BLOOD].m_bActive = true; ps[NINJA_BLOOD].m_bLoop = false;

		// FORMULA: str - def + dmg + accuracy * 1.5 + random(-5 to 5) + (QTE amt successful * 5)
		skill->DmgToRender( (int)((float)(character->GetStrength() - target->GetDefense() + 
			skill->GetDmg() + character->GetAccuracy()) * 1.5f + rand() % (5 + 4) - 5) + (skill->GetCurrAmtSuccessful() * 5) );
		target->SetHealth(target->GetHealth() - skill->DmgToRender());
		ps[NINJA_BLOOD].m_bActive = false;
		skill->Trigger(false);
	}
	/*ps[BLOOD].UpdateParticle(elapsedTime);
	ps[BLOOD].DrawParticle(CAssets::GetInstance()->aBloodParticle);*/
}
Exemplo n.º 10
0
void CCamera::Update( float fElapsedTime )
{
	int width( int( theCamera->GetWidth( )-theCamera->GetXOffset( ) ) );
	int height( int( theCamera->GetHeight( )-theCamera->GetYOffset( ) ) );

	RECT rCamera;
	rCamera.left    = LONG( GetXOffset() );
	rCamera.right   = LONG( rCamera.left + GetWidth() );
	rCamera.top     = LONG( GetYOffset() );
	rCamera.bottom  = LONG( rCamera.top + GetHeight() );

	CBase* pCurPlayer;

	RECT rPlayer;
	if( !((CPlayer*)thePlayer)->GetFainted() || thePlayer2 == NULL )
	{
		pCurPlayer = thePlayer;
	 rPlayer    = thePlayer->GetCollisionRect( fElapsedTime );
	}
	else if( thePlayer2 )
	{
		pCurPlayer = thePlayer2;

	 rPlayer    = thePlayer2->GetCollisionRect( fElapsedTime );
	}



	int CenterOfScreenX( int( theCamera->GetXOffset( ) + width / 2 ) );
	int CenterOfScreenY( int( theCamera->GetYOffset( ) + height / 2 ) );

	RECT rHook, r;
	int x          = thePlayer->GetWidth( );
	rHook.left     = CenterOfScreenX - ( thePlayer->GetWidth( ) << 1 );
	rHook.top      = CenterOfScreenY - ( thePlayer->GetHeight( ) );
	rHook.right    = CenterOfScreenX + ( thePlayer->GetWidth( ) << 1 );
	rHook.bottom   = CenterOfScreenY + ( thePlayer->GetHeight( ) );

	if( !IntersectRect( &r, &rPlayer, &rCamera ) )
	{
		theCamera->SetCameraXOffset( pCurPlayer->GetPosX( ) - width / 2 );
		theCamera->SetCameraYOffset( pCurPlayer->GetPosY( ) - height / 2 );
	}

	if (IntersectRect( &r, &rHook, &rPlayer ) )
	{
		theCamera->SetVelocityX( theCamera->GetVelocityX( ) * 0.95f );
		theCamera->SetVelocityY( theCamera->GetVelocityY( ) * 0.95f );
	}

	{
		if( rPlayer.left < rHook.left && pCurPlayer->GetVelX() < -110)
			theCamera->SetVelocityX( pCurPlayer->GetVelX());
		else if( rPlayer.left < rHook.left )
			theCamera->SetVelocityX( -100 );
		else if( rPlayer.right > rHook.right && pCurPlayer->GetVelX() > 110)
			theCamera->SetVelocityX( pCurPlayer->GetVelX() );
		else if( rPlayer.right > rHook.right )
			theCamera->SetVelocityX( 100 );

		if( rPlayer.top < rHook.top )
			theCamera->SetVelocityY( -100 );
		else if( rPlayer.bottom > rHook.bottom && pCurPlayer->GetVelY() > 200)
			theCamera->SetVelocityY( pCurPlayer->GetVelY() );
		else if(rPlayer.bottom > rHook.bottom)
			theCamera->SetVelocityY( 200 );
		
	}

	theCamera->SetCameraXOffset( theCamera->GetXOffset( ) + theCamera->GetVelocityX( ) * fElapsedTime );
	theCamera->SetCameraYOffset( theCamera->GetYOffset( ) + theCamera->GetVelocityY( ) * fElapsedTime );
}
Exemplo n.º 11
0
int _tmain(int argc, _TCHAR* argv[])
{
	//知识点:注意区分指针类型(编译时确定)和对象类型(运行时确定). 总之,非虚方法是根据指针类型来调用,虚方法是根据对象类型来调用
	//指针类型(CBase)    对象类型(CDerived())
	//CBase *pBase = new CDerived();
	CBase base;
	cout << "sizeof(base):" << sizeof(base) << endl; // 4
	cout << sizeof(long long) << endl;
	//base.Test();

	CDerived derived;
	cout << "sizeof(derived):" << sizeof(derived) << endl;
	derived.name();
	derived.derived_print();
	CBase* p = &derived; //隐式向上强制转换
	//当一个derived class object被交出去当作一个base class object时,
	//它原本所以“成为一个derived class object”的所有特征,都会被切除(slicing)掉,只留下内部一个base class object。
	//以by reference的方式传递参数,有另一个优点:可避免所谓的“切割(slicing)问题”。引用是除指针外另一个可以产生多态效果的手段。
	Test1(derived);//Output from CBase! 出现切割
	Test2(derived);//Output from CDerived!
	Test3(p);      //Output from CDerived!
	cout << "打印指针自身内存地址:" << &p << endl; 
	cout << "打印指针指向内存地址:" << (int *)p << endl;
	p->show();
	//p->range();//编译错误.“range”: 不是“CBase”的成员

	CDerived* derived2 = (CDerived *)&base; //显式向下强制转换
	derived2->range();//调用派生类独有的方法,不安全操作(如果方法内有访问CDerived独有的成员变量,用到this指针就会出问题)
	CDerived* derived3 = dynamic_cast<CDerived*>(&base);//用dynamic_cast来转换类型可以检查转换是否安全成功,失败返回空指针
	if (derived3)
	{
		cout<< "derived3 dynamic_cast successful !!" <<endl;
		derived3->range();
	}
	else
	{
		cout<< "derived3 dynamic_cast failed !!" <<endl;
	}
	CDerived* derived4 = dynamic_cast<CDerived*>(p);
	if (derived4)
	{
		cout<< "derived4 dynamic_cast successful !!" <<endl;
		derived4->range();
	}
	else
	{
		cout<< "derived4 dynamic_cast failed !!" <<endl;
	}
	derived2->Test();//Output from CBase (根据对象类型来判断)
	
	CBase *pBase = new CDerived();
	/*虚析构:
	如果一个类用作基类,我们通常需要virtual来修饰它的析构函数,这点很重要。
	如果基类的析构函数不是虚析构,当我们用delete来释放基类指针(它其实指向的是派生类的对象实例)占用的内存的时候,
	只有基类的析构函数被调用,而派生类的析构函数不会被调用,这就可能引起内存泄露。如果基类的析构函数是虚析构,
	那么在delete基类指针时,继承树上的析构函数会被自低向上依次调用,即最底层派生类的析构函数会被首先调用,
	然后一层一层向上直到该指针声明的类型。*/
	delete pBase;

	Person *person = new Person();
	person->showAge();
	person->show1();
	printf("%d\n", Person::date);
	Children *children = new Children();
	printf("%d\n", Children::date);
	children->show1();
	Person *person1 = children;
	//show2()没有使用virtual关键字,程序将根据引用或者指针类型选择方法。忠告:绝对不要重新定义继承而来的非虚拟函数
	person1->show2(); //Person::show2()
	Children* children2 = (Children*)person;//显式向下强制转换
	children2->show2(); //Children::show2()  发现转型之后还是可以调用Children的函数的,因为编译的时函数内存地址已经确定,如果函数里面需要用到this指针调用到成员变量就不安全
	Person *person2 = new Children();
	//person2->show4(); person2并不能调用show4(),只能调用Person类方法;
	person2->hide();
	//children->hide(); //Person的hide()函数给隐藏了,不能调用
	children->hide(1);

	//子类在外部调用父类方法!!!!好奇怪的语法
	Children child;
	child.Person::show2();
	Children *pChild = new Children();
	pChild->Person::show2();

	//测试覆盖
	person1->testOverride(10);
	person2->testOverride(10);
	children->testOverride(10);
	system("Pause");
	return 0;
}
Exemplo n.º 12
0
void Test2(CBase &test)//引用传递,会修改原来的值,不会重新创建CBase副本,能提高效率,临时变量构造、复制、析构过程都将消耗时间。
{
	test.Test();
}
Exemplo n.º 13
0
void Test1(CBase test)//这样传递非内部数据方式是值传递,即函数会产生临时变量复制数据副本,在函数体内修改不会影响原来的数据。而且这种方式会发生“切割”
{
	test.Test(); //函数结束test会给释放内存,运行析构函数
}
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);
	}
	}
}
Exemplo n.º 15
0
void print_class(CBase &obj)
{
    obj.f();
}
Exemplo n.º 16
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;
}