X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Flib%2Fscroll16.c;h=940baa8aab75b8ff30c3ca851d6b2584277a8011;hb=bca8e8542d6f90dd230c48d369bb232878b9f165;hp=cb014fd06bf126206eedaa47b6c2b776be4bfeae;hpb=989f287818c93cf9b1ff96c13e66720571210513;p=proj16%2F16.git diff --git a/src/lib/scroll16.c b/src/lib/scroll16.c index cb014fd0..940baa8a 100755 --- a/src/lib/scroll16.c +++ b/src/lib/scroll16.c @@ -46,7 +46,7 @@ void walk(map_view_t *pip, player_t *player, word pn) animatePlayer(pip, player, pn, 1); ScrollRight(pip, player, 3, pn); ScrollRight(pip, player, 2, pn); - mapScrollRight(pip, player, !(pip[0].video->p), pn); + //mapScrollRight(pip, player, !(pip[0].video->p), pn); mapScrollRight(pip, player, (pip[0].video->p), pn); if(!pageflipflop) modexShowPage(pip[1].page); player[pn].q++; @@ -90,7 +90,7 @@ void walk(map_view_t *pip, player_t *player, word pn) animatePlayer(pip, player, pn, 1); ScrollLeft(pip, player, 3, pn); ScrollLeft(pip, player, 2, pn); - mapScrollLeft(pip, player, !(pip[0].video->p), pn); + //mapScrollLeft(pip, player, !(pip[0].video->p), pn); mapScrollLeft(pip, player, (pip[0].video->p), pn); if(!pageflipflop) modexShowPage(pip[1].page); player[pn].q++; @@ -134,7 +134,7 @@ void walk(map_view_t *pip, player_t *player, word pn) animatePlayer(pip, player, pn, 1); ScrollDown(pip, player, 3, pn); ScrollDown(pip, player, 2, pn); - mapScrollDown(pip, player, !(pip[0].video->p), pn); + //mapScrollDown(pip, player, !(pip[0].video->p), pn); mapScrollDown(pip, player, (pip[0].video->p), pn); if(!pageflipflop) modexShowPage(pip[1].page); player[pn].q++; @@ -178,7 +178,7 @@ void walk(map_view_t *pip, player_t *player, word pn) animatePlayer(pip, player, pn, 1); ScrollUp(pip, player, 3, pn); ScrollUp(pip, player, 2, pn); - mapScrollUp(pip, player, !(pip[0].video->p), pn); + //mapScrollUp(pip, player, !(pip[0].video->p), pn); mapScrollUp(pip, player, (pip[0].video->p), pn); if(!pageflipflop) modexShowPage(pip[1].page); player[pn].q++; @@ -214,7 +214,7 @@ void walk(map_view_t *pip, player_t *player, word pn) } //panning page -void panpagemanual(map_view_t *pip, player_t *player, word pn) +void panPageManual(map_view_t *pip, player_t *player, word pn) { switch(player[pn].d) { @@ -224,7 +224,7 @@ void panpagemanual(map_view_t *pip, player_t *player, word pn) { if(player[pn].q<=player[pn].spt) { - pip[pip[0].pan->pn].page->dx+=4; + pip[pip[0].pan->pn].page[0].dx+=4; modexShowPage(pip[pip[0].pan->pn].page); player[pn].q++; } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx++; } @@ -237,7 +237,7 @@ void panpagemanual(map_view_t *pip, player_t *player, word pn) { if(player[pn].q<=player[pn].spt) { - pip[pip[0].pan->pn].page->dx-=4; + pip[pip[0].pan->pn].page[0].dx-=4; modexShowPage(pip[pip[0].pan->pn].page); player[pn].q++; } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx--; } @@ -250,7 +250,7 @@ void panpagemanual(map_view_t *pip, player_t *player, word pn) { if(player[pn].q<=player[pn].spt) { - pip[pip[0].pan->pn].page->dy+=4; + pip[pip[0].pan->pn].page[0].dy+=4; modexShowPage(pip[pip[0].pan->pn].page); player[pn].q++; } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty++; } @@ -263,16 +263,48 @@ void panpagemanual(map_view_t *pip, player_t *player, word pn) { if(player[pn].q<=player[pn].spt) { - pip[pip[0].pan->pn].page->dy-=4; + pip[pip[0].pan->pn].page[0].dy-=4; modexShowPage(pip[pip[0].pan->pn].page); player[pn].q++; } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty--; } - } + }//tx ty dx dy th tw break; } //if (player[pn].d!=2) printf("player[%u].d=%u player[%u].q=%u\n", pn, player[pn].d, pn, player[pn].q); } +/* + * modex mv setup +*/ +void modexMVSetup(map_view_t *pip, map_t *map, pan_t *pan, global_game_variables_t *gv) +{ + nibble i; + // 1st page + pip[0].page = &gv->video.page[0]; + pip[0].map = map; + pip[0].video = &gv->video; + pip[0].pan = pan; + modexMVInit(pip, 1, 1); + + for(i=1;ivideo.num_of_pages;i++) + { + pip[i].page = &gv->video.page[i]; + pip[i].map = pip[0].map; + pip[i].video = pip[0].video; + pip[i].pan = pip[0].pan; + //pip[i].tx = 1; + //pip[i].ty = 1; + } +} + +void modexMVInit(map_view_t *mv, int tx, int ty) +{ + mv[0].tx = tx; + mv[0].ty = ty; + //mv[0].tx = mv[1].tx = tx; + //mv[0].ty = mv[1].ty = ty; +} + /*map_t allocMap(int w, int h) { map_t result; @@ -365,24 +397,24 @@ void near mapScrollRight(map_view_t *mv, player_t *player, word id, word plid) word x;//, y; /* coordinate for drawing */ /* increment the pixel position and update the page */ - mv[id].page->dx += player[plid].speed; + mv[id].page[0].dx += player[plid].speed; /* check to see if this changes the tile */ - if(mv[id].page->dx >= mv[id].dxThresh ) + if(mv[id].page[0].dx >= mv[id].dxThresh ) { /* go forward one tile */ mv[id].tx++; /* Snap the origin forward */ mv[id].page->data += 4; - mv[id].page->dx = mv[id].map->tiles->tileWidth; + mv[id].page[0].dx = mv[id].map->tiles->tileWidth; } /* draw the next column */ x= mv[0].page->sw + mv[id].map->tiles->tileWidth; if(player[plid].q%4) if(id==0) - mapDrawCol(&mv[0], mv[0].tx + mv[0].page->tw, mv[0].ty-1, x, player, mv->page->dx); + mapDrawCol(&mv[0], mv[0].tx + mv[0].page->tw, mv[0].ty-1, x, player, mv->page[0].dx); else if(!pageflipflop && !pageploop) modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*(mv[0].page->th+2)); @@ -395,24 +427,24 @@ void near mapScrollLeft(map_view_t *mv, player_t *player, word id, word plid) word x;//,y; /* coordinate for drawing */ /* decrement the pixel position and update the page */ - mv[id].page->dx -= player[plid].speed; + mv[id].page[0].dx -= player[plid].speed; /* check to see if this changes the tile */ - if(mv[id].page->dx == 0) + if(mv[id].page[0].dx == 0) { /* go backward one tile */ mv[id].tx--; /* Snap the origin backward */ mv[id].page->data -= 4; - mv[id].page->dx = mv[id].map->tiles->tileWidth; + mv[id].page[0].dx = mv[id].map->tiles->tileWidth; } /* draw the next column */ x= 0; if(player[plid].q%4) if(id==0) - mapDrawCol(&mv[0], mv[0].tx - 1, mv[0].ty-1, x, player, mv->page->dx); + mapDrawCol(&mv[0], mv[0].tx - 1, mv[0].ty-1, x, player, mv->page[0].dx); else if(!pageflipflop && !pageploop) modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*(mv[0].page->th+2)); @@ -425,24 +457,24 @@ void near mapScrollUp(map_view_t *mv, player_t *player, word id, word plid) word y;//x, /* coordinate for drawing */ /* decrement the pixel position and update the page */ - mv[id].page->dy -= player[plid].speed; + mv[id].page[0].dy -= player[plid].speed; /* check to see if this changes the tile */ - if(mv[id].page->dy == 0 ) + if(mv[id].page[0].dy == 0 ) { /* go down one tile */ mv[id].ty--; /* Snap the origin downward */ mv[id].page->data -= mv[id].page->pi; - mv[id].page->dy = mv[id].map->tiles->tileHeight; + mv[id].page[0].dy = mv[id].map->tiles->tileHeight; } /* draw the next row */ y= 0; if(player[plid].q%3) if(id==0) - mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty-1, y, player, mv->page->dy); + mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty-1, y, player, mv->page[0].dy); else if(!pageflipflop && !pageploop) modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*(mv[0].page->tw+2), mv[id].map->tiles->tileHeight); @@ -454,24 +486,24 @@ void near mapScrollDown(map_view_t *mv, player_t *player, word id, word plid) word y;//x, /* coordinate for drawing */ /* increment the pixel position and update the page */ - mv[id].page->dy += player[plid].speed; + mv[id].page[0].dy += player[plid].speed; /* check to see if this changes the tile */ - if(mv[id].page->dy >= mv[id].dyThresh ) + if(mv[id].page[0].dy >= mv[id].dyThresh ) { /* go down one tile */ mv[id].ty++; /* Snap the origin downward */ mv[id].page->data += mv[id].page->pi; - mv[id].page->dy = mv[id].map->tiles->tileHeight; + mv[id].page[0].dy = mv[id].map->tiles->tileHeight; } /* draw the next row */ y= mv[0].page->sh + mv[id].map->tiles->tileHeight; if(player[plid].q%3) if(id==0) - mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty+mv[0].page->th, y, player, mv->page->dy); + mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty+mv[0].page->th, y, player, mv->page[0].dy); else if(!pageflipflop && !pageploop) modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*(mv[0].page->tw+2), mv[id].map->tiles->tileHeight); @@ -548,6 +580,16 @@ void near ScrollDown(map_view_t *mv, player_t *player, word id, word plid) } } +//=========================================================================== +//TODO: put player in starting position of assigned spot on map +//default player position on the viewable map +void playerXYpos(int x, int y, player_t *player, map_view_t *pip, nibble pn) +{ + player[pn].tx = x + pip[0].tx + pip[0].page->tilemidposscreenx; + player[pn].ty = y + pip[0].ty + pip[0].page->tilemidposscreeny; +} +//=========================================================================== + sword chkmap(map_t *map, word q) { // bitmap_t bp; @@ -580,14 +622,20 @@ sword chkmap(map_t *map, word q) //fix this to be far~ // bp = bitmapLoadPcx("data/ed.pcx"); // map->tiles->data = &bp; - map->tiles->debug_data = map->data; +#ifdef __DEBUG_MAP__ + dbg_mapdata = map->data; +#endif map->tiles->tileHeight = 16; map->tiles->tileWidth = 16; map->tiles->rows = 1; map->tiles->cols = 1; - map->tiles->debug_text = true; +#ifdef __DEBUG_MAP__ + dbg_maptext = true; +#endif } - else map->tiles->debug_text = false; +#ifdef __DEBUG_MAP__ + else dbg_maptext = false; +#endif return 0; } @@ -597,15 +645,7 @@ void mapGoTo(map_view_t *mv, int tx, int ty) int py;//px, unsigned int i; - /* set up the coordinates */ - mv[0].tx = mv[1].tx = tx; - mv[0].ty = mv[1].ty = ty; - mv[0].page->dx = mv[1].page->dx = mv[2].page->dx = mv[3].page->dx = mv->map->tiles->tileWidth; - mv[0].page->dy = mv[1].page->dy = mv[2].page->dy = mv[3].page->dy = mv->map->tiles->tileHeight; - - /* set up the thresholds */ - mv[0].dxThresh = mv[1].dxThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileWidth * 2; - mv[0].dyThresh = mv[1].dyThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileHeight * 2; + mapinitmapview(mv, tx, ty); /* draw the tiles */ modexClearRegion(mv[0].page, 0, 0, mv[0].page->width, mv[0].page->height, 0); @@ -629,6 +669,19 @@ void mapGoTo(map_view_t *mv, int tx, int ty) modexCopyPageRegion(mv[3].page, mv[0].page, 0/**/, 0/**/, 0, 0, 24, 32); } +void mapinitmapview(map_view_t *mv, int tx, int ty) +{ + /* set up the coordinates */ + mv[0].tx = mv[1].tx = tx; + mv[0].ty = mv[1].ty = ty; + mv[0].page->dx = mv[1].page->dx = mv[2].page->dx = mv[3].page->dx = mv->map->tiles->tileWidth; + mv[0].page->dy = mv[1].page->dy = mv[2].page->dy = mv[3].page->dy = mv->map->tiles->tileHeight; + + /* set up the thresholds */ + mv[0].dxThresh = mv[1].dxThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileWidth * 2; + mv[0].dyThresh = mv[1].dyThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileHeight * 2; +} + void near mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) { @@ -646,11 +699,13 @@ mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth); ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight); ////0000printf("i=%d\n", i); - switch(t->debug_text) +#ifdef __DEBUG_MAP__ + switch(dbg_maptext) { case 0: +#endif #ifndef TILERENDER - modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, ((t->debug_data[i])+1)); + modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, ((dbg_mapdata[i])+1)); //modexprint(page, x, y, 1, 15, 0, (char const *)(t->debug_data[i])); #else PBUFBFUN (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data)); @@ -658,9 +713,10 @@ mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) //draw_vrl1_vgax_modex(x-rx,y-ry,vrl_header,vrl_lineoffs,buffer+sizeof(*vrl_header),bufsz-sizeof(*vrl_header)); //modexDrawBmpRegion (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data)); #endif +#ifdef __DEBUG_MAP__ break; case 1: - modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, (t->debug_data[i])+1); + modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, (dbg_mapdata[i])+1); //modexprintbig(page, x, y, 1, 15, 0, (t->debug_data)); /*for(texty=0; texty<2; texty++) { @@ -671,6 +727,7 @@ mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) }*/ break; } +#endif } } @@ -920,3 +977,95 @@ void near animatePlayer(map_view_t *pip, player_t *player, word pn, sword scroll //printf("x=%d y=%d bx=%d by=%d\n", x, y, bx, by); pip->video->r=1; } + +/* + * from zcroll16.c +*/ + +boolean boundary_check(int x, int y, int dx, int dy, int h, int w) +{ + return (dx > 0 && (x + dx) < w) || (dx < 0 && (x + dx) >= 0) || (dy > 0 && (y + dy) < h) || (dy < 0 && (y + dy) >= 0) || (dx == dy && dx == 0); +} + +boolean coll_check(int x, int y, int dx, int dy, map_view_t *map_v) +{ + // Assume everything crosses at most 1 tile at once + return dx && 1;//crossable_tile(x + dx, map_v) || dy && crossable_tile(y + dy, map_v); +} + +boolean ZC_walk(entity_t *ent, map_view_t *map_v) +{ + //return 1; + int dx = 1; + int dy = 1; + switch(ent->d) + { + case 2: + return 0; + case 1: + dx = -dx; + case 3: + dy = 0; + break; + case 0: + dy = -dy; + case 4: + dx = 0; + break; + } + if(coll_check(ent->x, ent->y, dx, dy, map_v)) + { + // Allow movement + // Set speed + // Start animation + // Mark next tile as occupied + // Mark this tile as vacant + return 1; + } + return 0; +} + +void player_walk(player_t *player, map_view_t *map_v){ + int dx=16, dy=16; + if(ZC_walk(player->ent, map_v) && boundary_check(map_v->tx, map_v->ty, dx, dy, map_v->map->width - 2*map_v->page->tilesw, map_v->map->height - 2*map_v->page->tilesh)) + { + mapScroll(map_v, player); + // (Un)load stuff? + } +} + +void near mapScroll(map_view_t *mv, player_t *player) +{ + //word x, y; /* coordinate for drawing */ + int c = 1; + int delta; + mv->delta += player->dx | player->dy; + delta = mv->delta; + mv->d = (player->dx) ? (player->dx > 0) ? 3 : 1 : (player->dy) ? (player->dy > 0) ? 4 : 0 : 2; + switch(mv->d){ + case 4: + c = -1; + delta = -delta; + case 0: + if(!(delta + mv->dxThresh)) + { + mv->delta = 0; + mv->ty += c; + } + break; + case 3: + c = -1; + delta = -delta; + case 1: + if(!(delta + mv->dyThresh)) + { + mv->delta = 0; + mv->tx += c; + } + break; + default: + break; + } + + mv->video->r=1; +}