supertux
bullet.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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 
17 #ifndef HEADER_SUPERTUX_OBJECT_BULLET_HPP
18 #define HEADER_SUPERTUX_OBJECT_BULLET_HPP
19 
20 #include "sprite/sprite_ptr.hpp"
21 #include "supertux/direction.hpp"
22 #include "supertux/moving_object.hpp"
23 #include "supertux/physic.hpp"
24 #include "supertux/player_status.hpp"
25 #include "video/layer.hpp"
26 
27 class Player;
28 
29 class Bullet final : public MovingObject
30 {
31 public:
32  Bullet(const Vector& pos, const Vector& xm, Direction dir, BonusType type, Player& player);
33 
34  virtual GameObjectClasses get_class_types() const override { return MovingObject::get_class_types().add(typeid(Bullet)); }
35 
36  virtual void update(float dt_sec) override;
37  virtual void draw(DrawingContext& context) override;
38  virtual void collision_solid(const CollisionHit& hit) override;
39  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
40  virtual bool is_saveable() const override { return false; }
41 
42  virtual int get_layer() const override { return LAYER_OBJECTS; }
43 
48  void ricochet(GameObject& other, const CollisionHit& hit);
49 
50  BonusType get_type() const { return type; }
51 
52  Player& get_player() const { return m_player; }
53 
54 private:
55  Player& m_player;
56  Physic physic;
57  int life_count;
58  SpritePtr sprite;
59  SpritePtr lightsprite;
60  BonusType type;
61 
62 private:
63  Bullet(const Bullet&) = delete;
64  Bullet& operator=(const Bullet&) = delete;
65 };
66 
67 #endif
68 
69 /* EOF */
Definition: bullet.hpp:29
Physics engine.
Definition: physic.hpp:27
virtual void collision_solid(const CollisionHit &hit) override
this function is called when the object collided with something solid
Definition: bullet.cpp:103
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: bullet.cpp:124
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
void ricochet(GameObject &other, const CollisionHit &hit)
Makes bullet bounce off an object (that got hit).
Definition: bullet.cpp:118
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:35
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: bullet.cpp:94
virtual void update(float dt_sec) override
This function is called once per frame and allows the object to update it&#39;s state.
Definition: bullet.cpp:61
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: moving_object.hpp:49
A helper structure to list all the type_indexes of the classes in the type hierarchy of a given class...
Definition: game_object.hpp:57
virtual bool is_saveable() const override
Indicates if the object will be saved.
Definition: bullet.hpp:40
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: bullet.hpp:34
This module contains methods controlling the player.
Definition: player.hpp:47
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
This class collects data about a collision.
Definition: collision_hit.hpp:44