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, int lp, 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 static int persist_aniframe = 0; /* gonna be increased to 1 before being used, so 0 is ok for default */
68 page_t screen, screen2;
71 map_view_t *bg, *spri, *tmp;
76 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 drawn properly
83 ptmp = bitmapLoadPcx("ptmp.pcx"); // load sprite
85 modexPalUpdate(ptmp.palette);
86 screen = modexDefaultPage();
87 screen.width += (TILEWH*2);
88 screen.height += (TILEWH*2);
90 screen2 = modexNextPage(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, player.x-4, player.y-TILEWH, 24, 32);
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 #define INC_PER_FRAME if(q&1) persist_aniframe++; if(persist_aniframe>4) persist_aniframe = 1;
118 if(keyp(77) && !keyp(75))
120 if(bg->tx >= 0 && bg->tx+20 < MAPX && player.tx == bg->tx + 10)
122 for(q=1; q<=(TILEWH/SPEED); q++)
125 animatePlayer(bg, spri, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
126 mapScrollRight(bg, SPEED);
127 mapScrollRight(spri, SPEED);
128 modexShowPage(spri->page);
132 else if(player.tx < MAPX)
134 for(q=1; q<=(TILEWH/SPEED); q++)
138 animatePlayer(bg, spri, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp);
139 modexShowPage(spri->page);
145 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
146 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 32, 24, 32, &ptmp);
147 modexShowPage(spri->page);
151 if(keyp(75) && !keyp(77))
153 if(bg->tx > 0 && bg->tx+20 <= MAPX && player.tx == bg->tx + 10)
155 for(q=1; q<=(TILEWH/SPEED); q++)
158 animatePlayer(bg, spri, 3, 1, player.x, player.y, persist_aniframe, q, &ptmp);
159 mapScrollLeft(bg, SPEED);
160 mapScrollLeft(spri, SPEED);
161 modexShowPage(spri->page);
165 else if(player.tx > 1)
167 for(q=1; q<=(TILEWH/SPEED); q++)
171 animatePlayer(bg, spri, 3, 0, player.x, player.y, persist_aniframe, q, &ptmp);
172 modexShowPage(spri->page);
178 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
179 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 96, 24, 32, &ptmp);
180 modexShowPage(spri->page);
184 if(keyp(80) && !keyp(72))
186 if(bg->ty >= 0 && bg->ty+15 < MAPY && player.ty == bg->ty + 8)
188 for(q=1; q<=(TILEWH/SPEED); q++)
191 animatePlayer(bg, spri, 2, 1, player.x, player.y, persist_aniframe, q, &ptmp);
192 mapScrollDown(bg, SPEED);
193 mapScrollDown(spri, SPEED);
194 modexShowPage(spri->page);
198 else if(player.ty < MAPY)
200 for(q=1; q<=(TILEWH/SPEED); q++)
204 animatePlayer(bg, spri, 2, 0, player.x, player.y, persist_aniframe, q, &ptmp);
205 modexShowPage(spri->page);
211 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
212 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
213 modexShowPage(spri->page);
217 if(keyp(72) && !keyp(80))
219 if(bg->ty > 0 && bg->ty+15 <= MAPY && player.ty == bg->ty + 8)
221 for(q=1; q<=(TILEWH/SPEED); q++)
224 animatePlayer(bg, spri, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp);
225 mapScrollUp(bg, SPEED);
226 mapScrollUp(spri, SPEED);
227 modexShowPage(spri->page);
231 else if(player.ty > 1)
233 for(q=1; q<=(TILEWH/SPEED); q++)
237 animatePlayer(bg, spri, 0, 0, player.x, player.y, persist_aniframe, q, &ptmp);
238 modexShowPage(spri->page);
244 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
245 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 0, 24, 32, &ptmp);
246 modexShowPage(spri->page);
254 printf("Project 16 scroll.exe\n");
255 printf("tx: %d\n", bg->tx);
256 printf("ty: %d\n", bg->ty);
257 printf("player.x: %d\n", player.x);
258 printf("player.y: %d\n", player.y);
259 printf("player.tx: %d\n", player.tx);
260 printf("player.ty: %d\n", player.ty);
265 allocMap(int w, int h) {
270 result.data = malloc(sizeof(byte) * w * h);
277 initMap(map_t *map) {
278 /* just a place holder to fill out an alternating pattern */
282 map->tiles = malloc(sizeof(tiles_t));
284 /* create the tile set */
285 map->tiles->data = malloc(sizeof(bitmap_t));
286 map->tiles->data->width = (TILEWH*2);
287 map->tiles->data->height= TILEWH;
288 map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
289 map->tiles->tileHeight = TILEWH;
290 map->tiles->tileWidth =TILEWH;
291 map->tiles->rows = 1;
292 map->tiles->cols = 2;
295 for(y=0; y<TILEWH; y++) {
296 for(x=0; x<(TILEWH*2); x++) {
298 map->tiles->data->data[i] = 0x24;
300 map->tiles->data->data[i] = 0x34;
306 for(y=0; y<map->height; y++) {
307 for(x=0; x<map->width; x++) {
318 mapScrollRight(map_view_t *mv, byte offset) {
319 word x, y; /* coordinate for drawing */
321 /* increment the pixel position and update the page */
322 mv->page->dx += offset;
324 /* check to see if this changes the tile */
325 if(mv->page->dx >= mv->dxThresh ) {
326 /* go forward one tile */
328 /* Snap the origin forward */
330 mv->page->dx = mv->map->tiles->tileWidth;
333 /* draw the next column */
334 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
335 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
341 mapScrollLeft(map_view_t *mv, byte offset) {
342 word x, y; /* coordinate for drawing */
344 /* increment the pixel position and update the page */
345 mv->page->dx -= offset;
347 /* check to see if this changes the tile */
348 if(mv->page->dx == 0) {
349 /* go backward one tile */
352 /* Snap the origin backward */
354 mv->page->dx = mv->map->tiles->tileWidth;
356 /* draw the next column */
357 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
363 mapScrollUp(map_view_t *mv, byte offset) {
364 word x, y; /* coordinate for drawing */
366 /* increment the pixel position and update the page */
367 mv->page->dy -= offset;
369 /* check to see if this changes the tile */
370 if(mv->page->dy == 0 ) {
371 /* go down one tile */
373 /* Snap the origin downward */
374 mv->page->data -= mv->page->width*4;
375 mv->page->dy = mv->map->tiles->tileHeight;
378 /* draw the next row */
380 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
386 mapScrollDown(map_view_t *mv, byte offset) {
387 word x, y; /* coordinate for drawing */
389 /* increment the pixel position and update the page */
390 mv->page->dy += offset;
392 /* check to see if this changes the tile */
393 if(mv->page->dy >= mv->dyThresh ) {
394 /* go down one tile */
396 /* Snap the origin downward */
397 mv->page->data += mv->page->width*4;
398 mv->page->dy = mv->map->tiles->tileHeight;
401 /* draw the next row */
402 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
403 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
410 mapGoTo(map_view_t *mv, int tx, int ty) {
414 /* set up the coordinates */
417 mv->page->dx = mv->map->tiles->tileWidth;
418 mv->page->dy = mv->map->tiles->tileHeight;
420 /* set up the thresholds */
421 mv->dxThresh = mv->map->tiles->tileWidth * 2;
422 mv->dyThresh = mv->map->tiles->tileHeight * 2;
425 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
427 i=mv->ty * mv->map->width + mv->tx;
428 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
429 mapDrawRow(mv, tx-1, ty, py);
430 i+=mv->map->width - tx;
436 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
439 rx = (i % t->cols) * t->tileWidth;
440 ry = (i / t->cols) * t->tileHeight;
441 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
446 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
450 /* the position within the map array */
451 i=ty * mv->map->width + tx;
452 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
454 /* we are in the map, so copy! */
455 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
463 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
467 /* location in the map array */
468 i=ty * mv->map->width + tx;
470 /* We'll copy all of the columns in the screen,
471 i + 1 row above and one below */
472 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
474 /* we are in the map, so copy away! */
475 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
482 animatePlayer(map_view_t *src, map_view_t *dest, short d1, short d2, int x, int y, int ls, int lp, bitmap_t *bmp)
488 else qq = ((lp)*SPEED);
512 //TODO: make flexible animation thingy
513 modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
514 if(2>ls && ls>=1) { modexDrawSpriteRegion(dest->page, x, y, 48, dire, 24, 32, bmp); }else
515 if(3>ls && ls>=2) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }else
516 if(4>ls && ls>=3) { modexDrawSpriteRegion(dest->page, x, y, 0, dire, 24, 32, bmp); }else
517 if(5>ls && ls>=4) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }