static void LocalSave( void ) { int x; char *user; int i; localuser=-1; for( i=0; i < 8; i++ ) if ( score > hsc[i].points ) break; if ( i==8 ) return; Fx2PigPause(); FBFillRect( 500,32,3*52,4*52+4,BLACK ); FBFillRect( 150,420,470,64,BLACK ); FBDrawRect( 149,419,472,66,WHITE ); FBDrawRect( 148,418,474,68,WHITE ); x=FBDrawString( 154,420,64,"name : ",WHITE,0); user=FBEnterWord(154+x,420,64,9,WHITE); Fx2PigResume(); if ( i < 7 ) memmove( hsc+i+1,hsc+i,sizeof(HScore)*(7-i) ); strcpy(hsc[i].name,user); hsc[i].points=score; localuser=i; }
/** * Draws the complete board according to the values of the cells * and the fx logo * * Possible field values: * # : inactive cell (not reachable with mouse) * ' ' : field which is not on the board * n,b,B: empty field * x : cell with a tux * s : selected cell with a tux */ void DrawBoard(void) { int x; int y; unsigned char *p = maze; for( y = 0; y < MAZEH; y++ ) { for( x = 0; x < MAZEW; x++, p++ ) { switch ( *p ) { case '#' : FBFillRect( x*32, y*32, 32, 32, STEELBLUE ); break; case ' ' : FBFillRect( x*32, y*32, 32, 32, BLACK ); break; case 'n' : FBCopyImage( x*32, y*32, 32, 32, dout ); break; case 'b' : FBCopyImage( x*32, y*32, 32, 32, dout ); break; case 'B' : FBCopyImage( x*32, y*32, 32, 32, dout ); break; case 'x' : FBCopyImage ( x*32, y*32, 32, 32, dtux ); break; case 's' : FBCopyImage( x*32, y*32, 32, 32, dselectedtux ); break; } } } // draw white frame around board FBDrawRect( 3*32-3, 3*32-3, 9*32+5, 9*32+5, WHITE ); FBDrawRect( 3*32-4, 3*32-4, 9*32+7, 9*32+7, WHITE ); FBDrawString( LOGO_X-90, LOGO_Y, 32, "powered by", WHITE, 0 ); FBDrawFx2Logo( LOGO_X, LOGO_Y ); FBDrawString( LOGO_X-90, LOGO_Y+70, 32, "brought to you by", WHITE, 0 ); FBDrawString( LOGO_X-80, LOGO_Y+110, 32, "ChakaZulu", WHITE, 0 ); gettimeofday(&starttv,0); DrawMouse(); }
void RunKey( void ) { Sprite *s; int nac; int sel_type=0; unsigned long otype; switch( actcode ) { #ifdef KEY_TOPLEFT case KEY_TOPLEFT: case KEY_TOPRIGHT: case KEY_BOTTOMLEFT: case KEY_BOTTOMRIGHT: #endif case RC_LEFT : case RC_RIGHT : case RC_UP : case RC_DOWN : HandleDirection ( actcode ); break; case RC_RED : // kill all lemmings if ( pause || (action!=2) || !in_level ) break; SoundPlay( SND_OHNO ); FBGetImage( 11*32+32, 384, 32, 48, svdimage[11] ); FBDrawRect( 11*32+32, 384, 31, 47, RED ); FBDrawRect( 11*32+33, 385, 29, 45, RED ); killall=1; break; case RC_BLUE : // PAUSE - GO if ( action!=2 ) return; if ( pause == 1 ) FBCopyImage( 10*32+32, 384, 32, 48, svdimage[10] ); pause = pause ? 0 : 1; if ( pause ) { FBGetImage( 10*32+32, 384, 32, 48, svdimage[10] ); FBDrawRect( 10*32+32, 384, 31, 47, BLUE ); FBDrawRect( 10*32+33, 385, 29, 45, BLUE ); } break; case RC_1 : case RC_2 : case RC_3 : case RC_4 : case RC_5 : case RC_6 : case RC_7 : case RC_8 : // select lemm-action if ( pause || !action || (action>2)) break; nac=actcode-1; if ( afunc == actcode-1 ) break; if ( !portfolio[ actcode-1 ] ) break; FBGetImage( (nac+2)*32+32, 384, 32, 48, svdimage[nac+2] ); // save if ( afunc != -1 ) { FBCopyImage( (afunc+2)*32+32, 384, 32, 48, svdimage[afunc+2] ); DrawNumber( 106+afunc*32, 389, portfolio[afunc] ); } FBDrawRect( (nac+2)*32+32, 384, 31, 47, YELLOW ); FBDrawRect( (nac+2)*32+33, 385, 29, 45, YELLOW ); afunc=nac; break; case RC_PLUS : if ( pause || (action!=2) ) break; newspeed--; if ( newspeed < 1 ) newspeed=1; else { DrawNumber( 74, 389, 100-newspeed ); } break; case RC_MINUS : if ( pause || (action!=2) ) break; newspeed++; if ( newspeed > minspeed ) newspeed=minspeed; else { DrawNumber( 74, 389, 100-newspeed ); } break; case RC_OK : if( !action ) { action=1; s=deko[1]; // tor; s->anilocked=0; SoundPlay( SND_DOOR ); break; } if (( action != 2 ) || pause || ( sel_sprite == -1 ) || !portfolio[afunc]) break; s=lemm[ sel_sprite ]; if ( !s ) break; if ( afunc == 2 ) // EXPLODE { if ( !( s->type & TYP_EXPLODE ) ) { s->type |= TYP_EXPLODE; s->counter1=0; portfolio[ afunc ]--; DrawNumber( 106+afunc*32, 389, portfolio[afunc] ); } } else if ( afunc == 0 ) // CLIMB { if ( !( s->type & TYP_CLIMB ) ) { s->type |= TYP_CLIMB; portfolio[ afunc ]--; DrawNumber( 106+afunc*32, 389, portfolio[afunc] ); } } else { switch( afunc ) { case 3 : sel_type = TYP_STOPPER; break; case 4 : sel_type = TYP_BUILDER; break; case 6 : sel_type = TYP_DIGDIAG; break; case 7 : sel_type = TYP_DIGDOWN; break; } otype=s->type & TYP_WORK; while( 1 ) { if ( otype == sel_type ) { if (( otype == TYP_BUILDER ) && ( s->counter2 > 11 )) break; sel_type = 0; break; } if ( !( otype & TYP_STOPPER ) && !( s->type & TYP_FALLEN )) break; sel_type = 0; break; } if ( sel_type ) { otype = s->type; s->type = sel_type; portfolio[ afunc ]--; DrawNumber( 106+afunc*32, 389, portfolio[afunc] ); // erstmal die sprite-koordinaten wieder auf 0 if (( otype & TYP_BUILDER ) && ( s->counter2 < 12 )) { s->y+=3; } else if (( otype & TYP_BUILDER ) && ( s->counter2 == 12 )) { s->y-=2; } else if ( otype & TYP_DIGDIAG ) { s->y+=5; if ( !s->dir ) s->x+=7; } else if ( otype & TYP_DIGDOWN ) { s->y+=2; } // sprite-koordinaten eventl. verschieben if ( sel_type == TYP_DIGDOWN ) { s->y-=2; SpriteChangePic( s, 5 ); // lemming3 } if ( sel_type == TYP_STOPPER ) { s->counter1=0; SpriteChangePic( s, 4 ); // lemming2 bgRect( s->x+(s->width/2), s->y, 1, s->height-2, 150 ); } if ( sel_type == TYP_BUILDER ) { s->counter1=0; s->counter2=0; s->y -= 3; // 2 SpriteChangePic( s, 31 ); // builder if ( s->dir ) { s->x++; MirrorSprite( s ); } else s->x--; } if ( sel_type == TYP_DIGDIAG ) { s->counter1=0; s->counter2=0; s->y -= 5; SpriteChangePic( s, 33 ); // hacke if ( s->dir ) { MirrorSprite( s ); } else s->x-=7; } } } break; } }
void RunLemm( void ) { static int counter1=0; static int blinkc=0; int i; int f; int b; Sprite *s; int cursor_get=0; int kab=0; int hbk=0; // hat boden kontakt //int hhy=0; blinkc++; if ( action==3 ) { counter1=0; action=4; DrawSprite( deko[0] ); return; } if ( action==4 ) { counter1++; if ( counter1 < 24 ) return; if ( to_rescue > lem_in ) { FBDrawString( 252, 142, 64, "You lost !", WHITE, 0 ); FBDrawString( 250, 140, 64, "You lost !", RED, 0 ); } else { level++; if ( level>LASTLEVEL ) { FBDrawString( 252, 142, 64, "all level solved", WHITE, 0 ); FBDrawString( 250, 140, 64, "all level solved", GREEN, 0 ); FBDrawString( 240, 250, 36, "thanx to emuman for his javacode,", WHITE, 0 ); FBDrawString( 240, 286, 36, "Psygnosis and DMA for artwork...", WHITE, 0 ); level=1; doexit=2; return; } else { FBDrawString( 252, 142, 64, "Level solved", WHITE, 0 ); FBDrawString( 250, 140, 64, "Level solved", GREEN, 0 ); } } if ( afunc != -1 ) FBCopyImage( (afunc+2)*32+32, 384, 32, 48, svdimage[afunc+2] ); action=5; doexit=1; } if ( action != 2 ) { DrawSprite( deko[0] ); return; } if ( pause ) { UndrawSprite( deko[0] ); for( i=0; i<lem_run; i++ ) { if ( !lemm[i] ) continue; UndrawSprite( lemm[i] ); } DrawSprite( deko[1] ); // ziel DrawSprite( deko[2] ); // ziel for( i=0; i<lem_run; i++ ) { if ( !lemm[i] ) continue; s=lemm[i]; if (( s->type & TYP_EXPLODE ) && ( s->countdown > 0 )) { DrawSimpleNumber( s->x-main_x, s->y-6, s->countdown, 1 ); } SpriteGetBackground( s ); DrawSprite( s ); } SpriteSelPic( deko[0], 0 ); SpriteGetBackground( deko[0] ); DrawSprite( deko[0] ); if ( blinkc%5 ) return; if ( pause == 1 ) { FBCopyImage( 10*32+32, 384, 32, 48, svdimage[10] ); pause=2; } else { FBDrawRect( 10*32+32, 384, 31, 47, BLUE ); FBDrawRect( 10*32+33, 385, 29, 45, BLUE ); pause=1; } return; } sel_sprite=-1; if (( lem_run < lem_cnt ) && !( counter1%((newspeed/2)+3) ) && !killall ) { lemm[ lem_run ] = CreateSprite(3,0,deko[1]->x+19,deko[1]->y); lemm[ lem_run ]->dir=0; // rechts lemm[ lem_run ]->type = TYP_WALKER; in_level++; lem_run++; DrawInfo(1); } if ( in_level ) UndrawSprite( deko[0] ); for( i=0; i<lem_run; i++ ) { if ( !lemm[i] ) continue; s=lemm[i]; if ( s->type & TYP_EXPLODE ) restorecd( i ); else if (( s->type & TYP_FALLEN ) && s->partikel ) restorecd( i ); UndrawSprite( s ); s->counter1++; if ( !( s->counter1 % 10 ) && ( s->type & TYP_EXPLODE ) ) { s->countdown--; if ( s->countdown == -1 ) { s->counter1=0; bg2CopyImage( s->x-7, s->y-4, 21, 21, pbomb ); CopyBg2Screen( s->x-7,s->y-4, 21, 21); } } if (( s->counter1 == 2 ) && ( s->type & TYP_STOPPER ) && !( s->type & TYP_EXPLODE )) bgRect( s->x+1, s->y, s->width-1, s->height-2, 150 ); } // DrawSprite( deko[2] ); // ziel UnanimatedDeko(); for( i=0; i<lem_run; i++ ) { if ( !lemm[i] ) continue; s=lemm[i]; if ( killall && !kab ) { if ( !(s->type & TYP_EXPLODE ) ) { s->type |= TYP_EXPLODE; s->counter1=1; kab++; } } if ( (s->countdown==-1) && ( s->type & TYP_EXPLODE ) ) { s->partikel=1; partikel(i,1); } if ( !( s->counter1 % 10 ) && ( s->type & TYP_EXPLODE ) ) { if ( s->countdown == -1 ) { s->y-=4; s->x-=4; SpriteChangePic( s, 8 ); // explosion SpriteGetBackground( s ); DrawSprite(s); SoundPlay( SND_EXPLODE ); } if ( s->countdown == -2 ) { partikel(i,0); killlem( i ); s=0; DrawInfo(1); } } if ( s && ( s->countdown < 0 )) s=0; if ( s && ( s->type & TYP_FALLEN ) ) { if ( s->counter1 < 10 ) { s->partikel=1; partikel(i,1); } else { killlem( i ); DrawInfo(1); } s=0; } if ( s&&(s->countdown>0) ) { SpriteNextPic( s ); if ( s->type&TYP_ATHOME ) { s->y-=1; if(s->ani==4) { lem_in++; killlem(i); SoundPlay( SND_OING ); DrawInfo(3); } } else { /* lemming im ziel ? */ if((s->x==haus_x)&&(s->y>haus_y1)&& (s->y<haus_y2)) { s->type=TYP_ATHOME; s->counter2=0; SpriteChangePic( s, 6 ); // lemming4 } else { /* kein bodenkontakt ? */ switch( s->type & TYP_WORK ) { case TYP_WALKER : case TYP_DIGDOWN : hbk=isBrick(s->x+1,s->y+s->height,0)|| isBrick(s->x-2+s->width,s->y+s->height,0); break; case TYP_STOPPER : hbk=isBrick(s->x+1,s->y+s->height+1,0)|| isBrick(s->x-2+s->width,s->y+s->height+1,0); break; case TYP_DIGDIAG : hbk=isBrick(s->x+10,s->y+s->height-2,0)|| isBrick(s->x+11,s->y+s->height-2,0); break; case TYP_BUILDER : hbk=1; break; } if ( !hbk ) { #if 0 if ( s->type & TYP_DIGDIAG ) { hhy=s->y+s->height-2; printf("kein boden on %d, %d\n",s->x,s->y+s->height); } #endif if( !( s->type&TYP_WALKER ) ) { switch( s->type & TYP_WORK ) { case TYP_STOPPER : bgRect(s->x+1,s->y,s->width-1,s->height-2,14); break; case TYP_DIGDIAG : s->y+=5; if ( !s->dir ) s->x+=7; break; case TYP_DIGDOWN : s->y+=2; break; } s->type=TYP_WALKER|(s->type&TYP_UTILS); SpriteChangePic( s, 3 ); // lemming1-faller if ( s->dir ) MirrorSprite( s ); } // freier fall s->y += 2; s->counter2++; // aus bild gefallen if(s->y>=160) { SoundPlay( SND_DIE ); killlem(i); DrawInfo(1); } } else { if(s->type&TYP_WALKER) { /* aufgeschlagen */ if(s->counter2>=40) { s->counter1=0; s->type=TYP_FALLEN; SoundPlay( SND_DIE ); s->partikel=1; partikel(i,1); s=0; } else { /* wieder auf boden */ s->counter2=0; /* laeufer - getestet wird oben */ if((isBrick(s->x,s->y+1,1)&& (s->dir==1))|| (isBrick(s->x+s->width,s->y+1,1)&& (s->dir==0))) { MirrorSprite( s ); s->dir^=1; } else { s->x += (s->dir?-1:1); if ( s->dir ) { for(b=8;b>0;b--) { if(isBrick(s->x, s->y+s->height-b,0)) { s->y-=1; b=0; } } } else { for(b=8;b>0;b--) { if(isBrick(s->x+s->width, s->y+s->height-b,0)) { s->y-=1; b=0; } } } } } /* else, kein matsch */ } /** walker **/ else if(s&&(s->type&TYP_BUILDER)) { unsigned char c=118; // stair if ( !s->ani ) { s->counter2++; s->y--; if ( s->counter2 != 13 ) { if ( s->dir ) { s->x-=2; bghLine(s->x+2,s->y+s->height,6,&c,1); CopyBg2Screen( s->x+2,s->y+s->height,6,1); if ( isBrick(s->x+1,s->y+2,1) ) { s->y+=2; s->dir=0; s->counter2=13; } } else { s->x+=2; bghLine(s->x+1,s->y+s->height,6,&c,1); CopyBg2Screen( s->x+1,s->y+s->height,6,1); if ( isBrick(s->x+s->width,s->y+2,1) ) { s->y+=2; s->dir=1; s->counter2=13; } } } if ( s->counter2 == 12 ) { s->y+=2; SpriteChangePic( s, 32 );//keinesteine if ( s->dir ) MirrorSprite( s ); } if ( s->counter2 == 13 ) { s->type&=TYP_UTILS; s->type|=TYP_WALKER; SpriteChangePic( s, 3 );// lemming1 if ( s->dir ) MirrorSprite( s ); } } } else if(s&&(s->type&TYP_DIGDOWN)) { if(!(s->counter1%8)) { if(s->y<160) { bgRect( s->x+1, s->y+4, 10, 8-max(0,s->y-152), STEELBLUE ); s->y+=1; cursor_get=1; } } } /* digger */ else if(s&&(s->type&TYP_DIGDIAG)) { if ( s->ani == 8 ) { if ( s->dir ) { unsigned char *data = GetMirrorPic(34); bg2CopyImage(s->x+1,s->y+2,6,14,data); } else { inBg(34,0,s->x+11,s->y+2); } } if ( !s->ani ) { s->y+=1; if ( s->dir ) s->x-=2; else s->x+=2; } } } /* freier fall */ } /* nicht am ziel */ } /* countdown */ if ( s&&(level==5) ) { /* ab ins feuer ? */ for( f=5; f<11; f++ ) { if ( SpriteCollide( deko[f], s->x+s->width, s->y ) ) { SoundPlay( SND_DIE ); killlem(i); s=0; break; } } } } /* typ-fallen */ if ( !lemm[i] || !s ) continue; if (( s->type & TYP_EXPLODE ) && ( s->countdown > 0 )) { DrawSimpleNumber( s->x-main_x, s->y-6, s->countdown, 1 ); } SpriteGetBackground( s ); DrawSprite( s ); if ( SpriteCollide( s, deko[0]->x+7, deko[0]->y+7 ) ) { sel_sprite=i; } } if ( cursor_get ) SpriteGetBackground( deko[0] ); if ( sel_sprite != -1 ) { SpriteSelPic( deko[0], 1 ); } else { SpriteSelPic( deko[0], 0 ); } DrawSprite( deko[0] ); #if 0 if ( hhy ) FBDrawLine(32,hhy+hhy+32,656,hhy+hhy+32,RED); #endif counter1++; }
static void SaveGame( void ) { #ifdef HAVE_CURL CURL *curl; CURLcode res; FILE *fp; char url[ 512 ]; char *user=0; char luser[ 32 ]; int x; int n; char *p; struct timeval tv; unsigned long chk=0; doexit=0; #endif // HAVE_CURL if ( score < 31 ) return; LocalSave(); #ifdef HAVE_CURL LocalSave(); if ( !use_ihsc ) return; for( x=0; x < 8; x++ ) { if ( score > ihsc[x].points ) break; } if ( x == 8 ) return; FBDrawString( 100,230,64,"Inet-Send Highscore ? (OK/BLUE)",GREEN,0); #if defined(USEX) || defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE) FBFlushGrafic(); #endif while( realcode != 0xee ) RcGetActCode(); actcode=0xee; while( !doexit ) { tv.tv_sec = 0; tv.tv_usec = 100000; select( 0,0,0,0, &tv ); RcGetActCode(); if ( actcode == RC_BLUE ) return; if ( actcode == RC_OK ) break; } if ( doexit ) return; if ( localuser != -1 ) { strcpy(luser,hsc[localuser].name); user=luser; } else { Fx2PigPause(); FBFillRect( 500,32,3*52,4*52+4,BLACK ); FBFillRect( 150,420,470,64,BLACK ); FBDrawRect( 149,419,472,66,WHITE ); FBDrawRect( 148,418,474,68,WHITE ); x=FBDrawString( 154,420,64,"name : ",WHITE,0); user=FBEnterWord(154+x,420,64,9,WHITE); Fx2PigResume(); } n=FBDrawString( 210,360,48,"sending",BLACK,WHITE); /* clean name */ x = strlen(user); p=user; for( p=user; *p; x--, p++ ) { if (( *p == ' ' ) || ( *p == '&' ) || ( *p == '/' )) memcpy(p,p+1,x); } chk=BuildCheck( user, score ); sprintf(url,"%s/games/tetris.php?action=put&user=%s&score=%ld&chk=%lu", hscore,user,score,chk); curl = curl_easy_init(); if ( !curl ) return; fp = fopen( "/var/tmp/trash", "w"); if ( !fp ) { curl_easy_cleanup(curl); return; } curl_easy_setopt( curl, CURLOPT_URL, url ); curl_easy_setopt( curl, CURLOPT_FILE, fp ); curl_easy_setopt( curl, CURLOPT_NOPROGRESS, TRUE ); if ( proxy_addr ) { curl_easy_setopt( curl, CURLOPT_PROXY, proxy_addr ); if ( proxy_user ) curl_easy_setopt( curl, CURLOPT_PROXYUSERPWD, proxy_user ); } res = curl_easy_perform(curl); FBFillRect( 210,360,n,48,GRAY); if ( !res ) FBDrawString( 210,360,48,"success",GREEN,GRAY); else FBDrawString( 210,360,48,"failed",RED,GRAY); curl_easy_cleanup(curl); fclose( fp ); unlink( "/var/tmp/trash" ); LoadHScore(); return; #endif // HAVE_CURL }