From 86bfed735e28fe86ec40e89e59eb868c4a0a9b19 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 19 Dec 2013 17:32:06 +0100 Subject: Added cFloater class. --- src/Entities/Floater.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/Entities/Floater.cpp (limited to 'src/Entities/Floater.cpp') diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp new file mode 100644 index 000000000..ebbf72b63 --- /dev/null +++ b/src/Entities/Floater.cpp @@ -0,0 +1,58 @@ +#include "Globals.h" + +#include "Floater.h" +#include "Player.h" +#include "../Clienthandle.h" + +cFloater::cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID) : + cEntity(etFloater, a_X, a_Y, a_Z, 0.98, 0.98), + m_PlayerID(a_PlayerID), + m_CanPickupItem(false), + m_PickupCountDown(0) +{ + SetSpeed(a_Speed); +} + + + + + +void cFloater::SpawnOn(cClientHandle & a_Client) +{ + a_Client.SendSpawnObject(*this, 90, m_PlayerID, 0, 0); +} + + + + + +void cFloater::Tick(float a_Dt, cChunk & a_Chunk) +{ + HandlePhysics(a_Dt, a_Chunk); + if (IsBlockWater(m_World->GetBlock((int) GetPosX(), (int) GetPosY(), (int) GetPosZ()))) + { + if (m_World->GetTickRandomNumber(100) == 0) + { + SetSpeedY(-1); + m_CanPickupItem = true; + m_PickupCountDown = 20; + LOGD("Floater %i can be picked up", GetUniqueID()); + } + else + { + SetSpeedY(1); + } + } + SetSpeedX(GetSpeedX() * 0.95); + SetSpeedZ(GetSpeedZ() * 0.95); + if (CanPickup()) + { + m_PickupCountDown--; + if (m_PickupCountDown == 0) + { + m_CanPickupItem = false; + LOGD("The fish is gone. Floater %i can not pick an item up.", GetUniqueID()); + } + } + BroadcastMovementUpdate(); +} \ No newline at end of file -- cgit v1.2.3