about summary refs log tree commit diff stats
path: root/data/maps/the_perceptive/rooms
ModeNameSize
-rw-r--r--Main Area.txtpb100log stats plain blame
er Kelly Rauchenberger <fefferburbia@gmail.com> 2015-03-07 11:29:57 -0500 Created entity-component system' href='/therapy/commit/src/entity.h?h=proto-objs&id=b53826079429939cdfbda073608cb85be8ba0738'>b538260 ^
7f0e8c7 ^












1a392a7 ^
47d9d78 ^
6b1dcc5 ^

7f0e8c7 ^






b538260 ^

b538260 ^

b538260 ^
0e03897 ^
b8d62ce ^
7f0e8c7 ^


b538260 ^
7f0e8c7 ^

b538260 ^






0e03897 ^
7f0e8c7 ^
b8d62ce ^
7f0e8c7 ^

b538260 ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63


                

                     




                
 












                             
               
          

                  






                                      

  

              
                                                    
                                              
                                     


                                                                                               
    

                                       






                                                     
                                                           
                                                    
                                                

                                                                                       


      
#ifndef ENTITY_H
#define ENTITY_H

#include <list>
#include "renderer.h"

class Game;
class Map;
class Entity;
class Component;

class Message {
  public:
    enum class Type {
      walkLeft,
      walkRight,
      stopWalking,
      stopMovingHorizontally,
      stopMovingVertically,
      collision,
      jump,
      stopJump,
      drop,
      canDrop,
      cantDrop,
      die,
      stopDying,
      hitTheGround
    };
    
    Message(Type type) : type(type) {}
    
    Type type;
    Entity* collisionEntity;
    int dropAxis;
};

class Entity {
  public:
    void addComponent(std::shared_ptr<Component> c);
    void send(Game& game, const Message& msg);
    void tick(Game& game, double dt);
    void input(Game& game, int key, int action);
    void render(Game& game, Texture& buffer);
    void detectCollision(Game& game, Entity& collider, std::pair<double, double> old_position);
    
    std::pair<double, double> position;
    std::pair<int, int> size;
    
  private:
    std::list<std::shared_ptr<Component>> components;
};

class Component {
  public:
    virtual void receive(Game&, Entity&, const Message&) {}
    virtual void render(Game&, Entity&, Texture&) {}
    virtual void tick(Game&, Entity&, double) {}
    virtual void input(Game&, Entity&, int, int) {}
    virtual void detectCollision(Game&, Entity&, Entity&, std::pair<double, double>) {}
};

#endif