6 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
\r
40 map_t allocMap(int w, int h);
\r
41 void initMap(map_t *map);
\r
42 void mapScrollRight(map_view_t *mv, byte offset);
\r
43 void mapScrollLeft(map_view_t *mv, byte offest);
\r
44 void mapScrollUp(map_view_t *mv, byte offset);
\r
45 void mapScrollDown(map_view_t *mv, byte offset);
\r
46 void mapGoTo(map_view_t *mv, int tx, int ty);
\r
47 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
\r
48 void mapDrawRow(map_view_t *mv, int tx, int ty, word y);
\r
49 void mapDrawCol(map_view_t *mv, int tx, int ty, word x);
\r
52 #define QUADWH (TILEWH/4)
\r
53 #define SWAP(a, b) tmp=a; a=b; b=tmp;
\r
61 page_t screen,screen2;
\r
64 map_view_t *draw, *show, *tmp;
\r
66 //default player position on the viewable map
\r
71 /* create the map */
\r
72 map = allocMap(40,30); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly
\r
77 /* draw the tiles */
\r
80 screen = modexDefaultPage();
\r
84 screen2=modexNextPage(mv.page);
\r
85 mv2.page = &screen2;
\r
86 mapGoTo(&mv2, 0, 0);
\r
87 modexShowPage(mv.page);
\r
95 // for(q=0; q<TILEWH; q++) {
\r
96 mapScrollRight(draw, 1);
\r
97 // modexShowPage(draw->page);
\r
98 // mapScrollRight(draw, 1);
\r
99 // SWAP(draw, show);
\r
104 // for(q=0; q<TILEWH; q++) {
\r
105 mapScrollLeft(draw, 1);
\r
106 // modexShowPage(draw->page);
\r
107 // mapScrollLeft(show, 1);
\r
108 // SWAP(draw, show);
\r
113 // for(q=0; q<TILEWH; q++) {
\r
114 mapScrollDown(draw, 1);
\r
115 // modexShowPage(draw->page);
\r
116 // mapScrollDown(show, 1);
\r
117 // SWAP(draw, show);
\r
122 // for(q=0; q<TILEWH; q++) {
\r
123 mapScrollUp(draw, 1);
\r
124 // modexShowPage(draw->page);
\r
125 // mapScrollUp(show, 1);
\r
126 // SWAP(draw, show);
\r
131 modexShowPage(draw->page);
\r
141 allocMap(int w, int h) {
\r
146 result.data = malloc(sizeof(byte) * w * h);
\r
153 initMap(map_t *map) {
\r
154 /* just a place holder to fill out an alternating pattern */
\r
158 map->tiles = malloc(sizeof(tiles_t));
\r
160 /* create the tile set */
\r
161 map->tiles->data = malloc(sizeof(bitmap_t));
\r
162 map->tiles->data->width = (TILEWH*2);
\r
163 map->tiles->data->height= TILEWH;
\r
164 map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
\r
165 map->tiles->tileHeight = TILEWH;
\r
166 map->tiles->tileWidth =TILEWH;
\r
167 map->tiles->rows = 1;
\r
168 map->tiles->cols = 2;
\r
171 for(y=0; y<TILEWH; y++) {
\r
172 for(x=0; x<(TILEWH*2); x++) {
\r
174 map->tiles->data->data[i] = 0x24;
\r
176 map->tiles->data->data[i] = 0x34;
\r
182 for(y=0; y<map->height; y++) {
\r
183 for(x=0; x<map->width; x++) {
\r
184 map->data[i] = tile;
\r
185 tile = tile ? 0 : 1;
\r
188 tile = tile ? 0 : 1;
\r
194 mapScrollRight(map_view_t *mv, byte offset) {
\r
195 word x, y; /* coordinate for drawing */
\r
197 /* increment the pixel position and update the page */
\r
198 mv->page->dx += offset;
\r
200 /* check to see if this changes the tile */
\r
201 if(mv->page->dx >= mv->dxThresh ) {
\r
202 /* go forward one tile */
\r
204 /* Snap the origin forward */
\r
205 mv->page->data += 4;
\r
206 mv->page->dx = mv->map->tiles->tileWidth;
\r
209 /* draw the next column */
\r
210 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
211 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
217 mapScrollLeft(map_view_t *mv, byte offset) {
\r
218 word x, y; /* coordinate for drawing */
\r
220 /* increment the pixel position and update the page */
\r
221 mv->page->dx -= offset;
\r
223 /* check to see if this changes the tile */
\r
224 if(mv->page->dx == 0) {
\r
225 /* go backward one tile */
\r
228 /* Snap the origin backward */
\r
229 mv->page->data -= 4;
\r
230 mv->page->dx = mv->map->tiles->tileWidth;
\r
232 /* draw the next column */
\r
233 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
239 mapScrollUp(map_view_t *mv, byte offset) {
\r
240 word x, y; /* coordinate for drawing */
\r
242 /* increment the pixel position and update the page */
\r
243 mv->page->dy -= offset;
\r
245 /* check to see if this changes the tile */
\r
246 if(mv->page->dy == 0 ) {
\r
247 /* go down one tile */
\r
249 /* Snap the origin downward */
\r
250 mv->page->data -= mv->page->width*4;
\r
251 mv->page->dy = mv->map->tiles->tileHeight;
\r
254 /* draw the next row */
\r
256 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
262 mapScrollDown(map_view_t *mv, byte offset) {
\r
263 word x, y; /* coordinate for drawing */
\r
265 /* increment the pixel position and update the page */
\r
266 mv->page->dy += offset;
\r
268 /* check to see if this changes the tile */
\r
269 if(mv->page->dy >= mv->dyThresh ) {
\r
270 /* go down one tile */
\r
272 /* Snap the origin downward */
\r
273 mv->page->data += mv->page->width*4;
\r
274 mv->page->dy = mv->map->tiles->tileHeight;
\r
277 /* draw the next row */
\r
278 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
279 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
286 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
290 /* set up the coordinates */
\r
293 mv->page->dx = mv->map->tiles->tileWidth;
\r
294 mv->page->dy = mv->map->tiles->tileHeight;
\r
296 /* set up the thresholds */
\r
297 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
298 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
300 /* draw the tiles */
\r
301 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
303 i=mv->ty * mv->map->width + mv->tx;
\r
304 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
305 mapDrawRow(mv, tx-1, ty, py);
\r
306 i+=mv->map->width - tx;
\r
312 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
315 rx = (i % t->cols) * t->tileWidth;
\r
316 ry = (i / t->cols) * t->tileHeight;
\r
317 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
322 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
326 /* the position within the map array */
\r
327 i=ty * mv->map->width + tx;
\r
328 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
330 /* we are in the map, so copy! */
\r
331 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
339 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
343 /* location in the map array */
\r
344 i=ty * mv->map->width + tx;
\r
346 /* We'll copy all of the columns in the screen,
\r
347 i + 1 row above and one below */
\r
348 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
350 /* we are in the map, so copy away! */
\r
351 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
353 i += mv->map->width;
\r