-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.h
123 lines (102 loc) · 2.46 KB
/
Game.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#pragma once
#include<allegro5\allegro5.h>
#include<allegro5\allegro_native_dialog.h>
#include<allegro5\allegro_primitives.h>
#include<allegro5\allegro_image.h>
#include<vector>
#include <string>
#include<fstream>
#include <sstream>
#include<cctype>
#include<stdio.h>
#include<string>
#include<vector>
#include<iostream>
using namespace std;
#ifndef Game_h
#define Game_h
#define screenW 640 //platos 640
#define screenH 480 //ypsos 480
#define blocksize 16
#define TILE_WIDTH 16
#define TILE_HEIGHT 16
#define TileSetWidth 12
#define TileSetHeight 21
#define TILES TileSetWidth*TileSetHeight
#define X_MOVEMENT 8
#define Y_MOVEMENT 8
#define MOVE_SPEED 4
#define FPS_TIMER 20
#define FPS_FRAME 60
#define MAX_WIDTH 128
#define MAX_HEIGHT 32
typedef unsigned short Index; // [MSB X][LSB Y]
typedef int Dim; // [MSB X][LSB Y]
typedef vector<vector<int>> TileMap;
class Game {
protected:
enum Direction { DOWN, LEFT, RIGHT, UP }; //movement
ALLEGRO_DISPLAY* display;
ALLEGRO_KEYBOARD_STATE keyState;
ALLEGRO_TRANSFORM camera;
ALLEGRO_TIMER* timer;
ALLEGRO_TIMER* frameTimer;
ALLEGRO_EVENT_QUEUE* event_queue;
ALLEGRO_BITMAP* tileset;
//ALLEGRO_BITMAP* player;
ALLEGRO_EVENT events;
float cameraPosition[2] = { 0,0 };
bool active = false, draw = true, done = false;
float x = X_MOVEMENT, y = Y_MOVEMENT;
int dir = DOWN, sourceX = 8, sourceY = 0;
int divIndex[TILES];
int modIndex[TILES];
/**
* Given a csv file fill a 2d vector with its values.
*/
void LoadMap(string filename, vector<vector<int>>& map);
public:
TileMap map1;
TileMap map2;
void SetTile(TileMap* m, Dim col, Dim row, Index index);
Index GetTile(const TileMap* m, Dim col, Dim row);
ALLEGRO_DISPLAY* GetDisplay() { return display; }
/**
* load map1/map2 and init tileset.
*/
void LoadMaps();
/**
* set display of the window.
*/
void setDisplay(int Width, int Height);
/**
* set display with already defined values.
*/
void setDisplayMainValues();
/**
* init timer/fpstimer.
*/
void initTimers();
/**
* register timer/dispay/key.
*/
void registerValues();
/**
* update camera on movement.
*/
void CameraUpdate(float* cameraPosition, float x, float y, int width, int height);
/**
* Draw a map given a 2d vector.
*/
void DrawMap(vector<vector<int>> map, ALLEGRO_BITMAP* tileset, int divIndex[], int modIndex[]);
/**
* main loop for program.
*/
void MainLoop();
void MainLoopIteration();
/**
* destroy allegro objects.
*/
void Destroy();
};
#endif // !Game_h