Gamestate gamestate_init(){ Gamestate gs; int i; printf("gamestate_init : stub now \n"); gs.playernum = 3; for (i=0; i<gs.playernum; i++){ gs.hand[i] = hands_init(); gs.hand[i]=hands_add(gs.hand[i], i*3); gs.hand[i]=hands_add(gs.hand[i], i*3+1); gs.hand[i]=hands_add(gs.hand[i], i*3+2); gs.passes[i] = 0; gs.win[i] = 0; } gs.lastplayer = gs.playernum; gs.player = gs.playernum; gs.ba = hands_init(); gamestate_display(gs); return gs; }
int main (int argc, char *argv[]) { SDL_Surface *screen; printf ("Initializing SDL.\n"); /* Initializes Audio and the CDROM, add SDL_INIT_VIDEO for Video */ if (SDL_Init(SDL_INIT_VIDEO)< 0) { printf("Could not initialize SDL:%s\n", SDL_GetError()); SDL_Quit(); return 1; } if(TTF_Init() != 0) { printf("Could not initialize TTF:%s\n", SDL_GetError()); return 1; } printf("Video initialized correctly\n"); atexit( SDL_Quit ); printf("SCREENW : %d, SCREENH : %d\n", SCREENW, SCREENW); screen = SDL_SetVideoMode( SCREENW, SCREENH, 16, SDL_HWSURFACE ); SDL_WM_SetCaption( "421", 0 ); if( screen == NULL ) { printf( "Can't set video mode: %s\n", SDL_GetError( ) ); return EXIT_FAILURE; } // Part of the bitmap that we want to draw SDL_Rect bgsource; bgsource.x = 0; bgsource.y = 0; bgsource.w = 1000; bgsource.h = 903; // Part of the screen we want to draw the sprite to SDL_Rect bgdestination; bgdestination.x = 0; bgdestination.y = 0; bgdestination.w = 1000; bgdestination.h = 903; SDL_Surface *background; background = (SDL_Surface*) IMG_Load("pixs/background.png"); background = SDL_DisplayFormat(background); SDL_BlitSurface(background, &bgsource, screen, &bgdestination); SDL_Flip(screen); // Part of the bitmap that we want to draw SDL_Rect d1source; d1source.x = 0; d1source.y = 0; d1source.w = 189; d1source.h = 199; // Part of the screen we want to draw the sprite to SDL_Rect d1destination; d1destination.x = 0; d1destination.y = 0; d1destination.w = 189; d1destination.h = 199; SDL_Surface *dice; dice = (SDL_Surface*) IMG_Load("pixs/dices.png"); dice = SDL_DisplayFormat(dice); Uint32 colorkey = SDL_MapRGB(dice->format, 0, 255, 0); SDL_SetColorKey(dice, SDL_RLEACCEL | SDL_SRCCOLORKEY, colorkey ); bool quit = false; SDL_Event event; struct dice *d1, *d2, *d3; d1 = NULL; d2 = NULL; d3 = NULL; hands *ah; ah = hands_new(); ah = hands_init(ah); hands_print(ah); while(quit == false) { while( SDL_PollEvent( &event ) ) { int x = 0; int y = 0; if(event.type == SDL_MOUSEBUTTONDOWN) { x = event.motion.x; y = event.motion.y; printf("Down (%d, %d)!!!! \n", x, y); //board_click(bd, x/24, y/24); d1 = dice_new(490, 240); d2 = dice_new(340, 340); d3 = dice_new(650, 440); if(!d1->rolling) d1 = dice_roll(d1); if(!d2->rolling) d2 = dice_roll(d2); if(!d3->rolling) d3 = dice_roll(d3); } // User press key if( event.type == SDL_KEYDOWN ) { Uint8 *keystates = SDL_GetKeyState( NULL ); // User press ESCAPE if( keystates[ SDLK_ESCAPE ] ) { quit = true; } } // User press X if( event.type == SDL_QUIT ) { quit = true; } } if(d1 && d2 && d3) if(d1->rolling || d2->rolling || d3->rolling) { SDL_BlitSurface(background, &bgsource, screen, &bgdestination); d1 = dice_check_dices_collisions(d1, d2, d3); d2 = dice_check_dices_collisions(d2, d3, d1); d3 = dice_check_dices_collisions(d3, d1, d2); } if(d1) { if(d1->rolling) d1 = dice_update(d1); d1source.x = d1->imgoffset; d1destination.x = d1->position->x; d1destination.y = d1->position->y; SDL_BlitSurface(dice, &d1source, screen, &d1destination); } if(d2) { if(d2->rolling) d2 = dice_update(d2); d1source.x = d2->imgoffset; d1destination.x = d2->position->x; d1destination.y = d2->position->y; SDL_BlitSurface(dice, &d1source, screen, &d1destination); } if(d3) { if(d3->rolling) d3 = dice_update(d3); d1source.x = d3->imgoffset; d1destination.x = d3->position->x; d1destination.y = d3->position->y; SDL_BlitSurface(dice, &d1source, screen, &d1destination); } SDL_Flip(screen); } return 0; }