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 *src, map_view_t *dest, 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, 36);
109 modexShowPage(bg->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
117 //TODO: fexible speeds
120 if(bg->tx >= 0 && bg->tx+20 < MAPX && player.tx == bg->tx + 10)
122 for(q=0; q<(TILEWH/SPEED); q++)
124 animatePlayer(bg, spri, 1, 1, player.x, player.y, q, &ptmp);
125 mapScrollRight(bg, SPEED);
126 mapScrollRight(spri, SPEED);
127 modexShowPage(spri->page);
131 else if(player.tx < MAPX)
133 for(q=0; q<(TILEWH/SPEED); q++)
136 animatePlayer(bg, spri, 1, 0, player.x, player.y, q, &ptmp);
137 modexShowPage(spri->page);
143 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH-2, player.x-4, player.y-TILEWH-2, 24, 36);
144 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 32, 24, 32, &ptmp);
145 modexShowPage(spri->page);
151 if(bg->tx > 0 && bg->tx+20 <= MAPX && player.tx == bg->tx + 10)
153 for(q=0; q<(TILEWH/SPEED); q++)
156 animatePlayer(bg, spri, 3, 1, player.x, player.y, q, &ptmp);
157 mapScrollLeft(bg, SPEED);
158 mapScrollLeft(spri, SPEED);
159 modexShowPage(spri->page);
163 else if(player.tx > 1)
165 for(q=0; q<(TILEWH/SPEED); q++)
168 animatePlayer(bg, spri, 3, 0, player.x, player.y, q, &ptmp);
169 modexShowPage(spri->page);
175 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH-2, player.x-4, player.y-TILEWH-2, 24, 36);
176 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 96, 24, 32, &ptmp);
177 modexShowPage(spri->page);
183 if(bg->ty >= 0 && bg->ty+15 < MAPY && player.ty == bg->ty + 8)
185 for(q=0; q<(TILEWH/SPEED); q++)
187 animatePlayer(bg, spri, 2, 1, player.x, player.y, q, &ptmp);
188 mapScrollDown(bg, SPEED);
189 mapScrollDown(spri, SPEED);
190 modexShowPage(spri->page);
194 else if(player.ty < MAPY)
196 for(q=0; q<(TILEWH/SPEED); q++)
199 animatePlayer(bg, spri, 2, 0, player.x, player.y, q, &ptmp);
200 modexShowPage(spri->page);
206 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH-2, player.x-4, player.y-TILEWH-2, 24, 36);
207 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
208 modexShowPage(spri->page);
214 if(bg->ty > 0 && bg->ty+15 <= MAPY && player.ty == bg->ty + 8)
216 for(q=0; q<(TILEWH/SPEED); q++)
218 animatePlayer(bg, spri, 0, 1, player.x, player.y, q, &ptmp);
219 mapScrollUp(bg, SPEED);
220 mapScrollUp(spri, SPEED);
221 modexShowPage(spri->page);
225 else if(player.ty > 1)
227 for(q=0; q<(TILEWH/SPEED); q++)
230 animatePlayer(bg, spri, 0, 0, player.x, player.y, q, &ptmp);
231 modexShowPage(spri->page);
237 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH-2, player.x-4, player.y-TILEWH-2, 24, 36);
238 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 0, 24, 32, &ptmp);
239 modexShowPage(spri->page);
247 printf("Project 16 scroll.exe\n");
248 printf("tx: %d\n", bg->tx);
249 printf("ty: %d\n", bg->ty);
250 printf("player.x: %d\n", player.x);
251 printf("player.y: %d\n", player.y);
252 printf("player.tx: %d\n", player.tx);
253 printf("player.ty: %d\n", player.ty);
258 allocMap(int w, int h) {
263 result.data = malloc(sizeof(byte) * w * h);
270 initMap(map_t *map) {
271 /* just a place holder to fill out an alternating pattern */
275 map->tiles = malloc(sizeof(tiles_t));
277 /* create the tile set */
278 map->tiles->data = malloc(sizeof(bitmap_t));
279 map->tiles->data->width = (TILEWH*2);
280 map->tiles->data->height= TILEWH;
281 map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
282 map->tiles->tileHeight = TILEWH;
283 map->tiles->tileWidth =TILEWH;
284 map->tiles->rows = 1;
285 map->tiles->cols = 2;
288 for(y=0; y<TILEWH; y++) {
289 for(x=0; x<(TILEWH*2); x++) {
291 map->tiles->data->data[i] = 0x24;
293 map->tiles->data->data[i] = 0x34;
299 for(y=0; y<map->height; y++) {
300 for(x=0; x<map->width; x++) {
311 mapScrollRight(map_view_t *mv, byte offset) {
312 word x, y; /* coordinate for bging */
314 /* increment the pixel position and update the page */
315 mv->page->dx += offset;
317 /* check to see if this changes the tile */
318 if(mv->page->dx >= mv->dxThresh ) {
319 /* go forward one tile */
321 /* Snap the origin forward */
323 mv->page->dx = mv->map->tiles->tileWidth;
326 /* bg the next column */
327 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
328 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
334 mapScrollLeft(map_view_t *mv, byte offset) {
335 word x, y; /* coordinate for bging */
337 /* increment the pixel position and update the page */
338 mv->page->dx -= offset;
340 /* check to see if this changes the tile */
341 if(mv->page->dx == 0) {
342 /* go backward one tile */
345 /* Snap the origin backward */
347 mv->page->dx = mv->map->tiles->tileWidth;
349 /* bg the next column */
350 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
356 mapScrollUp(map_view_t *mv, byte offset) {
357 word x, y; /* coordinate for bging */
359 /* increment the pixel position and update the page */
360 mv->page->dy -= offset;
362 /* check to see if this changes the tile */
363 if(mv->page->dy == 0 ) {
364 /* go down one tile */
366 /* Snap the origin downward */
367 mv->page->data -= mv->page->width*4;
368 mv->page->dy = mv->map->tiles->tileHeight;
371 /* bg the next row */
373 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
379 mapScrollDown(map_view_t *mv, byte offset) {
380 word x, y; /* coordinate for bging */
382 /* increment the pixel position and update the page */
383 mv->page->dy += offset;
385 /* check to see if this changes the tile */
386 if(mv->page->dy >= mv->dyThresh ) {
387 /* go down one tile */
389 /* Snap the origin downward */
390 mv->page->data += mv->page->width*4;
391 mv->page->dy = mv->map->tiles->tileHeight;
394 /* bg the next row */
395 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
396 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
403 mapGoTo(map_view_t *mv, int tx, int ty) {
407 /* set up the coordinates */
410 mv->page->dx = mv->map->tiles->tileWidth;
411 mv->page->dy = mv->map->tiles->tileHeight;
413 /* set up the thresholds */
414 mv->dxThresh = mv->map->tiles->tileWidth * 2;
415 mv->dyThresh = mv->map->tiles->tileHeight * 2;
418 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
420 i=mv->ty * mv->map->width + mv->tx;
421 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
422 mapDrawRow(mv, tx-1, ty, py);
423 i+=mv->map->width - tx;
429 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
432 rx = (i % t->cols) * t->tileWidth;
433 ry = (i / t->cols) * t->tileHeight;
434 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
439 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
443 /* the position within the map array */
444 i=ty * mv->map->width + tx;
445 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
447 /* we are in the map, so copy! */
448 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
456 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
460 /* location in the map array */
461 i=ty * mv->map->width + tx;
463 /* We'll copy all of the columns in the screen,
464 i + 1 row above and one below */
465 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
467 /* we are in the map, so copy away! */
468 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
475 animatePlayer(map_view_t *src, map_view_t *dest, short d1, short d2, int x, int y, int ls, bitmap_t *bmp)
479 short lo = ((TILEWH / SPEED) / 3);
480 short loo = (ls + lo);
483 else qq = ((ls+1)*SPEED);
506 } //TODO: make flexible animation thingy
507 if(ls<1) { modexCopyPageRegion(dest->page, src->page, x, y-2, x, y-2, 24, 36);// modexWaitBorder();
508 modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }else
509 if(4>ls && ls>=1) { modexCopyPageRegion(dest->page, src->page, x, y-2, x, y-2, 24, 36);// modexWaitBorder();
510 modexDrawSpriteRegion(dest->page, x, y, 48, dire, 24, 32, bmp); }else
511 if(7>ls && ls>=4) { modexCopyPageRegion(dest->page, src->page, x, y-2, x, y-2, 24, 36);// modexWaitBorder();
512 modexDrawSpriteRegion(dest->page, x, y, 0, dire, 24, 32, bmp); }else
513 if(8>=ls && ls>=7) { modexCopyPageRegion(dest->page, src->page, x, y-2, x, y-2, 24, 36);// modexWaitBorder();
514 modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }else ls-=ls;