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
65 map_view_t *draw, *show, *tmp;
\r
67 //default player position on the viewable map
\r
72 /* create the map */
\r
73 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
78 /* draw the tiles */
\r
81 screen = modexDefaultPage();
\r
82 screen.width += (TILEWH*2);
\r
84 mapGoTo(&mv, 16, 16);
\r
85 screen2=modexNextPage(mv.page);
\r
86 mv2.page = &screen2;
\r
87 mapGoTo(&mv2, 16, 16);
\r
88 modexShowPage(mv.page);
94 //TODO: set player position data here according to the viewable map screen thingy
97 //TODO: top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
98 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
99 //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
101 // for(q=0; q<TILEWH; q++) {
\r
102 mapScrollRight(draw, 1);
\r
103 // modexShowPage(draw->page);
\r
104 // mapScrollRight(draw, 1);
\r
105 // SWAP(draw, show);
\r
110 // for(q=0; q<TILEWH; q++) {
\r
111 mapScrollLeft(draw, 1);
\r
112 // modexShowPage(draw->page);
\r
113 // mapScrollLeft(show, 1);
\r
114 // SWAP(draw, show);
\r
119 // for(q=0; q<TILEWH; q++) {
\r
120 mapScrollDown(draw, 1);
\r
121 // modexShowPage(draw->page);
\r
122 // mapScrollDown(show, 1);
\r
123 // SWAP(draw, show);
\r
128 // for(q=0; q<TILEWH; q++) {
\r
129 mapScrollUp(draw, 1);
\r
130 // modexShowPage(draw->page);
\r
131 // mapScrollUp(show, 1);
\r
132 // SWAP(draw, show);
\r
137 modexShowPage(draw->page);
\r
147 allocMap(int w, int h) {
\r
152 result.data = malloc(sizeof(byte) * w * h);
\r
159 initMap(map_t *map) {
\r
160 /* just a place holder to fill out an alternating pattern */
\r
164 map->tiles = malloc(sizeof(tiles_t));
\r
166 /* create the tile set */
\r
167 map->tiles->data = malloc(sizeof(bitmap_t));
\r
168 map->tiles->data->width = (TILEWH*2);
\r
169 map->tiles->data->height= TILEWH;
\r
170 map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
\r
171 map->tiles->tileHeight = TILEWH;
\r
172 map->tiles->tileWidth =TILEWH;
\r
173 map->tiles->rows = 1;
\r
174 map->tiles->cols = 2;
\r
177 for(y=0; y<TILEWH; y++) {
\r
178 for(x=0; x<(TILEWH*2); x++) {
\r
180 map->tiles->data->data[i] = 0x24;
\r
182 map->tiles->data->data[i] = 0x34;
\r
188 for(y=0; y<map->height; y++) {
\r
189 for(x=0; x<map->width; x++) {
\r
190 map->data[i] = tile;
\r
191 tile = tile ? 0 : 1;
\r
194 tile = tile ? 0 : 1;
\r
200 mapScrollRight(map_view_t *mv, byte offset) {
\r
201 word x, y; /* coordinate for drawing */
\r
203 /* increment the pixel position and update the page */
\r
204 mv->page->dx += offset;
\r
206 /* check to see if this changes the tile */
\r
207 if(mv->page->dx >= mv->dxThresh ) {
\r
208 /* go forward one tile */
\r
210 /* Snap the origin forward */
\r
211 mv->page->data += 4;
\r
212 mv->page->dx = mv->map->tiles->tileWidth;
\r
215 /* draw the next column */
\r
216 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
217 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
223 mapScrollLeft(map_view_t *mv, byte offset) {
\r
224 word x, y; /* coordinate for drawing */
\r
226 /* increment the pixel position and update the page */
\r
227 mv->page->dx -= offset;
\r
229 /* check to see if this changes the tile */
\r
230 if(mv->page->dx == 0) {
\r
231 /* go backward one tile */
\r
234 /* Snap the origin backward */
\r
235 mv->page->data -= 4;
\r
236 mv->page->dx = mv->map->tiles->tileWidth;
\r
238 /* draw the next column */
\r
239 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
245 mapScrollUp(map_view_t *mv, byte offset) {
\r
246 word x, y; /* coordinate for drawing */
\r
248 /* increment the pixel position and update the page */
\r
249 mv->page->dy -= offset;
\r
251 /* check to see if this changes the tile */
\r
252 if(mv->page->dy == 0 ) {
\r
253 /* go down one tile */
\r
255 /* Snap the origin downward */
\r
256 mv->page->data -= mv->page->width*4;
\r
257 mv->page->dy = mv->map->tiles->tileHeight;
\r
260 /* draw the next row */
\r
262 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
268 mapScrollDown(map_view_t *mv, byte offset) {
\r
269 word x, y; /* coordinate for drawing */
\r
271 /* increment the pixel position and update the page */
\r
272 mv->page->dy += offset;
\r
274 /* check to see if this changes the tile */
\r
275 if(mv->page->dy >= mv->dyThresh ) {
\r
276 /* go down one tile */
\r
278 /* Snap the origin downward */
\r
279 mv->page->data += mv->page->width*4;
\r
280 mv->page->dy = mv->map->tiles->tileHeight;
\r
283 /* draw the next row */
\r
284 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
285 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
292 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
296 /* set up the coordinates */
\r
299 mv->page->dx = mv->map->tiles->tileWidth;
\r
300 mv->page->dy = mv->map->tiles->tileHeight;
\r
302 /* set up the thresholds */
\r
303 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
304 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
306 /* draw the tiles */
\r
307 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
309 i=mv->ty * mv->map->width + mv->tx;
\r
310 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
311 mapDrawRow(mv, tx-1, ty, py);
\r
312 i+=mv->map->width - tx;
\r
318 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
321 rx = (i % t->cols) * t->tileWidth;
\r
322 ry = (i / t->cols) * t->tileHeight;
\r
323 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
328 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
332 /* the position within the map array */
\r
333 i=ty * mv->map->width + tx;
\r
334 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
336 /* we are in the map, so copy! */
\r
337 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
345 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
349 /* location in the map array */
\r
350 i=ty * mv->map->width + tx;
\r
352 /* We'll copy all of the columns in the screen,
\r
353 i + 1 row above and one below */
\r
354 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
356 /* we are in the map, so copy away! */
\r
357 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
359 i += mv->map->width;
\r