6 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
14 //unsigned int tilex,tiley; // tile position on the map
29 int tx; //appears to be the top left tile position on the viewable screen map
30 int ty; //appears to be the top left tile position on the viewable screen map
36 int x; //player exact position on the viewable map
37 int y; //player exact position on the viewable map
38 int tx; //player tile position on the viewable map
39 int ty; //player tile position on the viewable map
40 int hp; //hitpoints of the player
44 map_t allocMap(int w, int h);
45 void initMap(map_t *map);
46 void mapScrollRight(map_view_t *mv, byte offset);
47 void mapScrollLeft(map_view_t *mv, byte offest);
48 void mapScrollUp(map_view_t *mv, byte offset);
49 void mapScrollDown(map_view_t *mv, byte offset);
50 void mapGoTo(map_view_t *mv, int tx, int ty);
51 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
52 void mapDrawRow(map_view_t *mv, int tx, int ty, word y);
53 void mapDrawCol(map_view_t *mv, int tx, int ty, word x);
54 void animatePlayer(map_view_t *mv, map_view_t *src, short d1, short d2, int x, int y, int ls, bitmap_t *bmp);
57 #define QUADWH (TILEWH/4)
60 //place holder definitions
63 #define SWAP(a, b) tmp=a; a=b; b=tmp;
65 bitmap_t ptmp; // player sprite
67 page_t screen, screen2;
70 map_view_t *bg, *spri, *tmp;
75 map = allocMap(MAPX,MAPY); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be bgn properly
82 ptmp = bitmapLoadPcx("ptmp.pcx"); // load sprite
84 modexPalUpdate(ptmp.palette);
85 screen = modexDefaultPage();
86 screen.width += (TILEWH*2);
88 screen2 = modexNextPage(mv.page);
89 screen2.width += (TILEWH*2);
91 //modexShowPage(mv.page);
97 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
101 //TODO: put player in starting position of spot
102 //default player position on the viewable map
103 player.tx = bg->tx + 10;
104 player.ty = bg->ty + 8;
105 player.x = player.tx*TILEWH;
106 player.y = player.ty*TILEWH;
107 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
108 modexCopyPageRegion(bg->page, spri->page, player.x-4, player.y-TILEWH-2, player.x-4, player.y-TILEWH-2, 24, 34);
109 modexShowPage(spri->page);
112 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
113 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
114 //when player.tx or player.ty == 0 or player.tx == 20 or player.ty == 15 then stop because that is edge of map and you do not want to walk of the map
116 //TODO: render the player properly with animation and sprite sheet
119 if(bg->tx >= 0 && bg->tx+20 < MAPX && player.tx == bg->tx + 10)
121 for(q=0; q<(TILEWH/SPEED); q++)
123 animatePlayer(spri, bg, 1, 1, player.x, player.y, q, &ptmp);
124 mapScrollRight(bg, SPEED);
125 mapScrollRight(spri, SPEED);
126 modexShowPage(spri->page);
130 else if(player.tx < MAPX)
132 for(q=0; q<(TILEWH/SPEED); q++)
135 animatePlayer(spri, bg, 1, 0, player.x, player.y, q, &ptmp);
136 modexShowPage(spri->page);
144 if(bg->tx > 0 && bg->tx+20 <= MAPX && player.tx == bg->tx + 10)
146 for(q=0; q<(TILEWH/SPEED); q++)
149 animatePlayer(spri, bg, 3, 1, player.x, player.y, q, &ptmp);
150 mapScrollLeft(bg, SPEED);
151 mapScrollLeft(spri, SPEED);
152 modexShowPage(spri->page);
156 else if(player.tx > 1)
158 for(q=0; q<(TILEWH/SPEED); q++)
161 animatePlayer(spri, bg, 3, 0, player.x, player.y, q, &ptmp);
162 modexShowPage(spri->page);
170 if(bg->ty >= 0 && bg->ty+15 < MAPY && player.ty == bg->ty + 8)
172 for(q=0; q<(TILEWH/SPEED); q++)
174 animatePlayer(spri, bg, 2, 1, player.x, player.y, q, &ptmp);
175 mapScrollDown(bg, SPEED);
176 mapScrollDown(spri, SPEED);
177 modexShowPage(spri->page);
181 else if(player.ty < MAPY)
183 for(q=0; q<(TILEWH/SPEED); q++)
186 animatePlayer(spri, bg, 2, 0, player.x, player.y, q, &ptmp);
187 modexShowPage(spri->page);
195 if(bg->ty > 0 && bg->ty+15 <= MAPY && player.ty == bg->ty + 8)
197 for(q=0; q<(TILEWH/SPEED); q++)
199 animatePlayer(spri, bg, 0, 1, player.x, player.y, q, &ptmp);
200 mapScrollUp(bg, SPEED);
201 mapScrollUp(spri, SPEED);
202 modexShowPage(spri->page);
206 else if(player.ty > 1)
208 for(q=0; q<(TILEWH/SPEED); q++)
211 animatePlayer(spri, bg, 0, 0, player.x, player.y, q, &ptmp);
212 modexShowPage(spri->page);
222 printf("Project 16 scroll.exe\n");
223 printf("tx: %d\n", bg->tx);
224 printf("ty: %d\n", bg->ty);
225 printf("player.x: %d\n", player.x);
226 printf("player.y: %d\n", player.y);
227 printf("player.tx: %d\n", player.tx);
228 printf("player.ty: %d\n", player.ty);
233 allocMap(int w, int h) {
238 result.data = malloc(sizeof(byte) * w * h);
245 initMap(map_t *map) {
246 /* just a place holder to fill out an alternating pattern */
250 map->tiles = malloc(sizeof(tiles_t));
252 /* create the tile set */
253 map->tiles->data = malloc(sizeof(bitmap_t));
254 map->tiles->data->width = (TILEWH*2);
255 map->tiles->data->height= TILEWH;
256 map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
257 map->tiles->tileHeight = TILEWH;
258 map->tiles->tileWidth =TILEWH;
259 map->tiles->rows = 1;
260 map->tiles->cols = 2;
263 for(y=0; y<TILEWH; y++) {
264 for(x=0; x<(TILEWH*2); x++) {
266 map->tiles->data->data[i] = 0x24;
268 map->tiles->data->data[i] = 0x34;
274 for(y=0; y<map->height; y++) {
275 for(x=0; x<map->width; x++) {
286 mapScrollRight(map_view_t *mv, byte offset) {
287 word x, y; /* coordinate for bging */
289 /* increment the pixel position and update the page */
290 mv->page->dx += offset;
292 /* check to see if this changes the tile */
293 if(mv->page->dx >= mv->dxThresh ) {
294 /* go forward one tile */
296 /* Snap the origin forward */
298 mv->page->dx = mv->map->tiles->tileWidth;
301 /* bg the next column */
302 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
303 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
309 mapScrollLeft(map_view_t *mv, byte offset) {
310 word x, y; /* coordinate for bging */
312 /* increment the pixel position and update the page */
313 mv->page->dx -= offset;
315 /* check to see if this changes the tile */
316 if(mv->page->dx == 0) {
317 /* go backward one tile */
320 /* Snap the origin backward */
322 mv->page->dx = mv->map->tiles->tileWidth;
324 /* bg the next column */
325 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
331 mapScrollUp(map_view_t *mv, byte offset) {
332 word x, y; /* coordinate for bging */
334 /* increment the pixel position and update the page */
335 mv->page->dy -= offset;
337 /* check to see if this changes the tile */
338 if(mv->page->dy == 0 ) {
339 /* go down one tile */
341 /* Snap the origin downward */
342 mv->page->data -= mv->page->width*4;
343 mv->page->dy = mv->map->tiles->tileHeight;
346 /* bg the next row */
348 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
354 mapScrollDown(map_view_t *mv, byte offset) {
355 word x, y; /* coordinate for bging */
357 /* increment the pixel position and update the page */
358 mv->page->dy += offset;
360 /* check to see if this changes the tile */
361 if(mv->page->dy >= mv->dyThresh ) {
362 /* go down one tile */
364 /* Snap the origin downward */
365 mv->page->data += mv->page->width*4;
366 mv->page->dy = mv->map->tiles->tileHeight;
369 /* bg the next row */
370 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
371 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
378 mapGoTo(map_view_t *mv, int tx, int ty) {
382 /* set up the coordinates */
385 mv->page->dx = mv->map->tiles->tileWidth;
386 mv->page->dy = mv->map->tiles->tileHeight;
388 /* set up the thresholds */
389 mv->dxThresh = mv->map->tiles->tileWidth * 2;
390 mv->dyThresh = mv->map->tiles->tileHeight * 2;
393 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
395 i=mv->ty * mv->map->width + mv->tx;
396 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
397 mapDrawRow(mv, tx-1, ty, py);
398 i+=mv->map->width - tx;
404 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
407 rx = (i % t->cols) * t->tileWidth;
408 ry = (i / t->cols) * t->tileHeight;
409 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
414 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
418 /* the position within the map array */
419 i=ty * mv->map->width + tx;
420 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
422 /* we are in the map, so copy! */
423 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
431 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
435 /* location in the map array */
436 i=ty * mv->map->width + tx;
438 /* We'll copy all of the columns in the screen,
439 i + 1 row above and one below */
440 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
442 /* we are in the map, so copy away! */
443 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
449 void animatePlayer(map_view_t *mv, map_view_t *src, short d1, short d2, int x, int y, int ls, bitmap_t *bmp)
452 int lo = ((TILEWH / SPEED) / 3);
456 else qq = ((ls+1)*SPEED);
461 if(ls<1) { modexCopyPageRegion(mv->page, src->page, x-4, y-qq-TILEWH, x-4, y-qq-TILEWH, 24, 34);
462 modexDrawSpriteRegion(mv->page, x-4, y-qq-TILEWH, 24, 0, 24, 32, bmp); }
463 if(4>ls && ls>=1) { modexCopyPageRegion(mv->page, src->page, x-4, y-qq-TILEWH, x-4, y-qq-TILEWH, 24, 34);
464 modexDrawSpriteRegion(mv->page, x-4, y-qq-TILEWH, 48, 0, 24, 32, bmp); }
465 if(7>ls && ls>=4) { modexCopyPageRegion(mv->page, src->page, x-4, y-qq-TILEWH, x-4, y-qq-TILEWH, 24, 34);
466 modexDrawSpriteRegion(mv->page, x-4, y-qq-TILEWH, 0, 0, 24, 32, bmp); }
467 if(ls>=7) { modexCopyPageRegion(mv->page, src->page, x-4, y-qq-TILEWH, x-4, y-qq-TILEWH, 24, 34);
468 modexDrawSpriteRegion(mv->page, x-4, y-qq-TILEWH, 24, 0, 24, 32, bmp); }
472 if(ls<1) { modexCopyPageRegion(mv->page, src->page, x+qq-4, y-TILEWH, x+qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
473 modexDrawSpriteRegion(mv->page, x+qq-4, y-TILEWH, 24, 32, 24, 32, bmp); }
474 if(4>ls && ls>=1) { modexCopyPageRegion(mv->page, src->page, x+qq-4, y-TILEWH, x+qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
475 modexDrawSpriteRegion(mv->page, x+qq-4, y-TILEWH, 48, 32, 24, 32, bmp); }
476 if(7>ls && ls>=4) { modexCopyPageRegion(mv->page, src->page, x+qq-4, y-TILEWH, x+qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
477 modexDrawSpriteRegion(mv->page, x+qq-4, y-TILEWH, 0, 32, 24, 32, bmp); }
478 if(ls>=7) { modexCopyPageRegion(mv->page, src->page, x+qq-4, y-TILEWH, x+qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
479 modexDrawSpriteRegion(mv->page, x+qq-4, y-TILEWH, 24, 32, 24, 32, bmp); }
483 if(ls<1) { modexCopyPageRegion(mv->page, src->page, x-4, y+qq-TILEWH-2, x-4, y+qq-TILEWH-2, 24, 34);
484 modexDrawSpriteRegion(mv->page, x-4, y+qq-TILEWH, 24, 64, 24, 32, bmp); }
485 if(4>ls && ls>=1) { modexCopyPageRegion(mv->page, src->page, x-4, y+qq-TILEWH-2, x-4, y+qq-TILEWH-2, 24, 34);
486 modexDrawSpriteRegion(mv->page, x-4, y+qq-TILEWH, 48, 64, 24, 32, bmp); }
487 if(7>ls && ls>=4) { modexCopyPageRegion(mv->page, src->page, x-4, y+qq-TILEWH-2, x-4, y+qq-TILEWH-2, 24, 34);
488 modexDrawSpriteRegion(mv->page, x-4, y+qq-TILEWH, 0, 64, 24, 32, bmp); }
489 if(ls>=7) { modexCopyPageRegion(mv->page, src->page, x-4, y+qq-TILEWH-2, x-4, y+qq-TILEWH-2, 24, 34);
490 modexDrawSpriteRegion(mv->page, x-4, y+qq-TILEWH, 24, 64, 24, 32, bmp); }
494 if(ls<1) { modexCopyPageRegion(mv->page, src->page, x-qq-4, y-TILEWH, x-qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
495 modexDrawSpriteRegion(mv->page, x-qq-4, y-TILEWH, 24, 96, 24, 32, bmp); }
496 if(4>ls && ls>=1) { modexCopyPageRegion(mv->page, src->page, x-qq-4, y-TILEWH, x-qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
497 modexDrawSpriteRegion(mv->page, x-qq-4, y-TILEWH, 48, 96, 24, 32, bmp); }
498 if(7>ls && ls>=4) { modexCopyPageRegion(mv->page, src->page, x-qq-4, y-TILEWH, x-qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
499 modexDrawSpriteRegion(mv->page, x-qq-4, y-TILEWH, 0, 96, 24, 32, bmp); }
500 if(ls>=7) { modexCopyPageRegion(mv->page, src->page, x-qq-4, y-TILEWH, x-qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
501 modexDrawSpriteRegion(mv->page, x-qq-4, y-TILEWH, 24, 96, 24, 32, bmp); }