+++ /dev/null
-/* Project 16 Source Code~\r
- * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
- *\r
- * This file is part of Project 16.\r
- *\r
- * Project 16 is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Project 16 is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>, or\r
- * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
- * Fifth Floor, Boston, MA 02110-1301 USA.\r
- *\r
- */\r
-/*\r
- scroll16 library~\r
-*/\r
-#include "src/lib/zcroll16.h"\r
-\r
-boolean boundary_check(int x, int y, int dx, int dy, int h, int w){\r
- 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);\r
-}\r
-\r
-boolean coll_check(int x, int y, int dx, int dy, map_view_t *map_v){\r
- // Assume everything crosses at most 1 tile at once\r
- return dx && 1;//crossable_tile(x + dx, map_v) || dy && crossable_tile(y + dy, map_v);\r
-}\r
-\r
-boolean walk(entity_t *ent, map_view_t *map_v){\r
- return 1;\r
- int dx = 1;\r
- int dy = 1;\r
- switch(ent->d){\r
- case STOP:\r
- return 0;\r
- case LEFT:\r
- dx = -dx;\r
- case RIGHT:\r
- dy = 0;\r
- break;\r
- case UP:\r
- dy = -dy;\r
- case DOWN:\r
- dx = 0;\r
- break;\r
- }\r
- if(coll_check(ent->x, ent->y, dx, dy, map_v)){\r
- // Allow movement\r
- // Set speed\r
- // Start animation\r
- // Mark next tile as occupied\r
- // Mark this tile as vacant\r
- return 1;\r
- }\r
- return 0;\r
-}\r
-\r
-void player_walk(player_t *player, map_view_t *map_v){\r
- int dx, dy;\r
- if(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)){\r
- mapScroll(map_v, player);\r
- // (Un)load stuff?\r
- }\r
-}\r
-\r
-void mapGoTo(map_view_t *mv, int tx, int ty)\r
-{\r
- return;\r
-}\r
-\r
-void near mapScroll(map_view_t *mv, player_t *player){\r
- word x, y; /* coordinate for drawing */\r
- int c = 1;\r
- int delta;\r
- mv->delta += player->dx | player->dy;\r
- delta = mv->delta;\r
- mv->d = (player->dx) ? (player->dx > 0) ? RIGHT : LEFT : (player->dy) ? (player->dy > 0) ? DOWN : UP : STOP;\r
- switch(mv->d){\r
- case DOWN:\r
- c = -1;\r
- delta = -delta;\r
- case UP:\r
- if(!(delta + mv->dxThresh)){\r
- mv->delta = 0;\r
- mv->ty += c;\r
- }\r
- break;\r
- case RIGHT:\r
- c = -1;\r
- delta = -delta;\r
- case LEFT:\r
- if(!(delta + mv->dyThresh)){\r
- mv->delta = 0;\r
- mv->tx += c;\r
- }\r
- break;\r
- default:\r
- break;\r
- }\r
-\r
- mv->video->r=1;\r
-}\r
-\r
-sword chkmap(map_t *map, word q)\r
-{\r
- /*\r
-// bitmap_t bp;\r
- static byte x[(MAPW*MAPH)+1] =\r
-{ 1, 2, 3, 4, 0, 3, 3, 3, 3, 3, 3, 3, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 6, 7, 8, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 10, 11, 12, 4, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10 };\r
- //check for failed to load map\r
- if((map->width == map->height == 0) && (q>0))\r
- {\r
- //initiate a null map!\r
- map->width=MAPW;///2;\r
- map->height=MAPH;///2;\r
-// map->data = malloc(((map->width*map->height)+1)*sizeof(byte));\r
- map->data = &x;\r
- map->tiles = malloc(sizeof(tiles_t));\r
- //fix this to be far~\r
-// bp = bitmapLoadPcx("data/ed.pcx");\r
-// map->tiles->data = &bp;\r
- map->tiles->debug_data = map->data;\r
- map->tiles->tileHeight = 16;\r
- map->tiles->tileWidth = 16;\r
- map->tiles->rows = 1;\r
- map->tiles->cols = 1;\r
- map->tiles->debug_text = true;\r
- }\r
- else map->tiles->debug_text = false;*/\r
- return 0;\r
-}\r
-\r
-//TODO: player position here\r
-\r
-void near\r
-mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)\r
-{\r
- word rx;\r
- word ry;\r
- word textx=0;\r
- word texty=0;\r
- //if(i==0) i=2;\r
- if(i==0)\r
- {\r
- //wwww\r
- modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 0); //currently the over scan color!\r
- }\r
- else\r
- {\r
- rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);\r
- ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);\r
-////0000printf("i=%d\n", i);\r
- switch(t->debug_text)\r
- {\r
- case 0:\r
-#ifndef TILERENDER\r
- modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, ((t->debug_data[i])+1));\r
- //modexprint(page, x, y, 1, 15, 0, (char const *)(t->debug_data[i]));\r
-#else\r
- PBUFBFUN (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));\r
- /* then the sprite. note modding ram ptr means we just draw to (x&3,0) */\r
- //draw_vrl1_vgax_modex(x-rx,y-ry,vrl_header,vrl_lineoffs,buffer+sizeof(*vrl_header),bufsz-sizeof(*vrl_header));\r
- //modexDrawBmpRegion (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));\r
-#endif\r
- break;\r
- case 1:\r
- modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, (t->debug_data[i])+1);\r
- //modexprintbig(page, x, y, 1, 15, 0, (t->debug_data));\r
- /*for(texty=0; texty<2; texty++)\r
- {\r
- for(textx=0; textx<2; textx++)\r
- {*/\r
-// modexprint(page, x+(textx*8), y+(texty*8), 1, (word)(t->debug_data), 0, (t->debug_data));\r
-/* }\r
- }*/\r
- break;\r
- }\r
- }\r
-}\r
-\r
-boolean pageflipflop = 1;\r
-\r
-void near animatePlayer(map_view_t *pip, player_t *player, sword scrollswitch)\r
-{\r
- sword x = player->x;\r
- sword y = player->y;\r
- sword bx = x+16; //buffer's x\r
- sword by = y+16; //buffer's y\r
- word dire=32; //direction\r
- sword qq; //scroll offset\r
- word ls = player->persist_aniframe;\r
-\r
- switch(scrollswitch)\r
- {\r
- case 0:\r
- qq = 0;\r
- break;\r
- default:\r
- qq = ((player->q)*(player->speed));\r
- break;\r
- }\r
- //x-=4;\r
- //y-=pip->map->tiles->tileHeight;\r
- switch (player->d)\r
- {\r
- case 0:\r
- //up\r
- dire*=player->d;\r
- y-=qq;\r
- by-=4;\r
- break;\r
- case 3:\r
- // right\r
- dire*=(player->d-2);\r
- x+=qq;\r
- bx+=4;\r
- break;\r
- case 2:\r
- break;\r
- case 4:\r
- //down\r
- dire*=(player->d-2);\r
- y+=qq;\r
- by+=4;\r
- break;\r
- case 1:\r
- //left\r
- dire*=(player->d+2);\r
- x-=qq;\r
- bx-=4;\r
- break;\r
- }\r
-\r
-#ifdef SPRITE\r
-#define FRAME1 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 48, dire, 24, 32, PLAYERBMPDATA);\r
-#define FRAME2 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 24, dire, 24, 32, PLAYERBMPDATA);\r
-#define FRAME3 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 0, dire, 24, 32, PLAYERBMPDATA);\r
-#define FRAME4 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 24, dire, 24, 32, PLAYERBMPDATA);\r
-#else\r
-#define FRAME1 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 24, 32, 2+dire);\r
-#define FRAME2 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 24, 32, 1+dire);\r
-#define FRAME3 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 24, 32, dire);\r
-#define FRAME4 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 24, 32, 1+dire);\r
-#endif\r
- if(!pageflipflop)\r
- modexCopyPageRegion(pip->page, pip->page, x-4, y-4, x-4, y-4, 28, 36);\r
- else{\r
- //copy old bg to page0\r
- //modexCopyPageRegion(pip[3].page, pip[0].page, bx, by, 0, 0, 20, 36);\r
- //update buffer\r
- //modexCopyPageRegion(pip[0].page, pip[3].page, 0, 0, x, y, 20, 36);\r
- }\r
- switch(ls)\r
- {\r
- case 1:\r
- FRAME1\r
- break;\r
- case 2:\r
- FRAME2\r
- break;\r
- case 3:\r
- FRAME3\r
- break;\r
- case 4:\r
- FRAME4\r
- break;\r
- }\r
- pip->video->r=1;\r
-}\r