summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-02-19 02:21:55 (EST)
committer P. J. McDermott <pjm@nac.net>2013-02-19 02:21:55 (EST)
commit3804573d65c9aef27f212dcece16fdb8f57b5f7d (patch)
treee900d1670167f311b04dbfa6186661dbb0ffe199 /src
parent8aff6e6c8590c23f7935fef5085f683d95e24db0 (diff)
downloadoverworld-rpg-3804573d65c9aef27f212dcece16fdb8f57b5f7d.zip
overworld-rpg-3804573d65c9aef27f212dcece16fdb8f57b5f7d.tar.gz
overworld-rpg-3804573d65c9aef27f212dcece16fdb8f57b5f7d.tar.bz2
Improve demo and clean up main().
Diffstat (limited to 'src')
-rw-r--r--src/area.c12
-rw-r--r--src/main.c199
2 files changed, 58 insertions, 153 deletions
diff --git a/src/area.c b/src/area.c
index 111a1a8..b0daca0 100644
--- a/src/area.c
+++ b/src/area.c
@@ -121,6 +121,8 @@ render_area_to_surface(struct area *area, SDL_Rect *arearect,
SDL_Surface *surface, SDL_Rect *surfacerect)
{
SDL_Rect srcrect, dstrect;
+ /* For demo */
+ SDL_Rect tmprect;
memcpy(&srcrect, arearect, sizeof(srcrect));
memcpy(&dstrect, surfacerect, sizeof(dstrect));
@@ -130,6 +132,12 @@ render_area_to_surface(struct area *area, SDL_Rect *arearect,
SDL_FillRect(surface, &dstrect,
SDL_MapRGB(surface->format, 63, 63, 63));
+ /* For demo */
+ tmprect.x = dstrect.x + 112;
+ tmprect.y = dstrect.y + 72;
+ tmprect.w = 16;
+ tmprect.h = 16;
+
/* Avoid fun glitches due to negative coordinates in source
* rectangles. */
if (srcrect.x < 0) {
@@ -159,6 +167,10 @@ render_area_to_surface(struct area *area, SDL_Rect *arearect,
/* TODO: Blit low sprites. */
+ /* For demo */
+ SDL_FillRect(surface, &tmprect,
+ SDL_MapRGB(surface->format, 31, 31, 127));
+
/* Blit middle objects layer. */
SDL_BlitSurface(area->map_layers[AREA_LAYER_OBJ_MID], &srcrect,
surface, &dstrect);
diff --git a/src/main.c b/src/main.c
index 71e465d..6d521be 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,113 +6,54 @@
#include "viewport.h"
#include "area.h"
+#define DEMO() \
+ do { \
+ vp->x = x * map->tilewidth + map->tilewidth / 2 - vp->w / 2; \
+ vp->y = y * map->tileheight + map->tileheight / 2 - vp->h / 2; \
+ render_area_to_viewport(a, vp); \
+ SDL_Flip(vp->screen); \
+ SDL_Delay(100); \
+ } while (0)
+
int
main(void)
{
struct viewport *vp;
- SDL_Surface *screen;
struct map *map;
struct image *img;
struct map_tileset *ts;
struct map_exit *e;
- SDL_Rect imgrect, surfacerect;
struct area *a;
+ int x, y;
init();
vp = init_viewport(240, 160, 32);
- screen = vp->screen;
map = map_get("data/forest1-8bit.tmx");
a = area_new(map);
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(500);
-
-#if 0
- vp->x = 208;
- vp->y = 544;
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(125);
- for (; vp->y >= 464; vp->y -= 4) {
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(50);
- }
- for (; vp->x <= 256; vp->x += 4) {
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(50);
- }
- for (; vp->y >= 192; vp->y -= 4) {
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(50);
- }
- for (; vp->x >= 160; vp->x -= 4) {
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(50);
- }
- for (; vp->y <= 288; vp->y += 4) {
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(50);
- }
-#endif
- vp->x = 208;
- vp->y = 544;
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(125);
- for (; vp->y >= 464; vp->y -= 4) {
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(25);
- }
- for (; vp->x <= 256; vp->x += 4) {
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(25);
- }
- for (; vp->y >= 192; vp->y -= 4) {
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(25);
- }
- for (; vp->x >= 160; vp->x -= 4) {
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(25);
- }
- for (; vp->y <= 320; vp->y += 4) {
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(25);
- }
- for (; vp->x >= -16; vp->x -= 4) {
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(25);
- }
- for (; vp->y >= 192; vp->y -= 4) {
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(25);
- }
- for (; vp->x <= 64; vp->x += 4) {
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(25);
- }
- for (; vp->y >= 0; vp->y -= 4) {
- render_area_to_viewport(a, vp);
- SDL_Flip(screen);
- SDL_Delay(25);
- }
-
- quit(0);
+ 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) {
@@ -129,68 +70,20 @@ main(void)
e->target_x_coord, e->target_y_coord);
}
- img = img_png_get("../forest-6-layer-test_ground.png");
- debug("screen: bpp: %u, masks: 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x",
- screen->format->BitsPerPixel,
- screen->format->Rmask, screen->format->Gmask,
- screen->format->Bmask, screen->format->Amask);
- 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);
- quit(0);
- return 0;
- img = img_png_get("../forest-6-layer-test_ground.png");
- img = img_png_get("../forest-6-layer-test_ground.png");
- img = img_png_get("../forest-6-layer-test_ground.png");
- img = img_png_get("../forest-6-layer-test_ground.png");
- img_png_free(img);
- img_png_free(img);
- img_png_free(img);
- img = img_png_get("../forest-6-layer-test_ground.png");
- imgrect.w = 240;
- imgrect.h = 160;
- surfacerect.x = 0;
- surfacerect.y = 0;
- surfacerect.w = 240;
- surfacerect.h = 160;
-
- imgrect.x = 208;
- imgrect.y = 480;
- SDL_BlitSurface(img->image, &imgrect, screen, &surfacerect);
- SDL_Flip(screen);
- SDL_Delay(500);
-
- imgrect.x = 208;
- imgrect.y = 464;
- SDL_BlitSurface(img->image, &imgrect, screen, &surfacerect);
- SDL_Flip(screen);
- SDL_Delay(500);
-
- imgrect.x = 224;
- imgrect.y = 464;
- SDL_BlitSurface(img->image, &imgrect, screen, &surfacerect);
- SDL_Flip(screen);
- SDL_Delay(500);
-
- imgrect.x = 240;
- imgrect.y = 464;
- SDL_BlitSurface(img->image, &imgrect, screen, &surfacerect);
- SDL_Flip(screen);
- SDL_Delay(500);
-
- imgrect.x = 256;
- imgrect.y = 464;
- SDL_BlitSurface(img->image, &imgrect, screen, &surfacerect);
- SDL_Flip(screen);
- SDL_Delay(500);
-
- imgrect.x = 256;
- imgrect.y = 448;
- SDL_BlitSurface(img->image, &imgrect, screen, &surfacerect);
- SDL_Flip(screen);
- SDL_Delay(500);
+ /* Demo */
+ x = 19;
+ y = 38;
+ for (; y > 34; y -= 1) DEMO(); /* Up */
+ for (; x < 23; x += 1) DEMO(); /* Right */
+ for (; y > 16; y -= 1) DEMO(); /* Up */
+ for (; x > 15; x -= 1) DEMO(); /* Left */
+ for (; y < 25; y += 1) DEMO(); /* Down */
+ for (; x > 4; x -= 1) DEMO(); /* Left */
+ for (; y > 18; y -= 1) DEMO(); /* Up */
+ for (; x < 9; x += 1) DEMO(); /* Right */
+ for (; y > 5; y -= 1) DEMO(); /* Up */
+ for (; x < 15; x += 1) DEMO(); /* Right */
+ for (; y > 1; y -= 1) DEMO(); /* Up */
quit(0);