#include #include #include #include #include #include #include #include #include #include "clock.h" #define GRID_H 10 #define GRID_W 16 #define CELL_SIZE 15 #define SCREEN_W 396 #define SCREEN_H 224 #define GRID_CENTER_X (SCREEN_W/2-40) #define GRID_Y (SCREEN_H-14) SDL_Surface* screen = NULL; SDL_Surface* background = NULL; SDL_Surface* blocks = NULL; cSDL_Font *font; typedef struct { char color; bool marked; bool next; } block; block GridBoard[GRID_W][GRID_H]; uint32_t timerstart=0; uint32_t currenttimer=0; float currentX=0; uint32_t time_frame=0; void drawGrid( SDL_Surface *surf ) { for(int x=0; xGRID_W*CELL_SIZE) x=0; *currentpositionX=x; for(int y=1; y<20; y++) if (x-y>=0) lineRGBA( surf, GRID_CENTER_X-GRID_W/2*CELL_SIZE+x-y, GRID_Y-GRID_H*CELL_SIZE-1, GRID_CENTER_X-GRID_W/2*CELL_SIZE+x-y, GRID_Y+1, 255, 255, 0, 255-y*10 ); else lineRGBA( surf, GRID_CENTER_X+GRID_W/2*CELL_SIZE+x-y, GRID_Y-GRID_H*CELL_SIZE-1, GRID_CENTER_X+GRID_W/2*CELL_SIZE+x-y, GRID_Y+1, 255, 255, 0, 255-y*10 ); lineRGBA( surf, GRID_CENTER_X-GRID_W/2*CELL_SIZE+x, GRID_Y-GRID_H*CELL_SIZE-1, GRID_CENTER_X-GRID_W/2*CELL_SIZE+x, GRID_Y+1, 255, 255, 0, 255 ); lineRGBA( surf, GRID_CENTER_X-GRID_W/2*CELL_SIZE+x+1, GRID_Y-GRID_H*CELL_SIZE-1, GRID_CENTER_X-GRID_W/2*CELL_SIZE+x+1, GRID_Y+1, 255, 255, 0, 255 ); } void initBoard( void ) { srand( 0 ); for(int x=0; x9) GridBoard[x][y].color=9; GridBoard[x][y].marked = false; GridBoard[x][y].next = false; } } } void drawBlockGrid( SDL_Surface *surf ) { for(int x=0; xformat, SDL_SWSURFACE ); //if (!background) return 1; blocks = SDL_ConvertSurface( (SDL_Surface*) gint_world_switch( GINT_CALL( IMG_Load, "./Lumines/Blocks/test.png" ) ), screen->format, SDL_SWSURFACE ); //if (!blocks) return 1; initBoard( ); timerstart=0; bool done = false; while (!done) { perf = prof_make(); prof_enter(perf); currenttimer=SDL_GetTicks(); uint32_t deltatimer = currenttimer-timerstart; timerstart=currenttimer; // message processing loop SDL_Event event; while (SDL_PollEvent(&event)) { // check for messages switch (event.type) { // exit if the window is closed case SDL_QUIT: done = true; break; // check for keypresses case SDL_KEYDOWN: { // exit if ESCAPE is pressed if (event.key.keysym.sym == SDLK_PRZ_KEY_EXIT) done = true; break; } } // end switch } // end of message processing //SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 127, 127, 127)); drawBackground( screen ); drawGrid( screen ); /* drawBlock( screen, 0, 0, 0 ); drawBlock( screen, 0, 1, 1 ); drawBlock( screen, 2, 0, 2 ); drawBlock( screen, 2, 1, 3 ); drawBlock( screen, 4, 0, 4 ); drawBlock( screen, 4, 1, 5 ); drawBlock( screen, 6, 0, 6 ); drawBlock( screen, 6, 1, 7 ); drawBlock( screen, 8, 0, 8 ); drawBlock( screen, 8, 1, 9 ); */ drawBlockGrid( screen ); checkSquareGroups( screen, currentX ); updateColumn( screen, currentX ); drawSweepLine( screen, deltatimer, 1, ¤tX ); cSDL_DrawString( screen, font, 10, 10, "Delta t: %d", time_frame/1000 ); cSDL_DrawString( screen, font, 10, 20, "Hello !!" ); SDL_Flip(screen); prof_leave(perf); time_frame = prof_time(perf); } // end main loop SDL_FreeSurface( blocks ); SDL_FreeSurface( background ); cSDL_FreeFont( font ); SDL_Quit(); clock_overclock( levelOCinit ); return 0; }