-}\r
-\r
-\r
-map_t\r
-allocMap(int w, int h) {\r
- map_t result;\r
-\r
- result.width =w;\r
- result.height=h;\r
- result.data = malloc(sizeof(byte) * w * h);\r
-\r
- return result;\r
-}\r
-\r
-\r
-void\r
-initMap(map_t *map) {\r
- /* just a place holder to fill out an alternating pattern */\r
- int x, y;\r
- int i;\r
- int tile = 1;\r
- map->tiles = malloc(sizeof(tiles_t));\r
-\r
- /* create the tile set */\r
- map->tiles->data = malloc(sizeof(bitmap_t));\r
- map->tiles->data->width = (TILEWH*2);\r
- map->tiles->data->height= TILEWH;\r
- map->tiles->data->data = malloc((TILEWH*2)*TILEWH);\r
- map->tiles->tileHeight = TILEWH;\r
- map->tiles->tileWidth =TILEWH;\r
- map->tiles->rows = 1;\r
- map->tiles->cols = 2;\r
-\r
- i=0;\r
- for(y=0; y<TILEWH; y++) {\r
- for(x=0; x<(TILEWH*2); x++) {\r
- if(x<TILEWH)\r
- map->tiles->data->data[i] = 0x24;\r
- else\r
- map->tiles->data->data[i] = 0x34;\r
- i++;\r
- }\r
- }\r
-\r
- i=0;\r
- for(y=0; y<map->height; y++) {\r
- for(x=0; x<map->width; x++) {\r
- map->data[i] = tile;\r
- tile = tile ? 0 : 1;\r
- i++;\r
- }\r
- tile = tile ? 0 : 1;\r
- }\r
-}\r
-\r
-\r
-void\r
-mapScrollRight(map_view_t *mv, byte offset) {\r
- word x, y; /* coordinate for bging */\r
-\r
- /* increment the pixel position and update the page */\r
- mv->page->dx += offset;\r
-\r
- /* check to see if this changes the tile */\r
- if(mv->page->dx >= mv->dxThresh ) {\r
- /* go forward one tile */\r
- mv->tx++;\r
- /* Snap the origin forward */\r
- mv->page->data += 4;\r
- mv->page->dx = mv->map->tiles->tileWidth;\r
-\r
-\r
- /* bg the next column */\r
- x= SCREEN_WIDTH + mv->map->tiles->tileWidth;\r
- mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);\r
- }\r
-}\r
-\r
-\r
-void\r
-mapScrollLeft(map_view_t *mv, byte offset) {\r
- word x, y; /* coordinate for bging */\r
-\r
- /* increment the pixel position and update the page */\r
- mv->page->dx -= offset;\r
-\r
- /* check to see if this changes the tile */\r
- if(mv->page->dx == 0) {\r
- /* go backward one tile */\r
- mv->tx--;\r
- \r
- /* Snap the origin backward */\r
- mv->page->data -= 4;\r
- mv->page->dx = mv->map->tiles->tileWidth;\r
-\r
- /* bg the next column */\r
- mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);\r
- }\r
-}\r
-\r
-\r
-void\r
-mapScrollUp(map_view_t *mv, byte offset) {\r
- word x, y; /* coordinate for bging */\r
-\r
- /* increment the pixel position and update the page */\r
- mv->page->dy -= offset;\r
-\r
- /* check to see if this changes the tile */\r
- if(mv->page->dy == 0 ) {\r
- /* go down one tile */\r
- mv->ty--;\r
- /* Snap the origin downward */\r
- mv->page->data -= mv->page->width*4;\r
- mv->page->dy = mv->map->tiles->tileHeight;\r
-\r
-\r
- /* bg the next row */\r
- y= 0;\r
- mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);\r
- }\r
-}\r
-\r
-\r
-void\r
-mapScrollDown(map_view_t *mv, byte offset) {\r
- word x, y; /* coordinate for bging */\r
-\r
- /* increment the pixel position and update the page */\r
- mv->page->dy += offset;\r
-\r
- /* check to see if this changes the tile */\r
- if(mv->page->dy >= mv->dyThresh ) {\r
- /* go down one tile */\r
- mv->ty++;\r
- /* Snap the origin downward */\r
- mv->page->data += mv->page->width*4;\r
- mv->page->dy = mv->map->tiles->tileHeight;\r
-\r
-\r
- /* bg the next row */\r
- y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;\r
- mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);\r
- }\r
-\r
-}\r
-\r
-\r
-void\r
-mapGoTo(map_view_t *mv, int tx, int ty) {\r
- int px, py;\r
- unsigned int i;\r
-\r
- /* set up the coordinates */\r
- mv->tx = tx;\r
- mv->ty = ty;\r
- mv->page->dx = mv->map->tiles->tileWidth;\r
- mv->page->dy = mv->map->tiles->tileHeight;\r
-\r
- /* set up the thresholds */\r
- mv->dxThresh = mv->map->tiles->tileWidth * 2;\r
- mv->dyThresh = mv->map->tiles->tileHeight * 2;\r
-\r
- /* bg the tiles */\r
- modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);\r
- py=0;\r
- i=mv->ty * mv->map->width + mv->tx;\r
- for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {\r
- mapDrawRow(mv, tx-1, ty, py);\r
- i+=mv->map->width - tx;\r
- }\r
-}\r
-\r
-\r
-void\r
-mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {\r
- word rx;\r
- word ry;\r
- rx = (i % t->cols) * t->tileWidth;\r
- ry = (i / t->cols) * t->tileHeight;\r
- modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);\r
-}\r
-\r
-\r
-void \r
-mapDrawRow(map_view_t *mv, int tx, int ty, word y) {\r
- word x;\r
- int i;\r
-\r
- /* the position within the map array */\r
- i=ty * mv->map->width + tx;\r
- for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {\r
- if(i>=0) {\r
- /* we are in the map, so copy! */\r
- mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);\r
- }\r
- i++; /* next! */\r
- }\r
-}\r
-\r
-\r
-void \r
-mapDrawCol(map_view_t *mv, int tx, int ty, word x) {\r
- int y;\r
- int i;\r
-\r
- /* location in the map array */\r
- i=ty * mv->map->width + tx;\r
-\r
- /* We'll copy all of the columns in the screen, \r
- i + 1 row above and one below */\r
- for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {\r
- if(i>=0) {\r
- /* we are in the map, so copy away! */\r
- mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);\r
- }\r
- i += mv->map->width;\r
- }\r
-}\r
-
-void animatePlayer(map_view_t *mv, map_view_t *src, short d1, short d2, int x, int y, int ls, bitmap_t *bmp)
+ printf("player.triggx: %d\n", player.triggerx);
+ printf("player.triggy: %d\n", player.triggery);
+}
+
+
+map_t
+allocMap(int w, int h) {
+ map_t result;
+
+ result.width =w;
+ result.height=h;
+ result.data = malloc(sizeof(byte) * w * h);
+
+ return result;
+}
+
+
+void
+initMap(map_t *map) {
+ /* just a place holder to fill out an alternating pattern */
+ int x, y;
+ int i;
+ int tile = 1;
+ map->tiles = malloc(sizeof(tiles_t));
+
+ /* create the tile set */
+ map->tiles->data = malloc(sizeof(bitmap_t));
+ map->tiles->data->width = (TILEWH*2);
+ map->tiles->data->height= TILEWH;
+ map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
+ map->tiles->tileHeight = TILEWH;
+ map->tiles->tileWidth =TILEWH;
+ map->tiles->rows = 1;
+ map->tiles->cols = 2;
+
+ i=0;
+ for(y=0; y<TILEWH; y++) {
+ for(x=0; x<(TILEWH*2); x++) {
+ if(x<TILEWH)
+ map->tiles->data->data[i] = 0x24;
+ else
+ map->tiles->data->data[i] = 0x34;
+ i++;
+ }
+ }
+
+ i=0;
+ for(y=0; y<map->height; y++) {
+ for(x=0; x<map->width; x++) {
+ map->data[i] = tile;
+ tile = tile ? 0 : 1;
+ i++;
+ }
+ tile = tile ? 0 : 1;
+ }
+}
+
+
+void
+mapScrollRight(map_view_t *mv, byte offset) {
+ word x, y; /* coordinate for drawing */
+
+ /* increment the pixel position and update the page */
+ mv->page->dx += offset;
+
+ /* check to see if this changes the tile */
+ if(mv->page->dx >= mv->dxThresh ) {
+ /* go forward one tile */
+ mv->tx++;
+ /* Snap the origin forward */
+ mv->page->data += 4;
+ mv->page->dx = mv->map->tiles->tileWidth;
+
+
+ /* draw the next column */
+ x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
+ mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
+ }
+}
+
+
+void
+mapScrollLeft(map_view_t *mv, byte offset) {
+ word x, y; /* coordinate for drawing */
+
+ /* increment the pixel position and update the page */
+ mv->page->dx -= offset;
+
+ /* check to see if this changes the tile */
+ if(mv->page->dx == 0) {
+ /* go backward one tile */
+ mv->tx--;
+
+ /* Snap the origin backward */
+ mv->page->data -= 4;
+ mv->page->dx = mv->map->tiles->tileWidth;
+
+ /* draw the next column */
+ mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
+ }
+}
+
+
+void
+mapScrollUp(map_view_t *mv, byte offset) {
+ word x, y; /* coordinate for drawing */
+
+ /* increment the pixel position and update the page */
+ mv->page->dy -= offset;
+
+ /* check to see if this changes the tile */
+ if(mv->page->dy == 0 ) {
+ /* go down one tile */
+ mv->ty--;
+ /* Snap the origin downward */
+ mv->page->data -= mv->page->width*4;
+ mv->page->dy = mv->map->tiles->tileHeight;
+
+
+ /* draw the next row */
+ y= 0;
+ mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
+ }
+}
+
+
+void
+mapScrollDown(map_view_t *mv, byte offset) {
+ word x, y; /* coordinate for drawing */
+
+ /* increment the pixel position and update the page */
+ mv->page->dy += offset;
+
+ /* check to see if this changes the tile */
+ if(mv->page->dy >= mv->dyThresh ) {
+ /* go down one tile */
+ mv->ty++;
+ /* Snap the origin downward */
+ mv->page->data += mv->page->width*4;
+ mv->page->dy = mv->map->tiles->tileHeight;
+
+
+ /* draw the next row */
+ y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
+ mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
+ }
+
+}
+
+
+void
+mapGoTo(map_view_t *mv, int tx, int ty) {
+ int px, py;
+ unsigned int i;
+
+ /* set up the coordinates */
+ mv->tx = tx;
+ mv->ty = ty;
+ mv->page->dx = mv->map->tiles->tileWidth;
+ mv->page->dy = mv->map->tiles->tileHeight;
+
+ /* set up the thresholds */
+ mv->dxThresh = mv->map->tiles->tileWidth * 2;
+ mv->dyThresh = mv->map->tiles->tileHeight * 2;
+
+ /* draw the tiles */
+ modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
+ py=0;
+ i=mv->ty * mv->map->width + mv->tx;
+ for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
+ mapDrawRow(mv, tx-1, ty, py);
+ i+=mv->map->width - tx;
+ }
+}
+
+
+void
+mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
+ word rx;
+ word ry;
+ rx = (i % t->cols) * t->tileWidth;
+ ry = (i / t->cols) * t->tileHeight;
+ modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
+}
+
+
+void
+mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
+ word x;
+ int i;
+
+ /* the position within the map array */
+ i=ty * mv->map->width + tx;
+ for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
+ if(i>=0) {
+ /* we are in the map, so copy! */
+ mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
+ }
+ i++; /* next! */
+ }
+}
+
+
+void
+mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
+ int y;
+ int i;
+
+ /* location in the map array */
+ i=ty * mv->map->width + tx;
+
+ /* We'll copy all of the columns in the screen,
+ i + 1 row above and one below */
+ for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
+ if(i>=0) {
+ /* we are in the map, so copy away! */
+ mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
+ }
+ i += mv->map->width;
+ }
+}
+
+void
+animatePlayer(map_view_t *src, map_view_t *dest, /*map_view_t *top, */short d1, short d2, int x, int y, int ls, int lp, bitmap_t *bmp)