uni

University stuff
git clone git://git.christosmarg.xyz/uni-assignments.git
Log | Files | Refs | README | LICENSE

Engine.hpp (1211B)


      1 #ifndef _ENGINE_HPP_
      2 #define _ENGINE_HPP_
      3 
      4 #include <cmath>
      5 #include <csignal>
      6 #include <cstdlib>
      7 #include <ctime>
      8 #include <iostream>
      9 #include <fstream>
     10 #include <map>
     11 #include <string>
     12 #include <vector>
     13 
     14 #include <ncurses.h>
     15 
     16 #include "Gnome.hpp"
     17 #include "Potter.hpp"
     18 #include "Traal.hpp"
     19 #include "Score.hpp"
     20 
     21 #ifndef ESC
     22 #define ESC 27
     23 #endif /* ESC */
     24 
     25 #define CENTER(x, y) (((x) >> 1) - ((y) >> 1))
     26 
     27 class Engine {
     28 private:
     29 
     30 	std::vector<Movable *> entities;
     31 	std::vector<std::vector<char>> map;
     32 	std::vector<int> colors;
     33 	Potter *player;
     34 	Score *score;
     35 	WINDOW *gw;
     36 	int xmax;
     37 	int ymax;
     38 	int wxmax;
     39 	int wymax;
     40 	int w;
     41 	int h;
     42 	int nenemies = 5;
     43 	volatile sig_atomic_t f_running;
     44 
     45 public:
     46 	explicit Engine(const char *mapfile, const char *scorefile);
     47 	~Engine();
     48 
     49 	void kbd_input();
     50 	void enemies_move();
     51 	void collisions();
     52 	void upd_score();
     53 	void redraw();
     54 	bool is_running();
     55 
     56 private:
     57 	bool load_map(const char *mapfile);
     58 	bool init_curses();
     59 	void calc_pos(int *x, int *y);
     60 	bool init_entities();
     61 	bool init_score(const char *scorefile);
     62 	bool collides_with_wall(int x, int y);
     63 	void ctrl_menu();
     64 	void calc_dist(std::map<int, int>& dists, int ex, int ey, int dir);
     65 };
     66 
     67 #endif /* _ENGINE_HPP_ */