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 mapScrollRight(draw, SPEED);
\r
121 modexShowPage(draw->page);
\r
122 // mapScrollRight(draw, 1);
\r
123 // SWAP(draw, show);
\r
127 else if(player.tx < MAPX)
129 for(q=0; q<(TILEWH/SPEED); q++)
132 modexDrawBmp(draw->page, player.x, player.y, &bmp);
133 modexShowPage(draw->page);
140 if(draw->tx > 0 && draw->tx+20 <= MAPX && player.tx == draw->tx + 10)
142 for(q=0; q<(TILEWH/SPEED); q++)
144 mapScrollLeft(draw, SPEED);
\r
145 modexShowPage(draw->page);
\r
146 // mapScrollLeft(show, 1);
\r
147 // SWAP(draw, show);
\r
151 else if(player.tx > 0)
153 for(q=0; q<(TILEWH/SPEED); q++)
156 modexDrawBmp(draw->page, player.x, player.y, &bmp);
157 modexShowPage(draw->page);
165 if(draw->ty >= 0 && draw->ty+15 < MAPY && player.ty == draw->ty + 8)
167 for(q=0; q<(TILEWH/SPEED); q++)
169 mapScrollDown(draw, SPEED);
\r
170 modexShowPage(draw->page);
\r
171 // mapScrollDown(show, 1);
\r
172 // SWAP(draw, show);
\r
176 else if(player.ty < MAPY)
178 for(q=0; q<(TILEWH/SPEED); q++)
181 modexDrawBmp(draw->page, player.x, player.y, &bmp);
182 modexShowPage(draw->page);
190 if(draw->ty > 0 && draw->ty+15 <= MAPY && player.ty == draw->ty + 8)
192 for(q=0; q<(TILEWH/SPEED); q++)
194 mapScrollUp(draw, SPEED);
\r
195 modexShowPage(draw->page);
\r
196 // mapScrollUp(show, 1);
\r
197 // SWAP(draw, show);
\r
201 else if(player.ty > 0)// && player.ty <= draw->ty + 8)// && player.ty >= draw->ty+8)
203 for(q=0; q<(TILEWH/SPEED); q++)
206 modexDrawBmp(draw->page, player.x, player.y, &bmp);
207 modexShowPage(draw->page);
212 modexDrawBmp(draw->page, player.x, player.y, &bmp);
\r
213 //modexShowPage(draw->page);
\r
219 printf("Project 16 scroll.exe\n");
220 printf("tx: %d\n", draw->tx);
221 printf("ty: %d\n", draw->ty);
222 printf("player.tx: %d\n", player.tx);
223 printf("player.ty: %d\n", player.ty);
228 allocMap(int w, int h) {
\r
233 result.data = malloc(sizeof(byte) * w * h);
\r
240 initMap(map_t *map) {
\r
241 /* just a place holder to fill out an alternating pattern */
\r
245 map->tiles = malloc(sizeof(tiles_t));
\r
247 /* create the tile set */
\r
248 map->tiles->data = malloc(sizeof(bitmap_t));
\r
249 map->tiles->data->width = (TILEWH*2);
\r
250 map->tiles->data->height= TILEWH;
\r
251 map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
\r
252 map->tiles->tileHeight = TILEWH;
\r
253 map->tiles->tileWidth =TILEWH;
\r
254 map->tiles->rows = 1;
\r
255 map->tiles->cols = 2;
\r
258 for(y=0; y<TILEWH; y++) {
\r
259 for(x=0; x<(TILEWH*2); x++) {
\r
261 map->tiles->data->data[i] = 0x24;
\r
263 map->tiles->data->data[i] = 0x34;
\r
269 for(y=0; y<map->height; y++) {
\r
270 for(x=0; x<map->width; x++) {
\r
271 map->data[i] = tile;
\r
272 tile = tile ? 0 : 1;
\r
275 tile = tile ? 0 : 1;
\r
281 mapScrollRight(map_view_t *mv, byte offset) {
\r
282 word x, y; /* coordinate for drawing */
\r
284 /* increment the pixel position and update the page */
\r
285 mv->page->dx += offset;
\r
287 /* check to see if this changes the tile */
\r
288 if(mv->page->dx >= mv->dxThresh ) {
\r
289 /* go forward one tile */
\r
291 /* Snap the origin forward */
\r
292 mv->page->data += 4;
\r
293 mv->page->dx = mv->map->tiles->tileWidth;
\r
296 /* draw the next column */
\r
297 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
298 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
304 mapScrollLeft(map_view_t *mv, byte offset) {
\r
305 word x, y; /* coordinate for drawing */
\r
307 /* increment the pixel position and update the page */
\r
308 mv->page->dx -= offset;
\r
310 /* check to see if this changes the tile */
\r
311 if(mv->page->dx == 0) {
\r
312 /* go backward one tile */
\r
315 /* Snap the origin backward */
\r
316 mv->page->data -= 4;
\r
317 mv->page->dx = mv->map->tiles->tileWidth;
\r
319 /* draw the next column */
\r
320 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
326 mapScrollUp(map_view_t *mv, byte offset) {
\r
327 word x, y; /* coordinate for drawing */
\r
329 /* increment the pixel position and update the page */
\r
330 mv->page->dy -= offset;
\r
332 /* check to see if this changes the tile */
\r
333 if(mv->page->dy == 0 ) {
\r
334 /* go down one tile */
\r
336 /* Snap the origin downward */
\r
337 mv->page->data -= mv->page->width*4;
\r
338 mv->page->dy = mv->map->tiles->tileHeight;
\r
341 /* draw the next row */
\r
343 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
349 mapScrollDown(map_view_t *mv, byte offset) {
\r
350 word x, y; /* coordinate for drawing */
\r
352 /* increment the pixel position and update the page */
\r
353 mv->page->dy += offset;
\r
355 /* check to see if this changes the tile */
\r
356 if(mv->page->dy >= mv->dyThresh ) {
\r
357 /* go down one tile */
\r
359 /* Snap the origin downward */
\r
360 mv->page->data += mv->page->width*4;
\r
361 mv->page->dy = mv->map->tiles->tileHeight;
\r
364 /* draw the next row */
\r
365 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
366 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
373 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
377 /* set up the coordinates */
\r
380 mv->page->dx = mv->map->tiles->tileWidth;
\r
381 mv->page->dy = mv->map->tiles->tileHeight;
\r
383 /* set up the thresholds */
\r
384 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
385 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
387 /* draw the tiles */
\r
388 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
390 i=mv->ty * mv->map->width + mv->tx;
\r
391 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
392 mapDrawRow(mv, tx-1, ty, py);
\r
393 i+=mv->map->width - tx;
\r
399 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
402 rx = (i % t->cols) * t->tileWidth;
\r
403 ry = (i / t->cols) * t->tileHeight;
\r
404 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
409 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
413 /* the position within the map array */
\r
414 i=ty * mv->map->width + tx;
\r
415 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
417 /* we are in the map, so copy! */
\r
418 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
426 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
430 /* location in the map array */
\r
431 i=ty * mv->map->width + tx;
\r
433 /* We'll copy all of the columns in the screen,
\r
434 i + 1 row above and one below */
\r
435 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
437 /* we are in the map, so copy away! */
\r
438 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
440 i += mv->map->width;
\r