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 tx; //player position on the viewable map
\r
39 int ty; //player position on the viewable map
\r
43 map_t allocMap(int w, int h);
\r
44 void initMap(map_t *map);
\r
45 void mapScrollRight(map_view_t *mv, byte offset);
\r
46 void mapScrollLeft(map_view_t *mv, byte offest);
\r
47 void mapScrollUp(map_view_t *mv, byte offset);
\r
48 void mapScrollDown(map_view_t *mv, byte offset);
\r
49 void mapGoTo(map_view_t *mv, int tx, int ty);
\r
50 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
\r
51 void mapDrawRow(map_view_t *mv, int tx, int ty, word y);
\r
52 void mapDrawCol(map_view_t *mv, int tx, int ty, word x);
\r
55 #define QUADWH (TILEWH/4)
58 //place holder definitions
61 //#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
75 //default player position on the viewable map
\r
80 /* create the map */
\r
81 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
85 //initiate bottem right edge trigger
86 // mv.ttx = mv.tx + 20;
87 // mv.tty = mv.ty + 15;
\r
90 /* draw the tiles */
\r
93 screen = modexDefaultPage();
\r
94 screen.width += (TILEWH*2);
\r
96 // screen2=modexNextPage(mv.page);
\r
97 // mv2.page = &screen2;
\r
98 // mapGoTo(&mv2, 16, 16);
\r
99 // modexShowPage(mv.page);
\r
101 /* set up paging */
\r
106 mapGoTo(draw, 0, 0);
\r
108 //TODO: set player position data here according to the viewable map screen thingy
\r
110 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
\r
116 if(draw->tx >= 0 && draw->tx+20 < MAPX)
\r
117 for(q=0; q<16; q++) {
\r
118 mapScrollRight(draw, SPEED);
\r
119 modexShowPage(draw->page);
\r
120 // mapScrollRight(draw, 1);
\r
121 // SWAP(draw, show);
\r
127 if(draw->tx > 0 && draw->tx+20 <= MAPX)
\r
128 for(q=0; q<16; q++) {
\r
129 mapScrollLeft(draw, SPEED);
\r
130 modexShowPage(draw->page);
\r
131 // mapScrollLeft(show, 1);
\r
132 // SWAP(draw, show);
\r
138 if(draw->ty >= 0 && draw->ty+15 < MAPY)
\r
139 for(q=0; q<16; q++) {
\r
140 mapScrollDown(draw, SPEED);
\r
141 modexShowPage(draw->page);
\r
142 // mapScrollDown(show, 1);
\r
143 // SWAP(draw, show);
\r
149 if(draw->ty > 0 && draw->ty+15 <= MAPY)
\r
150 for(q=0; q<16; q++) {
\r
151 mapScrollUp(draw, SPEED);
\r
152 modexShowPage(draw->page);
\r
153 // mapScrollUp(show, 1);
\r
154 // SWAP(draw, show);
\r
160 //modexShowPage(draw->page);
\r
166 printf("Project 16 scroll.exe\n");
167 printf("tx: %d\n", draw->tx);
168 printf("ty: %d\n", draw->ty);
169 //printf("ttx: %d\n", draw->ttx);
170 //printf("tty: %d\n", draw->tty);
175 allocMap(int w, int h) {
\r
180 result.data = malloc(sizeof(byte) * w * h);
\r
187 initMap(map_t *map) {
\r
188 /* just a place holder to fill out an alternating pattern */
\r
192 map->tiles = malloc(sizeof(tiles_t));
\r
194 /* create the tile set */
\r
195 map->tiles->data = malloc(sizeof(bitmap_t));
\r
196 map->tiles->data->width = (TILEWH*2);
\r
197 map->tiles->data->height= TILEWH;
\r
198 map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
\r
199 map->tiles->tileHeight = TILEWH;
\r
200 map->tiles->tileWidth =TILEWH;
\r
201 map->tiles->rows = 1;
\r
202 map->tiles->cols = 2;
\r
205 for(y=0; y<TILEWH; y++) {
\r
206 for(x=0; x<(TILEWH*2); x++) {
\r
208 map->tiles->data->data[i] = 0x24;
\r
210 map->tiles->data->data[i] = 0x34;
\r
216 for(y=0; y<map->height; y++) {
\r
217 for(x=0; x<map->width; x++) {
\r
218 map->data[i] = tile;
\r
219 tile = tile ? 0 : 1;
\r
222 tile = tile ? 0 : 1;
\r
228 mapScrollRight(map_view_t *mv, byte offset) {
\r
229 word x, y; /* coordinate for drawing */
\r
231 /* increment the pixel position and update the page */
\r
232 mv->page->dx += offset;
\r
234 /* check to see if this changes the tile */
\r
235 if(mv->page->dx >= mv->dxThresh ) {
\r
236 /* go forward one tile */
\r
238 /* Snap the origin forward */
\r
239 mv->page->data += 4;
\r
240 mv->page->dx = mv->map->tiles->tileWidth;
\r
243 /* draw the next column */
\r
244 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
245 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
251 mapScrollLeft(map_view_t *mv, byte offset) {
\r
252 word x, y; /* coordinate for drawing */
\r
254 /* increment the pixel position and update the page */
\r
255 mv->page->dx -= offset;
\r
257 /* check to see if this changes the tile */
\r
258 if(mv->page->dx == 0) {
\r
259 /* go backward one tile */
\r
262 /* Snap the origin backward */
\r
263 mv->page->data -= 4;
\r
264 mv->page->dx = mv->map->tiles->tileWidth;
\r
266 /* draw the next column */
\r
267 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
273 mapScrollUp(map_view_t *mv, byte offset) {
\r
274 word x, y; /* coordinate for drawing */
\r
276 /* increment the pixel position and update the page */
\r
277 mv->page->dy -= offset;
\r
279 /* check to see if this changes the tile */
\r
280 if(mv->page->dy == 0 ) {
\r
281 /* go down one tile */
\r
283 /* Snap the origin downward */
\r
284 mv->page->data -= mv->page->width*4;
\r
285 mv->page->dy = mv->map->tiles->tileHeight;
\r
288 /* draw the next row */
\r
290 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
296 mapScrollDown(map_view_t *mv, byte offset) {
\r
297 word x, y; /* coordinate for drawing */
\r
299 /* increment the pixel position and update the page */
\r
300 mv->page->dy += offset;
\r
302 /* check to see if this changes the tile */
\r
303 if(mv->page->dy >= mv->dyThresh ) {
\r
304 /* go down one tile */
\r
306 /* Snap the origin downward */
\r
307 mv->page->data += mv->page->width*4;
\r
308 mv->page->dy = mv->map->tiles->tileHeight;
\r
311 /* draw the next row */
\r
312 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
313 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
320 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
324 /* set up the coordinates */
\r
327 mv->page->dx = mv->map->tiles->tileWidth;
\r
328 mv->page->dy = mv->map->tiles->tileHeight;
\r
330 /* set up the thresholds */
\r
331 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
332 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
334 /* draw the tiles */
\r
335 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
337 i=mv->ty * mv->map->width + mv->tx;
\r
338 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
339 mapDrawRow(mv, tx-1, ty, py);
\r
340 i+=mv->map->width - tx;
\r
346 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
349 rx = (i % t->cols) * t->tileWidth;
\r
350 ry = (i / t->cols) * t->tileHeight;
\r
351 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
356 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
360 /* the position within the map array */
\r
361 i=ty * mv->map->width + tx;
\r
362 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
364 /* we are in the map, so copy! */
\r
365 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
373 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
377 /* location in the map array */
\r
378 i=ty * mv->map->width + tx;
\r
380 /* We'll copy all of the columns in the screen,
\r
381 i + 1 row above and one below */
\r
382 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
384 /* we are in the map, so copy away! */
\r
385 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
387 i += mv->map->width;
\r