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 drawn properly
82 ptmp = bitmapLoadPcx("ptmp.pcx"); // load sprite
84 modexPalUpdate(ptmp.palette);
85 screen = modexDefaultPage();
86 screen.width += (TILEWH*2);
87 screen.height += (TILEWH*2);
89 screen2 = modexNextPage(mv.page);
96 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
100 //TODO: put player in starting position of spot
101 //default player position on the viewable map
102 player.tx = bg->tx + 10;
103 player.ty = bg->ty + 8;
104 player.x = player.tx*TILEWH;
105 player.y = player.ty*TILEWH;
106 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
107 modexCopyPageRegion(bg->page, spri->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
108 modexShowPage(bg->page);
111 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
112 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
113 //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
115 //TODO: render the player properly with animation and sprite sheet
116 //TODO: fexible speeds
117 if(keyp(77) && !keyp(75))
119 if(bg->tx >= 0 && bg->tx+20 < MAPX && player.tx == bg->tx + 10)
121 for(q=1; q<=(TILEWH/SPEED); q++)
123 animatePlayer(bg, spri, 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=1; q<=(TILEWH/SPEED); q++)
135 animatePlayer(bg, spri, 1, 0, player.x, player.y, q, &ptmp);
136 modexShowPage(spri->page);
142 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
143 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 32, 24, 32, &ptmp);
144 modexShowPage(spri->page);
148 if(keyp(75) && !keyp(77))
150 if(bg->tx > 0 && bg->tx+20 <= MAPX && player.tx == bg->tx + 10)
152 for(q=1; q<=(TILEWH/SPEED); q++)
155 animatePlayer(bg, spri, 3, 1, player.x, player.y, q, &ptmp);
156 mapScrollLeft(bg, SPEED);
157 mapScrollLeft(spri, SPEED);
158 modexShowPage(spri->page);
162 else if(player.tx > 1)
164 for(q=1; q<=(TILEWH/SPEED); q++)
167 animatePlayer(bg, spri, 3, 0, player.x, player.y, q, &ptmp);
168 modexShowPage(spri->page);
174 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
175 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 96, 24, 32, &ptmp);
176 modexShowPage(spri->page);
180 if(keyp(80) && !keyp(72))
182 if(bg->ty >= 0 && bg->ty+15 < MAPY && player.ty == bg->ty + 8)
184 for(q=1; q<=(TILEWH/SPEED); q++)
186 animatePlayer(bg, spri, 2, 1, player.x, player.y, q, &ptmp);
187 mapScrollDown(bg, SPEED);
188 mapScrollDown(spri, SPEED);
189 modexShowPage(spri->page);
193 else if(player.ty < MAPY)
195 for(q=1; q<=(TILEWH/SPEED); q++)
198 animatePlayer(bg, spri, 2, 0, player.x, player.y, q, &ptmp);
199 modexShowPage(spri->page);
205 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
206 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
207 modexShowPage(spri->page);
211 if(keyp(72) && !keyp(80))
213 if(bg->ty > 0 && bg->ty+15 <= MAPY && player.ty == bg->ty + 8)
215 for(q=1; q<=(TILEWH/SPEED); q++)
217 animatePlayer(bg, spri, 0, 1, player.x, player.y, q, &ptmp);
218 mapScrollUp(bg, SPEED);
219 mapScrollUp(spri, SPEED);
220 modexShowPage(spri->page);
224 else if(player.ty > 1)
226 for(q=1; q<=(TILEWH/SPEED); q++)
229 animatePlayer(bg, spri, 0, 0, player.x, player.y, q, &ptmp);
230 modexShowPage(spri->page);
236 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
237 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 0, 24, 32, &ptmp);
238 modexShowPage(spri->page);
246 printf("Project 16 scroll.exe\n");
247 printf("tx: %d\n", bg->tx);
248 printf("ty: %d\n", bg->ty);
249 printf("player.x: %d\n", player.x);
250 printf("player.y: %d\n", player.y);
251 printf("player.tx: %d\n", player.tx);
252 printf("player.ty: %d\n", player.ty);
257 allocMap(int w, int h) {
262 result.data = malloc(sizeof(byte) * w * h);
269 initMap(map_t *map) {
270 /* just a place holder to fill out an alternating pattern */
274 map->tiles = malloc(sizeof(tiles_t));
276 /* create the tile set */
277 map->tiles->data = malloc(sizeof(bitmap_t));
278 map->tiles->data->width = (TILEWH*2);
279 map->tiles->data->height= TILEWH;
280 map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
281 map->tiles->tileHeight = TILEWH;
282 map->tiles->tileWidth =TILEWH;
283 map->tiles->rows = 1;
284 map->tiles->cols = 2;
287 for(y=0; y<TILEWH; y++) {
288 for(x=0; x<(TILEWH*2); x++) {
290 map->tiles->data->data[i] = 0x24;
292 map->tiles->data->data[i] = 0x34;
298 for(y=0; y<map->height; y++) {
299 for(x=0; x<map->width; x++) {
310 mapScrollRight(map_view_t *mv, byte offset) {
311 word x, y; /* coordinate for drawing */
313 /* increment the pixel position and update the page */
314 mv->page->dx += offset;
316 /* check to see if this changes the tile */
317 if(mv->page->dx >= mv->dxThresh ) {
318 /* go forward one tile */
320 /* Snap the origin forward */
322 mv->page->dx = mv->map->tiles->tileWidth;
325 /* draw the next column */
326 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
327 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
333 mapScrollLeft(map_view_t *mv, byte offset) {
334 word x, y; /* coordinate for drawing */
336 /* increment the pixel position and update the page */
337 mv->page->dx -= offset;
339 /* check to see if this changes the tile */
340 if(mv->page->dx == 0) {
341 /* go backward one tile */
344 /* Snap the origin backward */
346 mv->page->dx = mv->map->tiles->tileWidth;
348 /* draw the next column */
349 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
355 mapScrollUp(map_view_t *mv, byte offset) {
356 word x, y; /* coordinate for drawing */
358 /* increment the pixel position and update the page */
359 mv->page->dy -= offset;
361 /* check to see if this changes the tile */
362 if(mv->page->dy == 0 ) {
363 /* go down one tile */
365 /* Snap the origin downward */
366 mv->page->data -= mv->page->width*4;
367 mv->page->dy = mv->map->tiles->tileHeight;
370 /* draw the next row */
372 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
378 mapScrollDown(map_view_t *mv, byte offset) {
379 word x, y; /* coordinate for drawing */
381 /* increment the pixel position and update the page */
382 mv->page->dy += offset;
384 /* check to see if this changes the tile */
385 if(mv->page->dy >= mv->dyThresh ) {
386 /* go down one tile */
388 /* Snap the origin downward */
389 mv->page->data += mv->page->width*4;
390 mv->page->dy = mv->map->tiles->tileHeight;
393 /* draw the next row */
394 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
395 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
402 mapGoTo(map_view_t *mv, int tx, int ty) {
406 /* set up the coordinates */
409 mv->page->dx = mv->map->tiles->tileWidth;
410 mv->page->dy = mv->map->tiles->tileHeight;
412 /* set up the thresholds */
413 mv->dxThresh = mv->map->tiles->tileWidth * 2;
414 mv->dyThresh = mv->map->tiles->tileHeight * 2;
417 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
419 i=mv->ty * mv->map->width + mv->tx;
420 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
421 mapDrawRow(mv, tx-1, ty, py);
422 i+=mv->map->width - tx;
428 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
431 rx = (i % t->cols) * t->tileWidth;
432 ry = (i / t->cols) * t->tileHeight;
433 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
438 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
442 /* the position within the map array */
443 i=ty * mv->map->width + tx;
444 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
446 /* we are in the map, so copy! */
447 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
455 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
459 /* location in the map array */
460 i=ty * mv->map->width + tx;
462 /* We'll copy all of the columns in the screen,
463 i + 1 row above and one below */
464 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
466 /* we are in the map, so copy away! */
467 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
474 animatePlayer(map_view_t *src, map_view_t *dest, short d1, short d2, int x, int y, int ls, bitmap_t *bmp)
478 short lo = ((TILEWH / SPEED) / 3);
479 short loo = (ls + lo);
482 else qq = ((ls)*SPEED);
506 //TODO: make flexible animation thingy
507 modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
508 if(2>ls && ls>=1) { modexDrawSpriteRegion(dest->page, x, y, 48, dire, 24, 32, bmp); }else
509 if(3>ls && ls>=2) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }else
510 if(4>ls && ls>=3) { modexDrawSpriteRegion(dest->page, x, y, 0, dire, 24, 32, bmp); }else
511 if(5>ls && ls>=4) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }