Character2D.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include <Urho3D/Scene/LogicComponent.h>
  24. // All Urho3D classes reside in namespace Urho3D
  25. using namespace Urho3D;
  26. const float MOVE_SPEED_X = 4.0f;
  27. const int LIFES = 3;
  28. /// Character2D component controling Imp behavior.
  29. class Character2D : public LogicComponent
  30. {
  31. URHO3D_OBJECT(Character2D, LogicComponent);
  32. public:
  33. /// Construct.
  34. explicit Character2D(Context* context);
  35. /// Register object factory and attributes.
  36. static void RegisterObject(Context* context);
  37. /// Handle update. Called by LogicComponent base class.
  38. void Update(float timeStep) override;
  39. /// Handle player state/behavior when wounded.
  40. void HandleWoundedState(float timeStep);
  41. /// Handle death of the player.
  42. void HandleDeath();
  43. /// Flag when player is wounded.
  44. bool wounded_;
  45. /// Flag when player is dead.
  46. bool killed_;
  47. /// Timer for particle emitter duration.
  48. float timer_;
  49. /// Number of coins in the current level.
  50. int maxCoins_;
  51. /// Counter for remaining coins to pick.
  52. int remainingCoins_;
  53. /// Counter for remaining lifes.
  54. int remainingLifes_;
  55. /// Scaling factor based on tiles' aspect ratio (definitively set at tile map creation).
  56. float moveSpeedScale_;
  57. /// Camera's zoom (used to scale movement speed based on camera zoom).
  58. float zoom_;
  59. };