-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphics.cpp
More file actions
129 lines (102 loc) · 4.58 KB
/
Graphics.cpp
File metadata and controls
129 lines (102 loc) · 4.58 KB
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
#include "Graphics.h"
void loadSprite(ALLEGRO_BITMAP * &image, const std::string file) {
ALLEGRO_PATH * path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
al_append_path_component(path, "Resources");
al_append_path_component(path, "Sprites");
al_change_directory(al_path_cstr(path, '/'));
al_destroy_path(path); //Until here modified to change the current working directory
image = al_load_bitmap(file.c_str());
}
void loadSprite(std::vector<ALLEGRO_BITMAP*> &tImage, std::string directory, int width_num, int height_num) {
ALLEGRO_PATH * path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
al_append_path_component(path, "Resources");
al_append_path_component(path, "Animations");
al_change_directory(al_path_cstr(path, '/'));
al_destroy_path(path);
tImage.push_back(al_load_bitmap(directory.c_str()));
int width = al_get_bitmap_width(tImage[0]) / width_num;
int height = al_get_bitmap_height(tImage[0]) / height_num;
for (int i = 0; i < height_num; i++) {
for (int j = 0; j < width_num; j++) {
tImage.push_back(al_create_sub_bitmap(tImage[0], j * width, i * height, width, height));
}
}
}
void loadSprite(std::vector<ALLEGRO_BITMAP*> &tImage, std::string directory) {
}
bool saveSprite(ALLEGRO_BITMAP * &image, std::string directory) {
return al_save_bitmap(directory.c_str(), image);
}
void drawSprite(ALLEGRO_BITMAP *image, float posx, float posy) {
al_draw_bitmap(image, posx, posy, NULL);
}
void drawSprite(ALLEGRO_BITMAP *image, float posx, float posy, ALLEGRO_COLOR tint) {
al_draw_tinted_bitmap(image, tint, posx, posy, NULL);
}
void drawSprite(ALLEGRO_BITMAP *image, float posx, float posy, float centerx, float centery, float angle) {
al_draw_rotated_bitmap(image, centerx, centery, posx, posy, angle, NULL);
}
void drawSprite(ALLEGRO_BITMAP *image, float posx, float posy, float swidth, float sheight)
{
float width, height;
width = swidth * al_get_bitmap_width(image);
height = sheight * al_get_bitmap_height(image);
al_draw_scaled_bitmap(image, 0, 0, al_get_bitmap_width(image), al_get_bitmap_height(image), posx, posy, width, height, NULL);
}
void drawSprite(ALLEGRO_BITMAP *image, float posx, float posy, ALLEGRO_COLOR tint, float centerx, float centery, float angle) {
al_draw_tinted_rotated_bitmap(image, tint, centerx, centery, posx, posy, angle, NULL);
}
void drawSprite(ALLEGRO_BITMAP *image, float posx, float posy, ALLEGRO_COLOR tint, float swidth, float sheight){
float width, height;
width = swidth * al_get_bitmap_width(image);
height = sheight * al_get_bitmap_height(image);
al_draw_tinted_scaled_bitmap(image, tint, 0, 0, al_get_bitmap_width(image), al_get_bitmap_height(image), posx, posy, width, height, NULL);
}
void drawSprite(ALLEGRO_BITMAP *image, float posx, float posy, float centerx, float centery, float angle, float swidth, float sheight){
al_draw_scaled_rotated_bitmap(image, centerx, centery, posx, posy, swidth, sheight, angle, NULL);
}
void drawSprite(ALLEGRO_BITMAP *image, float posx, float posy, ALLEGRO_COLOR tint, float centerx, float centery, float angle, float swidth, float sheight) {
al_draw_tinted_scaled_rotated_bitmap(image, tint, centerx, centery, posx, posy, swidth, sheight, angle, NULL);
}
float getSpriteWidth(ALLEGRO_BITMAP *image) {
return al_get_bitmap_width(image);
}
float getSpriteHeight(ALLEGRO_BITMAP *image) {
return al_get_bitmap_height(image);
}
void destroySprite(ALLEGRO_BITMAP * &image) {
al_destroy_bitmap(image);
image = nullptr;
}
void destroySprite(std::vector <ALLEGRO_BITMAP*> &tImage) {
for (size_t i = tImage.size(); i > 0; i--) {
al_destroy_bitmap(tImage[i - 1]);
tImage[i - 1] = nullptr;
tImage.pop_back();
}
}
void loadFont(ALLEGRO_FONT * &font, std::string font_name, int size) {
ALLEGRO_PATH * path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
al_append_path_component(path, "Resources");
al_append_path_component(path, "Fonts");
al_change_directory(al_path_cstr(path, '/'));
al_destroy_path(path);
font = al_load_font(font_name.c_str(), size, NULL);
}
void drawFont(ALLEGRO_FONT * font, ALLEGRO_COLOR text_color, int x, int y, textType text_type, std::string text) {
al_draw_text(font, text_color, x, y, text_type, text.c_str());
}
void destroyFont(ALLEGRO_FONT * &font) {
al_destroy_font(font);
font = nullptr;
}
void showScreen(ALLEGRO_COLOR back_color) {
al_flip_display();
al_clear_to_color(back_color);
}
void showScreen(ALLEGRO_COLOR back_color, int x, int y, int width, int height, int SCREEN_WIDTH, int SCREEN_HEIGHT) {
al_flip_display();
al_set_clipping_rectangle(x, y, width, height);
al_clear_to_color(back_color);
al_set_clipping_rectangle(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}