int GameMoveSelectedBall() { int ball; // Check move rules; return 0 if the move isn't valid if (!GameCheckPathExists(g_TileSelectX, g_TileSelectY, g_TileCursorX, g_TileCursorY)) return 0; g_okShowTileCursor = 0; // Hide cursor ball = g_Board[g_TileSelectY][g_TileSelectX]; g_Board[g_TileSelectY][g_TileSelectX] = BALL_NONE; g_TileSelectX = g_TileSelectY = -1; // Clear selection DrawGameScreen(); SDL_Flip(g_pSurface); SDL_Delay(100); g_Board[g_TileCursorY][g_TileCursorX] = ball; DrawGameScreen(); SDL_Flip(g_pSurface); SDL_Delay(100); g_okShowTileCursor = 1; // Show cursor return 1; }
void GameStart() { // Clear board memset(g_Board, 0, sizeof(g_Board)); // Clear score g_Score = 0; g_KingScore = 100; //TODO g_TileCursorX = g_TileCursorY = 4; // Cursor to center of the board g_okShowTileCursor = 0; // Hide cursor g_TileSelectX = g_TileSelectY = -1; // No selection g_NextColors[0] = rand() % BALLCOLORCOUNT + 1; g_NextColors[1] = rand() % BALLCOLORCOUNT + 1; g_NextColors[2] = rand() % BALLCOLORCOUNT + 1; DrawGameScreen(); SDL_Flip(g_pSurface); SDL_Delay(100); // Put first three random balls GamePutThreeRandomBalls(); g_okShowTileCursor = 1; // Show cursor g_GameMode = GAMEMODE_PLAY; }
void GamePutThreeRandomBalls() { int i; for (i = 0; i < 3; i++) { GamePutRandomBall(); DrawGameScreen(); SDL_Flip(g_pSurface); SDL_Delay(100); } }
// the render function // is called for every frame update // cointains a variable called screen which we have used to set multiple screens up // we have the game screen // and the about screen void RenderScreen(int Screen) { switch(Screen) { case ID_GAME: { DrawGameScreen(); // call to DrawGameScreen function } break; case ID_ABOUT: { DrawAboutScreen(); // call to DrawAboutScreen function } break; } }
void onScreenRender() { printf("onRender()\n"); glClearColor(1, 1, 1, 0); glClear(GL_COLOR_BUFFER_BIT); if (Window == W_MAINMENU) { DrawMainMenuScreen(); } else if (Window == W_GAME) { DrawGameScreen(); } else if (Window == W_GAMESETTINGS) { DrawGameSettingsScreen(); } else if (Window == W_HIGHSCORES) { DrawHighScoresScreen(); } else if (Window == W_CHAMPION) { DrawChampionScreen(); } else { printf("Unknown window value\n"); } glutSwapBuffers(); }
int main(int argc, char * argv[]) { int flags = 0; SDL_Event evt; SDL_Surface *tempSurface; #ifdef _WIN32 _putenv("SDL_VIDEO_WINDOW_POS=250,200"); #endif // Init randomizer srand(SDL_GetTicks()); // Init SDL video if (SDL_Init(SDL_INIT_VIDEO) < 0) return 255; // Unable to initialize SDL // Prepare screen surface g_pSurface = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, flags); if (g_pSurface == NULL) return 254; // Unable to set video mode #ifdef _WIN32 SDL_WM_SetCaption("Color Lines SDL", "Color Lines SDL"); #else SDL_ShowCursor(SDL_DISABLE); #endif // Load font tempSurface = SDL_LoadBMP("ColorLinesData/font.bmp"); if (tempSurface == NULL) return 253; // Unable to load bitmap g_pFont = SDL_DisplayFormat(tempSurface); SDL_FreeSurface(tempSurface); // Load sprites tempSurface = SDL_LoadBMP("ColorLinesData/sprites.bmp"); if (tempSurface == NULL) return 253; // Unable to load bitmap g_pSprites = SDL_DisplayFormat(tempSurface); SDL_FreeSurface(tempSurface); MenuStart(); while (!g_okQuit) { while (SDL_PollEvent(&evt)) { if (evt.type == SDL_QUIT) { g_okQuit = 1; break; } else { if (g_GameMode == GAMEMODE_MENU) MenuProcessEvent(evt); else GameProcessEvent(evt); } } if (g_GameMode == GAMEMODE_PLAY) { DrawGameScreen(); SDL_Flip(g_pSurface); } SDL_Delay(20); } SDL_FreeSurface(g_pSprites); SDL_FreeSurface(g_pFont); SDL_Quit(); return 0; }
int GameCheckToRemove() { int i, j, c, dx, dy; int ball, count; int bestball, bestcount, bestx = 0, besty = 0, bestdx = 0, bestdy = 0; bestball = BALL_NONE; bestcount = 0; // Check horizontal lines for (i = 0; i < 9; i++) { ball = BALL_NONE; count = 0; for (j = 0; j < 9; j++) { if (ball != BALL_NONE && g_Board[i][j] == ball) count++; else { if (count >= 5 && count > bestcount) { bestball = ball; bestcount = count; bestx = j - count; besty = i; bestdx = 1; bestdy = 0; } ball = g_Board[i][j]; count = 1; } } if (count >= 5 && count > bestcount) { bestball = ball; bestcount = count; bestx = j - count; besty = i; bestdx = 1; bestdy = 0; } } // Check vertical lines for (j = 0; j < 9; j++) { ball = BALL_NONE; count = 0; for (i = 0; i < 9; i++) { if (ball != BALL_NONE && g_Board[i][j] == ball) count++; else { if (count >= 5 && count > bestcount) { bestball = ball; bestcount = count; bestx = j; besty = i - count; bestdx = 0; bestdy = 1; } ball = g_Board[i][j]; count = 1; } } if (count >= 5 && count > bestcount) { bestball = ball; bestcount = count; bestx = j; besty = i - count; bestdx = 0; bestdy = 1; } } // Check diagonal lines: from SW to NE dx = 1; dy = -1; for (c = 0; c < 9; c++) { i = (c <= 4) ? c + 4 : 8; j = (c <= 4) ? 0 : c - 4; ball = BALL_NONE; count = 0; for (;;) { if (ball != BALL_NONE && g_Board[i][j] == ball) count++; else { if (count >= 5 && count > bestcount) { bestball = ball; bestcount = count; bestx = j - count; besty = i + count; bestdx = dx; bestdy = dy; } ball = g_Board[i][j]; count = 1; } i += dy; j += dx; if (i >= 9 || j >= 9) { if (count >= 5 && count > bestcount) { bestball = ball; bestcount = count; bestx = j - count; besty = i + count; bestdx = dx; bestdy = dy; } break; } } } // Check diagonal lines: from NW to SE dx = 1; dy = 1; for (c = 0; c < 9; c++) { i = (c <= 4) ? 4 - c : 0; j = (c <= 4) ? 0 : c - 4; ball = BALL_NONE; count = 0; for (;;) { if (ball != BALL_NONE && g_Board[i][j] == ball) count++; else { if (count >= 5 && count > bestcount) { bestball = ball; bestcount = count; bestx = j - count; besty = i - count; bestdx = dx; bestdy = dy; } ball = g_Board[i][j]; count = 1; } i += dy; j += dx; if (i >= 9 || j >= 9) { if (count >= 5 && count > bestcount) { bestball = ball; bestcount = count; bestx = j - count; besty = i - count; bestdx = dx; bestdy = dy; } break; } } } if (bestball == BALL_NONE) return 0; // Balls to remove was not found // Remove the balls i = besty; j = bestx; for (c = 0; c < bestcount; c++) { g_Board[i][j] = BALL_NONE; g_Score += 10; DrawGameScreen(); SDL_Flip(g_pSurface); SDL_Delay(25); i += bestdy; j += bestdx; } return 1; }