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 CCrossBow::Render(PointD nPos) { SetPosX(nPos.x); SetPosY(nPos.y); CBaseCharacter::Render(); }
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)); }
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); }
void CCrossBow::Render(PointD nPos,DWORD WHICHCOLORYOUWANTHIMTOGLOWBRO) { SetPosX(nPos.x); SetPosY(nPos.y); CBaseCharacter::Render(WHICHCOLORYOUWANTHIMTOGLOWBRO); }
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 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); } } }
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); }
//////////////////////////////////////////////////////// // 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); }
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()); } }
// ---------------------------------------------------------------------------- // Name : ResetPosition() // Desc : // ---------------------------------------------------------------------------- void CUIChildQuickSlot::ResetPosition( PIX pixMinI, PIX pixMinJ, PIX pixMaxI, PIX pixMaxJ ) { int nX = (pixMaxI - this->GetPosX()) - m_nWidth; int nY = (pixMaxJ - this->GetPosY()) - m_nHeight; int nBaseYGap = 0; BOOL bSave = TRUE; switch(m_nID) { case UI_QUICKSLOT2: { nBaseYGap = 37; if (g_iXPosQuickSlotEX1 == 0 && g_iYPosQuickSlotEX1 == 0) { m_nStartX = pixMaxI - m_nWidth; m_nStartY = pixMaxJ - m_nHeight - 44/*QUICKSLOT_HEIGHT*/; bSave = FALSE; } break; } case UI_QUICKSLOT3: { nBaseYGap = 74; if (g_iXPosQuickSlotEX2 == 0 && g_iYPosQuickSlotEX2 == 0) { m_nStartX = pixMaxI - m_nWidth; m_nStartY = pixMaxJ - m_nHeight - 44/*QUICKSLOT_HEIGHT*/ - CHILD_QUICKSLOT_HEIGHT; bSave = FALSE; } break; } } if (nX > 0 && nY > 0) { return; } else if (nX < 0 && nY > 0) { SetPos(this->GetPosX() + nX, this->GetPosY() - nBaseYGap); } else if (nX > 0 && nY < 0) { SetPosY(this->GetPosY() + nY - nBaseYGap); } else { SetPos(this->GetPosX() + nX, this->GetPosY() + nY - nBaseYGap); } if (bSave) { SetPosEXQSlot(); } }
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()"); }
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); }
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; }
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); }
void CDeathPirate::Update(float fElapsedTime) { CIdleEnemy::Update(fElapsedTime); m_fTimeWaited += fElapsedTime; if(GetGround()) { SetBaseVelY(0); } else { SetBaseVelY(GetBaseVelY() + 50*fElapsedTime); if(GetBaseVelY() > 75) SetBaseVelY(75); SetPosY(GetPosY() + GetBaseVelY() *fElapsedTime); } switch(ReturnAIState()) { case Idle: GetAnimations()->SetCurrentAnimation(0); break; case iActive: if(m_fTimeWaited >= 15.0f && !GetCulling()) { m_fTimeWaited = 0.0f; if(Spawn_01 == NULL) { CGame::GetInstance()->GetMessageSystemPointer()->SendMsg(new CCreateEnemyMessage(6, (int)GetPosX()-100, (int)GetPosY()-150, NULL)); } else if(Spawn_02 == NULL) { CGame::GetInstance()->GetMessageSystemPointer()->SendMsg(new CCreateEnemyMessage(6, (int)GetPosX()+GetWidth()+150, (int)GetPosY()-150, NULL)); } } GetAnimations()->SetCurrentAnimation(1); if(!GetAnimations()->SameFrame() && GetAnimations()->GetTrigger() != 0) { CGame::GetInstance()->GetMessageSystemPointer()->SendMsg(new CCreateBulletMessage(this)); } break; case iDead: ReleaseSpawner(); CGame::GetInstance()->GetMessageSystemPointer()->SendMsg(new CDestroyEnemyMessage((CBaseEnemy*)this)); CSinglePlayerState::GetInstance()->SetWin(true); break; }; }
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; }
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" ); } }
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; } }
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 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); } }
// 移动形状一定的位移 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; }
void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) { int PosY = (int)floor(GetPosY()); if ((PosY <= 0) || (PosY >= cChunkDef::Height)) { // Outside the world, just process normal falling physics super::HandlePhysics(a_Dt, a_Chunk); BroadcastMovementUpdate(); return; } int RelPosX = (int)floor(GetPosX()) - a_Chunk.GetPosX() * cChunkDef::Width; int RelPosZ = (int)floor(GetPosZ()) - a_Chunk.GetPosZ() * cChunkDef::Width; cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); if (Chunk == NULL) { // Inside an unloaded chunk, bail out all processing return; } BLOCKTYPE BelowType = Chunk->GetBlock(RelPosX, PosY - 1, RelPosZ); BLOCKTYPE InsideType = Chunk->GetBlock(RelPosX, PosY, RelPosZ); if (IsBlockRail(BelowType)) { HandleRailPhysics(a_Dt, *Chunk); } else { if (IsBlockRail(InsideType)) { SetPosY(PosY + 1); HandleRailPhysics(a_Dt, *Chunk); } else { super::HandlePhysics(a_Dt, *Chunk); BroadcastMovementUpdate(); } } }
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); }
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 cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) { // Initialise to 'slow down' values int AccelDecelSpeed = -2; int AccelDecelNegSpeed = 2; if ((a_RailMeta & 0x8) == 0x8) { // Rail powered - set variables to 'speed up' values AccelDecelSpeed = 1; AccelDecelNegSpeed = -1; } switch (a_RailMeta & 0x07) { case E_META_RAIL_ZM_ZP: // NORTHSOUTH { SetYaw(270); SetPosY(floor(GetPosY()) + 0.55); SetSpeedY(0); SetSpeedX(0); bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; if (GetSpeedZ() != 0) { if (GetSpeedZ() > 0) { AddSpeedZ(AccelDecelSpeed); } else { AddSpeedZ(AccelDecelNegSpeed); } } break; } case E_META_RAIL_XM_XP: // EASTWEST { SetYaw(180); SetPosY(floor(GetPosY()) + 0.55); SetSpeedY(0); SetSpeedZ(0); bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; if (GetSpeedX() != 0) { if (GetSpeedX() > 0) { AddSpeedX(AccelDecelSpeed); } else { AddSpeedX(AccelDecelNegSpeed); } } break; } case E_META_RAIL_ASCEND_XM: // ASCEND EAST { SetYaw(180); SetSpeedZ(0); if (GetSpeedX() >= 0) { if (GetSpeedX() <= MAX_SPEED) { AddSpeedX(AccelDecelSpeed); SetSpeedY(-GetSpeedX()); } } else { AddSpeedX(AccelDecelNegSpeed); SetSpeedY(-GetSpeedX()); } break; } case E_META_RAIL_ASCEND_XP: // ASCEND WEST { SetYaw(180); SetSpeedZ(0); if (GetSpeedX() > 0) { AddSpeedX(AccelDecelSpeed); SetSpeedY(GetSpeedX()); } else { if (GetSpeedX() >= MAX_SPEED_NEGATIVE) { AddSpeedX(AccelDecelNegSpeed); SetSpeedY(GetSpeedX()); } } break; } case E_META_RAIL_ASCEND_ZM: // ASCEND NORTH { SetYaw(270); SetSpeedX(0); if (GetSpeedZ() >= 0) { if (GetSpeedZ() <= MAX_SPEED) { AddSpeedZ(AccelDecelSpeed); SetSpeedY(-GetSpeedZ()); } } else { AddSpeedZ(AccelDecelNegSpeed); SetSpeedY(-GetSpeedZ()); } break; } case E_META_RAIL_ASCEND_ZP: // ASCEND SOUTH { SetYaw(270); SetSpeedX(0); if (GetSpeedZ() > 0) { AddSpeedZ(AccelDecelSpeed); SetSpeedY(GetSpeedZ()); } else { if (GetSpeedZ() >= MAX_SPEED_NEGATIVE) { AddSpeedZ(AccelDecelNegSpeed); SetSpeedY(GetSpeedZ()); } } break; } default: ASSERT(!"Unhandled powered rail metadata!"); break; } }
void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) { /* NOTE: Please bear in mind that taking away from negatives make them even more negative, adding to negatives make them positive, etc. */ switch (a_RailMeta) { case E_META_RAIL_ZM_ZP: // NORTHSOUTH { SetYaw(270); SetPosY(floor(GetPosY()) + 0.55); SetSpeedY(0); // Don't move vertically as on ground SetSpeedX(0); // Correct diagonal movement from curved rails // Execute both the entity and block collision checks bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; if (GetSpeedZ() != 0) // Don't do anything if cart is stationary { if (GetSpeedZ() > 0) { // Going SOUTH, slow down AddSpeedZ(-0.1); } else { // Going NORTH, slow down AddSpeedZ(0.1); } } break; } case E_META_RAIL_XM_XP: // EASTWEST { SetYaw(180); SetPosY(floor(GetPosY()) + 0.55); SetSpeedY(0); SetSpeedZ(0); bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; if (GetSpeedX() != 0) { if (GetSpeedX() > 0) { AddSpeedX(-0.1); } else { AddSpeedX(0.1); } } break; } case E_META_RAIL_ASCEND_ZM: // ASCEND NORTH { SetYaw(270); SetSpeedX(0); if (GetSpeedZ() >= 0) { // SpeedZ POSITIVE, going SOUTH if (GetSpeedZ() <= MAX_SPEED) // Speed limit { AddSpeedZ(0.5); // Speed up SetSpeedY(-GetSpeedZ()); // Downward movement is negative (0 minus positive numbers is negative) } } else { // SpeedZ NEGATIVE, going NORTH AddSpeedZ(1); // Slow down SetSpeedY(-GetSpeedZ()); // Upward movement is positive (0 minus negative number is positive number) } break; } case E_META_RAIL_ASCEND_ZP: // ASCEND SOUTH { SetYaw(270); SetSpeedX(0); if (GetSpeedZ() > 0) { // SpeedZ POSITIVE, going SOUTH AddSpeedZ(-1); // Slow down SetSpeedY(GetSpeedZ()); // Upward movement positive } else { if (GetSpeedZ() >= MAX_SPEED_NEGATIVE) // Speed limit { // SpeedZ NEGATIVE, going NORTH AddSpeedZ(-0.5); // Speed up SetSpeedY(GetSpeedZ()); // Downward movement negative } } break; } case E_META_RAIL_ASCEND_XM: // ASCEND EAST { SetYaw(180); SetSpeedZ(0); if (GetSpeedX() >= 0) { if (GetSpeedX() <= MAX_SPEED) { AddSpeedX(0.5); SetSpeedY(-GetSpeedX()); } } else { AddSpeedX(1); SetSpeedY(-GetSpeedX()); } break; } case E_META_RAIL_ASCEND_XP: // ASCEND WEST { SetYaw(180); SetSpeedZ(0); if (GetSpeedX() > 0) { AddSpeedX(-1); SetSpeedY(GetSpeedX()); } else { if (GetSpeedX() >= MAX_SPEED_NEGATIVE) { AddSpeedX(-0.5); SetSpeedY(GetSpeedX()); } } break; } case E_META_RAIL_CURVED_ZM_XM: // Ends pointing NORTH and WEST { SetYaw(315); // Set correct rotation server side SetPosY(floor(GetPosY()) + 0.55); // Levitate dat cart SetSpeedY(0); TestBlockCollision(a_RailMeta); TestEntityCollision(a_RailMeta); // SnapToRail handles turning break; } case E_META_RAIL_CURVED_ZM_XP: // Curved NORTH EAST { SetYaw(225); SetPosY(floor(GetPosY()) + 0.55); SetSpeedY(0); TestBlockCollision(a_RailMeta); TestEntityCollision(a_RailMeta); break; } case E_META_RAIL_CURVED_ZP_XM: // Curved SOUTH WEST { SetYaw(135); SetPosY(floor(GetPosY()) + 0.55); SetSpeedY(0); TestBlockCollision(a_RailMeta); TestEntityCollision(a_RailMeta); break; } case E_META_RAIL_CURVED_ZP_XP: // Curved SOUTH EAST { SetYaw(45); SetPosY(floor(GetPosY()) + 0.55); SetSpeedY(0); TestBlockCollision(a_RailMeta); TestEntityCollision(a_RailMeta); break; } default: { ASSERT(!"Unhandled rail meta!"); // Dun dun DUN! break; } } }
void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) { if (IsDestroyed()) // Mainly to stop detector rails triggering again after minecart is dead { return; } int PosY = POSY_TOINT; if ((PosY <= 0) || (PosY >= cChunkDef::Height)) { // Outside the world, just process normal falling physics super::HandlePhysics(a_Dt, a_Chunk); BroadcastMovementUpdate(); return; } int RelPosX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; int RelPosZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); if (Chunk == NULL) { // Inside an unloaded chunk, bail out all processing return; } BLOCKTYPE InsideType; NIBBLETYPE InsideMeta; Chunk->GetBlockTypeMeta(RelPosX, PosY, RelPosZ, InsideType, InsideMeta); if (!IsBlockRail(InsideType)) { Chunk->GetBlockTypeMeta(RelPosX, PosY + 1, RelPosZ, InsideType, InsideMeta); // When an descending minecart hits a flat rail, it goes through the ground; check for this if (IsBlockRail(InsideType)) AddPosY(1); // Push cart upwards } bool WasDetectorRail = false; if (IsBlockRail(InsideType)) { if (InsideType == E_BLOCK_RAIL) { SnapToRail(InsideMeta); } else { SnapToRail(InsideMeta & 0x07); } switch (InsideType) { case E_BLOCK_RAIL: HandleRailPhysics(InsideMeta, a_Dt); break; case E_BLOCK_ACTIVATOR_RAIL: break; case E_BLOCK_POWERED_RAIL: HandlePoweredRailPhysics(InsideMeta); break; case E_BLOCK_DETECTOR_RAIL: { HandleDetectorRailPhysics(InsideMeta, a_Dt); WasDetectorRail = true; break; } default: VERIFY(!"Unhandled rail type despite checking if block was rail!"); break; } AddPosition(GetSpeed() * (a_Dt / 1000)); // Commit changes; as we use our own engine when on rails, this needs to be done, whereas it is normally in Entity.cpp } else { // Not on rail, default physics SetPosY(floor(GetPosY()) + 0.35); // HandlePhysics overrides this if minecart can fall, else, it is to stop ground clipping minecart bottom when off-rail super::HandlePhysics(a_Dt, *Chunk); } if (m_bIsOnDetectorRail && !Vector3i(POSX_TOINT, POSY_TOINT, POSZ_TOINT).Equals(m_DetectorRailPosition)) { m_World->SetBlock(m_DetectorRailPosition.x, m_DetectorRailPosition.y, m_DetectorRailPosition.z, E_BLOCK_DETECTOR_RAIL, m_World->GetBlockMeta(m_DetectorRailPosition) & 0x07); m_bIsOnDetectorRail = false; } else if (WasDetectorRail) { m_bIsOnDetectorRail = true; m_DetectorRailPosition = Vector3i(POSX_TOINT, POSY_TOINT, POSZ_TOINT); } // Broadcast positioning changes to client BroadcastMovementUpdate(); }