#ifndef MAP_H #define MAP_H #include #include #include class Entity; class Map { public: Map(int id); Map() : Map(-1) {} Map(const Map& map); Map(Map&& map); ~Map(); Map& operator= (Map other); friend void swap(Map& first, Map& second); enum class MoveType { Wall, Wrap, Warp, ReverseWarp }; enum class MoveDir { Left, Right, Up, Down }; struct EntityData { std::string name; std::pair position; std::map items; }; struct Adjacent { MoveType type = MoveType::Wall; int map = -1; }; static MoveType moveTypeForShort(std::string str); static MoveDir moveDirForShort(std::string str); static bool moveTypeTakesMap(MoveType type); int getID() const; const int* getMapdata() const; std::string getTitle() const; const Adjacent& getAdjacent(MoveDir dir) const; void createEntities(std::list>& entities) const; bool operator==(const Map& other) const; bool operator!=(const Map& other) const; void setMapdata(int* mapdata); void setTitle(std::string title); void setAdjacent(MoveDir dir, MoveType type, int map); void addEntity(EntityData& data); private: int* mapdata; std::string title; int id; std::list entities; std::map adjacents; }; #endif >tree commit diff stats
blob: a4620d49704ba5b7191ec6f6d00e312d3d1925f4 (plain) (blame)
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
#ifndef GAME_H
#define GAME_H

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

class Entity;
class Map;

const int TILE_WIDTH = 8;
const int TILE_HEIGHT = 8;
const int GAME_WIDTH = 320;
const int GAME_HEIGHT = 200;
const int MAP_WIDTH = GAME_WIDTH/TILE_WIDTH;
const int MAP_HEIGHT = GAME_HEIGHT/TILE_HEIGHT;

const int FRAMES_PER_SECOND = 60;
const double SECONDS_PER_FRAME = 1.0 / FRAMES_PER_SECOND;

struct Savefile {
  const Map* map;
  std::pair<double, double> position;
};

class Game {
  public:
    Game();
    void execute(GLFWwindow* window);
    void loadMap(const Map& map, std::pair<double, double> position);
    void detectCollision(Entity& collider, std::pair<double, double> old_position);
    void saveGame();
    void schedule(double time, std::function<void ()> callback);
    void playerDie();
    
  private:
    friend void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);

    std::list<std::shared_ptr<Entity>> entities;
    std::list<std::shared_ptr<Entity>> nextEntities;
    std::pair<double, double> nextPosition;
    bool newWorld;
    std::shared_ptr<Entity> player;
    const Map* currentMap;
    Savefile save;
    std::list<std::pair<double, std::function<void ()>>> scheduled;
    bool shouldQuit = false;
};

#endif