/* 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 "keys.h" #include "map.h" #include "mem.h" #include "tools.h" #include "text8bpp.h" #include "screen8bpp.h" #include "tiles.h" #include "tilesmap.h" #include "tilesplayer.h" #include "splash.h" /* Put your function prototypes here */ #define printRess() printSmall8bpp(uitoa(pers[0].ress, 3), 6*TILE_SIZE+8, ystatus1) #define printDiam() printSmall8bpp(uitoa(pers[0].diam, 3), 6*TILE_SIZE+8, ystatus2) #define printScore() printSmall8bpp(uitoa(score, 4), 50, ystatus2) #define printLife() printSmall8bpp(uitoa(pers[0].force, 3), 50, ystatus1) #define canHang(p,t) (t==6 && !p || t==5 || t==16) #define encodeCoords(x, y) ((((uint32_t)(y))<<16)|(x)) #define getTile(val) ((val)&0x7F) void setAutoCanvas(); void addCleared(uint8_t x, uint8_t y); void delayCleared(uint8_t x, uint8_t y); uint16_t updCleared(uint16_t i); void setTile(uint8_t* ptr, uint8_t val); void resetP(uint8_t i, uint8_t x, uint8_t y); void lightRoom(uint8_t x, uint8_t y); void updSpirale(); uint8_t canGo(uint8_t p, uint8_t t, uint8_t x, uint8_t y); void move(uint8_t p, uint8_t x0, uint8_t y0); /* Put your structures here */ typedef struct { uint8_t x; uint8_t xold; uint8_t y; uint8_t yold; uint8_t rx; uint8_t ry; uint8_t ress; uint8_t diam; uint8_t jumps; uint8_t force; uint8_t status; uint8_t idtile; uint8_t idtileold; uint8_t idtilep; } pers_t; /* Put all your globals here. */ #define MAXLIFE 100 #define X_START 38 #define Y_START 20 #define WAIT_DELAY1 5000 #define WAIT_DELAY2 2000 #define CLEAR_DELAY 31 #define MAXPERS 0x3 #define IS_FALLING 1 #define HASFIOLE 4 #define HASBOUEE 8 #define HASLAMPE 16 #define HASCLEF 32 #define HASPARCH 64 #define HASSTATUE 128 // Global non-pointers variables (DON'T FORGET TO INITIALIZE THEM) uint16_t ncleared = 0; uint16_t score = 0; uint16_t xold=MAP_WIDTH, yold=0; uint16_t x=0, y=0; uint8_t ystatus1 = SCR_HEIGHT-2*STXT_HEIGHT, ystatus2 = SCR_HEIGHT-STXT_HEIGHT, ystatus3=SCR_HEIGHT-3*STXT_HEIGHT/2; uint8_t sx=0, sy=0; uint8_t userBrightness = 100; // will get overwritten // Global arrays (DON'T FORGET TO INITIALIZE THEM) uint8_t reachable[NTILES] = {1,0,0,0,0,1,1,0 ,0 ,0 ,1 ,1 ,0 ,1 ,1 ,0 ,1 ,1 ,1 ,0 ,0 ,0 ,1 ,1 ,0 ,0 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,0 ,0,0 ,0,0 ,0 ,0, 1, 1, 1, 1, 1, 1,0 ,0 ,0 ,0 ,0,0 ,0 ,0 ,0 ,0}; uint8_t nextanim[NTILES] = {0,1,2,3,4,5,6,37,39,41,10,11,12,36,14,15,16,44,18,19,20,21,22,23,24,25,46,48,28,29,30,31,32,33,34,35,13,38,7,40,8,42,43,9,45,17,47,26,49,27,51,52,53,54,0,55,56,57,58,59}; pers_t* pers = {0}; uint32_t* cleared = {0}; uint8_t* spirale = {0}; uint8_t* light = {0}; uint8_t* screentiles = {0}; /* Put all your code here */ void main() { uint16_t i=0, i2=0, j=0, j2=0; uint8_t t=0, tbot=0, t2=0, t3=0, k=0, x0=0, y0=0, k2=0; uint8_t *pct=0, *pcr=0; uint8_t* tiles[NTILES] = {0}; uint8_t* tilesp[NTILESP] = {0}; cleanUp(); _OS( asm("di"); asm("CALL _RunIndicOff"); asm("CALL _ClrScrn"); ); userBrightness = getBrightness(); startScreen8bpp(); // splash screen dispBack(); increaseBrightness(userBrightness); pers=(pers_t*)myMalloc(MAXPERS*sizeof(pers_t)); initTilesP(tilesp); initMap(); screentiles = myMalloc(SCR_COLS*SCR_LINES); initTiles(tiles); cleared = myMalloc(SCR_COLS*SCR_LINES*4); spirale = myMalloc(MAP_RWIDTH*MAP_RHEIGHT); light = myMalloc(MAP_RWIDTH*MAP_RHEIGHT); memset(spirale,0xFF,MAP_RWIDTH*MAP_RHEIGHT); memset(light,0,MAP_RWIDTH*MAP_RHEIGHT); pct=map; for(j=0;j=20) i=18; else i++; if(i2>=3) i2=2; else i2++; if(j2>=60) { j2--; if(j2%5) j--; } } fillLines(23,SCR_HEIGHT-TILE_SIZE,SCR_HEIGHT-1); printSmall8bpp("Force :",1,ystatus1); printSmall8bpp("Score :",1, ystatus2); gc_drawTile(tiles[11],5*TILE_SIZE+1,SCR_LINES*TILE_SIZE,TILE_SIZE,TILE_SIZE,0,23); printSmall8bpp("x",6*TILE_SIZE-1,ystatus1); gc_drawTile(tiles[10],8*TILE_SIZE+7,SCR_LINES*TILE_SIZE,TILE_SIZE,TILE_SIZE,0,23); printSmall8bpp("x",8*TILE_SIZE+1,ystatus2); printSmall8bpp("[2nd]+[<>",11*TILE_SIZE+6,ystatus1); printSmall8bpp("] clear wall",15*TILE_SIZE,ystatus1); printSmall8bpp("[2nd]+[ ^",11*TILE_SIZE+6,ystatus2); printSmall8bpp("] big jump",15*TILE_SIZE,ystatus2); printRess(); printDiam(); for(i=0;i0) pers[i].force=0; } lightRoom(pers[0].rx,pers[0].ry); setAutoCanvas(); asm("ei"); startKeys(); while (!isKeyPressed(KEY_MODE)) { pcr=screentiles; pct = getMapPtr(x,y); for (j=0,j2=y;j=MAP_WIDTH || *pcr!=t || t3)) { gc_drawTile(tiles[t], i*TILE_SIZE, j*TILE_SIZE, TILE_SIZE, TILE_SIZE,0,0); *pcr = t; } pct++; pcr++; } pct+=MAP_WIDTH-SCR_COLS; } for (k=0;k>8; t2=1; for(t=0;t=55 && t<=58) t++; else { t=12; if(k==ncleared-1) ncleared--; } map[j*MAP_WIDTH+i]=t; } } } xold = x; yold = y; x0=pers[0].xold; y0=pers[0].yold; for(k=MAXPERS-1;k=MAP_HEIGHT) { if(!k) { pers[0].y=pers[0].yold; if(score>MAXLIFE) score-=MAXLIFE; else score=0; printScore(); resetP(0,X_START,Y_START); } else if(sypers[k].yold) pers[k].jumps=0; pct=getMapPtr(pers[k].x,pers[k].y); if(!canGo(k,getTile(*pct),pers[k].x,pers[k].y) || pers[k].y=21 && t<=23) || (t>=28 && t<=30))) { if(t==11) { pers[0].ress+=2; printRess(); } else if(t==10) { pers[0].diam++; if(pers[0].diam==105) *getMapPtr(2*ROOM_WIDTH+7,ROOM_HEIGHT+4)=30; printDiam(); } else if(t==18) { pers[0].status|=HASFIOLE; gc_drawTile(tiles[t],9*TILE_SIZE+4,SCR_LINES*TILE_SIZE,TILE_SIZE,TILE_SIZE,0,23); } else if(t==22) { pers[0].status|=HASLAMPE; gc_drawTile(tiles[t],12*TILE_SIZE+4,SCR_LINES*TILE_SIZE,TILE_SIZE,TILE_SIZE,0,23); } else if(t==23) { pers[0].status|=HASBOUEE; gc_drawTile(tiles[t],10*TILE_SIZE+4,SCR_LINES*TILE_SIZE,TILE_SIZE,TILE_SIZE,0,23); } else if(t==28) { pers[0].status|=HASCLEF; gc_drawTile(tiles[t],11*TILE_SIZE+4,SCR_LINES*TILE_SIZE,TILE_SIZE,TILE_SIZE,0,23); } else if(t==29) { pers[0].status|=HASSTATUE; gc_drawTile(tiles[t],14*TILE_SIZE+4,SCR_LINES*TILE_SIZE,TILE_SIZE,TILE_SIZE,0,23); } else if(t==30) { pers[0].status|=HASPARCH; gc_drawTile(tiles[t],13*TILE_SIZE+4,SCR_LINES*TILE_SIZE,TILE_SIZE,TILE_SIZE,0,23); *getMapPtr(9*ROOM_WIDTH,3*ROOM_HEIGHT+3)=0; } score+=20; printScore(); *pct=0; } } } t=pers[k].idtile; tbot=(pers[k].y=37 && tbot<=40 || tbot==8 || tbot==16 && !(pers[k].status&HASBOUEE)) && !pers[k].jumps && !canHang(k,t)))) { pers[k].force=0; if(!k) printLife(); } if(!k) { if(!pers[0].force) pers[0].idtilep=(pers[0].idtilep!=16)?16:17; else if(pers[0].xpers[0].xold && t!=5 && t!=16) { if(t==6) pers[0].idtilep=(pers[0].idtilep!=11)?11:12; else pers[0].idtilep=(pers[0].idtilep!=4)?4:5; } else if(t==6 && (pers[0].idtilep<8 || pers[0].idtilep>12)) pers[0].idtilep=8; else if(t==5 && (pers[0].x!=pers[0].xold || pers[0].y!=pers[0].yold)) pers[0].idtilep=(pers[0].idtilep!=6)?6:7; else if(t==16) pers[0].idtilep=(pers[0].idtilep!=13)?13:14; else if(pers[0].status&IS_FALLING && t!=5 && t!=6 && t!=16) pers[0].idtilep=15; else if(t!=6 && t!=5 && t!=16) pers[0].idtilep=(pers[0].idtilep)?0:1; } else { if(pers[k].idtilep==18 || pers[k].idtilep==19) pers[k].idtilep++; else pers[k].idtilep=18; } } setAutoCanvas(); nopwait(WAIT_DELAY1); if(x==xold && y==yold) nopwait(WAIT_DELAY2); } stopKeys(); endScreen8bpp(); cleanUp(); } void move(uint8_t p, uint8_t x0, uint8_t y0) { uint8_t y=pers[0].y; if(!pers[p].force) { if(!p) pers[0].y--; else pers[p].y=MAP_HEIGHT; } else if(pers[p].status&IS_FALLING) pers[p].y++; else if(!p) { pers[0].x = pers[0].x + isKeyPressed(KEY_RIGHT) - isKeyPressed(KEY_LEFT); pers[0].y = pers[0].y + isKeyPressed(KEY_DOWN) - isKeyPressed(KEY_UP); } else if(syy0 && canGo(p,*getMapPtr(pers[p].x,pers[p].y-1),pers[p].x,pers[p].y-1)) pers[p].y--; else if(pers[p].yx0 && canGo(p,*getMapPtr(pers[p].x-1,pers[p].y),pers[p].x-1,pers[p].y)) pers[p].x--; else if(pers[p].xy0) pers[p].y--; pers[0].y=y; } } uint8_t canGo(uint8_t p, uint8_t t, uint8_t x, uint8_t y) { uint8_t r=(((t==21) && (pers[p].status&HASCLEF)) || reachable[t]); uint8_t k=0; for(k=0;r && k>4; if(sy>=ROOM_HEIGHT) sy=MAP_HEIGHT; else { sx+=pers[0].rx*ROOM_WIDTH; sy+=pers[0].ry*ROOM_HEIGHT; } } void lightRoom(uint8_t x,uint8_t y) { uint8_t x0=x*ROOM_WIDTH; uint8_t y0=y*ROOM_HEIGHT; uint8_t i=0,j=0; uint8_t* ptr=0; ptr=getMapPtr(x0,y0); for(j=0;j0;i--) cleared[i]=cleared[i-1]; ncleared++; cleared[0]=val; } void delayCleared(uint8_t x, uint8_t y) { uint32_t val = (0<<15) | (((uint32_t)y)<<8) | ((uint32_t)x); uint8_t i=0; for (i=ncleared;i>0;i--) cleared[i]=cleared[i-1]; ncleared++; cleared[0]=val; } uint16_t updCleared(uint16_t i) { uint32_t n = cleared[i]>>15; if (n>0) { n--; cleared[i] = (cleared[i]&0x7FFF) | (n<<15); } return n; } void setAutoCanvas() { uint8_t x0=pers[0].x - SCR_COLS/2; uint8_t y0=pers[0].y - SCR_LINES/2, t=0; if(pers[0].force && pers[0].yx0 || 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; }