-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbase.h
147 lines (125 loc) · 3.36 KB
/
base.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#ifndef BASE_H
#define BASE_H
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <SDL.h>
#include <SDL_image.h>
#include <cmath>
#include "defs.h"
using namespace std;
Uint32 get_pixel32( SDL_Surface *surface, int x, int y );
void put_pixel32( SDL_Surface *surface, int x, int y, Uint32 pixel );
double round_3dec(double val);
float clamp(float value, float min, float max);
class colorRGBA {
public:
Uint8 r;
Uint8 g;
Uint8 b;
Uint8 a;
void fromPixel32(Uint32 pixel, const SDL_PixelFormat* format);
};
//====================================================================
class Timer {
private:
int stime;
public:
void start();
int elapsedTime();
};
//====================================================================
class Vector2 {
public:
float x, y;
Vector2();
Vector2(float x, float y);
void sub(Vector2 v);
void sub(float x, float y);
void add(Vector2 v);
void add(float x, float y);
void mul(float f);
Vector2 mul_N(float f);
void normalize();
float length();
double angle(Vector2 v);
void set(float x, float y);
void fromAngle(double angle);
void rotate(double angle);
};
Vector2 Bezier(Vector2 start, Vector2 control, Vector2 end, float t);
Vector2 Lerp(Vector2 start, Vector2 end, float t);
float Lerp(float start, float end, float t);
//====================================================================
class Camera {
public:
Vector2 ViewPortOffset;
void setViewPortOffset(Vector2 vpo);
void centerOn(Vector2 pos);
void follow(Vector2 pos);
Vector2 getCenter();
};
class GameWindow {
private:
SDL_Rect* drawrect;
public:
Camera* camera;
SDL_Window *win = NULL;
SDL_Renderer *renderer = NULL;
SDL_Texture* textureFromSurface(SDL_Surface* sur);
void draw(SDL_Texture* tex, const SDL_Rect* srcrect, const SDL_Rect* dstrect);
void draw(SDL_Texture* tex, const SDL_Rect* srcrect, const SDL_Rect* dstrect, const double angle, const SDL_Point* center, const SDL_RendererFlip flip);
void drawOverride(SDL_Texture* tex, const SDL_Rect* srcrect, const SDL_Rect* dstrect);
void drawOverride(SDL_Texture* tex, const SDL_Rect* srcrect, const SDL_Rect* dstrect, const double angle, const SDL_Point* center, const SDL_RendererFlip flip);
Vector2 getMousePosition();
void clear();
void present();
GameWindow();
int init();
};
//====================================================================
class Object {
protected:
GameWindow* gw;
char tag;
Vector2 pos;
public:
void setPos(Vector2 pos);
void setPos(int x, int y);
Vector2 getPos();
void draw();
void init();
Object(GameWindow* gw);
~Object();
};
//====================================================================
class Image : public Object {
protected:
SDL_Texture* tex;
SDL_Rect texr;
public:
float scale;
SDL_Rect getRect();
void setPosCenter(Vector2 pos);
void setPosCenter(int x, int y);
void setHeight(int h);
void draw();
void loadTexture(const char* path);
void update();
Image(GameWindow* gw);
~Image();
};
//====================================================================
//AdvImage is an Image but with a rotation angle and point
class AdvImage : public Image {
protected:
public:
double angle;
SDL_Point* center;
SDL_RendererFlip flip;
void draw();
void setFromTo(Vector2 from, Vector2 to, bool height);
AdvImage(GameWindow* gw);
~AdvImage();
};
#endif // BASE_H