Esempio 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);
  }
Esempio 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));

}
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);
}
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));

}
Esempio n. 6
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);
}
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);
}
Esempio n. 8
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 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);
}
Esempio n. 10
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;
		}
	}
}
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 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));
    }

}
void CBase::Update(float fElapsedTime)
{
	SetPosX( GetPosX() + GetVelX() * fElapsedTime );
	SetPosY( GetPosY() + GetVelY() * fElapsedTime );
}
Esempio n. 15
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;
	}

}
Esempio n. 16
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;
		}
	}

	
}