6 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
\r
14 //unsigned int tilex,tiley; // tile position on the map
\r
29 int tx; //appears to be the top left tile position on the viewable screen map
\r
30 int ty; //appears to be the top left tile position on the viewable screen map
31 // int ttx; //bottem right tile
32 // int tty; //bottem left tile
\r
33 word dxThresh; //????
\r
34 word dyThresh; //????
\r
38 int x; //player exact position on the viewable map
\r
39 int y; //player exact position on the viewable map
\r
40 int tx; //player tile position on the viewable map
\r
41 int ty; //player tile position on the viewable map
\r
45 map_t allocMap(int w, int h);
\r
46 void initMap(map_t *map);
\r
47 void mapScrollRight(map_view_t *mv, byte offset);
\r
48 void mapScrollLeft(map_view_t *mv, byte offest);
\r
49 void mapScrollUp(map_view_t *mv, byte offset);
\r
50 void mapScrollDown(map_view_t *mv, byte offset);
\r
51 void mapGoTo(map_view_t *mv, int tx, int ty);
\r
52 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
\r
53 void mapDrawRow(map_view_t *mv, int tx, int ty, word y);
\r
54 void mapDrawCol(map_view_t *mv, int tx, int ty, word x);
\r
57 #define QUADWH (TILEWH/4)
60 //place holder definitions
63 //#define SWAP(a, b) tmp=a; a=b; b=tmp;
\r
67 page_t screen;//,screen2;
\r
69 map_view_t mv;//, mv2;
\r
70 map_view_t *draw;//, *show, *tmp;
\r
74 /* create the map */
\r
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
\r
80 /* draw the tiles */
\r
82 bmp = bitmapLoadPcx("ptmp.pcx"); // load sprite
83 modexPalUpdate(bmp.palette);
\r
85 screen = modexDefaultPage();
\r
86 screen.width += (TILEWH*2);
\r
88 // screen2=modexNextPage(mv.page);
\r
89 // mv2.page = &screen2;
\r
90 // mapGoTo(&mv2, 16, 16);
\r
91 // modexShowPage(mv.page);
\r
98 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
99 mapGoTo(draw, 0, 0);
\r
101 //TODO: put player in starting position of spot
\r
102 //default player position on the viewable map
103 player.tx = draw->tx + 10;
104 player.ty = draw->ty + 8;
105 player.x = player.tx*TILEWH;
106 player.y = player.ty*TILEWH;
108 modexShowPage(draw->page);
\r
111 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
\r
112 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
\r
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
116 if(draw->tx >= 0 && draw->tx+20 < MAPX && player.tx == draw->tx + 10)
118 for(q=0; q<(TILEWH/SPEED); q++)
120 modexDrawBmp(draw->page, player.x+((q+1)*SPEED), player.y, &bmp);
121 mapScrollRight(draw, SPEED);
122 modexShowPage(draw->page);
\r
123 // mapScrollRight(draw, 1);
\r
124 // SWAP(draw, show);
\r
128 else if(player.tx < MAPX)
130 for(q=0; q<(TILEWH/SPEED); q++)
133 modexDrawBmp(draw->page, player.x, player.y, &bmp);
134 modexShowPage(draw->page);
141 if(draw->tx > 0 && draw->tx+20 <= MAPX && player.tx == draw->tx + 10)
143 for(q=0; q<(TILEWH/SPEED); q++)
145 modexDrawBmp(draw->page, player.x-((q+1)*SPEED), player.y, &bmp);
146 mapScrollLeft(draw, SPEED);
147 modexShowPage(draw->page);
\r
148 // mapScrollLeft(show, 1);
\r
149 // SWAP(draw, show);
\r
153 else if(player.tx > 1)
155 for(q=0; q<(TILEWH/SPEED); q++)
158 modexDrawBmp(draw->page, player.x, player.y, &bmp);
159 modexShowPage(draw->page);
167 if(draw->ty >= 0 && draw->ty+15 < MAPY && player.ty == draw->ty + 8)
169 for(q=0; q<(TILEWH/SPEED); q++)
171 modexDrawBmp(draw->page, player.x, player.y+((q+1)*SPEED), &bmp);
172 mapScrollDown(draw, SPEED);
173 modexShowPage(draw->page);
\r
174 // mapScrollDown(show, 1);
\r
175 // SWAP(draw, show);
\r
179 else if(player.ty < MAPY)
181 for(q=0; q<(TILEWH/SPEED); q++)
184 modexDrawBmp(draw->page, player.x, player.y, &bmp);
185 modexShowPage(draw->page);
193 if(draw->ty > 0 && draw->ty+15 <= MAPY && player.ty == draw->ty + 8)
195 for(q=0; q<(TILEWH/SPEED); q++)
197 modexDrawBmp(draw->page, player.x, player.y-((q+1)*SPEED), &bmp);
198 mapScrollUp(draw, SPEED);
199 modexShowPage(draw->page);
200 // mapScrollUp(show, 1);
\r
201 // SWAP(draw, show);
\r
205 else if(player.ty > 1)
207 for(q=0; q<(TILEWH/SPEED); q++)
210 modexDrawBmp(draw->page, player.x, player.y, &bmp);
211 modexShowPage(draw->page);
216 //modexDrawBmp(draw->page, player.x, player.y, &bmp);
\r
217 //modexShowPage(draw->page);
\r
223 printf("Project 16 scroll.exe\n");
224 printf("tx: %d\n", draw->tx);
225 printf("ty: %d\n", draw->ty);
226 printf("player.x: %d\n", player.x);
227 printf("player.y: %d\n", player.y);
228 printf("player.tx: %d\n", player.tx);
229 printf("player.ty: %d\n", player.ty);
234 allocMap(int w, int h) {
\r
239 result.data = malloc(sizeof(byte) * w * h);
\r
246 initMap(map_t *map) {
\r
247 /* just a place holder to fill out an alternating pattern */
\r
251 map->tiles = malloc(sizeof(tiles_t));
\r
253 /* create the tile set */
\r
254 map->tiles->data = malloc(sizeof(bitmap_t));
\r
255 map->tiles->data->width = (TILEWH*2);
\r
256 map->tiles->data->height= TILEWH;
\r
257 map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
\r
258 map->tiles->tileHeight = TILEWH;
\r
259 map->tiles->tileWidth =TILEWH;
\r
260 map->tiles->rows = 1;
\r
261 map->tiles->cols = 2;
\r
264 for(y=0; y<TILEWH; y++) {
\r
265 for(x=0; x<(TILEWH*2); x++) {
\r
267 map->tiles->data->data[i] = 0x24;
\r
269 map->tiles->data->data[i] = 0x34;
\r
275 for(y=0; y<map->height; y++) {
\r
276 for(x=0; x<map->width; x++) {
\r
277 map->data[i] = tile;
\r
278 tile = tile ? 0 : 1;
\r
281 tile = tile ? 0 : 1;
\r
287 mapScrollRight(map_view_t *mv, byte offset) {
\r
288 word x, y; /* coordinate for drawing */
\r
290 /* increment the pixel position and update the page */
\r
291 mv->page->dx += offset;
\r
293 /* check to see if this changes the tile */
\r
294 if(mv->page->dx >= mv->dxThresh ) {
\r
295 /* go forward one tile */
\r
297 /* Snap the origin forward */
\r
298 mv->page->data += 4;
\r
299 mv->page->dx = mv->map->tiles->tileWidth;
\r
302 /* draw the next column */
\r
303 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
304 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
310 mapScrollLeft(map_view_t *mv, byte offset) {
\r
311 word x, y; /* coordinate for drawing */
\r
313 /* increment the pixel position and update the page */
\r
314 mv->page->dx -= offset;
\r
316 /* check to see if this changes the tile */
\r
317 if(mv->page->dx == 0) {
\r
318 /* go backward one tile */
\r
321 /* Snap the origin backward */
\r
322 mv->page->data -= 4;
\r
323 mv->page->dx = mv->map->tiles->tileWidth;
\r
325 /* draw the next column */
\r
326 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
332 mapScrollUp(map_view_t *mv, byte offset) {
\r
333 word x, y; /* coordinate for drawing */
\r
335 /* increment the pixel position and update the page */
\r
336 mv->page->dy -= offset;
\r
338 /* check to see if this changes the tile */
\r
339 if(mv->page->dy == 0 ) {
\r
340 /* go down one tile */
\r
342 /* Snap the origin downward */
\r
343 mv->page->data -= mv->page->width*4;
\r
344 mv->page->dy = mv->map->tiles->tileHeight;
\r
347 /* draw the next row */
\r
349 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
355 mapScrollDown(map_view_t *mv, byte offset) {
\r
356 word x, y; /* coordinate for drawing */
\r
358 /* increment the pixel position and update the page */
\r
359 mv->page->dy += offset;
\r
361 /* check to see if this changes the tile */
\r
362 if(mv->page->dy >= mv->dyThresh ) {
\r
363 /* go down one tile */
\r
365 /* Snap the origin downward */
\r
366 mv->page->data += mv->page->width*4;
\r
367 mv->page->dy = mv->map->tiles->tileHeight;
\r
370 /* draw the next row */
\r
371 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
372 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
379 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
383 /* set up the coordinates */
\r
386 mv->page->dx = mv->map->tiles->tileWidth;
\r
387 mv->page->dy = mv->map->tiles->tileHeight;
\r
389 /* set up the thresholds */
\r
390 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
391 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
393 /* draw the tiles */
\r
394 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
396 i=mv->ty * mv->map->width + mv->tx;
\r
397 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
398 mapDrawRow(mv, tx-1, ty, py);
\r
399 i+=mv->map->width - tx;
\r
405 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
408 rx = (i % t->cols) * t->tileWidth;
\r
409 ry = (i / t->cols) * t->tileHeight;
\r
410 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
415 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
419 /* the position within the map array */
\r
420 i=ty * mv->map->width + tx;
\r
421 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
423 /* we are in the map, so copy! */
\r
424 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
432 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
436 /* location in the map array */
\r
437 i=ty * mv->map->width + tx;
\r
439 /* We'll copy all of the columns in the screen,
\r
440 i + 1 row above and one below */
\r
441 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
443 /* we are in the map, so copy away! */
\r
444 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
446 i += mv->map->width;
\r