1 /*
2  * Copyright (C) 2006-2019 Christopho, Solarus - http://www.solarus-games.org
3  *
4  * Solarus 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  * Solarus 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 along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef SOLARUS_CRYSTAL_H
18 #define SOLARUS_CRYSTAL_H
19 
20 #include "solarus/core/Common.h"
21 #include "solarus/core/Point.h"
22 #include "solarus/entities/Entity.h"
23 #include <list>
24 #include <string>
25 
26 namespace Solarus {
27 
28 /**
29  * \brief A switch that can be activated to change the state of the
30  * crystal blocks.
31  */
32 class Crystal: public Entity {
33 
34   public:
35 
36     static constexpr EntityType ThisType = EntityType::CRYSTAL;
37 
38     Crystal(const std::string& name, int layer, const Point& xy);
39 
40     virtual EntityType get_type() const override;
41 
42     virtual void notify_creating() override;
43     virtual bool is_obstacle_for(Entity& other) override;
44     virtual void notify_collision(Entity& entity_overlapping, CollisionMode collision_mode) override;
45     virtual void notify_collision(Entity& other_entity, Sprite& this_sprite, Sprite& other_sprite) override;
46     virtual bool notify_action_command_pressed() override;
47     void activate(Entity& entity_activating);
48 
49     virtual void update() override;
50     virtual void set_suspended(bool suspended) override;
51 
52   private:
53 
54     void twinkle();
55 
56     bool state;                                    /**< false if the orange blocks are lowered,
57                                                     * true if the blue blocks are lowered */
58     uint32_t next_possible_hit_date;               /**< date when the crystal can be hit again */
59     std::list<Entity*> entities_activating;        /**< list of entities that recently activated this crystal */
60     SpritePtr main_sprite;                         /**< Main sprite of the crystal. */
61     SpritePtr star_sprite;                         /**< sprite of the star twinkling on the crystal */
62 
63 };
64 
65 }
66 
67 #endif
68 
69