Entity.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #include <Critical.h>
  3. #include <Either.h>
  4. #include <Model3D.h>
  5. #include "Area.h"
  6. #include "EntityType.h"
  7. #include "FactoryCraftModel.h"
  8. class Block;
  9. struct MovementFrame
  10. {
  11. Framework::Vec3<float> direction;
  12. Framework::Vec3<float> targetPosition;
  13. int movementFlags = 0;
  14. double duration = 0;
  15. };
  16. enum MovementFlag
  17. {
  18. MOVEMENT_FLAG_NONE = 0,
  19. MOVEMENT_FLAG_FORWARD = 0x1,
  20. MOVEMENT_FLAG_LEFT = 0x2,
  21. MOVEMENT_FLAG_BACKWARD = 0x4,
  22. MOVEMENT_FLAG_RIGHT = 0x8,
  23. MOVEMENT_FLAG_DOWN = 0x10,
  24. MOVEMENT_FLAG_UP = 0x20,
  25. MOVEMENT_FLAG_JUMP = 0x40,
  26. MOVEMENT_FLAG_FLY = 0x80,
  27. };
  28. class Entity : public FactoryCraftModel
  29. {
  30. private:
  31. int id;
  32. const EntityType* zType;
  33. Framework::Critical cs;
  34. bool playerControlled;
  35. float maxMovementSpeed;
  36. int lastFlags;
  37. double timeSinceSync;
  38. float gravityMultiplier;
  39. float jumpSpeed;
  40. Framework::Vec3<float> lastDirection;
  41. Framework::Array<MovementFrame> movements;
  42. Framework::Vec3<float> speed;
  43. MovementFrame currentFrame;
  44. public:
  45. Entity(const EntityType* zType,
  46. Framework::Model3DData* model,
  47. Framework::Model3DTextur* texture,
  48. int id,
  49. Framework::Vec3<float> position,
  50. float maxMovementSpeed,
  51. float gravityMultiplier,
  52. float jumpSpeed,
  53. float size);
  54. ~Entity();
  55. void api(char* message);
  56. bool tick(double time) override;
  57. int getId() const;
  58. const EntityType* zEntityType() const;
  59. void lock();
  60. void unlock();
  61. void setPlayerControlled();
  62. };