void CPowerupRapidFire::HandleEvent(CEvent *pEvent)
{
	if (pEvent->GetEventID() == "scroll right")
		SetPosX(GetPosX() - (5 * CGame::GetInstance()->GetSpeed()));
	else if (pEvent->GetEventID() == "scroll left")
		SetPosX(GetPosX() + (5 * CGame::GetInstance()->GetSpeed()));
}
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));

}
示例#3
0
void CCrossBow::Render(PointD nPos,DWORD WHICHCOLORYOUWANTHIMTOGLOWBRO)
{
	SetPosX(nPos.x);
	SetPosY(nPos.y);

	CBaseCharacter::Render(WHICHCOLORYOUWANTHIMTOGLOWBRO);
}
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));

}
示例#5
0
void CHuman::Update(float fElapsedTime)
{
	CEnemy::Update( fElapsedTime );

	m_nCollisionWithStaticObjectsSphere.m_Center = tVector2D(GetPosX(), GetPosY());


	for( unsigned int i = 0; i < CGamePlayState::GetInstance()->m_StoreWalls.size(); i++)
	{
		Capsule* temp = CGamePlayState::GetInstance()->m_StoreWalls[i];
		tVector2D ClosestPoint = ClosestPointOnALine(temp->GetStartPoint(), temp->GetEndPoint(), tVector2D( GetPosX(), GetPosY()));

		// Create a circle based on clsoest point with capsule radius
		Circle testCircle;
		testCircle.m_Center = ClosestPoint;
		testCircle.m_fRadius = temp->GetRadius();

		if( GetSphere()->CheckCollision(testCircle) )
		{
			tVector2D sphere2_to_1 = GetSphere()->m_Center - testCircle.m_Center;
			sphere2_to_1 = Vector2DNormalize(sphere2_to_1);
			float dist = GetSphere()->m_fRadius + testCircle.m_fRadius;
			tVector2D scaler = (sphere2_to_1 * (dist * 0.01f));
			tVector2D newpos = GetSphere()->m_Center + scaler;

			SetPosX(newpos.fX);
			SetPosY(newpos.fY);
		}
	}
}
示例#6
0
void CCrossBow::Render(PointD nPos)
{
	SetPosX(nPos.x);
	SetPosY(nPos.y);

	CBaseCharacter::Render();
}
CSDLStateShowText::CSDLStateShowText( const string& sText, const string& sOnExitScript )
{
	DebugInfo( TypeCreate, "Creating text box." );
	m_sOnExitScript = sOnExitScript;

	m_pText = new CSDLMultilineTextObject( string("Dialog"), sText );
	
	SDL_Color stBlueish = { 100, 100, 255 };
	SDL_Color stWhite	= { 255, 255, 255 };

	m_pButtonOkay = new CSDLCenterTextObject( "GameDefault", "Close", stBlueish, stWhite );

	int iWidth = m_pText->GetWidth();
	int iHeight = m_pText->GetHeight();

	SetPosX( (800 / 2) - (iWidth / 2) );
	SetPosY( (600 / 2) - ((iHeight + 10 + m_pButtonOkay->GetHeight()) / 2) );

	m_pText->SetPos( GetPosX(), GetPosY() );

	int iButtonTop = (m_iPosY + iHeight) + 10;
	if ( (iButtonTop + m_pButtonOkay->GetHeight()) > 600 )
		iButtonTop = 600 - m_pButtonOkay->GetHeight() - 5;

	m_pButtonOkay->SetPos( GetPosX() + iWidth / 2, iButtonTop );
	m_pButtonOkay->SetCallbackContainer( this );

	m_stContainerRect = m_pText->GetRect();
	m_stContainerRect.x -= 5;
	m_stContainerRect.y -= 5;
	m_stContainerRect.w += 10;
	m_stContainerRect.h = m_pButtonOkay->GetButtom() + 5 - m_stContainerRect.y;
}
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;
	}
}
CEnemyDemon::CEnemyDemon()
{
    COptions *op = COptions::GetInstance();
    CSGD_EventSystem *pES = CSGD_EventSystem::GetInstance();

    SetHP(25 * op->GetDifficulty());
    SetVelX(100.0f * op->GetDifficulty());
    SetVelY(100.0f * op->GetDifficulty());
    SetXFlip(-1);
    SetHeight(64);
    SetWidth(64);
    SetPosX(500);
    SetPosY(500);
    SetType(ACTOR_ENEMY);
    SetPower(5 * op->GetDifficulty());
    SetScoreValue(100 * op->GetDifficulty());
    SetHit(false);

    rEnemyRect.top = 65;
    rEnemyRect.bottom = 123;
    rEnemyRect.left = 0;
    rEnemyRect.right = 60;

    m_nSoundID = CSGD_WaveManager::GetInstance()->LoadWave("Resource/sounds/JoA_Bark.wav");
    CSGD_WaveManager::GetInstance()->SetVolume(m_nSoundID,COptions::GetInstance()->GetSFXVolume()-40);


}
示例#10
0
void CCursor::Update(float fElapsedTime)
{
	SetType(OBJECT_CURSOR);
	CSGD_DirectInput* pDI = CSGD_DirectInput::GetInstance();
	SetPosX((float)GetPosX()+(pDI->MouseMovementX()*0.5f));
	SetPosY((float)GetPosY()+(pDI->MouseMovementY()*0.5f));

	if(GetPosX() < 0)
		SetPosX(0);
	else if((unsigned int)GetPosX() > CSGD_Direct3D::GetInstance()->GetPresentParams()->BackBufferWidth)
		SetPosX((float)CSGD_Direct3D::GetInstance()->GetPresentParams()->BackBufferWidth);
	if(GetPosY() < 0)
		SetPosY(0);
	else if((unsigned int)GetPosY() > CSGD_Direct3D::GetInstance()->GetPresentParams()->BackBufferHeight)
		SetPosY((float)CSGD_Direct3D::GetInstance()->GetPresentParams()->BackBufferHeight);
		
}
示例#11
0
void CJeep::HandleEvent( CEvent* pEvent )
{
	CPlayer* pPlayer = CPlayer::GetInstance();

	if(pEvent->GetEventID() == "Change_Position" && pEvent->GetParam() == this)
	{
		SetPosX(-200.0f);
		SetPosY(-200.0f);
	}

	if(pEvent->GetEventID() == "Spawn_Jeep" && pEvent->GetParam() == this)
	{
		SetPosX(pPlayer->GetPosX()+20);
		SetPosY(pPlayer->GetPosY());
		SetDirection(CJeepState::GetInstance()->GetDirectionX(), CJeepState::GetInstance()->GetDirectionY());
		SetRotation(CJeepState::GetInstance()->GetRotation());
	}
}
示例#12
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);
}
示例#13
0
文件: Projectile.cpp 项目: Esseh/Misc
Projectile::Projectile(float px, float py, float pDirection, float pVelocity, float pDamage, sf::Texture mSpriteTexture)
{
    CalculateVelocities(pDirection, pVelocity);

    SetDamage(pDamage);
    SetTexture(mSpriteTexture);
    SetDirection(pDirection);
    SetPosX(px);
    SetPosY(py);
}
示例#14
0
CBase::CBase(void)
{
	PROFILE("CBase::CBase()");
	m_unRefCount = 1;	//	Always start with a reference to yourself
	SetPosX( 0.0f );
	SetPosY( 0.0f );
	SetVelX( 1.0f );
	SetVelY( 1.0f );
	STOP("CBase::CBase()");
}
示例#15
0
CShape::CShape(void)
{
	m_lRegionID = 0;
	SetPosX(0.0f);
	SetPosY(0.0f);
	SetDir(0);
	SetPos(0);
	SetSpeed(2000.f);
	SetState(STATE_PEACE);
	SetAction(ACT_STAND);
	m_CurRgnType = RGN_NORMAL;
}
示例#16
0
CCursor::CCursor(void)
{
	SetCoverObject(false);
	SetImageID(CSGD_TextureManager::GetInstance()->LoadTexture("Resource/Graphics/Crosshair.png"));

	SetPosX(100.0f);
	SetPosY(100.0f);

	SetLayer(0);
	SetWidth(32);
	SetHeight(32);
}
示例#17
0
void CBullet::SetOwner(CBase* pOwner)
{
	if(m_pOwner != NULL)
	{
		m_pOwner->Release();
	}
	m_pOwner = pOwner;
	if(m_pOwner != NULL)
	{
		SetPosX(m_pOwner->GetPosX() + m_pOwner->GetWidth() / 2);
		SetPosY(m_pOwner->GetPosY() + m_pOwner->GetHeight() / 2);		
		m_pOwner->AddRef();
	}
}
bool		CSummonVolatileGhoul::SetSummonPosition ( void )
{
	int posX = (int)GetOwner()->GetPosX() / 32;
	int posY = (int)GetOwner()->GetPosY() / 32;
	pSummon->GetEffect(0)->KillParticles();

	if(CBattlePlay::GetInstance()->GetGrid()->GetATile(posY,posX - 1)->GetOccupied() == false)
	{
		SetPosX((posX - 1) * 32);
		SetPosY(posY * 32);

		return true;
	}
	else if(CBattlePlay::GetInstance()->GetGrid()->GetATile(posY -1 ,posX)->GetOccupied() == false)
	{
		SetPosX(posX * 32);
		SetPosY((posY - 1) * 32);

		return true;
	}
	else if(CBattlePlay::GetInstance()->GetGrid()->GetATile(posY + 1,posX)->GetOccupied() == false)
	{
		SetPosX(posX * 32);
		SetPosY((posY + 1) * 32);

		return true;
	}
	else if(CBattlePlay::GetInstance()->GetGrid()->GetATile(posY,posX + 1)->GetOccupied() == false)
	{
		SetPosX((posX + 1) * 32);
		SetPosY(posY * 32);

		return true;
	}

	return false;
}
示例#19
0
void CGuard::Update(float fElapsedTime)
{

	if(CheckForPlayer())
	{
		ComputeMovement(fElapsedTime);
		this->addTime(fElapsedTime);
		CBase::Update(fElapsedTime);
	}
	else
		CEnemy::Update( fElapsedTime );

	m_nCollisionWithStaticObjectsSphere.m_Center = tVector2D(GetPosX(), GetPosY());


	for( unsigned int i = 0; i < CGamePlayState::GetInstance()->m_StoreWalls.size(); i++)
	{
		Capsule* temp = CGamePlayState::GetInstance()->m_StoreWalls[i];
		tVector2D ClosestPoint = ClosestPointOnALine(temp->GetStartPoint(), temp->GetEndPoint(), tVector2D( GetPosX(), GetPosY()));

		// Create a circle based on clsoest point with capsule radius
		Circle testCircle;
		testCircle.m_Center = ClosestPoint;
		testCircle.m_fRadius = temp->GetRadius();

		if( GetSphere()->CheckCollision(testCircle) )
		{
			tVector2D sphere2_to_1 = GetSphere()->m_Center - testCircle.m_Center;
			sphere2_to_1 = Vector2DNormalize(sphere2_to_1);
			float dist = GetSphere()->m_fRadius + testCircle.m_fRadius;
			tVector2D scaler = (sphere2_to_1 * (dist * 0.01f));
			tVector2D newpos = GetSphere()->m_Center + scaler;

			SetPosX(newpos.fX);
			SetPosY(newpos.fY);
		}
	}

	if( CSGD_DirectInput::GetInstance()->KeyPressed(DIK_1))
	{
		IsUndead = true;
		AnimManager::GetInstance()->SetAnimation( GetAnimID(), "Zombie Walking" );
	}
	if( CSGD_DirectInput::GetInstance()->KeyPressed(DIK_2))
	{
		IsUndead = false;
		AnimManager::GetInstance()->SetAnimation( GetAnimID(), "Person Walking" );
	}
}
示例#20
0
void CRock_Fall::Update(float fElapsedTime)
{
	AnimationManager::GetInstance()->Update(fElapsedTime, *GetAnimInfo());
	//CEntity::Update(fElapsedTime);
	SetPosX(GetPosX());
	SetPosY(GetPosY() + GetSpeed() * fElapsedTime);
	CCamera* Game_Camera = CCamera::GetInstance();
	if(this->GetPosY() > Game_Camera->GetPosY() + Game_Camera->GetHeight())
	{
		CRemoveEntityMessage* pMsg = new CRemoveEntityMessage(this);
		CSGD_MessageSystem::GetInstance()->SendMsg(pMsg);
		pMsg = nullptr;
	}

}
示例#21
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);
}
示例#22
0
void CEnemy::Update(float fElapsedTime)
{
	// DANIEL CODE BEGIN
	if(IsDead())
	{
		if((timeGetTime() - m_dwDeadTimeStamp) > (m_fRespawnTime * 1000))
		{
			Ressurect();

			SetPosX(m_ptRespawnPosition.x);
			SetPosY(m_ptRespawnPosition.y);
		}
	}
	// DANIEL CODE END
	else
	{
		CBaseCharacter::Update(fElapsedTime);
	}
}
示例#23
0
// 移动形状一定的位移
bool Figure::Translate(const int offsetX, const int offsetY) {

    int i;

    // 次判断每个方块是否可以移动到指定位置
    for (i=0; i<4; ++i){
        if(!data[i].CanTranslate(offsetX, offsetY))
            return false;
    }

    // 分别移动每个方块
    for(i=0; i<4; ++i){
        data[i].Translate(offsetX, offsetY);
    }

    // 设置新的位置
    SetPosX(posX+offsetX);
    SetPosY(posY+offsetY);
    return true;
}
CEnemyPsycrow::CEnemyPsycrow()
{
	CSGD_EventSystem *pES = CSGD_EventSystem::GetInstance();
	CSGD_TextureManager *pTM = CSGD_TextureManager::GetInstance();
	COptions *op = COptions::GetInstance();

	pES->RegisterClient("psycrow fire", this);
	pES->RegisterClient("state transition 1", this);
	pES->RegisterClient("state transition 2", this);
	pES->RegisterClient("state transition 3", this);
	pES->RegisterClient("state transition 4", this);

	m_nState = PSYCROW_STATE1;
	m_nSoundID = CSGD_WaveManager::GetInstance()->LoadWave("Resource/sounds/JoA_Squawk.wav");
	CSGD_WaveManager::GetInstance()->SetVolume(m_nSoundID, op->GetSFXVolume() - 40);
	m_fFireReady = 5.0f;
	m_fHitTimer = 0.4f;
	m_nOffset = 0;
	bIsFired = false;
	m_fFiringTimer = 0.5f;
	m_fSineFloat = 3.14f;
	m_nColor = 255;
	m_nScale = 1.5f;

	SetHP(250 * op->GetDifficulty());
	SetVelX(75 * op->GetDifficulty());
	SetVelY(0.0f);
	SetXFlip(-1);
	SetHeight(84);
	SetWidth(70);
	SetPosX(320);
	SetPosY(240);
	SetPower(0);
	SetType(ACTOR_ENEMY);
	SetScoreValue(1000 * op->GetDifficulty());
	SetHit(false);
	pBullet = NULL;

	bIsFiring = false;

}
CEnemyBusiness::CEnemyBusiness()
{
	CSGD_EventSystem *pES = CSGD_EventSystem::GetInstance();
	CSGD_TextureManager *pTM = CSGD_TextureManager::GetInstance();
	COptions *op = COptions::GetInstance();
	CSGD_WaveManager *pWM = CSGD_WaveManager::GetInstance();

	pES->RegisterClient("businessman fire", this);

	SetHP(50 *op->GetDifficulty());
	SetVelX(-50.0f * op->GetDifficulty());
	SetVelY(0.0f);
	SetXFlip(-1);
	SetHeight(63);
	SetWidth(86);
	SetPosX(1000);
	SetPosY(220);
	SetPower(0);
	SetType(ACTOR_ENEMY);
	SetScoreValue(200 * op->GetDifficulty());
	SetHit(false);
	pBullet = NULL;

	bIsFiring = false;

	m_fFireReady = 5.0f;
	m_fHitTimer = 1.0f;
	m_nOffset = 0;
	m_fFiringTimer = 1.0f;

	rEnemyRect.top = 18;
	rEnemyRect.bottom = 61;
	rEnemyRect.left = 2;
	rEnemyRect.right = 54;

	m_nSoundID = pWM->LoadWave("Resource/sounds/JoA_Scream.wav");
	pWM->SetVolume(m_nSoundID,op->GetSFXVolume() - 25);
	

}
示例#26
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);
}
示例#27
0
bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
{
    switch (a_RailMeta)
    {
    case E_META_RAIL_ZM_ZP:
    {
        if (GetSpeedZ() > 0)
        {
            BLOCKTYPE Block = m_World->GetBlock(POSX_TOINT, POSY_TOINT, (int)ceil(GetPosZ()));
            if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block))
            {
                // We could try to detect a block in front based purely on coordinates, but xoft made a bounding box system - why not use? :P
                cBoundingBox bbBlock(Vector3d(POSX_TOINT, POSY_TOINT, (int)ceil(GetPosZ())), 0.5, 1);
                cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight());

                if (bbBlock.DoesIntersect(bbMinecart))
                {
                    SetSpeed(0, 0, 0);
                    SetPosZ(floor(GetPosZ()) + 0.4);
                    return true;
                }
            }
        }
        else if (GetSpeedZ() < 0)
        {
            BLOCKTYPE Block = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT - 1);
            if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block))
            {
                cBoundingBox bbBlock(Vector3d(POSX_TOINT, POSY_TOINT, POSZ_TOINT - 1), 0.5, 1);
                cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ() - 1), GetWidth() / 2, GetHeight());

                if (bbBlock.DoesIntersect(bbMinecart))
                {
                    SetSpeed(0, 0, 0);
                    SetPosZ(floor(GetPosZ()) + 0.65);
                    return true;
                }
            }
        }
        break;
    }
    case E_META_RAIL_XM_XP:
    {
        if (GetSpeedX() > 0)
        {
            BLOCKTYPE Block = m_World->GetBlock((int)ceil(GetPosX()), POSY_TOINT, POSZ_TOINT);
            if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block))
            {
                cBoundingBox bbBlock(Vector3d((int)ceil(GetPosX()), POSY_TOINT, POSZ_TOINT), 0.5, 1);
                cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight());

                if (bbBlock.DoesIntersect(bbMinecart))
                {
                    SetSpeed(0, 0, 0);
                    SetPosX(floor(GetPosX()) + 0.4);
                    return true;
                }
            }
        }
        else if (GetSpeedX() < 0)
        {
            BLOCKTYPE Block = m_World->GetBlock(POSX_TOINT - 1, POSY_TOINT, POSZ_TOINT);
            if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block))
            {
                cBoundingBox bbBlock(Vector3d(POSX_TOINT - 1, POSY_TOINT, POSZ_TOINT), 0.5, 1);
                cBoundingBox bbMinecart(Vector3d(GetPosX() - 1, floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight());

                if (bbBlock.DoesIntersect(bbMinecart))
                {
                    SetSpeed(0, 0, 0);
                    SetPosX(floor(GetPosX()) + 0.65);
                    return true;
                }
            }
        }
        break;
    }
    case E_META_RAIL_CURVED_ZM_XM:
    case E_META_RAIL_CURVED_ZM_XP:
    case E_META_RAIL_CURVED_ZP_XM:
    case E_META_RAIL_CURVED_ZP_XP:
    {
        BLOCKTYPE BlockXM = m_World->GetBlock(POSX_TOINT - 1, POSY_TOINT, POSZ_TOINT);
        BLOCKTYPE BlockXP = m_World->GetBlock(POSX_TOINT + 1, POSY_TOINT, POSZ_TOINT);
        BLOCKTYPE BlockZM = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT - 1);
        BLOCKTYPE BlockZP = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT + 1);
        if (
            (!IsBlockRail(BlockXM) && cBlockInfo::IsSolid(BlockXM)) ||
            (!IsBlockRail(BlockXP) && cBlockInfo::IsSolid(BlockXP)) ||
            (!IsBlockRail(BlockZM) && cBlockInfo::IsSolid(BlockZM)) ||
            (!IsBlockRail(BlockZP) && cBlockInfo::IsSolid(BlockZP))
        )
        {
            SetSpeed(0, 0, 0);
            SetPosition(POSX_TOINT + 0.5, GetPosY(), POSZ_TOINT + 0.5);
            return true;
        }
        break;
    }
    default:
        break;
    }
    return false;
}
示例#28
0
void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta)
{
    switch (a_RailMeta)
    {
    case E_META_RAIL_ASCEND_XM:
    case E_META_RAIL_ASCEND_XP:
    case E_META_RAIL_XM_XP:
    {
        SetSpeedZ(0);
        SetPosZ(floor(GetPosZ()) + 0.5);
        break;
    }
    case E_META_RAIL_ASCEND_ZM:
    case E_META_RAIL_ASCEND_ZP:
    case E_META_RAIL_ZM_ZP:
    {
        SetSpeedX(0);
        SetPosX(floor(GetPosX()) + 0.5);
        break;
    }
    // Curved rail physics: once minecart has reached more than half of the block in the direction that it is travelling in, jerk it in the direction of curvature
    case E_META_RAIL_CURVED_ZM_XM:
    {
        if (GetPosZ() > floor(GetPosZ()) + 0.5)
        {
            if (GetSpeedZ() > 0)
            {
                SetSpeedX(-GetSpeedZ() * 0.7);
            }

            SetSpeedZ(0);
            SetPosZ(floor(GetPosZ()) + 0.5);
        }
        else if (GetPosX() > floor(GetPosX()) + 0.5)
        {
            if (GetSpeedX() > 0)
            {
                SetSpeedZ(-GetSpeedX() * 0.7);
            }

            SetSpeedX(0);
            SetPosX(floor(GetPosX()) + 0.5);
        }
        SetSpeedY(0);
        break;
    }
    case E_META_RAIL_CURVED_ZM_XP:
    {
        if (GetPosZ() > floor(GetPosZ()) + 0.5)
        {
            if (GetSpeedZ() > 0)
            {
                SetSpeedX(GetSpeedZ() * 0.7);
            }

            SetSpeedZ(0);
            SetPosZ(floor(GetPosZ()) + 0.5);
        }
        else if (GetPosX() < floor(GetPosX()) + 0.5)
        {
            if (GetSpeedX() < 0)
            {
                SetSpeedZ(GetSpeedX() * 0.7);
            }

            SetSpeedX(0);
            SetPosX(floor(GetPosX()) + 0.5);
        }
        SetSpeedY(0);
        break;
    }
    case E_META_RAIL_CURVED_ZP_XM:
    {
        if (GetPosZ() < floor(GetPosZ()) + 0.5)
        {
            if (GetSpeedZ() < 0)
            {
                SetSpeedX(GetSpeedZ() * 0.7);
            }

            SetSpeedZ(0);
            SetPosZ(floor(GetPosZ()) + 0.5);
        }
        else if (GetPosX() > floor(GetPosX()) + 0.5)
        {
            if (GetSpeedX() > 0)
            {
                SetSpeedZ(GetSpeedX() * 0.7);
            }

            SetSpeedX(0);
            SetPosX(floor(GetPosX()) + 0.5);
        }
        SetSpeedY(0);
        break;
    }
    case E_META_RAIL_CURVED_ZP_XP:
    {
        if (GetPosZ() < floor(GetPosZ()) + 0.5)
        {
            if (GetSpeedZ() < 0)
            {
                SetSpeedX(-GetSpeedZ() * 0.7);
            }

            SetSpeedZ(0);
            SetPosZ(floor(GetPosZ()) + 0.5);
        }
        else if (GetPosX() < floor(GetPosX()) + 0.5)
        {
            if (GetSpeedX() < 0)
            {
                SetSpeedZ(-GetSpeedX() * 0.7);
            }

            SetSpeedX(0);
            SetPosX(floor(GetPosX()) + 0.5);
        }
        SetSpeedY(0);
        break;
    }
    default:
        break;
    }
}
示例#29
0
void Player::Update(float eTime)
{
	ZeroIScene::Update(eTime);

	if (!reading)
	{

		if (smalling)
		{
			if (this->scaleY == 1.f)
			{
				this->scaleX = 0.5f;
				this->scaleY = 0.5f;
			}
		}
		else
		{
			if (this->scaleY == 0.5f)
			{
				this->scaleX = 1.f;
				this->scaleY = 1.f;
			}
		}


		if (this->Pos().x <= MaxLeft) // 플레이어가 맵 끝에 도달 했을 때 못나오게 유지
			SetPosX(MaxLeft);
		if (this->Pos().x >= MaxRight)
			SetPosX(MaxRight);

		if (shooting) // 플레이어가 총을 쏠 시 반동같지 않은 반동에 의해 살짝 멈춤
		{
			GeTime += eTime;
			if (GeTime >= 0.5f)
			{
				shooting = false;
				GeTime = 0.f;
			}
		}

		if (reversing) // 중력이 뒤집혔을 때
		{
			if (this->Rot() != 180) // 뒤집혔는지 여부
				this->SetRot(180);

			if (left)
			{
				if (scaleX < 0)
					scaleX *= -1;
				this->SetScale(scaleX, scaleY);
			}
			else
			{
				if (scaleX > 0)
					scaleX *= -1;
				this->SetScale(scaleX, scaleY);
			}

			if (jumping)
			{
				if (JumpNum == 1) // 플레이어가 점프했을 때
				{
					if ((jumpH - JeTime) >= 0.f && JeTime < 650.f)
					{
						this->AddPosY((jumpH - JeTime) * eTime);
						JeTime += 30.f;
					}
					else
					{
						jumping = false;
						falling = true;
					}
				}

				if (JumpNum == 2) // 더블 점프 시
				{
					if ((jumpH - JeTime) >= 0.f && JeTime < 650.f)
					{
						this->AddPosY((jumpH - JeTime) * eTime);
						JeTime += 30.f;
					}
					else
					{
						jumping = false;
						falling = true;
					}
				}
			}

			else if (falling)
			{
				if (Pos().y > 0)
				{
					this->AddPosY(-1 * (jumpH - JeTime) * eTime);
					JeTime -= 30.f;
				}
			}

			else if (Pos().y > 0) // 공중에 있을 시 바닥으로 슈우우웅
			{
				if (!changing && !onBox)
					changing = true;
				this->AddPosY(JeTime * eTime);
				JeTime -= 30.f;
			}

			if (this->Pos().y <= 0) // 플레이어가 점프시 바닥에 착지
			{
				this->SetPosY(0);
				if (jumping)
					jumping = false;
				falling = false;
				JeTime = 0.f;
				JumpNum = 0;
				if (changing)
					changing = false;
			}
		}

		else // 중력이 정상일 때
		{
		if (this->Rot() != 0) // 원래대로 돌아왔는지 여부
			this->SetRot(0);

			if (left)
			{
				if (scaleX > 0)
					scaleX *= -1;
				this->SetScale(scaleX, scaleY);
			}
			else
			{
				if (scaleX < 0)
					scaleX *= -1;
				this->SetScale(scaleX, scaleY);
			}

			if (climbing)
			{
				jumping = false;
				JumpNum = 0;
				JeTime = 0.f;
			}

			if (jumping && !climbing)
			{
				onGround = false;
				if (JumpNum == 1) // 플레이어가 점프했을 때
				{
					if ((jumpH - JeTime) >= 0.f && JeTime < 650.f)
					{
						this->AddPosY(-1 * (jumpH - JeTime) * eTime);
						JeTime += 30.f;
					}
					else
					{
						jumping = false;
						falling = true;
					}
				}

				if (doubleJumping && JumpNum == 2) // 더블 점프 시
				{
					onGround = false;
					if ((jumpH - JeTime) >= 0.f && JeTime < 650.f)
					{
						this->AddPosY(-1 * (jumpH - JeTime) * eTime);
						JeTime += 30.f;
					}
					else
					{
						jumping = false;
						falling = true;
					}
				}
			}

			else if (falling && !climbing && !downJumping)
			{
				if (save[6] == 00)
				{
					if (this->Pos().y < 792 - this->Height())
					{
						this->AddPosY((jumpH - JeTime) * eTime);
						JeTime -= 30.f;
					}
					else if (this->Pos().y < 1490 - this->Height() && this->Pos().y + this->Height() > 812)
					{
						this->AddPosY((jumpH - JeTime) * eTime);
						JeTime -= 30.f;
					}
					else if (this->Pos().y < 2190 - this->Height() && this->Pos().y + this->Height() > 1512)
					{
						this->AddPosY((jumpH - JeTime) * eTime);
						JeTime -= 30.f;
					}
					else if (this->Pos().y < 2890 - this->Height() && this->Pos().y + this->Height() > 2212)
					{
						this->AddPosY((jumpH - JeTime) * eTime);
						JeTime -= 30.f;
					}
				}
				else if (save[6] == 11)
				{
					if (this->Pos().y < 1152 - 80 - this->Height())
					{
						this->AddPosY((jumpH - JeTime) * eTime);
						JeTime -= 30.f;
					}
				}
			}

			else if (!onGround && (!climbing || downJumping)) // 공중에 있을 시 바닥으로 슈우우웅
			{/*
				if (!changing && !onBox)
					changing = true;*/
				this->AddPosY(JeTime * eTime);
				JeTime += 30.f;
			}

			if (onGround) // 플레이어가 바닥에 착지
			{
				falling = false;
				jumping = false;
				changing = false;
				downJumping = false;
				JeTime = 0.f;
				JumpNum = 0;
			}

			if (shooting)
			{
				GeTime += eTime;
				if (GeTime >= 0.5f)
				{
					shooting = false;
					GeTime = 0.f;
				}
			}
		}
	}
}
示例#30
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;
		}
	}
}