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 tile position on the viewable screen map
\r
30 int ty; //???? appears to be the tile position on the viewable screen map
\r
31 word dxThresh; //????
\r
32 word dyThresh; //????
\r
36 int tx; //player position on the viewable map
\r
37 int ty; //player position on the viewable map
\r
41 map_t allocMap(int w, int h);
\r
42 void initMap(map_t *map);
\r
43 void mapScrollRight(map_view_t *mv, byte offset);
\r
44 void mapScrollLeft(map_view_t *mv, byte offest);
\r
45 void mapScrollUp(map_view_t *mv, byte offset);
\r
46 void mapScrollDown(map_view_t *mv, byte offset);
\r
47 void mapGoTo(map_view_t *mv, int tx, int ty);
\r
48 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
\r
49 void mapDrawRow(map_view_t *mv, int tx, int ty, word y);
\r
50 void mapDrawCol(map_view_t *mv, int tx, int ty, word x);
\r
53 #define QUADWH (TILEWH/4)
\r
54 //#define SWAP(a, b) tmp=a; a=b; b=tmp;
\r
62 page_t screen;//,screen2;
\r
64 map_view_t mv;//, mv2;
\r
65 map_view_t *draw;//, *show, *tmp;
\r
68 //default player position on the viewable map
\r
73 /* create the map */
\r
74 map = allocMap(160,120); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly
\r
79 /* draw the tiles */
\r
82 screen = modexDefaultPage();
\r
83 screen.width += (TILEWH*2);
\r
85 mapGoTo(&mv, 16, 16);
\r
86 // screen2=modexNextPage(mv.page);
\r
87 // mv2.page = &screen2;
\r
88 // mapGoTo(&mv2, 16, 16);
\r
89 // modexShowPage(mv.page);
\r
96 //TODO: set player position data here according to the viewable map screen thingy
\r
99 //TODO: top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
\r
100 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
\r
101 //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
103 // for(q=0; q<TILEWH; q++) {
\r
104 mapScrollRight(draw, 1);
\r
105 // modexShowPage(draw->page);
\r
106 // mapScrollRight(draw, 1);
\r
107 // SWAP(draw, show);
\r
112 // for(q=0; q<TILEWH; q++) {
\r
113 mapScrollLeft(draw, 1);
\r
114 // modexShowPage(draw->page);
\r
115 // mapScrollLeft(show, 1);
\r
116 // SWAP(draw, show);
\r
121 // for(q=0; q<TILEWH; q++) {
\r
122 mapScrollDown(draw, 1);
\r
123 // modexShowPage(draw->page);
\r
124 // mapScrollDown(show, 1);
\r
125 // SWAP(draw, show);
\r
130 // for(q=0; q<TILEWH; q++) {
\r
131 mapScrollUp(draw, 1);
\r
132 // modexShowPage(draw->page);
\r
133 // mapScrollUp(show, 1);
\r
134 // SWAP(draw, show);
\r
139 modexShowPage(draw->page);
\r
149 allocMap(int w, int h) {
\r
154 result.data = malloc(sizeof(byte) * w * h);
\r
161 initMap(map_t *map) {
\r
162 /* just a place holder to fill out an alternating pattern */
\r
166 map->tiles = malloc(sizeof(tiles_t));
\r
168 /* create the tile set */
\r
169 map->tiles->data = malloc(sizeof(bitmap_t));
\r
170 map->tiles->data->width = (TILEWH*2);
\r
171 map->tiles->data->height= TILEWH;
\r
172 map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
\r
173 map->tiles->tileHeight = TILEWH;
\r
174 map->tiles->tileWidth =TILEWH;
\r
175 map->tiles->rows = 1;
\r
176 map->tiles->cols = 2;
\r
179 for(y=0; y<TILEWH; y++) {
\r
180 for(x=0; x<(TILEWH*2); x++) {
\r
182 map->tiles->data->data[i] = 0x24;
\r
184 map->tiles->data->data[i] = 0x34;
\r
190 for(y=0; y<map->height; y++) {
\r
191 for(x=0; x<map->width; x++) {
\r
192 map->data[i] = tile;
\r
193 tile = tile ? 0 : 1;
\r
196 tile = tile ? 0 : 1;
\r
202 mapScrollRight(map_view_t *mv, byte offset) {
\r
203 word x, y; /* coordinate for drawing */
\r
205 /* increment the pixel position and update the page */
\r
206 mv->page->dx += offset;
\r
208 /* check to see if this changes the tile */
\r
209 if(mv->page->dx >= mv->dxThresh ) {
\r
210 /* go forward one tile */
\r
212 /* Snap the origin forward */
\r
213 mv->page->data += 4;
\r
214 mv->page->dx = mv->map->tiles->tileWidth;
\r
217 /* draw the next column */
\r
218 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
219 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
225 mapScrollLeft(map_view_t *mv, byte offset) {
\r
226 word x, y; /* coordinate for drawing */
\r
228 /* increment the pixel position and update the page */
\r
229 mv->page->dx -= offset;
\r
231 /* check to see if this changes the tile */
\r
232 if(mv->page->dx == 0) {
\r
233 /* go backward one tile */
\r
236 /* Snap the origin backward */
\r
237 mv->page->data -= 4;
\r
238 mv->page->dx = mv->map->tiles->tileWidth;
\r
240 /* draw the next column */
\r
241 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
247 mapScrollUp(map_view_t *mv, byte offset) {
\r
248 word x, y; /* coordinate for drawing */
\r
250 /* increment the pixel position and update the page */
\r
251 mv->page->dy -= offset;
\r
253 /* check to see if this changes the tile */
\r
254 if(mv->page->dy == 0 ) {
\r
255 /* go down one tile */
\r
257 /* Snap the origin downward */
\r
258 mv->page->data -= mv->page->width*4;
\r
259 mv->page->dy = mv->map->tiles->tileHeight;
\r
262 /* draw the next row */
\r
264 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
270 mapScrollDown(map_view_t *mv, byte offset) {
\r
271 word x, y; /* coordinate for drawing */
\r
273 /* increment the pixel position and update the page */
\r
274 mv->page->dy += offset;
\r
276 /* check to see if this changes the tile */
\r
277 if(mv->page->dy >= mv->dyThresh ) {
\r
278 /* go down one tile */
\r
280 /* Snap the origin downward */
\r
281 mv->page->data += mv->page->width*4;
\r
282 mv->page->dy = mv->map->tiles->tileHeight;
\r
285 /* draw the next row */
\r
286 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
287 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
294 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
298 /* set up the coordinates */
\r
301 mv->page->dx = mv->map->tiles->tileWidth;
\r
302 mv->page->dy = mv->map->tiles->tileHeight;
\r
304 /* set up the thresholds */
\r
305 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
306 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
308 /* draw the tiles */
\r
309 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
311 i=mv->ty * mv->map->width + mv->tx;
\r
312 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
313 mapDrawRow(mv, tx-1, ty, py);
\r
314 i+=mv->map->width - tx;
\r
320 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
323 rx = (i % t->cols) * t->tileWidth;
\r
324 ry = (i / t->cols) * t->tileHeight;
\r
325 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
330 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
334 /* the position within the map array */
\r
335 i=ty * mv->map->width + tx;
\r
336 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
338 /* we are in the map, so copy! */
\r
339 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
347 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
351 /* location in the map array */
\r
352 i=ty * mv->map->width + tx;
\r
354 /* We'll copy all of the columns in the screen,
\r
355 i + 1 row above and one below */
\r
356 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
358 /* we are in the map, so copy away! */
\r
359 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
361 i += mv->map->width;
\r