summaryrefslogtreecommitdiffstats
path: root/src/main.c
blob: 6a1100ffad2d100589ec11ecb69344bb852abd3c (plain)
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
#include <SDL.h>
#include "init.h"
#include "logging.h"
#include "resources/image.h"
#include "resources/map.h"
#include "viewport.h"
#include "area.h"

#define DEMO()                                                                 \
	do {                                                                   \
		vp->x = x + map->tilewidth / 2 - vp->w / 2;                    \
		vp->y = y + map->tileheight / 2 - vp->h / 2;                   \
		render_area_to_viewport(a, vp);                                \
		SDL_Flip(vp->screen);                                          \
		SDL_Delay(10);                                                 \
	} while (0)

int
main(void)
{
	struct viewport *vp;
	struct map *map;
	struct image *img;
	struct map_tileset *ts;
	struct map_exit *e;
	struct area *a;
	int x, y;

	init();
	vp = init_viewport(240, 160, 32);

	map = map_get("data/forest1-8bit.tmx");
	a = area_new(map);

	debug("screen: bpp: %u, masks: 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x",
			vp->screen->format->BitsPerPixel,
			vp->screen->format->Rmask, vp->screen->format->Gmask,
			vp->screen->format->Bmask, vp->screen->format->Amask);
	img = img_png_get("../forest-6-layer-test_ground.png");
	debug("image:  bpp: %u, masks: 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x",
			img->image->format->BitsPerPixel,
			img->image->format->Rmask, img->image->format->Gmask,
			img->image->format->Bmask, img->image->format->Amask);
	img_png_free(img);
	img = img_png_get("data/tilesets/mountain_landscape_19-16.png");
	debug("image:  bpp: %u, masks: 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x",
			img->image->format->BitsPerPixel,
			img->image->format->Rmask, img->image->format->Gmask,
			img->image->format->Bmask, img->image->format->Amask);
	img_png_free(img);
	img = img_png_get("data/tilesets/mountain_landscape_19-16-8bit.png");
	debug("image:  bpp: %u, masks: 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x",
			img->image->format->BitsPerPixel,
			img->image->format->Rmask, img->image->format->Gmask,
			img->image->format->Bmask, img->image->format->Amask);
	img_png_free(img);

	debug("Map dimensions: %dx%d", map->width, map->height);
	for (ts = map->tilesets_head; ts != NULL; ts = ts->next) {
		debug("Tileset name: %s", ts->tileset->name);
		debug("Tileset firstgid: %d", ts->firstgid);
	}
	for (e = map->map_exits_head; e != NULL; e = e->next) {
		debug("Exit target (size %dx%d) at (%d,%d) "
				"to map %s (size %dx%d) at (%d,%d)",
				e->width, e->height,
				e->x, e->y,
				e->target_map_name,
				e->target_map->width, e->target_map->height,
				e->target_x_coord, e->target_y_coord);
	}

	/* Demo */
	x = 19 * map->tilewidth ;
	y = 38 * map->tileheight;
	for (; y > 34 * map->tileheight; y -= 2) DEMO(); /* Up */
	for (; x < 23 * map->tilewidth ; x += 2) DEMO(); /* Right */
	for (; y > 16 * map->tileheight; y -= 2) DEMO(); /* Up */
	for (; x > 15 * map->tilewidth ; x -= 2) DEMO(); /* Left */
	for (; y < 25 * map->tileheight; y += 2) DEMO(); /* Down */
	for (; x >  4 * map->tilewidth ; x -= 2) DEMO(); /* Left */
	for (; y > 18 * map->tileheight; y -= 2) DEMO(); /* Up */
	for (; x <  9 * map->tilewidth ; x += 2) DEMO(); /* Right */
	for (; y >  5 * map->tileheight; y -= 2) DEMO(); /* Up */
	for (; x < 15 * map->tilewidth ; x += 2) DEMO(); /* Right */
	for (; y >  1 * map->tileheight; y -= 2) DEMO(); /* Up */

	quit(0);

	/* Control doesn't actually reach here. */
	return 0;
}