// Mandragore - Xavier Andréani - TI-Planet.org // v1.2 - 02.03.2016 // GPL3 license : http://www.gnu.org/licenses/gpl-3.0.txt // Licence GPL3 : http://www.rodage.org/gpl-3.0.fr.txt /* Keep these headers */ #include #include #include #include /* Standard headers - it's recommended to leave them included */ #include #include #include #include /* Other available headers */ // stdarg.h, setjmp.h, assert.h, ctype.h, float.h, iso646.h, limits.h, errno.h #include "text8bpp.h" #include "tools.h" #include "mem.h" #include "screen8bpp.h" #include "splash.h" #include "map.h" #include "tiles.h" #include "tilesplayer.h" #include "tilesmap.h" #include "keys.h" /* Put your function prototypes here */ void setAutoCanvas(); uint8_t isDonjVis(uint16_t x, uint16_t y); uint8_t isVillVis(uint16_t x, uint16_t y); #define printGold() printSmall8bpp(uitoa(g, 5), 52, ystatus2) #define printDung() printSmall8bpp(uitoa(donj, 2), 205, ystatus1) #define printParts() printSmall8bpp(uitoa(b, 1), 205, ystatus2) #define printDist() printSmall8bpp(uitoa(d, 5), 52, ystatus1) #define canGo(t) (((t) != 1) && ((t) != 3 || (b) >= NVILLES)) #define encodeCoords(x, y) ((((uint32_t)(y))<<16)|(x)) /* Put all your globals here. */ #define NDONJONS 10 #define NVILLES 9 #define WAIT_DELAY1 1000 #define WAIT_DELAY2 10000 // Global non-pointers variables (DON'T FORGET TO INITIALIZE THEM) uint32_t d = 0; uint16_t xold=MAP_WIDTH, yold=0; uint16_t xp=52, yp=47; uint16_t xpold=0, ypold=0; uint16_t x=0, y=0; uint16_t g=0, donj=0; uint8_t b=0, ndonjvis=0; uint8_t ystatus1 = SCR_HEIGHT-2*STXT_HEIGHT, ystatus2 = SCR_HEIGHT-STXT_HEIGHT; uint8_t userBrightness = 100; // will get overwritten // Global arrays uint32_t* donjvis = {0}; uint32_t* villvis = {0}; uint8_t* screentiles = {0}; /* Put all your code here */ void main() { uint16_t i=0, j=0, gold=g; uint8_t t=0, told=0, bold=b, s=1, ct=0, skip=0; cleanUp(); _OS( asm("di"); asm("CALL _RunIndicOff"); asm("CALL _ClrScrn"); ); userBrightness = getBrightness(); startScreen8bpp(); // splash screen dispBack(); increaseBrightness(userBrightness); setAutoCanvas(); initMap(); t = getMapType(xp, yp); donjvis = (uint32_t*)myMalloc(NDONJONS*4); villvis = (uint32_t*)myMalloc(NVILLES*4); screentiles = myMalloc(SCR_COLS*SCR_LINES); initTilesP(tilesp); initTiles(tiles); while(!GetCSC()); fillLines(4,SCR_HEIGHT-TILE_SIZE,SCR_HEIGHT-1); printSmall8bpp("Route : km Dungeons : /10",1,ystatus1); printSmall8bpp("", 0, ystatus1); printSmall8bpp("Gold : $ Boat pieces : /9",11,ystatus2); asm("ei"); startKeys(); while (!isKeyPressed(KEY_MODE) && !isKeyPressed(KEY_DEL) && !isKeyPressed(KEY_CLEAR)) { if (x!=xold || y!=yold) { for (j=0;j=MAP_WIDTH || screentiles[j*SCR_COLS+i]!=ct || xp-x==i-x+xold && yp-y==j-y+yold) { gc_drawTile((uint8_t*)tiles[ct], i*TILE_SIZE, j*TILE_SIZE, TILE_SIZE, TILE_SIZE,0,0); screentiles[j*SCR_COLS+i] = ct; } if (xp==x+i && yp==y+j) { gc_drawTile((uint8_t*)tilesp[(t==3)?1:(t==2)?2:0], i*TILE_SIZE, j*TILE_SIZE, TILE_SIZE, TILE_SIZE,0,0); } } } xold = x; yold = y; } else if (xp!=xpold || yp!=ypold) { gc_drawTile((uint8_t*)tiles[getMapType(xpold,ypold)], (xpold-x)*TILE_SIZE, (ypold-y)*TILE_SIZE, TILE_SIZE, TILE_SIZE,0,0); gc_drawTile((uint8_t*)tilesp[(t==3)?1:(t==2)?2:0], (xp-x)*TILE_SIZE, (yp-y)*TILE_SIZE, TILE_SIZE, TILE_SIZE,0,0); } told=t; xpold=xp; ypold=yp; xp = xp + isKeyPressed(KEY_RIGHT) - isKeyPressed(KEY_LEFT); yp = yp + isKeyPressed(KEY_DOWN) - isKeyPressed(KEY_UP); if (xp!=xpold || yp!=ypold) { if (yp!=ypold) { t = getMapType(xpold,yp); if(!canGo(t)) { yp=ypold; t=told; } else xp=xpold; } if(xp!=xpold) { t = getMapType(xp,yp); if (!canGo(t)) { t=told; xp=xpold; } } if (xp!=xpold || yp!=ypold) { d++; printDist(); // setAutoCanvas(); if (t==7) { if (!isDonjVis(xp,yp)) { g += 1000; donj++; donjvis[ndonjvis] = encodeCoords(xp,yp); ndonjvis++; printDung(); printGold(); } } else if (t==6 && g) { if (!isVillVis(xp,yp)) { villvis[b] = encodeCoords(xp,yp); b++; g -= 1000; printParts(); printGold(); } } } } setAutoCanvas(); nopwait(WAIT_DELAY1); if(x==xold && y==yold) nopwait(WAIT_DELAY2); } stopKeys(); endScreen8bpp(); cleanUp(); } /* Other functions */ uint8_t isDonjVis(uint16_t x, uint16_t y) { uint32_t val = encodeCoords(xp, yp); uint8_t i; for(i=0; ix0 || x0>=MAP_WIDTH) x--; else if(xy0 || y0>=MAP_HEIGHT) y--; else if(y=MAP_WIDTH-SCR_COLS+1) x = xold; if (y>=MAP_HEIGHT-SCR_LINES+1) y = yold; } /* void setAutoCanvas() { x = xp - SCR_COLS/2; y = yp - SCR_LINES/2; if (x>=MAP_WIDTH-SCR_COLS+1) x = xold; if (y>=MAP_HEIGHT-SCR_LINES+1) y = yold; }*/