Mover.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include <Urho3D/Scene/LogicComponent.h>
  5. // All Urho3D classes reside in namespace Urho3D
  6. using namespace Urho3D;
  7. /// Mover logic component
  8. /// - Handles entity (enemy, platform...) translation along a path (set of Vector2 points)
  9. /// - Supports looping paths and animation flip
  10. /// - Default speed is 0.8 if 'Speed' property is not set in the tmx file objects
  11. class Mover : public LogicComponent
  12. {
  13. URHO3D_OBJECT(Mover, LogicComponent);
  14. public:
  15. /// Construct.
  16. explicit Mover(Context* context);
  17. /// Register object factory and attributes.
  18. static void RegisterObject(Context* context);
  19. /// Handle scene update. Called by LogicComponent base class.
  20. void Update(float timeStep) override;
  21. /// Return path attribute.
  22. Vector<byte> GetPathAttr() const;
  23. /// Set path attribute.
  24. void SetPathAttr(const Vector<byte>& value);
  25. /// Path.
  26. Vector<Vector2> path_;
  27. /// Movement speed.
  28. float speed_;
  29. /// ID of the current path point.
  30. int currentPathID_;
  31. /// Timer for particle emitter duration.
  32. float emitTime_;
  33. /// Timer used for handling "attack" animation.
  34. float fightTimer_;
  35. /// Flip animation based on direction, or player position when fighting.
  36. float flip_;
  37. };