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
|
#include "map.h"
#include "sprite.h"
#include "standard.h"
void init_map(Map* map) {
const Sprite* floor, * bricks;
const Bitmap* fbmp, * bbmp;
Bitmap bitmap;
int i, x, y;
bitmap.pixels = map->pixels;
bitmap.w = mbmp_w;
bitmap.h = mbmp_h;
floor = get_sprite(sprite_floor_tile);
bricks = get_sprite(sprite_bricks);
fbmp = get_bitmap(floor->bitmap);
bbmp = get_bitmap(bricks->bitmap);
for (i = 0; i < mbmp_w * mbmp_h; i++) {
bitmap.pixels[i] = make_black();
}
for (x = 1; x < map_width - 1; x++) {
for (y = 1; y < map_height - 1; y++) {
blit(
&bitmap,
fbmp,
map_tile_size * x,
map_tile_size * y,
&floor->rect
);
}
}
for (x = 0; x < map_width; x++) {
blit(
&bitmap,
bbmp,
map_tile_size * x,
0,
&bricks->rect
);
blit(
&bitmap,
bbmp,
map_tile_size * x,
(map_height - 1) * map_tile_size,
&bricks->rect
);
}
for (y = 0; y < map_height; y++) {
blit(
&bitmap,
bbmp,
0,
map_tile_size * y,
&bricks->rect
);
blit(
&bitmap,
bbmp,
(map_width - 1) * map_tile_size,
map_tile_size * y,
&bricks->rect
);
}
for (i = 0; i < 20; i++) {
x = rand_range(0, map_width - 1) * map_tile_size;
y = rand_range(0, map_height - 1) * map_tile_size;
blit(
&bitmap,
bbmp,
x,
y,
&bricks->rect
);
}
}
void render_map(Map* map, int cx, int cy) {
Bitmap bitmap;
Rectangle rect;
bitmap.pixels = map->pixels;
bitmap.w = mbmp_w;
bitmap.h = mbmp_h;
rect.x = 0;
rect.y = 0;
rect.w = bitmap.w;
rect.h = bitmap.h;
render_bitmap(&bitmap, -cx >> fbits, -cy >> fbits, &rect);
}
|