-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.h
92 lines (77 loc) · 1.6 KB
/
main.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
#include <SDL2/SDL.h>
//#include <SDL2/SDL_image.h>
#include <stdio.h>
#include <string>
#include <vector>
#define INTERNAL_WIDTH 256
#define INTERNAL_HEIGHT 240
#define SPRITESIZE 16
#define BLOCKSIZEX 16
#define BLOCKSIZEY 15
class SpriteSheet {
public:
SpriteSheet();
~SpriteSheet();
bool loadFromFile(std::string path);
void free();
void render(int x, int y, int frameOffset);
private:
SDL_Texture* mTexture;
};
class Player {
public:
Player();
void move();
void render();
void handleEvents(SDL_Event& e);
private:
void setCamera();
void jump();
void animate();
bool loadFromFile(std::string path);
SDL_Texture* mTexture;
int frame = 0;
bool isMoving = false, isJumping = false, isGrounded = true;
float x,y, xVel = 80.0f, gravity = 700.0f, yVel = 50.0f;
SDL_RendererFlip flip = SDL_FLIP_NONE;
Uint32 lastAnimated=0;
SDL_Point hotSpot1, hotSpot2;
int getTileAt(int x, int y);
};
enum {
TILE_TYPE_NONE = 0,
TILE_TYPE_NORMAL,
TILE_TYPE_BLOCK,
TILE_TYPE_LADDER
};
class Tile {
public:
int tileID;
int typeID;
int x;
int y;
public:
Tile();
};
class Map {
public:
SDL_Surface* Surf_Tileset;
private:
std::vector<Tile> TileList;
public:
Map();
public:
bool load(int level[]);
Tile getTile(int px, int py);
void render();
};
bool init();
bool loadMedia();
void close();
bool collides(SDL_Rect *a, SDL_Rect *b);
SDL_Window* gWindow = NULL;
SDL_Renderer* gRenderer = NULL;
SpriteSheet gSpriteSheetTexture;
unsigned int lastTime = 0, currentTime;
int bIsFullscreen = false;
SDL_Rect camera = { 0, 0, INTERNAL_WIDTH, INTERNAL_HEIGHT };