forked from martinohanlon/mayhem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform_data.cpp
executable file
·96 lines (86 loc) · 3.5 KB
/
platform_data.cpp
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
#include "platform_data.h"
#include "allegro_compatibility.h"
#include "utils.h"
void init_level_dca(struct dca_data *dca, int xsrc, int ysrc, int area,
int delay) {
dca->xsrc = xsrc;
dca->ysrc = ysrc;
dca->area = area;
dca->delayed = 0;
dca->delay = delay;
dca->shoot = false;
struct tir_data *dca_tir;
for (int i = 0; i < MAX_DCA_TIR; i++) {
dca_tir = &(dca->dca_tir[i]);
dca_tir->x = dca->xsrc;
dca_tir->y = dca->ysrc;
dca_tir->xposprecise = itofix(0);
dca_tir->yposprecise = itofix(0);
dca_tir->dx = itofix(0);
dca_tir->dy = itofix(0);
dca_tir->free = true;
}
}
void init_level_data(struct level_data *leveldat, const char *bmpname,
const char *mini_bmpname, const char *collision_bmpname,
struct platform_data *platformdata, int nbplatforms,
struct edge_data edgedata,
struct level_ship_assets *shipsassets,
const char *explosion_spritename, bool use_dca,
bool wall_collision, int *particle_color_rgb) {
leveldat->bmpname = bmpname;
leveldat->mini_bmpname = mini_bmpname;
leveldat->collision_bmpname = collision_bmpname;
leveldat->nbplatforms = nbplatforms;
leveldat->platformdata = platformdata;
leveldat->use_dca = use_dca;
leveldat->wall_collision = wall_collision;
leveldat->edgedata = edgedata;
leveldat->shipsassets = shipsassets;
leveldat->explosion_spritename = explosion_spritename;
leveldat->particle_color_rgb = particle_color_rgb;
}
int load_level(struct level_data *leveldat, int largeur, int hauteur) {
leveldat->bitmap = al_load_bitmap(leveldat->bmpname);
leveldat->mini_bitmap = al_load_bitmap(leveldat->mini_bmpname);
leveldat->collision_bitmap = load_memory_bitmap(leveldat->collision_bmpname);
leveldat->mini_bitmap_buffer =
al_create_bitmap(10.0 * (largeur / 100.0), 15.0 * (largeur / 100.0));
leveldat->level_buffer =
create_clear_bitmap(al_get_bitmap_width(leveldat->bitmap),
al_get_bitmap_height(leveldat->bitmap));
int w = al_get_bitmap_width(leveldat->collision_bitmap);
int h = al_get_bitmap_height(leveldat->collision_bitmap);
leveldat->coll_map.init(w, h, 1);
ALLEGRO_LOCKED_REGION *reg =
al_lock_bitmap(leveldat->collision_bitmap, ALLEGRO_PIXEL_FORMAT_ANY,
ALLEGRO_LOCK_READONLY);
assert(reg);
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
auto pixel = get_pixel(reg, x, y);
leveldat->coll_map.set_pixel(x, y, 0, is_nonblack_pixel(pixel));
}
}
if (leveldat->bitmap && leveldat->mini_bitmap) {
// set_palette(leveldat->colormap);
// load the particle color after setting the palette
leveldat->particle_color = al_map_rgb(leveldat->particle_color_rgb[0],
leveldat->particle_color_rgb[1],
leveldat->particle_color_rgb[2]);
return 0;
} else
return -1;
}
void unload_level(struct level_data *leveldat) {
if (leveldat->bitmap)
al_destroy_bitmap(leveldat->bitmap);
if (leveldat->mini_bitmap)
al_destroy_bitmap(leveldat->mini_bitmap);
if (leveldat->mini_bitmap_buffer)
al_destroy_bitmap(leveldat->mini_bitmap_buffer);
if (leveldat->collision_bitmap)
al_destroy_bitmap(leveldat->collision_bitmap);
if (leveldat->level_buffer)
al_destroy_bitmap(leveldat->level_buffer);
}