summaryrefslogtreecommitdiffstats
path: root/source/Entities/ExpOrb.cpp
diff options
context:
space:
mode:
authorSTRWarrior <niels.breuker@hotmail.nl>2013-11-25 20:05:52 +0100
committerSTRWarrior <niels.breuker@hotmail.nl>2013-11-25 20:05:52 +0100
commit6641db058392dd6d7e170b95cd8616b920add63c (patch)
tree80691f970e071ec8277f5e4f601727d7b86ce4ca /source/Entities/ExpOrb.cpp
parentImplented SendExperienceOrb in ClientHandle. (diff)
downloadcuberite-6641db058392dd6d7e170b95cd8616b920add63c.tar
cuberite-6641db058392dd6d7e170b95cd8616b920add63c.tar.gz
cuberite-6641db058392dd6d7e170b95cd8616b920add63c.tar.bz2
cuberite-6641db058392dd6d7e170b95cd8616b920add63c.tar.lz
cuberite-6641db058392dd6d7e170b95cd8616b920add63c.tar.xz
cuberite-6641db058392dd6d7e170b95cd8616b920add63c.tar.zst
cuberite-6641db058392dd6d7e170b95cd8616b920add63c.zip
Diffstat (limited to '')
-rw-r--r--source/Entities/ExpOrb.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/source/Entities/ExpOrb.cpp b/source/Entities/ExpOrb.cpp
new file mode 100644
index 000000000..200f6e181
--- /dev/null
+++ b/source/Entities/ExpOrb.cpp
@@ -0,0 +1,60 @@
+#include "Globals.h"
+
+#include "ExpOrb.h"
+#include "Player.h"
+#include "../ClientHandle.h"
+
+
+cExpOrb::cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward) :
+ cEntity(etExpOrb, a_X, a_Y, a_Z, 0.98, 0.98),
+ m_Reward(a_Reward)
+{
+}
+
+
+
+
+
+cExpOrb::cExpOrb(const Vector3d & a_Pos, int a_Reward) :
+ cEntity(etExpOrb, a_Pos.x, a_Pos.y, a_Pos.z, 0.98, 0.98),
+ m_Reward(a_Reward)
+{
+}
+
+
+
+
+
+void cExpOrb::SpawnOn(cClientHandle & a_Client)
+{
+ a_Client.SendExperienceOrb(*this);
+ m_bDirtyPosition = false;
+ m_bDirtySpeed = false;
+ m_bDirtyOrientation = false;
+ m_bDirtyHead = false;
+}
+
+
+
+
+
+void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ cPlayer * a_ClosestPlayer(m_World->FindClosestPlayer(Vector3f(GetPosition()), 3));
+ if (a_ClosestPlayer)
+ {
+ Vector3f a_PlayerPos(a_ClosestPlayer->GetPosition());
+ Vector3f a_Distance(a_PlayerPos - GetPosition());
+ if (a_Distance.Length() < 0.1f)
+ {
+ a_ClosestPlayer->DeltaExperience(m_Reward);
+ a_ClosestPlayer->SendExperience();
+ Destroy(true);
+ }
+ a_Distance.y = 0;
+ a_Distance.Normalize();
+ a_Distance *= 3;
+ SetSpeedX( a_Distance.x );
+ SetSpeedZ( a_Distance.z );
+ }
+} \ No newline at end of file