#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) cSDL_Font *font; bool dropped = false; unsigned char curBlockX=6; unsigned char curBlockY=10; unsigned char curBlock[2][2]; unsigned char next1block[2][2]; unsigned char next2block[2][2]; unsigned char next3block[2][2]; SDL_Surface* screen = NULL; SDL_Surface* background = NULL; SDL_Surface* blocks = NULL; typedef struct { int8_t color; bool marked; } block; block GridBoard[GRID_W][GRID_H]; typedef struct { float x; float speed; uint8_t column; uint8_t positionincolumn; } sweepline; sweepline Sweeper; 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; Sweeper.x=x; Sweeper.column = ((int) Sweeper.x) / CELL_SIZE; Sweeper.positionincolumn = ((int) Sweeper.x) % CELL_SIZE; 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; } } for(int x=0; x<2; x++) { for(int y=0; y<2; y++) { curBlock[x][y] = (char) rand()%2; next1block[x][y] = (char) rand()%2; next2block[x][y] = (char) rand()%2; next3block[x][y] = (char) rand()%2; } } } void drawCurBlocks( SDL_Surface *surf ) { for(int x=0; x<2; x++) { for(int y=0; y<2; y++) { } } } void drawBlockGrid( SDL_Surface *surf ) { for(int x=0; x=Sweeper.column) for(int y=0; yformat, 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( ); Sweeper.x=0.0f; Sweeper.speed=1.0f; 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 ); drawSweepLine( screen, deltatimer ); checkSquareGroups( screen ); updateColumn( ); 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; }