Ejemplo n.º 1
0
  void Asteroid::Update(double dt) {
	tail.SetSpawning(GetVelX() * GetVelX() + GetVelY() * GetVelY() > 400 && GetSize() < 5.0);
	tail.Update(dt);
	tail.SetOwnerX(GetPosX());
	tail.SetOwnerY(GetPosY());
	tail.SetOwnerVelX(GetVelX());
	tail.SetOwnerVelY(GetVelY());
	tail.SetOwnerSize(GetSize());
	DecVelY(10 * dt);
  }
Ejemplo n.º 2
0
void CArrow::Render(void)
{
	RectD temp(0,0,GetWidth(),GetHeight());
	if(GetVelX() == 0 && GetVelY() > 0)
		TEX_MNG->Draw(GetImageID(), (int)GetPosX(), (int)GetPosY(),1.0f,1.0f,&temp.GetWindowsRECT(),GetWidth()*0.5f,GetHeight()*0.5f,3.14f*2.0f);
	else if(GetVelX() == 0 && GetVelY() < 0)
		TEX_MNG->Draw(GetImageID(), (int)GetPosX(), (int)GetPosY(),1.0f,1.0f,&temp.GetWindowsRECT(),GetWidth()*0.5f,GetHeight()*0.5f,3.14f*1.0f);
	else if(GetVelX() < 0 && GetVelY() == 0)
		TEX_MNG->Draw(GetImageID(), (int)GetPosX(), (int)GetPosY(),1.0f,1.0f,&temp.GetWindowsRECT(),GetWidth()*0.5f,GetHeight()*0.5f,3.14f*0.5f);
	else if(GetVelX() > 0 && GetVelY() == 0)
		TEX_MNG->Draw(GetImageID(), (int)GetPosX(), (int)GetPosY(),1.0f,1.0f,&temp.GetWindowsRECT(),GetWidth()*0.5f,GetHeight()*0.5f,-3.14f*0.5f);
}
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));

}
Ejemplo n.º 4
0
void CHeavyInfantry::Update(float fElapsedTime)
{
    if( GetDead() == false )
    {
        // If the unit is either not in a squad or it has been issued the order to attack from the squad
        if( Attack() == true )
        {
            if( GetCalculate() == true )
            {
                GetState()->CalculateAI(fElapsedTime, this);
            }

            if( GetHealth() < GetMaxHealth() * 0.5f )
            {
                SetCalculate(false);
                tVector2D vectorToPlayer;
                vectorToPlayer.fX = GetTarget()->GetPosX() - GetPosX();
                vectorToPlayer.fY = GetTarget()->GetPosY() - GetPosY();
                vectorToPlayer = Vector2DNormalize(vectorToPlayer);
                SetVelX(vectorToPlayer.fX*(GetSpeed()*2));
                SetVelX(vectorToPlayer.fY*(GetSpeed()*2));
            }
        }

        // Set Facing
        if( GetVelX() > GetVelY() )
        {
            SetFacing(1.0f,0.0f);
        }
        else if( -GetVelX() < -GetVelY() )
        {
            SetFacing(-1.0f,0.0f);
        }
        else if( GetVelY() > GetVelX() )
        {
            SetFacing(0.0f,1.0f);
        }
        else if( -GetVelY() < -GetVelX() )
        {
            SetFacing(0.0f,-1.0f);
        }

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

    CEnemy::Update(fElapsedTime);
}
Ejemplo n.º 5
0
void CSweepingWind::Update( float fElapsedTime )
{
	CSpecial::Update(fElapsedTime);

	if(IsFlipped())
		SetVelX(GetSpeed());
	else
		SetVelX(-GetSpeed());

	SetPosX(GetPosX() + GetVelX() * fElapsedTime);


	CCamera* Game_Camera = CCamera::GetInstance();
	if(this->GetPosX() < Game_Camera->GetPosX() || this->GetPosX() > Game_Camera->GetPosX() + Game_Camera->GetWidth())
	{		
		CRemoveEntityMessage* pMsg = new CRemoveEntityMessage(this);
		CSGD_MessageSystem::GetInstance()->SendMsg(pMsg);
		pMsg = nullptr;
	}

	if(CSpecial::Timer() == 0)
	{
		CRemoveEntityMessage* pMsg = new CRemoveEntityMessage(this);
		CSGD_MessageSystem::GetInstance()->SendMsg(pMsg);
		pMsg = nullptr;
	}
}
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));

}
Ejemplo n.º 7
0
////////////////////////////////////////////////////////
// Function: "Update"
//
// Paramaters: (float) fElapsedTime - Allows for time
//						based updates rather than frame
//
// Returns: void
void CBase::Update(float fElapsedTime)
{
	// Moves the object by its velocity
	SetPosX( GetPosX() + (GetVelX() * fElapsedTime));
	SetPosY( GetPosY() + (GetVelY() * fElapsedTime));

	//if(m_pAnimation != NULL)
		//m_pAnimation->Update(fElapsedTime);
}
Ejemplo n.º 8
0
bool CHeavyInfantry::CheckCollision( CBase *pBase )
{
    if( pBase->GetType() == OBJECT_PLAYER )
    {
        if(CBase::CheckCollision(pBase))
        {
            CPlayer::GetInstance()->SetPosX(CPlayer::GetInstance()->GetPosX()+GetVelX());
            CPlayer::GetInstance()->SetPosY(CPlayer::GetInstance()->GetPosY()+GetVelY());
        }
    }
    return CEnemy::CheckCollision(pBase);
}
void CBase::Render(void)
{
	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();

	pTM->Draw( GetImageID(), GetPosX() - m_nWidth/2, GetPosY() - m_nHeight/2, 
		1.0f, 1.0f, NULL, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(128, 255, 255, 255));

	CSGD_Direct3D* pD3D = CSGD_Direct3D::GetInstance();

	tVector2D tVisualize;
	tVisualize.fX = GetVelX();
	tVisualize.fY = GetVelY();

	tVisualize = Vector2DNormalize(tVisualize);
	tVisualize.fX *= 32.0f;
	tVisualize.fY *= 32.0f;

	pD3D->DrawLine(GetPosX(), GetPosY(), GetPosX() + tVisualize.fX, GetPosY() + tVisualize.fY,
						255, 0, 0);
}
Ejemplo n.º 10
0
void CBullet::Update(float fElapsedTime)
{
	if(GetIsScrew())
	{
		// Gravity is applied to screws		
		SetVelY(GetVelY() + 100.0f * GAME->GetTimer().GetDeltaTime());

		SetPosX(GetPosX()+(GetVelX() * GAME->GetTimer().GetDeltaTime()));
		SetPosY(GetPosY()+(GetVelY() * GAME->GetTimer().GetDeltaTime()));	

		//if((GetVelY() < 1.0f && GetVelY() > -1.0f) /*|| (GetVelX() < 1.0f && GetVelX() > -1.0f)*/)
		//	MS->SendMsg(new CDestroyBulletMessage(this));
	}

	// Killing the bullet if it gets offscreen
	if(m_fTimer > 10.0f)
		MS->SendMsg(new CDestroyBulletMessage(this));

	m_fTimer += GAME->GetTimer().GetDeltaTime();

	CBase::Update(fElapsedTime);
}
void CEnemyBusiness::Update(float fElapsedTime)
{

	CSGD_ObjectManager *pOM = CSGD_ObjectManager::GetInstance();
	CSGD_MessageSystem *pMS = CSGD_MessageSystem::GetInstance();
	CSGD_EventSystem *pES= CSGD_EventSystem::GetInstance();
	CGame *theGame = CGame::GetInstance();

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

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

	DWORD timer = GetTickCount();

	if (GetHit())
	{
		m_nOffset = 32;
		m_fHitTimer = 1.0f;
		SetVelX(0);
		rEnemyRect.left = 442;
		rEnemyRect.right = 463;
	}

	else if (!GetHit() && m_fHitTimer <= 0)
	{
		m_nOffset = 0;
		m_fFireReady -= fElapsedTime;
		SetVelX(GetXFlip() * -100);
		if (timer % 700 <= 100)
		{
			rEnemyRect.left = 2;
			rEnemyRect.right = 54;
		}
		else if (timer % 700 > 100 && timer % 700 <= 200)
		{
			rEnemyRect.left = 58;
			rEnemyRect.right = 115;
		}
		else if (timer % 700 > 200 && timer % 700 <= 300)
		{
			rEnemyRect.left = 119;
			rEnemyRect.right = 163;
		}
		else if (timer % 700 > 300 && timer % 700 <= 400)
		{
			rEnemyRect.left = 700;
			rEnemyRect.right = 753;
		}
		else if (timer % 700 > 400 && timer % 700 <= 500)
		{
			rEnemyRect.left = 756;
			rEnemyRect.right = 795;
		}
		else if (timer % 700 > 500 && timer % 700 <= 600)
		{
			rEnemyRect.left = 798;
			rEnemyRect.right = 850;
		}
		else if (timer % 700 > 600)
		{
			rEnemyRect.left = 853;
			rEnemyRect.right = 899;
		}
	}

	if (m_fFireReady <=0 && !GetHit() && GetHP() > 0)
		pES->SendEvent("businessman fire",&fElapsedTime);

	if (bIsFiring)
	{
		rEnemyRect.left = 329;
		rEnemyRect.right = 397;
		m_fFiringTimer -= fElapsedTime;
		SetVelX(0);
	}

	if (m_fFiringTimer <= 0)
	{
		bIsFiring = false;
		m_fFiringTimer = 1.0f;
	}

	if (GetPosX() < -32)
	{
		SetVelX(abs(GetVelX() * -1));
		SetXFlip(-abs(GetXFlip() * -1));
	}
	else if (GetPosX() > 640)
	{
		SetVelX(-abs(GetVelX() * -1));
		SetXFlip(abs(GetXFlip() * -1));
	}
	else if (GetPosY() > 480)
		SetVelY(-abs(GetVelY() * -1));
	else if (GetPosY() < -32)
		SetVelY(abs(GetVelY() * -1));

	m_fHitTimer -= fElapsedTime;

	SetHit(false);

	if (GetHP() <= 0)
	{
		CSGD_WaveManager::GetInstance()->Play(m_nSoundID,0);

		CSGD_EventSystem::GetInstance()->SendEvent("spawn powerups", NULL);
		pMS->SendMsg(new CDestroyMessage(this));

	}

}
void CEnemyDemon::Update(float fElapsedTime)
{

    CSGD_ObjectManager *pOM = CSGD_ObjectManager::GetInstance();
    CSGD_MessageSystem *pMS = CSGD_MessageSystem::GetInstance();
    CGame *theGame = CGame::GetInstance();

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

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

    if (GetPosX() < -32)
    {
        SetVelX(abs(GetVelX() * -1));
        SetXFlip(-abs(GetXFlip() * -1));
    }
    else if (GetPosX() > 640)
    {
        SetVelX(-abs(GetVelX() * -1));
        SetXFlip(abs(GetXFlip() * -1));
    }
    else if (GetPosY() > 480)
        SetVelY(-abs(GetVelY() * -1));
    else if (GetPosY() < -32)
        SetVelY(abs(GetVelY() * -1));


    DWORD timer = GetTickCount();

    if (abs(GetPosX() - CPlayerCharacter::GetInstance()->GetPosX()) < 128 && abs(GetPosY() - CPlayerCharacter::GetInstance()->GetPosY()) < 128)
        bIsClose = true;
    else
        bIsClose = false;

    if (!bIsClose)
    {
        if (timer % 525 <= 75)
        {
            rEnemyRect.left = 0;
            rEnemyRect.right = 48;
        }
        else if (timer % 525 > 75 && timer % 525 <= 150)
        {
            rEnemyRect.left = 51;
            rEnemyRect.right = 90;
        }
        else if (timer % 525 > 150 && timer % 525 <= 225)
        {
            rEnemyRect.left = 93;
            rEnemyRect.right = 138;
        }
        else if (timer % 525 > 225 && timer % 525 <= 300)
        {
            rEnemyRect.left = 142;
            rEnemyRect.right = 185;
        }
        else if (timer % 525 > 300 && timer % 525 <= 375)
        {
            rEnemyRect.left = 188;
            rEnemyRect.right = 234;
        }
        else if (timer % 525 > 375 && timer % 525 <= 450)
        {
            rEnemyRect.left = 237;
            rEnemyRect.right = 282;
        }
        else if (timer % 525 > 450)
        {
            rEnemyRect.left = 286;
            rEnemyRect.right = 332;
        }
    }
    else if (bIsClose)
    {
        if (timer % 600 <= 75)
        {
            rEnemyRect.left = 335;
            rEnemyRect.right = 372;
        }
        else if (timer % 600 > 75 && timer % 600 <= 150)
        {
            rEnemyRect.left = 375;
            rEnemyRect.right = 407;
        }
        else if (timer % 600 > 150 && timer % 600 <= 225)
        {
            rEnemyRect.left = 410;
            rEnemyRect.right = 445;
        }
        else if (timer % 600 > 225 && timer % 600 <= 300)
        {
            rEnemyRect.left = 448;
            rEnemyRect.right = 481;
        }
        else if (timer % 600 > 300 && timer % 600 <= 375)
        {
            rEnemyRect.left = 484;
            rEnemyRect.right = 515;
        }
        else if (timer % 600 > 375 && timer % 600 <= 450)
        {
            rEnemyRect.left = 518;
            rEnemyRect.right = 554;
            CSGD_WaveManager::GetInstance()->Play(m_nSoundID,0);

        }
        else if (timer % 600 > 450 && timer % 600 <= 525)
        {
            rEnemyRect.left = 558;
            rEnemyRect.right = 592;
        }
        else if (timer % 600 > 525)
        {
            rEnemyRect.left = 595;
            rEnemyRect.right = 636;
        }
    }
    SetHit(false);

    if (GetHP() <= 0)
    {
        CSGD_EventSystem::GetInstance()->SendEvent("spawn powerups", NULL);
        pMS->SendMsg(new CDestroyMessage(this));
    }

}
Ejemplo n.º 13
0
void CEnemy::Update( float fElapsedTime )
{
	if( ! ( CGameplayState::GetInstance()->GetLevel()->GetTile((int)GetPosX(), (int)GetPosY() ) ) )
	{
		SetHealth(0);
	}
	if(m_nHealth >0)
	{

		Frame * currFrame = (animation->GetAllFrames())[animation->GetFrame()];

		if(LastFrame && currAnimation == 2 || currAnimation == 1)
		{
			float oldheight = m_fLastPosition + (LastFrame->DrawRect.bottom - LastFrame->DrawRect.top) * m_fScale;

			while(oldheight < GetPosY() + (currFrame->DrawRect.bottom - currFrame->DrawRect.top) * m_fScale)
			{
				SetPosY(GetPosY() - 1);
			}
			while(oldheight > GetPosY() + (currFrame->DrawRect.bottom - currFrame->DrawRect.top) * m_fScale)
			{
				SetPosY(GetPosY() + 1);
			}
		}

		LastFrame = currFrame;
		m_fLastPosition = GetPosY();

		if(!m_bKnockBack)
		{
			m_fShotTimer = m_fShotTimer - fElapsedTime;

			if( 0.0f == m_fWaitTimer )
			{	
				if(m_SpellType == OBJ_WIND)
				{
					CBase::Update( fElapsedTime );
				}
				else
				{
					CCharacter::Update( fElapsedTime );
				}

				m_nAttackWho = currState->Update( fElapsedTime, this );

				if( m_nAttackWho && m_fShotTimer < 0 )
				{
					m_fWaitTimer += fElapsedTime;
					m_fShotTimer = 2.0f;
					animation->Reset();
					SetAnimation(m_nAnimation,2);

				}
			}
			else
			{
				m_fWaitTimer = m_fWaitTimer + fElapsedTime;

				/*if(m_SpellType !=OBJ_WIND)
				SetPosY( GetPosY( ) + 150.0f * fElapsedTime );*/


				char* pleasework = animation->GetTrigger();
				if(strcmp(pleasework, "Done") == 0)
				{	
					if( 1 == m_nAttackWho )
					{
						currState->Attack( CGameplayState::GetInstance( )->GetPlayerOne( ), this );
					}
					else if( 2 == m_nAttackWho )
					{
						currState->Attack( CGameplayState::GetInstance( )->GetPlayerTwo( ), this );
					}
					animation->Reset();
					SetAnimation(m_nAnimation,0);

					m_fWaitTimer = 0.0f;
				}

			}
		}
		else
		{
			if(m_fKnockBack < 0)
			{
				m_bKnockBack = false;
			}
			else
			{
				CCharacter::Update(fElapsedTime);
				m_fKnockBack-=fElapsedTime * 100;
			}
		}

		if(m_bBurning)
		{
			m_fBurnTimer -= fElapsedTime;

			if(m_fBurnTimer <= 0)
			{
				m_bBurning = false;
				m_nBurnDamage = 0;
			}

			if(!((int)m_fBurnTimer %  3))
			{
				m_fBurnTimer -= 1.0f;
				StickyNumbers* SN = new StickyNumbers();
				SN->SetTimer(2.5f);
				SN->SetPosX( GetPosX());
				SN->SetPosY( GetPosY() - 24);
				char buffer[16];
				sprintf_s(buffer, 16, "%i", TakeDamage(m_nBurnDamage));
				SN->SetText(buffer);
				SN->SetVelY(-30);

				Corona_ObjectManager::GetInstance()->AddObject(SN);
				SN->Release();
			}
		}

		if( m_bIsFrozen )
		{
			m_fFreezeTimer = m_fFreezeTimer - fElapsedTime;

			if( m_fFreezeTimer <= 0 )
				m_bIsFrozen = false;

			SetVelX( m_fFrozenSpeed );
		}
	}
	else
	{
		if(currAnimation != 1)
		{
			animation->Reset();
			SetAnimation(m_nAnimation,1);
		}
		char* pleasework = animation->GetTrigger();
		if(strcmp(pleasework,"Dead") ==0)
		{
			Corona_EventHandler::GetInstance( )->SendEvent( "EnemyDied", ( void* )this );
			SetActive( false );
		}
	}
	animation->Update(fElapsedTime);
	CHANGE_ANIM
	{
		if(GetVelX() <30)
		{
			IsRotated = true;
		}
		else if(GetVelX() >-30)
		{
			IsRotated = false;
		}
		m_fChangeAnimationTimer =0.0f;
	}
	else
	{
Ejemplo n.º 14
0
void CEarthBoss::Update(float fElapsedTime)
{
	CEnemy::Update(fElapsedTime);

	if (m_pEState->GetState() == EntityState::DEAD)
	{
		return;
	}

	m_fUpdateOldPos += fElapsedTime;
	if(m_nCoolDown > 0)
		m_nCoolDown -= fElapsedTime;

	if( m_fPunchCoolDown > 0.0f  && m_bPunching == true)
		m_fPunchCoolDown -= fElapsedTime;
	else
	{
		m_fPunchCoolDown = 2.5f;
		m_bPunching = false;
	}

	if (m_fSpecialTimer > 0.0f)
		m_fSpecialTimer -= fElapsedTime;
	else
	{
		CCreate_Rock_Fall_Message* pMsg = new CCreate_Rock_Fall_Message();
		CSGD_MessageSystem::GetInstance()->SendMsg(pMsg);
		pMsg = nullptr;

		m_fSpecialTimer = 15.0f;
	}

	//if not rushing do basic path finding to the player
	if(GetTarget() != nullptr)
	{
		float tar_pos_x = GetTarget()->GetPosX();
		float tar_pos_y = GetTarget()->GetPosY();
		if(tar_pos_x > GetPosX())
		{
			//set Grunt's animation's facing to the right
			SetFlipped(true);
		}
		else
		{
			SetFlipped(false);
		}


		if(m_fMoveAway <= 0)
		{

			//	tar_pos_x += (m_bFlipped) ? -236 : 236;

			//Simple Pathing twards the player
			if(tar_pos_y != GetPosY())//Above the Player
			{
				float min_Distance = (float)(GetTarget()->GetWidth()/2 + GetWidth()/2);
				if(GetPosX() + min_Distance > tar_pos_x && GetPosX() - min_Distance < tar_pos_x)
				{
					if( tar_pos_x < GetPosX())

						SetVelX(speed * fElapsedTime);
					else

						SetVelX(-speed * fElapsedTime);
				}
				else
				{
					if( tar_pos_y < GetPosY())

						SetVelY(-speed * fElapsedTime);
					else

						SetVelY(speed * fElapsedTime);
					if( tar_pos_x < GetPosX())

						SetVelX(-speed * fElapsedTime);
					else

						SetVelX(speed * fElapsedTime);

					if( tar_pos_x > (GetPosX() - 64) && tar_pos_x < (GetPosX() + 64) )
					{


						if( tar_pos_y > (GetPosY() - 32) && tar_pos_y < (GetPosY() + 32) && m_bPunching == false)
						{

							GetAnimInfo()->SetAnimationName("Boss1_Attack_Animation");
							m_bPunching = true;
							//dynamic_cast<CPlayer*>(GetTarget())->SetState(CEntityState::KNOCKED_DOWN);
						}
					}
				}
			}
			else
			{
				SetVelY(0);
				if( tar_pos_x < GetPosX())

					SetVelX(-speed * fElapsedTime);
				else

					SetVelX(speed * fElapsedTime);
			}

			//if the player can be shot at.
			if(m_nCoolDown <= 0 && GetPosX() - tar_pos_x < 128 && GetPosX() - tar_pos_x > -128 )
			{
				if(GetPosY() - tar_pos_y < 5 && GetPosY() - tar_pos_y > -5 && m_bPunching == false)
				{

					//GetAnimInfo()->SetAnimationName("Boss1_Shoot_Animation");
					////if in range rushing starts
					//CCreate_Projectile_Message* c_pProjectMSG = new CCreate_Projectile_Message(ENT_ENEMY, IsFlipped());
					//c_pProjectMSG->SetPosX(this->GetPosX());
					//c_pProjectMSG->SetPosY(this->GetPosY());

					//CSGD_MessageSystem::GetInstance()->SendMsg(c_pProjectMSG);
					m_nCoolDown += 5;
				}
			}
			//stop 'bouncing'
			int threshold = 5;
			if(tar_pos_x - GetPosX() < threshold && tar_pos_x - GetPosX() > -1 * threshold)
				SetVelX(0);
			if(tar_pos_y - GetPosY() < threshold && tar_pos_y - GetPosY() > -1 * threshold)
				SetVelY(0);
		}
		else //update move away
		{
			m_fMoveAway -= fElapsedTime;
			if(m_bEvadeUp)
				SetVelY(-speed * fElapsedTime);
			else
				SetVelY(speed * fElapsedTime);
		}
	}

	//Check Colider
	if(TileManager::GetInstance()->CheckBlockedTiles(GetPosX(), GetPosY(), GetVelX(), 0))
	{
		SetPosX(GetPosX() + GetVelX());
		if(TileManager::GetInstance()->CheckBlockedTiles(GetPosX(), GetPosY(), 0, GetVelY()))
		{
			SetPosY(GetPosY() + GetVelY());
		}
	}
	else
	{
		if( GetPosY() >= 600 )
			SetPosY( (GetPosY() - (GetPosY() - 599)) );
		else
			SetPosY(GetPosY() + 1);
		SetVelX(0);
		SetVelY(0);
	}
	if(GetPosX() < 0)
		SetPosX(0);

	//Set/use Move out of the way
	if(m_fUpdateOldPos >= 1.0f)
	{
		if(m_fPosXOld + 5 > GetPosX() && m_fPosXOld - 5 < GetPosX())
		{
			if(m_fPosYOld + 5 > GetPosY() && m_fPosYOld - 5 < GetPosY())
			{
				if(m_nCoolDown <= 0)
				{
					m_bEvadeUp = !m_bEvadeUp;
					if(m_fMoveAway <= 0)
						m_fMoveAway = 4.0f;
				}
			}
		}
		m_fPosXOld = GetPosX();
		m_fPosYOld = GetPosY();
		m_fUpdateOldPos = 0.0f;
	}

}
void CEnemyPsycrow::Update(float fElapsedTime)
{
	COptions *op = COptions::GetInstance();
	CSGD_ObjectManager *pOM = CSGD_ObjectManager::GetInstance();
	CSGD_MessageSystem *pMS = CSGD_MessageSystem::GetInstance();
	CSGD_EventSystem *pES= CSGD_EventSystem::GetInstance();
	CGame *theGame = CGame::GetInstance();

	if (m_nState % 2 == 0)
	{
		SetVelY(sin(m_fSineFloat) * 50 * op->GetDifficulty() * (m_nState + 0.5));
		rEnemyRect.top = 507;
		rEnemyRect.bottom = 561;
		rEnemyRect.left = 584;
		rEnemyRect.right = 650;

		if (!bIsFiring)
			m_fFireReady -= fElapsedTime;
		
		if (m_fFireReady <= 0)
			bIsFiring = true;

		if (bIsFiring)
		{
			m_fFiringTimer -= fElapsedTime;
			if (m_fFiringTimer <= 0.5f && m_fFiringTimer > 0.4f)
			{
				rEnemyRect.top = 507;
				rEnemyRect.bottom = 561;
				rEnemyRect.left = 494;
				rEnemyRect.right = 566;
				if (!bIsFired)
				{
					pES->SendEvent("psycrow fire", NULL);
					bIsFired = true;

				}
			}
			else if (m_fFiringTimer <= 0.4f && m_fFiringTimer > 0.3f)
			{
				rEnemyRect.top = 507;
				rEnemyRect.bottom = 567;
				rEnemyRect.left = 790;
				rEnemyRect.right = 856;
			}
			else if (m_fFiringTimer <= 0.3f && m_fFiringTimer > 0.2f)
			{
				rEnemyRect.top = 511;
				rEnemyRect.bottom = 564;
				rEnemyRect.left = 873;
				rEnemyRect.right = 935;
			}
			else if (m_fFiringTimer <= 0.2f && m_fFiringTimer > 0.1f)
			{
				rEnemyRect.top = 581;
				rEnemyRect.bottom = 641;
				rEnemyRect.left = 502;
				rEnemyRect.right = 573;
			}
			else if (m_fFiringTimer <= 0.1f)
			{
				rEnemyRect.top = 579;
				rEnemyRect.bottom = 639;
				rEnemyRect.left = 601;
				rEnemyRect.right = 673;
				bIsFiring = false;
				bIsFired = false;
				m_fFireReady = 5.0f;
				m_fFiringTimer = 0.5f;
			}

		}
	}
	else if (m_nState % 2 == 1)
	{
		rEnemyRect.top = 666;
		rEnemyRect.bottom = 726;
		DWORD timer = GetTickCount();
		if (timer % 300 <= 100)
		{
			rEnemyRect.left = 494;
			rEnemyRect.right = 533;
		}
		else if (timer % 300 > 100 && timer % 300 <= 200)
		{
			rEnemyRect.left = 542;
			rEnemyRect.right = 581;
		}
		else if (timer % 300 > 200)
		{
			rEnemyRect.left = 591;
			rEnemyRect.right = 630;
		}
	}

	if (GetHP() < op->GetDifficulty() * 200 && m_nState == PSYCROW_STATE1)
	{
		rEnemyRect.top = 674;
		rEnemyRect.bottom = 726;
		m_fHitTimer -= fElapsedTime;
		if (m_fHitTimer <= 0.4f && m_fHitTimer > 0.3f)
		{
			CSGD_WaveManager::GetInstance()->Play(m_nSoundID,0);
			rEnemyRect.left = 649;
			rEnemyRect.right = 708;
		}
		else if (m_fHitTimer <= 0.3f && m_fHitTimer > 0.2f)
		{
			rEnemyRect.left = 719;
			rEnemyRect.right = 772;
		}
		else if (m_fHitTimer <= 0.2f && m_fHitTimer > 0.1f)
		{
			rEnemyRect.left = 787;
			rEnemyRect.right = 844;
		}
		else if (m_fHitTimer <= 0.1f && m_fHitTimer > 0.0f)
		{
			rEnemyRect.left = 861;
			rEnemyRect.right = 912;
		}

		if (m_fHitTimer < 0)
			pES->SendEvent("state transition 1");
	}
	if (GetHP() < op->GetDifficulty() * 150 && m_nState == PSYCROW_STATE2)
	{
		rEnemyRect.top = 674;
		rEnemyRect.bottom = 726;
		m_fHitTimer -= fElapsedTime;
		if (m_fHitTimer <= 0.4f && m_fHitTimer > 0.3f)
		{
			CSGD_WaveManager::GetInstance()->Play(m_nSoundID,0);
			rEnemyRect.left = 649;
			rEnemyRect.right = 708;
		}
		else if (m_fHitTimer <= 0.3f && m_fHitTimer > 0.2f)
		{
			rEnemyRect.left = 719;
			rEnemyRect.right = 772;
		}
		else if (m_fHitTimer <= 0.2f && m_fHitTimer > 0.1f)
		{
			rEnemyRect.left = 787;
			rEnemyRect.right = 844;
		}
		else if (m_fHitTimer <= 0.1f && m_fHitTimer > 0.0f)
		{
			rEnemyRect.left = 861;
			rEnemyRect.right = 912;
		}

		if (m_fHitTimer < 0)
			pES->SendEvent("state transition 2");
	}
	if (GetHP() < op->GetDifficulty() * 100 && m_nState == PSYCROW_STATE3)
	{
		rEnemyRect.top = 674;
		rEnemyRect.bottom = 726;
		m_fHitTimer -= fElapsedTime;
		if (m_fHitTimer <= 0.4f && m_fHitTimer > 0.3f)
		{
			CSGD_WaveManager::GetInstance()->Play(m_nSoundID,0);
			rEnemyRect.left = 649;
			rEnemyRect.right = 708;
		}
		else if (m_fHitTimer <= 0.3f && m_fHitTimer > 0.2f)
		{
			rEnemyRect.left = 719;
			rEnemyRect.right = 772;
		}
		else if (m_fHitTimer <= 0.2f && m_fHitTimer > 0.1f)
		{
			rEnemyRect.left = 787;
			rEnemyRect.right = 844;
		}
		else if (m_fHitTimer <= 0.1f && m_fHitTimer > 0.0f)
		{
			rEnemyRect.left = 861;
			rEnemyRect.right = 912;
		}

		if (m_fHitTimer < 0)
			pES->SendEvent("state transition 3");
	}
	if (GetHP() < op->GetDifficulty() * 50 && m_nState == PSYCROW_STATE4)
	{
		rEnemyRect.top = 674;
		rEnemyRect.bottom = 726;
		m_fHitTimer -= fElapsedTime;
		if (m_fHitTimer <= 0.4f && m_fHitTimer > 0.3f)
		{
			CSGD_WaveManager::GetInstance()->Play(m_nSoundID,0);
			rEnemyRect.left = 649;
			rEnemyRect.right = 708;
		}
		else if (m_fHitTimer <= 0.3f && m_fHitTimer > 0.2f)
		{
			rEnemyRect.left = 719;
			rEnemyRect.right = 772;
		}
		else if (m_fHitTimer <= 0.2f && m_fHitTimer > 0.1f)
		{
			rEnemyRect.left = 787;
			rEnemyRect.right = 844;
		}
		else if (m_fHitTimer <= 0.1f && m_fHitTimer > 0.0f)
		{
			rEnemyRect.left = 861;
			rEnemyRect.right = 912;
		}

		if (m_fHitTimer < 0)
			pES->SendEvent("state transition 4");
	}
	if (GetHP() <= 0 && m_nState == PSYCROW_STATE5)
	{
		pMS->SendMsg(new CDestroyMessage(this));
	}

	if (CPlayerCharacter::GetInstance()->GetPosX() < GetPosX())
		SetXFlip(-1);
	else if (CPlayerCharacter::GetInstance()->GetPosX() >= GetPosX())
		SetXFlip(1);

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

	if (m_fSineFloat <= -3.14f)
		m_fSineFloat = 3.14f;

	m_fSineFloat -= fElapsedTime;

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

	if (GetPosX() < -32)
	{
		SetVelX(-1 * GetVelX());
		SetPosX(-31);
	}
	else if (GetPosX() > 600)
	{
		SetVelX(-1 * GetVelX());
		SetPosX(599);
	}
	if (GetPosY() < 0)
	{
		SetVelY(-1 * GetVelY());
		SetPosY(1);
	}
	else if (GetPosY() > 400)
	{
		SetVelY(-abs(GetVelY()));
		SetPosY(399);
	}

	DWORD timer = GetTickCount();

}
void CBase::Update(float fElapsedTime)
{
	SetPosX( GetPosX() + GetVelX() * fElapsedTime );
	SetPosY( GetPosY() + GetVelY() * fElapsedTime );
}
Ejemplo n.º 17
0
void CFighter::Update(float fElapsedTime)
{
	// Update common properties across all enemies
	CEnemy::Update(fElapsedTime);

	// if this enemy is cc'd don't 
	if (m_pEState->GetTimer() == true)
	{
		m_pEState->CEntityState::Update(fElapsedTime);
		return;
	}

	if (GetAnimInfo()->GetAnimationName() == GetAnimations("Idle") && m_bAttacking == true)
		m_bSecondAttackQueued = m_bAttacking = false;


	if (m_bAttacking == true)
		return;

	m_fUpdateOldPos += fElapsedTime;

	if(GetTarget() != nullptr)
	{
		float tar_pos_x = GetTarget()->GetPosX() - 32;
		float tar_pos_y = GetTarget()->GetPosY();

		if(tar_pos_x > GetPosX())
		{
			//set Grunt's animation's facing to the right
			SetFlipped( true );
		}
		else
		{
			SetFlipped( false );
		}


		if(m_fMoveAway <= 0)
		{

			//Simple Pathing twards the player
			if(tar_pos_y != GetPosY())//Above the Player
			{
				float min_Distance = (float)(GetTarget()->GetWidth()/2 + GetWidth()/2);
				if(GetPosX() + min_Distance > tar_pos_x && GetPosX() - min_Distance < tar_pos_x)
				{
					if( tar_pos_x < GetPosX())
						SetVelX(speed * fElapsedTime);
					else
						SetVelX(-speed * fElapsedTime);
				}
				else
				{
					if( tar_pos_y < GetPosY())
						SetVelY(-speed * fElapsedTime);
					else
						SetVelY(speed * fElapsedTime);
					if( tar_pos_x < GetPosX())
						SetVelX(-speed * fElapsedTime);
					else
						SetVelX(speed * fElapsedTime);
				}
				int threshold = 5;
				if(tar_pos_x - GetPosX() < threshold && tar_pos_x - GetPosX() > -1 * threshold)
					SetVelX(0);
				if(tar_pos_y - GetPosY() < threshold && tar_pos_y - GetPosY() > -1 * threshold)
					SetVelY(0);
			}
			else
			{
				SetVelY(0);
				if( tar_pos_x < GetPosX())
					SetVelX(-speed * fElapsedTime);
				else
					SetVelX(speed * fElapsedTime);
			}

		}
		else
		{
			m_fMoveAway -= fElapsedTime;
			if(m_bEvadeUp)
				SetVelY(-speed * fElapsedTime);
			else
				SetVelY(speed * fElapsedTime);
		}

		//Check Colider
		if(TileManager::GetInstance()->CheckBlockedTiles(GetPosX(), GetPosY(), GetVelX(), 0))
			SetPosX(GetPosX() + GetVelX());
		else if(TileManager::GetInstance()->CheckBlockedTiles(GetPosX(), GetPosY(), -GetVelX(), 0))
			SetPosX(GetPosX() - GetVelX());
		else
		{
			if(TileManager::GetInstance()->CheckBlockedTiles(GetPosX(), GetPosY(), 0, GetVelY()))
				SetPosY(GetPosY() + GetVelY());
			else if(TileManager::GetInstance()->CheckBlockedTiles(GetPosX(), GetPosY(), 0, -GetVelY()))
				SetPosY(GetPosY() - GetVelY());
			else
			{
				SetPosX(m_fStartPosX);
				SetPosY(m_fStartPosY);
			}
		}
		if(TileManager::GetInstance()->CheckBlockedTiles(GetPosX(), GetPosY(), 0, GetVelY()))
			SetPosY(GetPosY() + GetVelY());
		else if(TileManager::GetInstance()->CheckBlockedTiles(GetPosX(), GetPosY(), 0, -GetVelY()))
			SetPosY(GetPosY() - GetVelY());
		if(GetPosX() < 0)
			SetPosX(0);

		if(cooldown <= 0)
		{
			if((GetPosX() - tar_pos_x) < 120 && (GetPosX() - tar_pos_x) > -64 )
			{
				if(GetPosY() - tar_pos_y < 16 && GetPosY() - tar_pos_y > -16)
				{
					GetAnimInfo()->SetAnimationName(m_vAttacks[rand() % 4]);
					m_bAttacking = true;
					cooldown = 3.0f;
				}
			}
		}
		else
			cooldown -= fElapsedTime;

		//Update/use move away
		if(m_fUpdateOldPos >= 0.5f)
		{
			if(m_fPosXOld + 5 > GetPosX() && m_fPosXOld - 5 < GetPosX())
			{
				if(m_fPosYOld + 5 > GetPosY() && m_fPosYOld - 5 < GetPosY())
				{
					//if(!m_bRushing)
					{
						m_bEvadeUp = !m_bEvadeUp;
						if(m_fMoveAway <= 0)
							m_fMoveAway = 3.0f;
					}
				}
			}
			m_fPosXOld = GetPosX();
			m_fPosYOld = GetPosY();
			m_fUpdateOldPos = 0.0f;
		}
	}
}
Ejemplo n.º 18
0
void CGrunt::Update(float fElapsedTime)
{
	// Update common properties across all enemies
	CEnemy::Update(fElapsedTime);

	// if this enemy is cc'd don't 
	if (m_pEState->GetTimer() == true)
	{
		m_pEState->CEntityState::Update(fElapsedTime);
		return;
	}

	m_fUpdateOldPos += fElapsedTime;
	if( cooldown <= 0.0f )
		punching = false;

	if( punching == true )
		cooldown -= fElapsedTime;

	if (GetAnimInfo()->GetAnimationName() == "Grunt_Attack_Animation")
		return;

	if(GetTarget() != nullptr)
	{
		float tar_pos_x = GetTarget()->GetPosX();
		float tar_pos_y = GetTarget()->GetPosY();
		if(tar_pos_x > GetPosX())
		{
			//set Grunt's animation's facing to the right
			m_bFlipped = true;
		}
		else
		{
			// Set Grunt's animation to face to the left
			m_bFlipped = false;
		}

		SetFlipped( m_bFlipped );


		if(m_fMoveAway <= 0)
		{
			tar_pos_x += (m_bFlipped) ? -66 : 66;

			//Simple Pathing twards the player
			if(tar_pos_y != GetPosY() )//Above the Player
			{
				float min_Distance = (float)(GetTarget()->GetWidth()/2 + GetWidth()/2);
				if(GetPosX() + min_Distance > tar_pos_x && GetPosX() - min_Distance < tar_pos_x)
				{
					if( tar_pos_x < GetPosX())

						SetVelX(speed * fElapsedTime);
					else

						SetVelX(-speed * fElapsedTime);
				}
				else
				{
					if( tar_pos_y < GetPosY())

						SetVelY(-speed * fElapsedTime);
					else

						SetVelY(speed * fElapsedTime);
					if( tar_pos_x < GetPosX())

						SetVelX(-speed * fElapsedTime);
					else

						SetVelX(speed * fElapsedTime);
				}
			}
			else
			{
				SetVelY(0);
				if( tar_pos_x < GetPosX())

					SetVelX(-speed * fElapsedTime);
				else

					SetVelX(speed * fElapsedTime);
			}

			//stop 'bouncing'
			int threshold = 5;
			if(tar_pos_x - GetPosX() < threshold && tar_pos_x - GetPosX() > -1 * threshold)
				SetVelX(0);
			if(tar_pos_y - GetPosY() < threshold && tar_pos_y - GetPosY() > -1 * threshold)
				SetVelY(0);
		}
		else//update move away
		{
			m_fMoveAway -= fElapsedTime;
			if(m_bEvadeUp)
				SetVelY(-speed * fElapsedTime);
			else
				SetVelY(speed * fElapsedTime);
		}
		//Check Colider
		if(TileManager::GetInstance()->CheckBlockedTiles(GetPosX(), GetPosY(), GetVelX(), 0))
		{
			SetPosX(GetPosX() + GetVelX());
			if(TileManager::GetInstance()->CheckBlockedTiles(GetPosX(), GetPosY(), 0, GetVelY()))
				SetPosY(GetPosY() + GetVelY());
		}
		else
		{
			if( GetPosY() >= 600 )
				SetPosY( (GetPosY() - (GetPosY() - 599)) );
			else
				SetPosY(GetPosY() + 1);
			SetVelX(0);
			SetVelY(0);
		}
		if(GetPosX() < 0)
			SetPosX(0);
		if(punching == false && GetPosX() - tar_pos_x < 10 && GetPosX() - tar_pos_x > - 10 )
		{
			if(GetPosY() - tar_pos_y < 32 && GetPosY() - tar_pos_y > -32)
			{
				GetAnimInfo()->SetAnimationName("Grunt_Attack_Animation");
				punching = true;
				cooldown = 3.0f;
			}
		}
		//Set/use Move out of the way
		if(m_fUpdateOldPos >= 1.0f)
		{
			if(m_fPosXOld + 5 > GetPosX() && m_fPosXOld - 5 < GetPosX())
			{
				if(m_fPosYOld + 5 > GetPosY() && m_fPosYOld - 5 < GetPosY())
				{
					if(cooldown <= 0)
					{
						m_bEvadeUp = !m_bEvadeUp;
						if(m_fMoveAway <= 0)
							m_fMoveAway = 4.0f;
					}
				}
			}
			m_fPosXOld = GetPosX();
			m_fPosYOld = GetPosY();
			m_fUpdateOldPos = 0.0f;
		}
	}

	
}