1 /* Project 16 Source Code~
\r
2 * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
\r
4 * This file is part of Project 16.
\r
6 * Project 16 is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Project 16 is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
\r
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
\r
19 * Fifth Floor, Boston, MA 02110-1301 USA.
\r
25 #include "src/lib/scroll16.h"
\r
27 //#define INC_PER_FRAME if(player[pn].enti.q&1) player[pn].enti.persist_aniframe++; if(player[pn].enti.persist_aniframe>4) player[pn].enti.persist_aniframe = 1;
\r
28 #define ZC_WALKR ScrollRight(pip, player, 3, pn); \
\r
29 ScrollRight(pip, player, 2, pn); \
\r
30 mapScrollRight(pip, player, (0), pn); \
\r
31 if(pip[0].video->bgps) mapScrollRight(pip, player, (1), pn);
\r
32 #define ZC_WALKL ScrollLeft(pip, player, 3, pn); \
\r
33 ScrollLeft(pip, player, 2, pn); \
\r
34 mapScrollLeft(pip, player, (0), pn); \
\r
35 if(pip[0].video->bgps) mapScrollLeft(pip, player, (1), pn);
\r
36 #define ZC_WALKD ScrollDown(pip, player, 3, pn); \
\r
37 ScrollDown(pip, player, 2, pn); \
\r
38 mapScrollDown(pip, player, (0), pn); \
\r
39 if(pip[0].video->bgps) mapScrollDown(pip, player, (1), pn);
\r
40 #define ZC_WALKU ScrollUp(pip, player, 3, pn); \
\r
41 ScrollUp(pip, player, 2, pn); \
\r
42 mapScrollUp(pip, player, (0), pn); \
\r
43 if(pip[0].video->bgps) mapScrollUp(pip, player, (1), pn);
\r
45 void ZC_walk(map_view_t *pip, player_t *player, word pn)
\r
47 switch(player[pn].enti.d)
\r
51 //0000pip[0].video->startclk = (*clockw);
\r
55 if(pip[0].tx >= 0 && pip[0].tx+pip[0].page->ti.tw < pip[0].map->width && player[pn].enti.tx == pip[0].tx+pip[0].page->ti.tilemidposscreenx &&
\r
56 !(pip[0].map->data[(player[pn].enti.tx)+(pip[0].map->width*(player[pn].enti.ty-1))] == 0))//!(player[pn].enti.tx+1 == TRIGGX && player[pn].enti.ty == TRIGGY)) //collision detection!
\r
58 player[pn].walktype=2;
\r
59 if(player[pn].enti.q<=player[pn].enti.spt)
\r
61 ZC_animatePlayer(pip, player, pn, 2);
\r
63 player[pn].enti.q++;
\r
64 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
\r
65 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.tx++; }
\r
67 else if(player[pn].enti.tx < pip[0].map->width && !(pip[0].map->data[(player[pn].enti.tx)+(pip[0].map->width*(player[pn].enti.ty-1))] == 0))//!(player[pn].enti.tx+1 == TRIGGX && player[pn].enti.ty == TRIGGY))
\r
69 player[pn].walktype=1;
\r
70 if(player[pn].enti.q<=player[pn].enti.spt)
\r
72 player[pn].enti.x+=(player[pn].enti.speed);
\r
73 ZC_animatePlayer(pip, player, pn, 1);
\r
74 player[pn].enti.q++;
\r
75 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.tx++; }
\r
79 player[pn].walktype=0;
\r
80 ZC_animatePlayer(pip, player, pn, 0);
\r
81 player[pn].enti.d = 2;
\r
83 player[pn].enti.triggerx = player[pn].enti.tx+1;
\r
84 player[pn].enti.triggery = player[pn].enti.ty;
\r
88 if(pip[0].tx > 0 && pip[0].tx+pip[0].page->ti.tw <= pip[0].map->width && player[pn].enti.tx == pip[0].tx+pip[0].page->ti.tilemidposscreenx &&
\r
89 !(pip[0].map->data[(player[pn].enti.tx-2)+(pip[0].map->width*(player[pn].enti.ty-1))] == 0))//!(player[pn].enti.tx-1 == TRIGGX && player[pn].enti.ty == TRIGGY)) //collision detection!
\r
91 player[pn].walktype=2;
\r
92 if(player[pn].enti.q<=player[pn].enti.spt)
\r
94 ZC_animatePlayer(pip, player, pn, 2);
\r
96 player[pn].enti.q++;
\r
97 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
\r
98 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.tx--; }
\r
100 else if(player[pn].enti.tx > 1 && !(pip[0].map->data[(player[pn].enti.tx-2)+(pip[0].map->width*(player[pn].enti.ty-1))] == 0))//!(player[pn].enti.tx-1 == TRIGGX && player[pn].enti.ty == TRIGGY))
\r
102 player[pn].walktype=1;
\r
103 if(player[pn].enti.q<=player[pn].enti.spt)
\r
105 player[pn].enti.x-=(player[pn].enti.speed);
\r
106 ZC_animatePlayer(pip, player, pn, 1);
\r
107 player[pn].enti.q++;
\r
108 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.tx--; }
\r
112 player[pn].walktype=0;
\r
113 ZC_animatePlayer(pip, player, pn, 0);
\r
114 player[pn].enti.d = 2;
\r
116 player[pn].enti.triggerx = player[pn].enti.tx-1;
\r
117 player[pn].enti.triggery = player[pn].enti.ty;
\r
121 if(pip[0].ty >= 0 && pip[0].ty+pip[0].page->ti.th < pip[0].map->height && player[pn].enti.ty == pip[0].ty+pip[0].page->ti.tilemidposscreeny &&
\r
122 !(pip[0].map->data[(player[pn].enti.tx-1)+(pip[0].map->width*(player[pn].enti.ty))] == 0))//!(player[pn].enti.tx == TRIGGX && player[pn].enti.ty+1 == TRIGGY)) //collision detection!
\r
124 player[pn].walktype=2;
\r
125 if(player[pn].enti.q<=player[pn].enti.spt)
\r
127 ZC_animatePlayer(pip, player, pn, 2);
\r
129 player[pn].enti.q++;
\r
130 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
\r
131 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.ty++; }
\r
133 else if(player[pn].enti.ty < pip[0].map->height && !(pip[0].map->data[(player[pn].enti.tx-1)+(pip[0].map->width*(player[pn].enti.ty))] == 0))//!(player[pn].enti.tx == TRIGGX && player[pn].enti.ty+1 == TRIGGY))
\r
135 player[pn].walktype=1;
\r
136 if(player[pn].enti.q<=player[pn].enti.spt)
\r
138 player[pn].enti.y+=(player[pn].enti.speed);
\r
139 ZC_animatePlayer(pip, player, pn, 1);
\r
140 player[pn].enti.q++;
\r
141 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.ty++; }
\r
145 player[pn].walktype=0;
\r
146 ZC_animatePlayer(pip, player, pn, 0);
\r
147 player[pn].enti.d = 2;
\r
149 player[pn].enti.triggerx = player[pn].enti.tx;
\r
150 player[pn].enti.triggery = player[pn].enti.ty+1;
\r
154 if(pip[0].ty > 0 && pip[0].ty+pip[0].page->ti.th <= pip[0].map->height && player[pn].enti.ty == pip[0].ty+pip[0].page->ti.tilemidposscreeny &&
\r
155 !(pip[0].map->data[(player[pn].enti.tx-1)+(pip[0].map->width*(player[pn].enti.ty-2))] == 0))//!(player[pn].enti.tx == TRIGGX && player[pn].enti.ty-1 == TRIGGY)) //collision detection!
\r
157 player[pn].walktype=2;
\r
158 if(player[pn].enti.q<=player[pn].enti.spt)
\r
160 ZC_animatePlayer(pip, player, pn, 2);
\r
162 player[pn].enti.q++;
\r
163 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
\r
164 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.ty--; }
\r
166 else if(player[pn].enti.ty > 1 && !(pip[0].map->data[(player[pn].enti.tx-1)+(pip[0].map->width*(player[pn].enti.ty-2))] == 0))//!(player[pn].enti.tx == TRIGGX && player[pn].enti.ty-1 == TRIGGY))
\r
168 player[pn].walktype=1;
\r
169 if(player[pn].enti.q<=player[pn].enti.spt)
\r
171 player[pn].enti.y-=(player[pn].enti.speed);
\r
172 ZC_animatePlayer(pip, player, pn, 1);
\r
173 player[pn].enti.q++;
\r
174 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.ty--; }
\r
178 player[pn].walktype=0;
\r
179 ZC_animatePlayer(pip, player, pn, 0);
\r
180 player[pn].enti.d = 2;
\r
182 player[pn].enti.triggerx = player[pn].enti.tx;
\r
183 player[pn].enti.triggery = player[pn].enti.ty-1;
\r
190 void ZC_panPageManual(map_view_t *pip, player_t *player, word pn)
\r
192 #define SHOWMVFUN_ ZC_ShowMV(pip, 0, 0);
\r
193 switch(player[pn].enti.d)
\r
197 if(pip[0].tx >= 0 && pip[0].tx+pip[0].page->ti.tw < pip[0].page->ti.tilesw)
\r
199 if(player[pn].enti.q<=player[pn].enti.spt)
\r
201 pip[0].page->dx+=4;
\r
203 player[pn].enti.q++;
\r
204 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; pip[0].tx++; }
\r
210 if(pip[0].tx > 0 && pip[0].tx+pip[0].page->ti.tw <= pip[0].page->ti.tilesw)
\r
212 if(player[pn].enti.q<=player[pn].enti.spt)
\r
214 pip[0].page->dx-=4;
\r
216 player[pn].enti.q++;
\r
217 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; pip[0].tx--; }
\r
223 if(pip[0].ty >= 0 && pip[0].ty+pip[0].page->ti.th < pip[0].page->ti.tilesh)
\r
225 if(player[pn].enti.q<=player[pn].enti.spt)
\r
227 pip[0].page->dy+=4;
\r
229 player[pn].enti.q++;
\r
230 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; pip[0].ty++; }
\r
236 if(pip[0].ty > 0 && pip[0].ty+pip[0].page->ti.th <= pip[0].page->ti.tilesh)
\r
238 if(player[pn].enti.q<=player[pn].enti.spt)
\r
240 pip[0].page->dy-=4;
\r
242 player[pn].enti.q++;
\r
243 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; pip[0].ty--; }
\r
252 void ZC_MVSetup(map_view_t *pip, map_t *map, global_game_variables_t *gv)
\r
257 pip[0].page = &gv->video.page[0];
\r
259 pip[0].video = &gv->video;
\r
260 pip[0].p = &gv->video.p;
\r
261 pip[0].sp = &gv->video.sp;
\r
262 ZC_MVInit(pip, 1, 1);
\r
264 for(i=ZC_MVI;i<gv->video.num_of_pages;i++)
\r
266 pip[i].page = &gv->video.page[i];
\r
267 pip[i].map = pip[0].map;
\r
268 pip[i].video = pip[0].video;
\r
269 pip[i].p = pip[0].p;
\r
270 pip[i].sp = pip[0].sp;
\r
278 void ZC_MVInit(map_view_t *pip, int tx, int ty)
\r
282 //pip[0].tx = pip[1].tx = tx;
\r
283 //pip[0].ty = pip[1].ty = ty;
\r
286 void ZC_ShowMV(map_view_t *moo, boolean vsync, boolean sr)
\r
288 //VL_ShowPage(moo[moo[0].video->sp].page, vsync, sr);
\r
289 word high_address, low_address, offset;
\r
292 // calculate offset
\r
293 offset = (word) moo[moo[0].video->sp].page->data;
\r
294 offset += moo[0].page->dy * (moo[0].page->width >> 2 );
\r
295 offset += moo[0].page->dx >> 2;
\r
297 // calculate crtcOffset according to virtual width
\r
301 crtcOffset = moo[moo[0].video->sp].page->sw >> 3;
\r
305 crtcOffset = moo[0].page->width >> 3;
\r
309 high_address = HIGH_ADDRESS | (offset & 0xff00);
\r
310 low_address = LOW_ADDRESS | (offset << 8);
\r
312 // wait for appropriate timing and then program CRTC
\r
313 if(vsync) while ((inp(INPUT_STATUS_1) & DISPLAY_ENABLE));
\r
314 outpw(CRTC_INDEX, high_address);
\r
315 outpw(CRTC_INDEX, low_address);
\r
316 outp(CRTC_INDEX, 0x13);
\r
317 outp(CRTC_DATA, crtcOffset);
\r
319 // wait for one retrace
\r
320 if(vsync) while (!(inp(INPUT_STATUS_1) & VRETRACE));
\r
322 // do PEL panning here
\r
323 outp(AC_INDEX, 0x33);
\r
324 outp(AC_INDEX, (moo[0].page->dx & 0x03) << 1);
\r
328 initMap(map_t *map) {
\r
329 // just a place holder to fill out an alternating pattern
\r
335 for(y=0; y<map->height; y++) {
\r
336 for(x=0; x<map->width; x++) {
\r
338 // printf("[%d]", map->data[i]);
\r
339 tile = tile ? 0 : 1;
\r
342 tile = tile ? 0 : 1;
\r
346 //===========================================================================//
\r
349 void near mapScrollRight(map_view_t *mv, player_t *player, word id, word plid)
\r
351 word x;//, y; /* coordinate for drawing */
\r
353 ScrollRight(mv, player, id, plid);
\r
355 /* draw the next column */
\r
356 x= mv[0].page->sw + mv[0].map->tiles->tileWidth;
\r
358 if(player[plid].enti.q%4)
\r
360 if(player[plid].enti.q==4)
\r
363 mapDrawCol(&mv[id], mv[0].tx + mv[0].page->ti.tw, mv[0].ty-1, x, player, DRAWCOLNUM);
\r
365 // if(mv[0].video->bgps)
\r
366 // modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[0].map->tiles->tileWidth, mv[0].page->height);
\r
371 void near mapScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
\r
373 word x;//,y; /* coordinate for drawing */
\r
375 ScrollLeft(mv, player, id, plid);
\r
377 /* draw the next column */
\r
380 if(player[plid].enti.q%4)
\r
382 if(player[plid].enti.q==4)
\r
385 mapDrawCol(&mv[id], mv[0].tx - 1, mv[0].ty-1, x, player, DRAWCOLNUM);
\r
387 // if(mv[0].video->bgps)
\r
388 // modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[0].map->tiles->tileWidth, mv[0].page->height);
\r
393 void near mapScrollUp(map_view_t *mv, player_t *player, word id, word plid)
\r
395 word y;//x, /* coordinate for drawing */
\r
397 ScrollUp(mv, player, id, plid);
\r
399 /* draw the next row */
\r
402 if(player[plid].enti.q%3)
\r
404 if(player[plid].enti.q==4)
\r
407 mapDrawRow(&mv[id], mv[0].tx - 1, mv[0].ty-1, y, player, DRAWROWNUM);
\r
409 // if(mv[0].video->bgps)
\r
410 // modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[0].page->width, mv[0].map->tiles->tileHeight);
\r
415 void near mapScrollDown(map_view_t *mv, player_t *player, word id, word plid)
\r
417 word y;//x, /* coordinate for drawing */
\r
419 ScrollDown(mv, player, id, plid);
\r
421 /* draw the next row */
\r
422 y= mv[0].page->sh + mv[0].map->tiles->tileHeight;
\r
424 if(player[plid].enti.q%3)
\r
426 if(player[plid].enti.q==4)
\r
429 mapDrawRow(&mv[id], mv[0].tx - 1, mv[0].ty+mv[0].page->ti.th, y, player, DRAWROWNUM);
\r
431 // if(mv[0].video->bgps)
\r
432 // modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[0].page->width, mv[0].map->tiles->tileHeight);
\r
436 void ZC_mapScroll(map_view_t *mv, player_t *player, word pn)
\r
438 word b = mv[0].video->bgps;
\r
439 switch(player[pn].enti.d)
\r
444 ScrollRight(mv, player, 3, pn);
\r
445 ScrollRight(mv, player, 2, pn);
\r
446 mapScrollRight(mv, player, (0), pn);
\r
447 if(b) mapScrollRight(mv, player, (1), pn);
\r
450 ScrollLeft(mv, player, 3, pn);
\r
451 ScrollLeft(mv, player, 2, pn);
\r
452 mapScrollLeft(mv, player, (0), pn);
\r
453 if(b) mapScrollLeft(mv, player, (1), pn);
\r
456 ScrollDown(mv, player, 3, pn);
\r
457 ScrollDown(mv, player, 2, pn);
\r
458 mapScrollDown(mv, player, (0), pn);
\r
459 if(b) mapScrollDown(mv, player, (1), pn);
\r
462 ScrollUp(mv, player, 3, pn);
\r
463 ScrollUp(mv, player, 2, pn);
\r
464 mapScrollUp(mv, player, (0), pn);
\r
465 if(b) mapScrollUp(mv, player, (1), pn);
\r
468 printf("player[pn].enti.d=%u\n", player[pn].enti.d);
\r
472 //===========================================================================
\r
473 //TODO: put player in starting position of assigned spot on map
\r
474 //default player position on the viewable map
\r
475 void ZC_playerXYpos(int x, int y, player_t *player, map_view_t *pip, nibble pn)
\r
477 player[pn].enti.tx = x + pip[0].tx + pip[0].page->ti.tilemidposscreenx;
\r
478 player[pn].enti.ty = y + pip[0].ty + pip[0].page->ti.tilemidposscreeny;
\r
480 //===========================================================================
\r
482 sword chkmap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1, 1, 1, 1, \
\r
494 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, \
\r
495 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
\r
496 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
\r
497 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, \
\r
498 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
\r
499 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, \
\r
500 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
\r
501 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 1, 2, 3, 4 };*/
\r
502 //check for failed to load map
\r
503 if((map->width == map->height == 0) && (q>0))
\r
505 //initiate a null map!
\r
506 map->width=MAPW;///2;
\r
507 map->height=MAPH;///2;
\r
508 // map->data = malloc(((map->width*map->height)+1)*sizeof(byte));
\r
510 map->tiles = malloc(sizeof(tiles_t));
\r
511 //fix this to be far~
\r
512 // bp = bitmapLoadPcx("data/ed.pcx");
\r
513 // map->tiles->data = &bp;
\r
514 #ifdef __DEBUG_MAP__
\r
515 dbg_mapdata = map->data;
\r
517 map->tiles->tileHeight = 16;
\r
518 map->tiles->tileWidth = 16;
\r
519 map->tiles->rows = 1;
\r
520 map->tiles->cols = 1;
\r
521 #ifdef __DEBUG_MAP__
\r
522 dbg_maptext = true;
\r
525 #ifdef __DEBUG_MAP__
\r
526 else dbg_maptext = false;
\r
531 //TODO: player position here
\r
532 void mapGoTo(map_view_t *mv, int tx, int ty)
\r
537 ZC_mapinitMV(mv, tx, ty);
\r
539 /* draw the tiles */
\r
540 modexClearRegion(mv[0].page, 0, 0, mv[0].page->width, mv[0].page->height, 0);
\r
542 i=mv[0].ty * mv[0].map->width + mv[0].tx;
\r
543 for(ty=mv[0].ty-1; py < mv[0].page->sh+mv->dyThresh && ty < mv[0].map->height; ty++, py+=mv[0].map->tiles->tileHeight) {
\r
544 mapDrawWRow(&mv[0], tx-1, ty, py);
\r
545 i+=mv->map->width - tx;
\r
548 i=mv[1].ty * mv[1].map->width + mv[1].tx;
\r
549 for(ty=mv[1].ty-1; py < mv[1].page->sh+mv->dyThresh && ty < mv[1].map->height; ty++, py+=mv[1].map->tiles->tileHeight) {
\r
550 mapDrawWRow(&mv[1], tx-1, ty, py);
\r
551 i+=mv->map->width - tx;
\r
553 //if(mv[0].video->bgps) modexCopyPageRegion(mv[1].page, mv[0].page, 0, 0, 0, 0, mv[0].page->width, mv[0].page->height);
\r
556 void ZC_mapinitMV(map_view_t *mv, int tx, int ty)
\r
558 /* set up the coordinates */
\r
559 mv[0].tx = mv[1].tx = tx;
\r
560 mv[0].ty = mv[1].ty = ty;
\r
561 mv[0].page->dx = mv[1].page->dx = mv[2].page->dx = mv[3].page->dx = mv->map->tiles->tileWidth;
\r
562 mv[0].page->dy = mv[1].page->dy = mv[2].page->dy = mv[3].page->dy = mv->map->tiles->tileHeight;
\r
564 /* set up the thresholds */
\r
565 mv[0].dxThresh = mv[1].dxThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileWidth * 2;
\r
566 mv[0].dyThresh = mv[1].dyThresh = mv[2].dyThresh = mv[3].dyThresh = mv->map->tiles->tileHeight * 2;
\r
570 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)
\r
574 //word textx=0, texty=0;
\r
579 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 1); //currently the over scan color!
\r
583 rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);
\r
584 ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);
\r
585 ////0000printf("i=%d\n", i);
\r
586 #ifdef __DEBUG_MAP__
\r
587 switch(dbg_maptext)
\r
592 if(!pagenorendermap) modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, ((dbg_mapdata[i])+1));
\r
593 //modexprint(page, x, y, 1, 15, 0, (char const *)(t->debug_data[i]));
\r
595 modexDrawBmpRegion (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
\r
596 /* then the sprite. note modding ram ptr means we just draw to (x&3,0) */
\r
597 //draw_vrl1_vgax_modex(x-rx,y-ry,vrl_header,vrl_lineoffs,buffer+sizeof(*vrl_header),bufsz-sizeof(*vrl_header));
\r
598 //modexDrawBmpRegion (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
\r
600 #ifdef __DEBUG_MAP__
\r
603 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, (dbg_mapdata[i])+1);
\r
604 //modexprintbig(page, x, y, 1, 15, 0, (t->debug_data));
\r
605 /*for(texty=0; texty<2; texty++)
\r
607 for(textx=0; textx<2; textx++)
\r
609 // modexprint(page, x+(textx*8), y+(texty*8), 1, (word)(t->debug_data), 0, (t->debug_data));
\r
618 void near mapDrawRow(map_view_t *mv, int tx, int ty, word y, player_t *player, word poopoffset)
\r
621 if(pagedelayrendermap) if(!y) y+=TILEWH; else y-=TILEWH;
\r
622 poopoffset%=player[0].enti.speed;
\r
623 //printf("y: %d\n", poopoffset);
\r
624 if(pagedelayrendermap){ sprintf(global_temp_status_text, "%-3u", mv->dx); modexprint(mv[0].page, player[0].enti.x, player[0].enti.y-28-(poopoffset*8) , 1, 2, 1, global_temp_status_text); }
\r
625 /* the position within the map array */
\r
626 i=ty * mv->map->width + tx;
\r
627 for( mv->dx=poopoffset; mv->dx<(mv->page->sw+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width; mv->dx+=mv->map->tiles->tileWidth, tx++) {
\r
628 if(i>=0) /* we are in the map, so copy away! */
\r
629 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, mv->dx, y);
\r
632 //if(pagedelayrendermap) delay(200);
\r
635 void near mapDrawCol(map_view_t *mv, int tx, int ty, word x, player_t *player, word poopoffset)
\r
638 if(pagedelayrendermap) if(!x) x+=TILEWH; else x-=TILEWH;
\r
639 poopoffset%=player[0].enti.speed;
\r
640 //printf("x: %d\n", poopoffset);
\r
641 if(pagedelayrendermap){ sprintf(global_temp_status_text, "%-3u", mv->dy); modexprint(mv[0].page, player[0].enti.x, player[0].enti.y-28-(poopoffset*8) , 1, 2, 1, global_temp_status_text); }
\r
642 /* location in the map array */
\r
643 i=ty * mv->map->width + tx;
\r
644 /* We'll copy all of the columns in the screen,
\r
645 i + 1 row above and one below */
\r
646 for( mv->dy=poopoffset; mv->dy<(mv->page->sh+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height; mv->dy+=mv->map->tiles->tileHeight, ty++) {
\r
647 if(i>=0) /* we are in the map, so copy away! */
\r
648 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, mv->dy);
\r
649 i += mv->map->width;
\r
651 //if(pagedelayrendermap) delay(200);
\r
654 void mapDrawWRow(map_view_t *mv, int tx, int ty, word y)
\r
658 /* the position within the map array */
\r
659 i=ty * mv->map->width + tx;
\r
660 for(mv->dx=0; mv->dx<mv->page->sw+mv->dxThresh && tx < mv->map->width; mv->dx+=mv->map->tiles->tileWidth, tx++) {
\r
661 if(i>=0) /* we are in the map, so copy! */
\r
662 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, mv->dx, y);
\r
667 void mapDrawWCol(map_view_t *mv, int tx, int ty, word x)
\r
671 /* location in the map array */
\r
672 i=ty * mv->map->width + tx;
\r
674 /* We'll copy all of the columns in the screen,
\r
675 i + 1 row above and one below */
\r
676 for(mv->dy=0; mv->dy<mv->page->sh+mv->dyThresh && ty < mv->map->height; mv->dy+=mv->map->tiles->tileHeight, ty++) {
\r
677 if(i>=0) /* we are in the map, so copy away! */
\r
678 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, mv->dy);
\r
679 i += mv->map->width;
\r
688 boolean pagenorendermap = 0;
\r
689 boolean pagedelayrendermap = 0;
\r
692 void shinku(global_game_variables_t *gv)
\r
694 word x = (0) + gv->video.page[/*!*/(gv->video.p)].dx; // follow the screen
\r
695 word y = (0) + gv->video.page[/*!*/(gv->video.p)].dy; // follow the screen
\r
696 word col = 2, bgcol = 1, type = 1;//w = 64, h = 8,
\r
697 if(elapsed_timer(gv) >= (1.0 / gv->kurokku.frames_per_second))
\r
699 // NTS: For some bizarre reason, gv->pee is not initialized, but the pointer is not NULL even
\r
700 // though it should be. Instead it's NULL as a neAr pointer but contains a non-null
\r
701 // segment value, so testing against NULL doesn't work. It is initialized properly if
\r
702 // you call start_timer() though which uses neAr malloc. Rather than fight with that,
\r
703 // I decided it would be better to declare a temp buffer statically and sprintf to that.
\r
705 // This fixes *** Null pointer assignment detected error message in ZCROLL.EXE on exit.
\r
706 sprintf(global_temp_status_text, "%.0f fps", (double)gv->kurokku.tiku/ticktock(gv));
\r
707 modexprint(&(gv->video.page[/*!*/(gv->video.p)]), x, y, type, col, bgcol, global_temp_status_text);
\r
708 gv->kurokku.tiku=0;
\r
709 }else //copy dat sheet
\r
710 gv->kurokku.tiku++;
\r
712 switch(gv->kurokku.fpscap)
\r
715 modexprint(&(gv->video.page[0]), x, y+8, type, col, bgcol, "sanic!");
\r
716 gv->kurokku.frames_per_second=1;
\r
719 //turn this off if XT
\r
720 modexWaitBorder_start();
\r
721 //vga_wait_for_vsync();
\r
722 gv->kurokku.frames_per_second=60;
\r
730 modexCopyPageRegion(&(gv->video.page[ ]), &(gv->video.page[ ]), 0, 0, 0, 0, gv->video.page[ ].width, gv->video.page[ ].height);
\r
732 //modexCopyPageRegion(&video->page[0], &video->page[1], enti->x, enti->y, 0, 0, 24, 32);
\r
734 VL_ShowPage(&(gv->video.page[gv->video.sp]), gv->kurokku.fpscap, 0);
\r
735 gv->video.r =!gv->video.r ;
\r
736 //0000gv->video.tickclk = ((*clockw)-gv->video.startclk)/18.2;
\r
741 void near ZC_animatePlayer(map_view_t *pip, player_t *player, word pn, sword scrollswitch)
\r
743 sword x = player[pn].enti.x;
\r
744 sword y = player[pn].enti.y;
\r
745 sword qq,dd; //scroll offset
\r
746 player[pn].enti.dire=10; //direction
\r
748 switch(scrollswitch)
\r
760 qq = ((player[pn].enti.q)*(player[pn].enti.speed));
\r
764 y-=pip[0].map->tiles->tileHeight;
\r
765 switch (player[pn].enti.d)
\r
769 player[pn].enti.dire*=player[pn].enti.d+1;
\r
774 player[pn].enti.dire*=(player[pn].enti.d-1);
\r
781 player[pn].enti.dire*=(player[pn].enti.d-1);
\r
786 player[pn].enti.dire*=(player[pn].enti.d+3);
\r
790 player[pn].enti.dire+=dd;
\r
791 if((player[pn].enti.q==1 && player[pn].enti.pred != player[pn].enti.d) || !dd)
\r
793 set_anim_by_id(player[pn].enti.spri, player[pn].enti.dire); //pip->video->sprifilei = set_anim_by_id(player[pn].enti.spri, player[pn].enti.dire); if(pip->video->sprifilei == -1){ printf("ERROR! %u\n", player[pn].enti.dire); return; }
\r
794 player[pn].enti.pred = player[pn].enti.d;
\r
797 //setting xy position
\r
798 player[pn].enti.spri->x = x;
\r
799 player[pn].enti.spri->y = y;
\r
801 if(pip[0].video->bgps)
\r
802 modexCopyPageRegion(pip[0].page, pip[1].page, x-4, y-4, x-4, y-4, 28, 40);
\r
804 animate_spri(&player[pn].enti, pip->video);
\r
805 //0000if(player[pn].enti.q<2) delay(200);
\r
813 boolean boundary_check(int x, int y, int dx, int dy, int h, int w)
\r
815 return (dx > 0 && (x + dx) < w) || (dx < 0 && (x + dx) >= 0) || (dy > 0 && (y + dy) < h) || (dy < 0 && (y + dy) >= 0) || (dx == dy && dx == 0);
\r
818 boolean coll_check(int x, int y, int dx, int dy, map_view_t *map_v)
\r
820 // Assume everything crosses at most 1 tile at once
\r
821 return dx && 1;//crossable_tile(x + dx, map_v) || dy && crossable_tile(y + dy, map_v);
\r
824 boolean ZC_walk2(entity_t *enti, map_view_t *map_v)
\r
844 if(coll_check(enti->x, enti->y, dx, dy, map_v))
\r
849 // Mark next tile as occupied
\r
850 // Mark this tile as vacant
\r
856 void player_walk(player_t *player, map_view_t *map_v){
\r
858 if(ZC_walk2(&(player->enti), map_v) && boundary_check(map_v->tx, map_v->ty, dx, dy, map_v->map->width - 2*map_v->page->ti.tilesw, map_v->map->height - 2*map_v->page->ti.tilesh))
\r
860 mapScroll(map_v, player);
\r
865 void mapScroll(map_view_t *mv, player_t *player)
\r
867 //word x, y; /* coordinate for drawing */
\r
870 mv->delta += player->dx | player->dy;
\r
872 mv->d = (player->dx) ? (player->dx > 0) ? 3 : 1 : (player->dy) ? (player->dy > 0) ? 4 : 0 : 2;
\r
878 if(!(delta + mv->dxThresh))
\r
888 if(!(delta + mv->dyThresh))
\r