void Player::Respawn() { if (IsDead() == false) { return; } m_position = m_respawnPosition; // Make sure we create a chunk in the respawn position UpdateGridPosition(); m_pChunkManager->CreateNewChunk(GetGridX(), GetGridY(), GetGridZ()); m_health = m_maxHealth; VoxGame::GetInstance()->GetHUD()->UpdatePlayerData(); // Also go through all the equipped items and equip them for (int i = 0; i < EquipSlot_NumSlots; i++) { InventoryItem* pItem = m_pInventoryManager->GetInventoryItemForEquipSlot((EquipSlot)i); if (pItem != NULL) { EquipItem(pItem, true); } } m_dead = false; }
// Updating void Player::Update(float dt) { // Update grid position UpdateGridPosition(); // Update the voxel model float animationSpeeds[AnimationSections_NUMSECTIONS] = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; m_pVoxelCharacter->Update(dt, animationSpeeds); m_pVoxelCharacter->SetWeaponTrailsOriginMatrix(dt, m_worldMatrix); // Update animations UpdateAnimations(dt); // Update / Create weapon lights and particle effects UpdateWeaponLights(dt); UpdateWeaponParticleEffects(dt); // Update timers UpdateTimers(dt); // Physics update UpdatePhysics(dt); }
// Update void Item::Update(float dt) { if(m_erase) { return; } if(m_pVoxelItem != NULL) { m_pVoxelItem->Update(dt); } // Update grid position UpdateGridPosition(); // Update timers UpdateTimers(dt); // Update player magnet UpdatePlayerMagnet(dt); // If we don't belong to a chunk if(m_pCachedGridChunk == NULL) { return; } // Make sure that an owning chunk knows about us if(m_pOwningChunk == NULL || m_pOwningChunk->IsInsideChunk(m_position) == false) { if(m_pOwningChunk != NULL) { m_pOwningChunk->RemoveItem(this); } m_pOwningChunk = m_pChunkManager->GetChunkFromPosition(m_position.x, m_position.y, m_position.z); if(m_pOwningChunk != NULL) { m_pOwningChunk->AddItem(this); } else { //SetErase(true); } return; } // Auto disappear if(m_autoDisappear) { if(m_autoDisappearTimer <= 0.0f) { SetErase(true); return; } } // Update physics UpdatePhysics(dt); }