BallActor.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #include "BallActor.h"
  9. #include "Game.h"
  10. #include "Renderer.h"
  11. #include "MeshComponent.h"
  12. #include "Mesh.h"
  13. #include "BallMove.h"
  14. #include "AudioComponent.h"
  15. BallActor::BallActor(Game* game)
  16. :Actor(game)
  17. ,mLifeSpan(2.0f)
  18. {
  19. //SetScale(10.0f);
  20. MeshComponent* mc = new MeshComponent(this);
  21. Mesh* mesh = GetGame()->GetRenderer()->GetMesh("Assets/Sphere.gpmesh");
  22. mc->SetMesh(mesh);
  23. mMyMove = new BallMove(this);
  24. mMyMove->SetForwardSpeed(1500.0f);
  25. mAudioComp = new AudioComponent(this);
  26. }
  27. void BallActor::UpdateActor(float deltaTime)
  28. {
  29. Actor::UpdateActor(deltaTime);
  30. mLifeSpan -= deltaTime;
  31. if (mLifeSpan < 0.0f)
  32. {
  33. SetState(EDead);
  34. }
  35. }
  36. void BallActor::SetPlayer(Actor* player)
  37. {
  38. mMyMove->SetPlayer(player);
  39. }
  40. void BallActor::HitTarget()
  41. {
  42. mAudioComp->PlayEvent("event:/Ding");
  43. }