key.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SuperTux
  2. // Copyright (C) 2022 Daniel Ward <weluvgoatz@gmail.com>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #ifndef HEADER_SUPERTUX_OBJECT_KEY_HPP
  17. #define HEADER_SUPERTUX_OBJECT_KEY_HPP
  18. #include "object/moving_sprite.hpp"
  19. #include "object/player.hpp"
  20. #include "supertux/physic.hpp"
  21. #include "supertux/timer.hpp"
  22. #include <list>
  23. class Key final : public MovingSprite
  24. {
  25. public:
  26. Key(const ReaderMapping& reader);
  27. virtual void update(float dt_sec) override;
  28. virtual HitResponse collision(GameObject& other, const CollisionHit& hit_) override;
  29. virtual void draw(DrawingContext& context) override;
  30. static std::string class_name() { return "key"; }
  31. virtual std::string get_class_name() const override { return class_name(); }
  32. static std::string display_name() { return _("Key"); }
  33. virtual std::string get_display_name() const override { return display_name(); }
  34. virtual ObjectSettings get_settings() override;
  35. virtual void after_editor_set() override;
  36. void update_pos();
  37. private:
  38. enum KeyState {
  39. NORMAL,
  40. COLLECT,
  41. FOLLOW,
  42. FOUND,
  43. USE
  44. };
  45. std::list<Vector> m_pos_list;
  46. bool m_collected;
  47. KeyState m_state;
  48. Timer m_wait_timer;
  49. Timer m_unlock_timer;
  50. Physic m_physic;
  51. int m_chain_pos;
  52. Vector m_my_door_pos;
  53. Color m_color;
  54. Player* m_owner;
  55. SpritePtr m_lightsprite;
  56. float m_total_time_elapsed;
  57. float m_target_speed;
  58. private:
  59. void spawn_use_particles();
  60. private:
  61. Key(const Key&) = delete;
  62. Key& operator=(const Key&) = delete;
  63. };
  64. #endif
  65. /* EOF */