summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/map.c139
-rw-r--r--src/map.h7
2 files changed, 90 insertions, 56 deletions
diff --git a/src/map.c b/src/map.c
index 759edaf..824f369 100644
--- a/src/map.c
+++ b/src/map.c
@@ -737,62 +737,6 @@ _db_tmx_map_start(void *pv, const char *name, const char **attr)
}
}
-static int
-_db_map_render_layer(struct db_map *map, struct db_map_layer *layer,
- SDL_Renderer *renderer)
-{
- int i;
- int gid;
- SDL_Rect layer_rect;
-
- for (i = 0; i < map->w * map->h; ++i) {
- gid = layer->tiles[i];
- if (gid == 0) {
- continue;
- }
- layer_rect.x = map->tw * (i % map->w);
- layer_rect.y = map->th * (i / map->w);
- layer_rect.w = map->tw;
- layer_rect.h = map->th;
- db_tile_render(map->tileset_head, renderer, gid, &layer_rect);
- }
-
- return 0;
-}
-
-SDL_Texture *
-db_map_render(struct db_map *map, SDL_Renderer *renderer)
-{
- SDL_Texture *texture;
- SDL_Texture *old_target;
- struct db_map_layer *layer;
-
- texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,
- SDL_TEXTUREACCESS_TARGET, map->w * map->tw,
- map->h * map->th);
- old_target = SDL_GetRenderTarget(renderer);
- SDL_SetRenderTarget(renderer, texture);
- if (SDL_SetRenderDrawColor(renderer,
- map->bg_r, map->bg_g, map->bg_b, 0xFF) != 0) {
- db_err("Failed to set drawing color (%s)", SDL_GetError());
- return NULL;
- }
- if (SDL_RenderClear(renderer) != 0) {
- db_err("Failed to clear texture (%s)", SDL_GetError());
- return NULL;
- }
-
- for (layer = map->layer_head; layer != NULL; layer = layer->next) {
- if (_db_map_render_layer(map, layer, renderer) != 0) {
- return NULL;
- }
- }
-
- SDL_SetRenderTarget(renderer, old_target);
-
- return texture;
-}
-
struct db_map *
db_map_new(const char *game_id, const char *level_id)
{
@@ -884,3 +828,86 @@ db_map_new(const char *game_id, const char *level_id)
return map;
}
+
+static int
+_db_map_render_layer(struct db_map *map, struct db_map_layer *layer,
+ SDL_Renderer *renderer)
+{
+ int i;
+ int gid;
+ SDL_Rect layer_rect;
+
+ for (i = 0; i < map->w * map->h; ++i) {
+ gid = layer->tiles[i];
+ if (gid == 0) {
+ continue;
+ }
+ layer_rect.x = map->tw * (i % map->w);
+ layer_rect.y = map->th * (i / map->w);
+ layer_rect.w = map->tw;
+ layer_rect.h = map->th;
+ db_tile_render(map->tileset_head, renderer, gid, &layer_rect);
+ }
+
+ return 0;
+}
+
+SDL_Texture *
+db_map_render(struct db_map *map, SDL_Renderer *renderer)
+{
+ SDL_Texture *texture;
+ SDL_Texture *old_target;
+ struct db_map_layer *layer;
+
+ texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,
+ SDL_TEXTUREACCESS_TARGET, map->w * map->tw,
+ map->h * map->th);
+ old_target = SDL_GetRenderTarget(renderer);
+ SDL_SetRenderTarget(renderer, texture);
+ if (SDL_SetRenderDrawColor(renderer,
+ map->bg_r, map->bg_g, map->bg_b, 0xFF) != 0) {
+ db_err("Failed to set drawing color (%s)", SDL_GetError());
+ return NULL;
+ }
+ if (SDL_RenderClear(renderer) != 0) {
+ db_err("Failed to clear texture (%s)", SDL_GetError());
+ return NULL;
+ }
+
+ for (layer = map->layer_head; layer != NULL; layer = layer->next) {
+ if (_db_map_render_layer(map, layer, renderer) != 0) {
+ return NULL;
+ }
+ }
+
+ SDL_SetRenderTarget(renderer, old_target);
+
+ return texture;
+}
+
+struct db_tileset *
+db_map_get_tilesets(struct db_map *map)
+{
+ return map->tileset_head;
+}
+
+void
+db_map_get_player(struct db_map *map, int *x, int *y, int *r)
+{
+ *x = map->player_x;
+ *y = map->player_y;
+ *r = map->player_r;
+}
+
+void
+db_map_get_target(struct db_map *map, int *x, int *y, int *r)
+{
+ *x = map->target_x;
+ *y = map->target_y;
+ *r = map->target_r;
+}
+
+struct db_ball *db_map_get_balls(struct db_map *map)
+{
+ return map->ball_head;
+}
diff --git a/src/map.h b/src/map.h
index 2e6bd94..63aea5d 100644
--- a/src/map.h
+++ b/src/map.h
@@ -21,10 +21,17 @@
#define DB_MAP_H_
#include <SDL.h>
+#include "tileset.h"
struct db_map;
struct db_map *db_map_new(const char *game_id, const char *level_id);
SDL_Texture *db_map_render(struct db_map *map, SDL_Renderer *renderer);
+struct db_tileset *db_map_get_tilesets(struct db_map *map)
+ __attribute__((__pure__));
+void db_map_get_player(struct db_map *map, int *x, int *y, int *r);
+void db_map_get_target(struct db_map *map, int *x, int *y, int *r);
+struct db_ball *db_map_get_balls(struct db_map *map)
+ __attribute__((__pure__));
#endif /* DB_MAP_H_ */