Urho2DIsometricDemo.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "Sample.h"
  24. #include "Utilities2D/Sample2D.h"
  25. class Character2D;
  26. class Sample2D;
  27. /// Urho2D tile map example.
  28. /// This sample demonstrates:
  29. /// - Creating an isometric 2D scene with tile map
  30. /// - Displaying the scene using the Renderer subsystem
  31. /// - Handling keyboard to move a character and zoom 2D camera
  32. /// - Generating physics shapes from the tmx file's objects
  33. /// - Displaying debug geometry for physics and tile map
  34. /// Note that this sample uses some functions from Sample2D utility class.
  35. class Urho2DIsometricDemo : public Sample
  36. {
  37. URHO3D_OBJECT(Urho2DIsometricDemo, Sample);
  38. public:
  39. /// Construct.
  40. explicit Urho2DIsometricDemo(Context* context);
  41. /// Setup after engine initialization and before running the main loop.
  42. void Start() override;
  43. /// Setup before engine initialization. Modifies the engine parameters.
  44. void Setup() override;
  45. private:
  46. /// Construct the scene content.
  47. void CreateScene();
  48. /// Construct an instruction text to the UI.
  49. void CreateInstructions();
  50. /// Subscribe to application-wide logic update events.
  51. void SubscribeToEvents();
  52. /// Handle the logic update event.
  53. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  54. /// Handle the logic post update event.
  55. void HandlePostUpdate(StringHash eventType, VariantMap& eventData);
  56. /// Handle the post render update event.
  57. void HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData);
  58. /// Handle the end rendering event.
  59. void HandleSceneRendered(StringHash eventType, VariantMap& eventData);
  60. /// Handle reloading the scene.
  61. void ReloadScene(bool reInit);
  62. /// Handle the contact begin event (Box2D contact listener).
  63. void HandleCollisionBegin(StringHash eventType, VariantMap& eventData);
  64. /// Handle 'PLAY' button released event.
  65. void HandlePlayButton(StringHash eventType, VariantMap& eventData);
  66. /// The controllable character component.
  67. WeakPtr<Character2D> character2D_;
  68. /// Camera's zoom (used to scale movement speed based on camera zoom).
  69. float zoom_;
  70. /// Flag for drawing debug geometry.
  71. bool drawDebug_;
  72. /// Sample2D utility object.
  73. SharedPtr<Sample2D> sample2D_;
  74. };