aboutsummaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-09-29 16:39:31 +1000
committerquou <quou@disroot.org>2024-09-29 16:39:31 +1000
commitbe5c7263406aef867501c7965bcced6a7e2898a6 (patch)
tree1e7d5d3b435456c9eeb2d094c3288df259246750 /map.c
parent9ca0a79e9cc784e14c3d8111ccb9ea1a22225472 (diff)
animation, player movement, physics etc.
Diffstat (limited to 'map.c')
-rw-r--r--map.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/map.c b/map.c
new file mode 100644
index 0000000..855f636
--- /dev/null
+++ b/map.c
@@ -0,0 +1,68 @@
+#include "asset.h"
+#include "map.h"
+#include "rect.h"
+#include "render.h"
+
+#define null_tile 0xffff
+
+Rect tile_rects[] = {
+#define x(n, x, y) \
+ { x, y, map_tile_size, map_tile_size },
+ tiles_xmacro
+#undef x
+};
+
+void generate_floor(Map* m, int seed) {
+ int e = map_w * map_h, i;
+ for (i = 0; i < e; i++) {
+ m->tiles[i] = null_tile;
+ m->collision[i] = 0;
+ }
+ e = map_w * (map_h - 1);
+ for (i = 0; i < map_w; i++) {
+ int idx = i + e;
+ m->tiles[idx] = tile_stone;
+ m->collision[idx] = 1;
+ }
+#define set(x, y) \
+ m->tiles[x + y * map_w] = tile_brick; \
+ m->collision[x + y * map_w] = 1;
+ set(0, 13);
+ set(0, 12);
+ set(0, 11);
+ set(1, 11);
+ set(2, 11);
+ set(3, 11);
+ set(4, 11);
+ set(19, 13);
+ set(19, 12);
+ set(19, 11);
+ set(19, 10);
+ set(19, 9);
+ set(19, 8);
+#undef set
+ m->tiles[18 + 13 * map_w] = tile_stone_ramp9;
+ m->collision[18 + 13 * map_w] = 6;
+ m->tiles[1 + 12 * map_w] = tile_stone_ramp13;
+ m->collision[1 + 12 * map_w] = 10;
+ m->tiles[2 + 12 * map_w] = tile_stone_ramp14;
+ m->collision[2 + 12 * map_w] = 11;
+}
+
+void render_map(const Map* m, Renderer* r) {
+ const Bitmap* tm = get_bitmap(asset_id_map_img);
+ int t = 0, x, y;
+ for (y = 0; y < map_h; y++) {
+ for (x = 0; x < map_w; x++, t++) {
+ int tile = m->tiles[t];
+ if (tile != null_tile)
+ ren_map(
+ r,
+ x * map_tile_size,
+ y * map_tile_size,
+ &tile_rects[tile],
+ tm
+ );
+ }
+ }
+}