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
69 page_t screen;//,screen2;
\r
71 map_view_t mv;//, mv2;
\r
72 map_view_t *draw;//, *show, *tmp;
\r
76 /* create the map */
\r
77 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
82 /* draw the tiles */
\r
84 bmp = bitmapLoadPcx("ptmp.pcx"); // load sprite
85 modexPalUpdate(bmp.palette);
\r
87 screen = modexDefaultPage();
\r
88 screen.width += (TILEWH*2);
\r
90 // screen2=modexNextPage(mv.page);
\r
91 // mv2.page = &screen2;
\r
92 // mapGoTo(&mv2, 16, 16);
\r
93 // modexShowPage(mv.page);
\r
100 mapGoTo(draw, 0, 0);
\r
102 //TODO: set player position data here according to the viewable map screen thingy
\r
103 //default player position on the viewable map
104 player.tx = draw->tx + 10;
105 player.ty = draw->ty + 8;
106 player.x = player.tx*TILEWH;
107 player.y = player.ty*TILEWH;
109 modexShowPage(draw->page);
\r
112 //TODO: top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
\r
113 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
\r
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
117 if(draw->tx >= 0 && draw->tx+20 <= MAPX && player.tx == draw->tx + 10)
119 for(q=0; q<(TILEWH/SPEED); q++)
121 mapScrollRight(draw, SPEED);
\r
122 modexShowPage(draw->page);
\r
123 // mapScrollRight(draw, 1);
\r
124 // SWAP(draw, show);
\r
127 else if(player.tx < draw->tx+20 && player.tx >= draw->tx + 10)// && player.tx <= draw->tx+10)
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
150 else if(player.tx > 0 && player.tx <= draw->tx + 10)// && player.tx >= draw->tx+10)
152 for(q=0; q<(TILEWH/SPEED); q++)
155 modexDrawBmp(draw->page, player.x, player.y, &bmp);
156 modexShowPage(draw->page);
164 if(draw->ty >= 0 && draw->ty+15 <= MAPY && player.ty == draw->ty + 8)
166 for(q=0; q<(TILEWH/SPEED); q++)
168 mapScrollDown(draw, SPEED);
\r
169 modexShowPage(draw->page);
\r
170 // mapScrollDown(show, 1);
\r
171 // SWAP(draw, show);
\r
174 else if(player.ty < draw->ty+15 && player.ty >= draw->ty + 8)// && player.ty <= draw->ty+8)
176 for(q=0; q<(TILEWH/SPEED); q++)
179 modexDrawBmp(draw->page, player.x, player.y, &bmp);
180 modexShowPage(draw->page);
188 if(draw->ty >= 0 && draw->ty+15 <= MAPY && player.ty == draw->ty + 8)
190 for(q=0; q<(TILEWH/SPEED); q++)
192 mapScrollUp(draw, SPEED);
\r
193 modexShowPage(draw->page);
\r
194 // mapScrollUp(show, 1);
\r
195 // SWAP(draw, show);
\r
198 else if(player.ty > 0 && player.ty <= draw->ty + 8)// && player.ty >= draw->ty+8)
200 for(q=0; q<(TILEWH/SPEED); q++)
203 modexDrawBmp(draw->page, player.x, player.y, &bmp);
204 modexShowPage(draw->page);
209 modexDrawBmp(draw->page, player.x, player.y, &bmp);
\r
210 //modexShowPage(draw->page);
\r
216 printf("Project 16 scroll.exe\n");
217 printf("tx: %d\n", draw->tx);
218 printf("ty: %d\n", draw->ty);
219 printf("player.tx: %d\n", player.tx);
220 printf("player.ty: %d\n", player.ty);
225 allocMap(int w, int h) {
\r
230 result.data = malloc(sizeof(byte) * w * h);
\r
237 initMap(map_t *map) {
\r
238 /* just a place holder to fill out an alternating pattern */
\r
242 map->tiles = malloc(sizeof(tiles_t));
\r
244 /* create the tile set */
\r
245 map->tiles->data = malloc(sizeof(bitmap_t));
\r
246 map->tiles->data->width = (TILEWH*2);
\r
247 map->tiles->data->height= TILEWH;
\r
248 map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
\r
249 map->tiles->tileHeight = TILEWH;
\r
250 map->tiles->tileWidth =TILEWH;
\r
251 map->tiles->rows = 1;
\r
252 map->tiles->cols = 2;
\r
255 for(y=0; y<TILEWH; y++) {
\r
256 for(x=0; x<(TILEWH*2); x++) {
\r
258 map->tiles->data->data[i] = 0x24;
\r
260 map->tiles->data->data[i] = 0x34;
\r
266 for(y=0; y<map->height; y++) {
\r
267 for(x=0; x<map->width; x++) {
\r
268 map->data[i] = tile;
\r
269 tile = tile ? 0 : 1;
\r
272 tile = tile ? 0 : 1;
\r
278 mapScrollRight(map_view_t *mv, byte offset) {
\r
279 word x, y; /* coordinate for drawing */
\r
281 /* increment the pixel position and update the page */
\r
282 mv->page->dx += offset;
\r
284 /* check to see if this changes the tile */
\r
285 if(mv->page->dx >= mv->dxThresh ) {
\r
286 /* go forward one tile */
\r
288 /* Snap the origin forward */
\r
289 mv->page->data += 4;
\r
290 mv->page->dx = mv->map->tiles->tileWidth;
\r
293 /* draw the next column */
\r
294 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
295 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
301 mapScrollLeft(map_view_t *mv, byte offset) {
\r
302 word x, y; /* coordinate for drawing */
\r
304 /* increment the pixel position and update the page */
\r
305 mv->page->dx -= offset;
\r
307 /* check to see if this changes the tile */
\r
308 if(mv->page->dx == 0) {
\r
309 /* go backward one tile */
\r
312 /* Snap the origin backward */
\r
313 mv->page->data -= 4;
\r
314 mv->page->dx = mv->map->tiles->tileWidth;
\r
316 /* draw the next column */
\r
317 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
323 mapScrollUp(map_view_t *mv, byte offset) {
\r
324 word x, y; /* coordinate for drawing */
\r
326 /* increment the pixel position and update the page */
\r
327 mv->page->dy -= offset;
\r
329 /* check to see if this changes the tile */
\r
330 if(mv->page->dy == 0 ) {
\r
331 /* go down one tile */
\r
333 /* Snap the origin downward */
\r
334 mv->page->data -= mv->page->width*4;
\r
335 mv->page->dy = mv->map->tiles->tileHeight;
\r
338 /* draw the next row */
\r
340 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
346 mapScrollDown(map_view_t *mv, byte offset) {
\r
347 word x, y; /* coordinate for drawing */
\r
349 /* increment the pixel position and update the page */
\r
350 mv->page->dy += offset;
\r
352 /* check to see if this changes the tile */
\r
353 if(mv->page->dy >= mv->dyThresh ) {
\r
354 /* go down one tile */
\r
356 /* Snap the origin downward */
\r
357 mv->page->data += mv->page->width*4;
\r
358 mv->page->dy = mv->map->tiles->tileHeight;
\r
361 /* draw the next row */
\r
362 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
363 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
370 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
374 /* set up the coordinates */
\r
377 mv->page->dx = mv->map->tiles->tileWidth;
\r
378 mv->page->dy = mv->map->tiles->tileHeight;
\r
380 /* set up the thresholds */
\r
381 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
382 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
384 /* draw the tiles */
\r
385 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
387 i=mv->ty * mv->map->width + mv->tx;
\r
388 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
389 mapDrawRow(mv, tx-1, ty, py);
\r
390 i+=mv->map->width - tx;
\r
396 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
399 rx = (i % t->cols) * t->tileWidth;
\r
400 ry = (i / t->cols) * t->tileHeight;
\r
401 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
406 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
410 /* the position within the map array */
\r
411 i=ty * mv->map->width + tx;
\r
412 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
414 /* we are in the map, so copy! */
\r
415 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
423 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
427 /* location in the map array */
\r
428 i=ty * mv->map->width + tx;
\r
430 /* We'll copy all of the columns in the screen,
\r
431 i + 1 row above and one below */
\r
432 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
434 /* we are in the map, so copy away! */
\r
435 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
437 i += mv->map->width;
\r