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
29 void ZC_walk(map_view_t *pip, player_t *player, word pn)
\r
31 switch(player[pn].enti.d)
\r
35 //0000pip[0].video->startclk = (*clockw);
\r
39 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
40 !(pip[0].map->MAPDATAPTR[(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
42 player[pn].walktype=2;
\r
43 if(player[pn].enti.q<=player[pn].enti.spt)
\r
45 ZC_animatePlayer(pip, player, pn);
\r
46 ZC_mapScroll(pip, player, pn);
\r
47 player[pn].enti.q++;
\r
48 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
\r
49 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.tx++; }
\r
51 else if(player[pn].enti.tx < pip[0].map->width && !(pip[0].map->MAPDATAPTR[(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
53 player[pn].walktype=1;
\r
54 if(player[pn].enti.q<=player[pn].enti.spt)
\r
56 player[pn].enti.x+=(player[pn].enti.speed);
\r
57 ZC_animatePlayer(pip, player, pn);
\r
58 player[pn].enti.q++;
\r
59 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.tx++; }
\r
63 player[pn].walktype=0;
\r
64 ZC_animatePlayer(pip, player, pn);
\r
65 player[pn].enti.d = 2;
\r
67 player[pn].enti.triggerx = player[pn].enti.tx+1;
\r
68 player[pn].enti.triggery = player[pn].enti.ty;
\r
72 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
73 !(pip[0].map->MAPDATAPTR[(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
75 player[pn].walktype=2;
\r
76 if(player[pn].enti.q<=player[pn].enti.spt)
\r
78 ZC_animatePlayer(pip, player, pn);
\r
79 ZC_mapScroll(pip, player, pn);
\r
80 player[pn].enti.q++;
\r
81 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
\r
82 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.tx--; }
\r
84 else if(player[pn].enti.tx > 1 && !(pip[0].map->MAPDATAPTR[(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
86 player[pn].walktype=1;
\r
87 if(player[pn].enti.q<=player[pn].enti.spt)
\r
89 player[pn].enti.x-=(player[pn].enti.speed);
\r
90 ZC_animatePlayer(pip, player, pn);
\r
91 player[pn].enti.q++;
\r
92 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.tx--; }
\r
96 player[pn].walktype=0;
\r
97 ZC_animatePlayer(pip, player, pn);
\r
98 player[pn].enti.d = 2;
\r
100 player[pn].enti.triggerx = player[pn].enti.tx-1;
\r
101 player[pn].enti.triggery = player[pn].enti.ty;
\r
105 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
106 !(pip[0].map->MAPDATAPTR[(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
108 player[pn].walktype=2;
\r
109 if(player[pn].enti.q<=player[pn].enti.spt)
\r
111 ZC_animatePlayer(pip, player, pn);
\r
112 ZC_mapScroll(pip, player, pn);
\r
113 player[pn].enti.q++;
\r
114 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
\r
115 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.ty++; }
\r
117 else if(player[pn].enti.ty < pip[0].map->height && !(pip[0].map->MAPDATAPTR[(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
119 player[pn].walktype=1;
\r
120 if(player[pn].enti.q<=player[pn].enti.spt)
\r
122 player[pn].enti.y+=(player[pn].enti.speed);
\r
123 ZC_animatePlayer(pip, player, pn);
\r
124 player[pn].enti.q++;
\r
125 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.ty++; }
\r
129 player[pn].walktype=0;
\r
130 ZC_animatePlayer(pip, player, pn);
\r
131 player[pn].enti.d = 2;
\r
133 player[pn].enti.triggerx = player[pn].enti.tx;
\r
134 player[pn].enti.triggery = player[pn].enti.ty+1;
\r
138 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
139 !(pip[0].map->MAPDATAPTR[(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
141 player[pn].walktype=2;
\r
142 if(player[pn].enti.q<=player[pn].enti.spt)
\r
144 ZC_animatePlayer(pip, player, pn);
\r
145 ZC_mapScroll(pip, player, pn);
\r
146 player[pn].enti.q++;
\r
147 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
\r
148 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.ty--; }
\r
150 else if(player[pn].enti.ty > 1 && !(pip[0].map->MAPDATAPTR[(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
152 player[pn].walktype=1;
\r
153 if(player[pn].enti.q<=player[pn].enti.spt)
\r
155 player[pn].enti.y-=(player[pn].enti.speed);
\r
156 ZC_animatePlayer(pip, player, pn);
\r
157 player[pn].enti.q++;
\r
158 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.ty--; }
\r
162 player[pn].walktype=0;
\r
163 ZC_animatePlayer(pip, player, pn);
\r
164 player[pn].enti.d = 2;
\r
166 player[pn].enti.triggerx = player[pn].enti.tx;
\r
167 player[pn].enti.triggery = player[pn].enti.ty-1;
\r
174 void ZC_panPageManual(map_view_t *pip, player_t *player, word pn)
\r
176 #define SHOWMVFUN_ ZC_ShowMV(pip, 0, 0);
\r
177 switch(player[pn].enti.d)
\r
181 if(pip[0].tx >= 0 && pip[0].tx+pip[0].page->ti.tw < pip[0].page->ti.tilesw)
\r
183 if(player[pn].enti.q<=player[pn].enti.spt)
\r
185 pip[0].page->dx+=4;
\r
187 player[pn].enti.q++;
\r
188 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; pip[0].tx++; }
\r
194 if(pip[0].tx > 0 && pip[0].tx+pip[0].page->ti.tw <= pip[0].page->ti.tilesw)
\r
196 if(player[pn].enti.q<=player[pn].enti.spt)
\r
198 pip[0].page->dx-=4;
\r
200 player[pn].enti.q++;
\r
201 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; pip[0].tx--; }
\r
207 if(pip[0].ty >= 0 && pip[0].ty+pip[0].page->ti.th < pip[0].page->ti.tilesh)
\r
209 if(player[pn].enti.q<=player[pn].enti.spt)
\r
211 pip[0].page->dy+=4;
\r
213 player[pn].enti.q++;
\r
214 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; pip[0].ty++; }
\r
220 if(pip[0].ty > 0 && pip[0].ty+pip[0].page->ti.th <= pip[0].page->ti.tilesh)
\r
222 if(player[pn].enti.q<=player[pn].enti.spt)
\r
224 pip[0].page->dy-=4;
\r
226 player[pn].enti.q++;
\r
227 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; pip[0].ty--; }
\r
236 void ZC_MVSetup(map_view_t *pip, map_t *map, global_game_variables_t *gv)
\r
241 pip[0].page = &gv->video.page[0];
\r
243 pip[0].video = &gv->video;
\r
244 pip[0].p = &gv->video.p;
\r
245 pip[0].sp = &gv->video.sp;
\r
246 ZC_MVInit(pip, 1, 1);
\r
248 for(i=ZC_MVI;i<gv->video.num_of_pages;i++)
\r
250 pip[i].page = &gv->video.page[i];
\r
251 pip[i].map = pip[0].map;
\r
252 pip[i].video = pip[0].video;
\r
253 pip[i].p = pip[0].p;
\r
254 pip[i].sp = pip[0].sp;
\r
262 void ZC_MVInit(map_view_t *pip, int tx, int ty)
\r
266 //pip[0].tx = pip[1].tx = tx;
\r
267 //pip[0].ty = pip[1].ty = ty;
\r
270 void ZC_ShowMV(map_view_t *moo, boolean vsync, boolean sr)
\r
272 word high_address, low_address, offset;
\r
275 // calculate offset
\r
276 offset = (word) moo[moo[0].video->sp].page->data;
\r
277 offset += moo[0].page->dy * (moo[0].page->width >> 2 );
\r
278 offset += moo[0].page->dx >> 2;
\r
280 // calculate crtcOffset according to virtual width
\r
284 crtcOffset = moo[moo[0].video->sp].page->sw >> 3;
\r
288 crtcOffset = moo[0].page->width >> 3;
\r
292 high_address = HIGH_ADDRESS | (offset & 0xff00);
\r
293 low_address = LOW_ADDRESS | (offset << 8);
\r
295 // wait for appropriate timing and then program CRTC
\r
296 if(vsync) while ((inp(INPUT_STATUS_1) & DISPLAY_ENABLE));
\r
297 outpw(CRTC_INDEX, high_address);
\r
298 outpw(CRTC_INDEX, low_address);
\r
299 outp(CRTC_INDEX, 0x13);
\r
300 outp(CRTC_DATA, crtcOffset);
\r
302 // wait for one retrace
\r
303 if(vsync) while (!(inp(INPUT_STATUS_1) & VRETRACE));
\r
305 // do PEL panning here
\r
306 outp(AC_INDEX, 0x33);
\r
307 outp(AC_INDEX, (moo[0].page->dx & 0x03) << 1);
\r
308 vga_state.vga_draw_stride_limit = vga_state.vga_draw_stride = moo[0].page->stridew;
\r
312 initMap(map_t *map) {
\r
313 // just a place holder to fill out an alternating pattern
\r
319 for(y=0; y<map->height; y++) {
\r
320 for(x=0; x<map->width; x++) {
\r
321 map->MAPDATAPTR[i]=255;
\r
322 // printf("[%d]", map->MAPDATAPTR[i]);
\r
323 tile = tile ? 0 : 1;
\r
326 tile = tile ? 0 : 1;
\r
330 //===========================================================================//
\r
333 void near mapScrollRight(map_view_t *mv, player_t *player, word id, word plid)
\r
335 word x;//, y; /* coordinate for drawing */
\r
337 ScrollRight(mv, player, id, plid);
\r
339 /* draw the next column */
\r
340 x= mv[0].page->sw + mv[0].map->MAPTILESPTR->tileWidth;
\r
342 if(player[plid].enti.q%4)
\r
344 if(player[plid].enti.q==4)
\r
347 mapDrawCol(&mv[id], mv[0].tx + mv[0].page->ti.tw, mv[0].ty-1, x, player, DRAWCOLNUM);
\r
349 // if(mv[0].video->bgps)
\r
350 // modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[0].map->MAPTILESPTR->tileWidth, mv[0].page->height);
\r
351 //mv[0].video->dorender=1;//ScrollRight
\r
355 void near mapScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
\r
357 word x;//,y; /* coordinate for drawing */
\r
359 ScrollLeft(mv, player, id, plid);
\r
361 /* draw the next column */
\r
364 if(player[plid].enti.q%4)
\r
366 if(player[plid].enti.q==4)
\r
369 mapDrawCol(&mv[id], mv[0].tx - 1, mv[0].ty-1, x, player, DRAWCOLNUM);
\r
371 // if(mv[0].video->bgps)
\r
372 // modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[0].map->MAPTILESPTR->tileWidth, mv[0].page->height);
\r
373 //mv[0].video->dorender=1;//ScrollLeft
\r
377 void near mapScrollUp(map_view_t *mv, player_t *player, word id, word plid)
\r
379 word y;//x, /* coordinate for drawing */
\r
381 ScrollUp(mv, player, id, plid);
\r
383 /* draw the next row */
\r
386 if(player[plid].enti.q%3)
\r
388 if(player[plid].enti.q==4)
\r
391 mapDrawRow(&mv[id], mv[0].tx - 1, mv[0].ty-1, y, player, DRAWROWNUM);
\r
393 // if(mv[0].video->bgps)
\r
394 // modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[0].page->width, mv[0].map->MAPTILESPTR->tileHeight);
\r
395 //mv[0].video->dorender=1;//ScrollUp
\r
399 void near mapScrollDown(map_view_t *mv, player_t *player, word id, word plid)
\r
401 word y;//x, /* coordinate for drawing */
\r
403 ScrollDown(mv, player, id, plid);
\r
405 /* draw the next row */
\r
406 y= mv[0].page->sh + mv[0].map->MAPTILESPTR->tileHeight;
\r
408 if(player[plid].enti.q%3)
\r
410 if(player[plid].enti.q==4)
\r
413 mapDrawRow(&mv[id], mv[0].tx - 1, mv[0].ty+mv[0].page->ti.th, y, player, DRAWROWNUM);
\r
415 // if(mv[0].video->bgps)
\r
416 // modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[0].page->width, mv[0].map->MAPTILESPTR->tileHeight);
\r
417 //mv[0].video->dorender=1;//ScrollDown
\r
420 void ZC_mapScroll(map_view_t *mv, player_t *player, word pn)
\r
422 word b = mv[0].video->bgps;
\r
423 switch(player[pn].enti.d)
\r
428 ScrollRight(mv, player, 3, pn);
\r
429 ScrollRight(mv, player, 2, pn);
\r
430 mapScrollRight(mv, player, (0), pn);
\r
431 if(b) mapScrollRight(mv, player, (1), pn);
\r
434 ScrollLeft(mv, player, 3, pn);
\r
435 ScrollLeft(mv, player, 2, pn);
\r
436 mapScrollLeft(mv, player, (0), pn);
\r
437 if(b) mapScrollLeft(mv, player, (1), pn);
\r
440 ScrollDown(mv, player, 3, pn);
\r
441 ScrollDown(mv, player, 2, pn);
\r
442 mapScrollDown(mv, player, (0), pn);
\r
443 if(b) mapScrollDown(mv, player, (1), pn);
\r
446 ScrollUp(mv, player, 3, pn);
\r
447 ScrollUp(mv, player, 2, pn);
\r
448 mapScrollUp(mv, player, (0), pn);
\r
449 if(b) mapScrollUp(mv, player, (1), pn);
\r
452 //mv[0].video->dorender=1;//ZC_mapScroll
\r
455 //===========================================================================
\r
456 //TODO: put player in starting position of assigned spot on map
\r
457 //default player position on the viewable map
\r
458 void ZC_playerXYpos(int x, int y, player_t *player, map_view_t *pip, nibble pn, boolean defaultsw)
\r
460 player[pn].enti.tx = x + pip[0].tx;
\r
461 player[pn].enti.ty = y + pip[0].ty;
\r
466 player[pn].enti.tx += pip[0].page->ti.tilemidposscreenx;
\r
467 player[pn].enti.ty += pip[0].page->ti.tilemidposscreeny;
\r
473 //===========================================================================
\r
475 sword chkmap(map_t *map, word q)
\r
478 static byte x[(MAPW*MAPH)+1] =
\r
479 { 1, 2, 3, 4, 0, 3, 3, 3, 3, 3, 3, 3, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
\r
490 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, \
\r
491 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
\r
492 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, \
\r
493 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
\r
494 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 1, 2, 3, 4 };*/
\r
495 //check for failed to load map
\r
496 if((map->width == map->height == 0) && (q>0))
\r
498 //initiate a null map!
\r
499 map->width=MAPW;///2;
\r
500 map->height=MAPH;///2;
\r
501 // map->MAPDATAPTR = malloc(((map->width*map->height)+1)*sizeof(byte));
\r
502 map->MAPDATAPTR = &x;
\r
503 map->MAPTILESPTR = malloc(sizeof(tiles_t));
\r
504 //fix this to be far~
\r
505 // bp = bitmapLoadPcx("data/ed.pcx");
\r
506 // map->MAPTILESPTR->data = &bp;
\r
507 map->MAPTILESPTR->tileHeight = 16;
\r
508 map->MAPTILESPTR->tileWidth = 16;
\r
509 map->MAPTILESPTR->rows = 1;
\r
510 map->MAPTILESPTR->cols = 1;
\r
511 #ifdef __DEBUG_MAP__
\r
512 dbg_maptext = true;
\r
515 #ifdef __DEBUG_MAP__
\r
518 dbg_maptext = false;
\r
524 //TODO: player position here
\r
525 void mapGoTo(map_view_t *mv, int tx, int ty)
\r
527 ZC_mapinitMV(mv, tx, ty);
\r
529 /* draw the tiles */
\r
530 modexClearRegion(mv[0].page, 0, 0, mv[0].page->width, mv[0].page->height, 0);
\r
531 ZC_mapredraw(mv, tx, ty);
\r
533 //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
536 void ZC_mapinitMV(map_view_t *mv, int tx, int ty)
\r
538 /* set up the coordinates */
\r
539 mv[0].tx = mv[1].tx = tx;
\r
540 mv[0].ty = mv[1].ty = ty;
\r
541 mv[0].page->dx = mv[1].page->dx = mv[2].page->dx = mv[3].page->dx = mv->map->MAPTILESPTR->tileWidth;
\r
542 mv[0].page->dy = mv[1].page->dy = mv[2].page->dy = mv[3].page->dy = mv->map->MAPTILESPTR->tileHeight;
\r
544 /* set up the thresholds */
\r
545 mv[0].dxThresh = mv[1].dxThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->MAPTILESPTR->tileWidth * 2;
\r
546 mv[0].dyThresh = mv[1].dyThresh = mv[2].dyThresh = mv[3].dyThresh = mv->map->MAPTILESPTR->tileHeight * 2;
\r
549 void ZC_mapredraw(map_view_t *mv, int tx, int ty)
\r
555 i=mv[0].ty * mv[0].map->width + mv[0].tx;
\r
556 for(ty=mv[0].ty-1; py < mv[0].page->sh+mv->dyThresh && ty < mv[0].map->height; ty++, py+=mv[0].map->MAPTILESPTR->tileHeight) {
\r
557 mapDrawWRow(&mv[0], tx-1, ty, py);
\r
558 mapDrawWRow(&mv[1], tx-1, ty, py);
\r
559 i+=mv->map->width - tx;
\r
564 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)
\r
567 //word textx=0, texty=0;
\r
569 // printf("%02d ", i); if(x >= page->width - t->tileWidth) printf("\n");
\r
574 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 1); //currently the over scan color!
\r
577 rx = (((i-1) % ((t->pcximg->width)/t->tileWidth)) * t->tileWidth);
\r
578 ry = (((i-1) / ((t->pcximg->height)/t->tileHeight)) * t->tileHeight);
\r
580 if(!pagenorendermap) modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, i+1);
\r
582 modexDrawBmpRegion (page, x, y, rx, ry, t->tileWidth, t->tileHeight, i);
\r
583 //draw_vrl1_vgax_modex(x-rx,y-ry,vrl_header,vrl_lineoffs,buffer+sizeof(*vrl_header),bufsz-sizeof(*vrl_header));
\r
584 //modexDrawBmpRegion (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
\r
586 /*#ifdef __DEBUG_MAP__
\r
587 switch(dbg_maptext)
\r
592 sprintf(global_temp_status_text2, "%u", i); modexprint(page, x, y, 1, 1, 2, global_temp_status_text2);
\r
598 //sprintf(global_temp_status_text2, "%d", i); modexprint(page, x+3, y-1, 1, 1, 2, global_temp_status_text2);
\r
601 void near mapDrawRow(map_view_t *mv, int tx, int ty, word y, player_t *player, word poopoffset)
\r
604 if(pagedelayrendermap) if(!y) y+=TILEWH; else y-=TILEWH;
\r
605 poopoffset%=player[0].enti.speed;
\r
606 //printf("y: %d\n", poopoffset);
\r
607 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
608 /* the position within the map array */
\r
609 i=ty * mv->map->width + tx;
\r
610 for( mv->dx=poopoffset; mv->dx<(mv->page->sw+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width; mv->dx+=mv->map->MAPTILESPTR->tileWidth, tx++) {
\r
612 mapDrawTile(mv->map->MAPTILESPTR, mv->map->MAPDATAPTR[i], mv->page, mv->dx, y);
\r
615 if(pagedelayrendermap) delay(200);
\r
618 void near mapDrawCol(map_view_t *mv, int tx, int ty, word x, player_t *player, word poopoffset)
\r
621 if(pagedelayrendermap) if(!x) x+=TILEWH; else x-=TILEWH;
\r
622 poopoffset%=player[0].enti.speed;
\r
623 //printf("x: %d\n", poopoffset);
\r
624 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
625 /* location in the map array */
\r
626 i=ty * mv->map->width + tx;
\r
627 /* We'll copy all of the columns in the screen,
\r
628 i + 1 row above and one below */
\r
629 for( mv->dy=poopoffset; mv->dy<(mv->page->sh+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height; mv->dy+=mv->map->MAPTILESPTR->tileHeight, ty++) {
\r
631 mapDrawTile(mv->map->MAPTILESPTR, mv->map->MAPDATAPTR[i], mv->page, x, mv->dy);
\r
632 i += mv->map->width;
\r
634 if(pagedelayrendermap) delay(200);
\r
637 void mapDrawWRow(map_view_t *mv, int tx, int ty, word y)
\r
641 /* the position within the map array */
\r
642 i=ty * mv->map->width + tx;
\r
643 for(mv->dx=0; mv->dx<mv->page->sw+mv->dxThresh && tx < mv->map->width; mv->dx+=mv->map->MAPTILESPTR->tileWidth, tx++) {
\r
644 if(i>=0) /* we are in the map, so copy! */
\r
645 mapDrawTile(mv->map->MAPTILESPTR, mv->map->MAPDATAPTR[i], mv->page, mv->dx, y);
\r
650 void mapDrawWCol(map_view_t *mv, int tx, int ty, word x)
\r
654 /* location in the map array */
\r
655 i=ty * mv->map->width + tx;
\r
657 /* We'll copy all of the columns in the screen,
\r
658 i + 1 row above and one below */
\r
659 for(mv->dy=0; mv->dy<mv->page->sh+mv->dyThresh && ty < mv->map->height; mv->dy+=mv->map->MAPTILESPTR->tileHeight, ty++) {
\r
660 if(i>=0) /* we are in the map, so copy away! */
\r
661 mapDrawTile(mv->map->MAPTILESPTR, mv->map->MAPDATAPTR[i], mv->page, x, mv->dy);
\r
662 i += mv->map->width;
\r
666 boolean pagenorendermap = 0;
\r
667 boolean pagedelayrendermap = 0;
\r
670 void shinku(global_game_variables_t *gv)
\r
672 word x = gv->video.page[/*!*/(gv->video.p)].dx; //(gv->video.page[(gv->video.p)].tlx) - // follow the screen
\r
673 word y = gv->video.page[/*!*/(gv->video.p)].dy; //(gv->video.page[(gv->video.p)].tly) - // follow the screen
\r
674 word col = 2, bgcol = 1, type = 1;//w = 64, h = 8,
\r
675 if(elapsed_timer(gv) >= (1.0 / gv->kurokku.frames_per_second))
\r
677 // NTS: For some bizarre reason, gv->pee is not initialized, but the pointer is not NULL even
\r
678 // though it should be. Instead it's NULL as a neAr pointer but contains a non-null
\r
679 // segment value, so testing against NULL doesn't work. It is initialized properly if
\r
680 // you call start_timer() though which uses neAr malloc. Rather than fight with that,
\r
681 // I decided it would be better to declare a temp buffer statically and sprintf to that.
\r
683 // This fixes *** Null pointer assignment detected error message in ZCROLL.EXE on exit.
\r
684 sprintf(global_temp_status_text, "%.0f fps", (double)gv->kurokku.tiku/ticktock(gv));
\r
685 //modexprint(&(gv->video.page[/*!*/(gv->video.p)]), x, y, type, col, bgcol, global_temp_status_text);
\r
686 modexCopyPageRegion(&gv->video.page[0], &gv->video.page[1],
\r
687 gv->video.page[/*!*/(gv->video.p)].dx,
\r
688 gv->video.page[/*!*/(gv->video.p)].dy,
\r
689 gv->video.page[/*!*/(gv->video.p)].dx,
\r
690 gv->video.page[/*!*/(gv->video.p)].dy,
\r
692 modexprint(&(gv->video.page[/*!*/(gv->video.p)]), x, y, type, col, bgcol, global_temp_status_text);
\r
693 //0000printf("dx=%u dy=%u\n", gv->video.page[/*!*/(gv->video.p)].dx, gv->video.page[/*!*/(gv->video.p)].dy);
\r
694 gv->kurokku.tiku=0;
\r
695 }else //copy dat sheet
\r
696 gv->kurokku.tiku++;
\r
698 switch(gv->kurokku.fpscap)
\r
700 case 0: //turn this off if XT
\r
701 //modexprint(&(gv->video.page[0]), x, y+8, type, col, bgcol, "sanic!");
\r
702 gv->kurokku.frames_per_second=1;
\r
705 //modexWaitBorder();
\r
706 //modexWaitBorder_start();
\r
707 //vga_wait_for_vsync();
\r
708 vga_wait_for_vsync_end();
\r
709 gv->kurokku.frames_per_second=60;
\r
713 if(gv->video.dorender )
\r
717 modexCopyPageRegion(&(gv->video.page[ ]), &(gv->video.page[ ]), 0, 0, 0, 0, gv->video.page[ ].width, gv->video.page[ ].height);
\r
719 //modexCopyPageRegion(&video->page[0], &video->page[1], enti->x, enti->y, 0, 0, 24, 32);
\r
721 VL_ShowPage(&(gv->video.page[gv->video.sp]), gv->kurokku.fpscap, 0);
\r
722 gv->video.dorender =!gv->video.dorender ;
\r
723 //0000gv->video.tickclk = ((*clockw)-gv->video.startclk)/18.2;
\r
727 void near ZC_animatePlayer(map_view_t *pip, player_t *player, word pn)
\r
729 sword x = player[pn].enti.x;
\r
730 sword y = player[pn].enti.y;
\r
731 sword qq,dd; //scroll offset
\r
732 player[pn].enti.dire=10; //direction
\r
734 switch(player[pn].walktype)
\r
746 qq = player[pn].enti.q*player[pn].enti.speed;
\r
750 y-=pip[0].map->MAPTILESPTR->tileHeight;
\r
751 switch (player[pn].enti.d)
\r
755 player[pn].enti.dire*=player[pn].enti.d+1;
\r
760 player[pn].enti.dire*=(player[pn].enti.d-1);
\r
767 player[pn].enti.dire*=(player[pn].enti.d-1);
\r
772 player[pn].enti.dire*=(player[pn].enti.d+3);
\r
776 player[pn].enti.dire+=dd;
\r
777 //setting xy position
\r
778 player[pn].enti.spri->x = x;
\r
779 player[pn].enti.spri->y = y;
\r
781 if((player[pn].enti.q==1 && player[pn].enti.pred != player[pn].enti.d) || !dd)//when dir changed OR when player change face direction
\r
783 //0000printf(" q=%u pred=%u d=%u dd=%u\n", player[pn].enti.q, player[pn].enti.pred, player[pn].enti.d, dd);
\r
784 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
785 player[pn].enti.pred = player[pn].enti.d;
\r
786 if(!dd)//changed direction while NOT moving!
\r
788 modexCopyPageRegion(pip[0].page, pip[1].page, x-4, y-4, x-4, y-4, 28, 40);
\r
789 animate_spri(&player[pn].enti, pip[0].video);
\r
793 if(pip[0].video->bgps && dd)//if moving wwww
\r
795 modexCopyPageRegion(pip[0].page, pip[1].page, x-4, y-4, x-4, y-4, 28, 40);
\r
798 animate_spri(&player[pn].enti, pip[0].video);
\r
800 //0000if(player[pn].enti.q<4) delay(200);
\r
807 boolean boundary_check(int x, int y, int dx, int dy, int h, int w)
\r
809 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
812 boolean coll_check(int x, int y, int dx, int dy, map_view_t *map_v)
\r
814 // Assume everything crosses at most 1 tile at once
\r
815 return dx && 1;//crossable_tile(x + dx, map_v) || dy && crossable_tile(y + dy, map_v);
\r
818 boolean ZC_walk2(entity_t *enti, map_view_t *map_v)
\r
838 if(coll_check(enti->x, enti->y, dx, dy, map_v))
\r
843 // Mark next tile as occupied
\r
844 // Mark this tile as vacant
\r
850 void player_walk(player_t *player, map_view_t *map_v){
\r
852 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
854 mapScroll(map_v, player);
\r
859 void mapScroll(map_view_t *mv, player_t *player)
\r
861 //word x, y; /* coordinate for drawing */
\r
864 mv->delta += player->dx | player->dy;
\r
866 mv->d = (player->dx) ? (player->dx > 0) ? 3 : 1 : (player->dy) ? (player->dy > 0) ? 4 : 0 : 2;
\r
872 if(!(delta + mv->dxThresh))
\r
882 if(!(delta + mv->dyThresh))
\r