int main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading"); const char msgBm[64] = "THIS IS AN AngelCode SPRITE FONT"; const char msgTtf[64] = "THIS SPRITE FONT has been GENERATED from a TTF"; // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) SpriteFont fontBm = LoadSpriteFont("resources/fonts/bmfont.fnt"); // BMFont (AngelCode) SpriteFont fontTtf = LoadSpriteFont("resources/fonts/pixantiqua.ttf"); // TTF font Vector2 fontPosition; fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.size, 0).x/2; fontPosition.y = screenHeight/2 - fontBm.size/2 - 80; SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // TODO: Update variables here... //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawTextEx(fontBm, msgBm, fontPosition, fontBm.size, 0, MAROON); DrawTextEx(fontTtf, msgTtf, (Vector2){ 75.0f, 240.0f }, fontTtf.size*0.8f, 2, LIME); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadSpriteFont(fontBm); // AngelCode SpriteFont unloading UnloadSpriteFont(fontTtf); // TTF SpriteFont unloading CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
//---------------------------------------------------------------------------------- // Main entry point //---------------------------------------------------------------------------------- int main(void) { // Initialization //--------------------------------------------------------- const char windowTitle[30] = "SKULLY ESCAPE [KING GAMEJAM]"; InitWindow(screenWidth, screenHeight, windowTitle); // Global data loading (assets that must be available in all screens, i.e. fonts) InitAudioDevice(); music = LoadMusicStream("resources/audio/come_play_with_me.ogg"); PlayMusicStream(music); font = LoadSpriteFont("resources/textures/alagard.png"); doors = LoadTexture("resources/textures/doors.png"); sndDoor = LoadSound("resources/audio/door.ogg"); sndScream = LoadSound("resources/audio/scream.ogg"); InitPlayer(); // Setup and Init first screen currentScreen = LOGO; InitLogoScreen(); #if defined(PLATFORM_WEB) emscripten_set_main_loop(UpdateDrawFrame, 0, 1); #else SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { UpdateDrawFrame(); } #endif // De-Initialization //-------------------------------------------------------------------------------------- // Unload all global loaded data (i.e. fonts) here! UnloadPlayer(); UnloadSpriteFont(font); UnloadTexture(doors); UnloadSound(sndDoor); UnloadSound(sndScream); UnloadMusicStream(music); CloseAudioDevice(); CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
int main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite fonts usage"); const char msg1[50] = "THIS IS A custom SPRITE FONT..."; const char msg2[50] = "...and this is ANOTHER CUSTOM font..."; const char msg3[50] = "...and a THIRD one! GREAT! :D"; // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) SpriteFont font1 = LoadSpriteFont("resources/fonts/custom_mecha.png"); // SpriteFont loading SpriteFont font2 = LoadSpriteFont("resources/fonts/custom_alagard.png"); // SpriteFont loading SpriteFont font3 = LoadSpriteFont("resources/fonts/custom_jupiter_crash.png"); // SpriteFont loading Vector2 fontPosition1, fontPosition2, fontPosition3; fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, font1.size, -3).x/2; fontPosition1.y = screenHeight/2 - font1.size/2 - 80; fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, font2.size, -2).x/2; fontPosition2.y = screenHeight/2 - font2.size/2 - 10; fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, font3.size, 2).x/2; fontPosition3.y = screenHeight/2 - font3.size/2 + 50; //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // TODO: Update variables here... //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawTextEx(font1, msg1, fontPosition1, font1.size, -3, WHITE); DrawTextEx(font2, msg2, fontPosition2, font2.size, -2, WHITE); DrawTextEx(font3, msg3, fontPosition3, font3.size, 2, WHITE); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadSpriteFont(font1); // SpriteFont unloading UnloadSpriteFont(font2); // SpriteFont unloading UnloadSpriteFont(font3); // SpriteFont unloading CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
int main() { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 1280; const int screenHeight = 720; // Init window ShowLogo(); InitWindow(screenWidth, screenHeight, "Dr. Turtle & Mr. GAMERA"); // Initialize audio device InitAudioDevice(); // Load game resources: textures Texture2D sky = LoadTexture("resources/sky.png"); Texture2D mountains = LoadTexture("resources/mountains.png"); Texture2D sea = LoadTexture("resources/sea.png"); Texture2D title = LoadTexture("resources/title.png"); Texture2D turtle = LoadTexture("resources/turtle.png"); Texture2D gamera = LoadTexture("resources/gamera.png"); Texture2D shark = LoadTexture("resources/shark.png"); Texture2D orca = LoadTexture("resources/orca.png"); Texture2D swhale = LoadTexture("resources/swhale.png"); Texture2D fish = LoadTexture("resources/fish.png"); Texture2D gframe = LoadTexture("resources/gframe.png"); // Load game resources: fonts SpriteFont font = LoadSpriteFont("resources/komika.png"); // Load game resources: sounds Sound eat = LoadSound("resources/eat.wav"); Sound die = LoadSound("resources/die.wav"); Sound growl = LoadSound("resources/gamera.wav"); // Start playing streaming music PlayMusicStream("resources/speeding.ogg"); // Define scrolling variables int backScrolling = 0; int seaScrolling = 0; // Define current screen GameScreen currentScreen = TITLE; // Define player variables int playerRail = 1; Rectangle playerBounds = { 30 + 14, playerRail*120 + 90 + 14, 100, 100 }; bool gameraMode = false; // Define enemies variables Rectangle enemyBounds[MAX_ENEMIES]; int enemyRail[MAX_ENEMIES]; int enemyType[MAX_ENEMIES]; bool enemyActive[MAX_ENEMIES]; float enemySpeed = 10; // Init enemies variables for (int i = 0; i < MAX_ENEMIES; i++) { // Define enemy type (all same probability) //enemyType[i] = GetRandomValue(0, 3); // Probability system for enemies type int enemyProb = GetRandomValue(0, 100); if (enemyProb < 30) enemyType[i] = 0; else if (enemyProb < 60) enemyType[i] = 1; else if (enemyProb < 90) enemyType[i] = 2; else enemyType[i] = 3; // define enemy rail enemyRail[i] = GetRandomValue(0, 4); // Make sure not two consecutive enemies in the same row if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4); enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 }; enemyActive[i] = false; } // Define additional game variables int score = 0; float distance = 0.0f; int hiscore = 0; float hidistance = 0.0f; int foodBar = 0; int framesCounter = 0; unsigned char blue = 200; float timeCounter = 0; SetTargetFPS(60); // Setup game frames per second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- framesCounter++; // Sea color tint effect blue = 210 + 25 * sin(timeCounter); timeCounter += 0.01; // Game screens management switch (currentScreen) { case TITLE: { // Sea scrolling seaScrolling -= 2; if (seaScrolling <= -screenWidth) seaScrolling = 0; // Press enter to change to gameplay screen if (IsKeyPressed(KEY_ENTER)) { currentScreen = GAMEPLAY; framesCounter = 0; } } break; case GAMEPLAY: { // Background scrolling logic backScrolling--; if (backScrolling <= -screenWidth) backScrolling = 0; // Sea scrolling logic seaScrolling -= (enemySpeed - 2); if (seaScrolling <= -screenWidth) seaScrolling = 0; // Player movement logic if (IsKeyPressed(KEY_DOWN)) playerRail++; else if (IsKeyPressed(KEY_UP)) playerRail--; // Check player not out of rails if (playerRail > 4) playerRail = 4; else if (playerRail < 0) playerRail = 0; // Update player bounds playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 }; // Enemies activation logic (every 40 frames) if (framesCounter > 40) { for (int i = 0; i < MAX_ENEMIES; i++) { if (enemyActive[i] == false) { enemyActive[i] = true; i = MAX_ENEMIES; } } framesCounter = 0; } // Enemies logic for (int i = 0; i < MAX_ENEMIES; i++) { if (enemyActive[i]) { enemyBounds[i].x -= enemySpeed; } // Check enemies out of screen if (enemyBounds[i].x <= 0 - 128) { enemyActive[i] = false; enemyType[i] = GetRandomValue(0, 3); enemyRail[i] = GetRandomValue(0, 4); // Make sure not two consecutive enemies in the same row if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4); enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 }; } } if (!gameraMode) enemySpeed += 0.005; // Check collision player vs enemies for (int i = 0; i < MAX_ENEMIES; i++) { if (enemyActive[i]) { if (CheckCollisionRecs(playerBounds, enemyBounds[i])) { if (enemyType[i] < 3) // Bad enemies { if (gameraMode) { if (enemyType[i] == 0) score += 50; else if (enemyType[i] == 1) score += 150; else if (enemyType[i] == 2) score += 300; foodBar += 15; enemyActive[i] = false; // After enemy deactivation, reset enemy parameters to be reused enemyType[i] = GetRandomValue(0, 3); enemyRail[i] = GetRandomValue(0, 4); // Make sure not two consecutive enemies in the same row if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4); enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 }; PlaySound(eat); } else { // Player die logic PlaySound(die); currentScreen = ENDING; framesCounter = 0; // Save hiscore and hidistance for next game if (score > hiscore) hiscore = score; if (distance > hidistance) hidistance = distance; } } else // Sweet fish { enemyActive[i] = false; enemyType[i] = GetRandomValue(0, 3); enemyRail[i] = GetRandomValue(0, 4); // Make sure not two consecutive enemies in the same row if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4); enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 }; if (!gameraMode) foodBar += 80; else foodBar += 25; score += 10; if (foodBar == 400) { gameraMode = true; PlaySound(growl); } PlaySound(eat); } } } } // Gamera mode logic if (gameraMode) { foodBar--; if (foodBar <= 0) { gameraMode = false; enemySpeed -= 2; if (enemySpeed < 10) enemySpeed = 10; } } // Update distance counter distance += 0.5f; } break; case ENDING: { // Press enter to play again if (IsKeyPressed(KEY_ENTER)) { currentScreen = GAMEPLAY; // Reset player playerRail = 1; playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 }; gameraMode = false; // Reset enemies data for (int i = 0; i < MAX_ENEMIES; i++) { int enemyProb = GetRandomValue(0, 100); if (enemyProb < 30) enemyType[i] = 0; else if (enemyProb < 60) enemyType[i] = 1; else if (enemyProb < 90) enemyType[i] = 2; else enemyType[i] = 3; //enemyType[i] = GetRandomValue(0, 3); enemyRail[i] = GetRandomValue(0, 4); // Make sure not two consecutive enemies in the same row if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4); enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 }; enemyActive[i] = false; } enemySpeed = 10; // Reset game variables score = 0; distance = 0.0; foodBar = 0; framesCounter = 0; } } break; default: break; } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); // Draw background (common to all screens) DrawTexture(sky, 0, 0, WHITE); DrawTexture(mountains, backScrolling, 0, WHITE); DrawTexture(mountains, screenWidth + backScrolling, 0, WHITE); if (!gameraMode) { DrawTexture(sea, seaScrolling, 0, (Color){ 16, 189, blue, 255}); DrawTexture(sea, screenWidth + seaScrolling, 0, (Color){ 16, 189, blue, 255}); } else { DrawTexture(sea, seaScrolling, 0, (Color){ 255, 113, 66, 255}); DrawTexture(sea, screenWidth + seaScrolling, 0, (Color){ 255, 113, 66, 255}); } switch (currentScreen) { case TITLE: { // Draw title DrawTexture(title, screenWidth/2 - title.width/2, screenHeight/2 - title.height/2 - 80, WHITE); // Draw blinking text if ((framesCounter/30) % 2) DrawTextEx(font, "PRESS ENTER", (Vector2){ screenWidth/2 - 150, 480 }, GetFontBaseSize(font), 0, WHITE); } break; case GAMEPLAY: { // Draw water lines for (int i = 0; i < 5; i++) DrawRectangle(0, i*120 + 120, screenWidth, 110, Fade(SKYBLUE, 0.1f)); // Draw player if (!gameraMode) DrawTexture(turtle, playerBounds.x - 14, playerBounds.y - 14, WHITE); else DrawTexture(gamera, playerBounds.x - 64, playerBounds.y - 64, WHITE); // Draw player bounding box //if (!gameraMode) DrawRectangleRec(playerBounds, Fade(GREEN, 0.4f)); //else DrawRectangleRec(playerBounds, Fade(ORANGE, 0.4f)); // Draw enemies for (int i = 0; i < MAX_ENEMIES; i++) { if (enemyActive[i]) { // Draw enemies switch(enemyType[i]) { case 0: DrawTexture(shark, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break; case 1: DrawTexture(orca, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break; case 2: DrawTexture(swhale, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break; case 3: DrawTexture(fish, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break; default: break; } // Draw enemies bounding boxes /* switch(enemyType[i]) { case 0: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break; case 1: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break; case 2: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break; case 3: DrawRectangleRec(enemyBounds[i], Fade(GREEN, 0.5f)); break; default: break; } */ } } // Draw gameplay interface DrawRectangle(20, 20, 400, 40, Fade(GRAY, 0.4f)); DrawRectangle(20, 20, foodBar, 40, ORANGE); DrawRectangleLines(20, 20, 400, 40, BLACK); DrawTextEx(font, FormatText("SCORE: %04i", score), (Vector2){ screenWidth - 300, 20 }, GetFontBaseSize(font), -2, ORANGE); DrawTextEx(font, FormatText("DISTANCE: %04i", (int)distance), (Vector2){ 550, 20 }, GetFontBaseSize(font), -2, ORANGE); if (gameraMode) { DrawText("GAMERA MODE", 60, 22, 40, GRAY); DrawTexture(gframe, 0, 0, Fade(WHITE, 0.5f)); } } break; case ENDING: { // Draw a transparent black rectangle that covers all screen DrawRectangle(0, 0, screenWidth, screenHeight, Fade(BLACK, 0.4f)); DrawTextEx(font, "GAME OVER", (Vector2){ 300, 160 }, GetFontBaseSize(font)*3, -2, MAROON); DrawTextEx(font, FormatText("SCORE: %04i", score), (Vector2){ 680, 350 }, GetFontBaseSize(font), -2, GOLD); DrawTextEx(font, FormatText("DISTANCE: %04i", (int)distance), (Vector2){ 290, 350 }, GetFontBaseSize(font), -2, GOLD); DrawTextEx(font, FormatText("HISCORE: %04i", hiscore), (Vector2){ 665, 400 }, GetFontBaseSize(font), -2, ORANGE); DrawTextEx(font, FormatText("HIDISTANCE: %04i", (int)hidistance), (Vector2){ 270, 400 }, GetFontBaseSize(font), -2, ORANGE); // Draw blinking text if ((framesCounter/30) % 2) DrawTextEx(font, "PRESS ENTER to REPLAY", (Vector2){ screenWidth/2 - 250, 520 }, GetFontBaseSize(font), -2, LIGHTGRAY); } break; default: break; } EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- // Unload textures UnloadTexture(sky); UnloadTexture(mountains); UnloadTexture(sea); UnloadTexture(gframe); UnloadTexture(title); UnloadTexture(turtle); UnloadTexture(shark); UnloadTexture(orca); UnloadTexture(swhale); UnloadTexture(fish); UnloadTexture(gamera); // Unload font texture UnloadSpriteFont(font); // Unload sounds UnloadSound(eat); UnloadSound(die); UnloadSound(growl); StopMusicStream(); // Stop music CloseAudioDevice(); // Close audio device CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
//---------------------------------------------------------------------------------- // Main entry point //---------------------------------------------------------------------------------- int main() { // Initialization //-------------------------------------------------------------------------------------- const char windowTitle[30] = "raylib functionality demo"; //SetupFlags(FLAG_FULLSCREEN_MODE); InitWindow(screenWidth, screenHeight, windowTitle); InitAudioDevice(); // Initialize audio device // TITLE screen variables Initialization fontAlagard = LoadSpriteFont("resources/fonts/alagard.rbmf"); // rBMF font loading fontPixelplay = LoadSpriteFont("resources/fonts/pixelplay.rbmf"); // rBMF font loading fontMecha = LoadSpriteFont("resources/fonts/mecha.rbmf"); // rBMF font loading fontSetback = LoadSpriteFont("resources/fonts/setback.rbmf"); // rBMF font loading fontRomulus = LoadSpriteFont("resources/fonts/romulus.rbmf"); // rBMF font loading pongBallPosition = (Vector2){ screenWidth/2, screenHeight/2 + 20 }; pongBallSpeed = (Vector2){ 6, 6 }; pongPlayerRec = (Rectangle){ 20, screenHeight/2 - 50 + 40, 20, 100 }; pongEnemyRec = (Rectangle){ screenWidth - 40, screenHeight/2 - 60, 20, 120 }; // LOGO screen variables Initialization logoPositionX = screenWidth/2 - 128; logoPositionY = screenHeight/2 - 128; // MODULES screen variables Initialization raylibWindow = LoadTexture("resources/raylib_window.png"); raylibWindow01 = LoadTexture("resources/raylib_window_01.png"); raylibWindow02 = LoadTexture("resources/raylib_window_02.png"); raylibWindow03 = LoadTexture("resources/raylib_window_03.png"); platforms = LoadTexture("resources/platforms.png"); raylibLogoB = LoadTexture("resources/raylib_logo128x128.png"); lena = LoadTexture("resources/lena.png"); mandrill = LoadTexture("resources/mandrill.png"); texAlagard = LoadTexture("resources/fonts/custom_alagard.png"); fontMechaC = LoadSpriteFont("resources/fonts/custom_mecha.png"); fontAlagardC = LoadSpriteFont("resources/fonts/custom_alagard.png"); fontJupiterC = LoadSpriteFont("resources/fonts/custom_jupiter_crash.png"); ballPosition = (Vector2){ 520 + 656/2, 220 + 399/2 }; camera = (Camera){{ 0.0, 12.0, 15.0 }, { 0.0, 3.0, 0.0 }, { 0.0, 1.0, 0.0 }}; catTexture = LoadTexture("resources/catsham.png"); // Load model texture cat = LoadModel("resources/cat.obj"); // Load OBJ model SetModelTexture(&cat, catTexture); fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file for (int i = 0; i < MAX_BALLS; i++) { soundBallsPosition[i] = (Vector2){ 650 + 560/2 + GetRandomValue(-280, 280), 220 + 200 + GetRandomValue(-200, 200) }; soundBallsColor[i] = (Color){ GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255 }; soundBallsRadius[i] = GetRandomValue(2, 50); soundBallsAlpha[i] = 1.0f; soundBallsActive[i] = false; } // ENDING screen variables Initialization raylibLogoA = LoadTexture("resources/raylib_logo.png"); #ifndef PLATFORM_WEB SetTargetFPS(60); #endif #if defined(PLATFORM_WEB) emscripten_set_main_loop(UpdateDrawOneFrame, 0, 1); #else //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose() && !closeWindow) // Detect window close button or ESC key { UpdateDrawOneFrame(); } #endif // De-Initialization //-------------------------------------------------------------------------------------- // Unload all loaded data (textures, fonts, audio) UnloadSpriteFont(fontAlagard); // SpriteFont unloading UnloadSpriteFont(fontPixelplay); // SpriteFont unloading UnloadSpriteFont(fontMecha); // SpriteFont unloading UnloadSpriteFont(fontSetback); // SpriteFont unloading UnloadSpriteFont(fontRomulus); // SpriteFont unloading UnloadTexture(raylibWindow); UnloadTexture(raylibWindow01); UnloadTexture(raylibWindow02); UnloadTexture(raylibWindow03); UnloadTexture(platforms); UnloadTexture(raylibLogoA); UnloadTexture(raylibLogoB); UnloadTexture(lena); UnloadTexture(mandrill); UnloadTexture(texAlagard); UnloadSpriteFont(fontMechaC); UnloadSpriteFont(fontAlagardC); UnloadSpriteFont(fontJupiterC); UnloadTexture(catTexture); UnloadModel(cat); UnloadSound(fxWav); UnloadSound(fxOgg); CloseAudioDevice(); CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
//---------------------------------------------------------------------------------- // Main entry point //---------------------------------------------------------------------------------- int main(void) { // Initialization //--------------------------------------------------------- InitWindow(screenWidth, screenHeight, "GGJ16 - LIGHT MY RITUAL!"); // Global data loading (assets that must be available in all screens, i.e. fonts) InitAudioDevice(); Image image = LoadImage("resources/lights_map.png"); // Load image in CPU memory (RAM) lightsMap = GetImageData(image); // Get image pixels data as an array of Color lightsMapWidth = image.width; lightsMapHeight = image.height; UnloadImage(image); // Unload image from CPU memory (RAM) //PlayMusicStream("resources/audio/come_play_with_me.ogg"); font = LoadSpriteFont("resources/font_arcadian.png"); //doors = LoadTexture("resources/textures/doors.png"); //sndDoor = LoadSound("resources/audio/door.ogg"); // Setup and Init first screen currentScreen = LOGO_RL; //InitTitleScreen(); //InitGameplayScreen(); rlInitLogoScreen(); #if defined(PLATFORM_WEB) emscripten_set_main_loop(UpdateDrawFrame, 0, 1); #else SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { UpdateDrawFrame(); } #endif // De-Initialization //-------------------------------------------------------------------------------------- switch (currentScreen) { case LOGO_RL: rlUnloadLogoScreen(); break; case TITLE: UnloadTitleScreen(); break; case GAMEPLAY: UnloadGameplayScreen(); break; default: break; } // Unload all global loaded data (i.e. fonts) here! UnloadSpriteFont(font); //UnloadSound(sndDoor); free(lightsMap); CloseAudioDevice(); CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
// Load a BMFont file (AngelCode font file) static SpriteFont LoadBMFont(const char *fileName) { #define MAX_BUFFER_SIZE 256 SpriteFont font = { 0 }; font.texture.id = 0; char buffer[MAX_BUFFER_SIZE]; char *searchPoint = NULL; int fontSize = 0; int texWidth, texHeight; char texFileName[128]; int numChars = 0; int base; // Useless data FILE *fntFile; fntFile = fopen(fileName, "rt"); if (fntFile == NULL) { TraceLog(WARNING, "[%s] FNT file could not be opened", fileName); return font; } // NOTE: We skip first line, it contains no useful information fgets(buffer, MAX_BUFFER_SIZE, fntFile); //searchPoint = strstr(buffer, "size"); //sscanf(searchPoint, "size=%i", &fontSize); fgets(buffer, MAX_BUFFER_SIZE, fntFile); searchPoint = strstr(buffer, "lineHeight"); sscanf(searchPoint, "lineHeight=%i base=%i scaleW=%i scaleH=%i", &fontSize, &base, &texWidth, &texHeight); TraceLog(DEBUG, "[%s] Font size: %i", fileName, fontSize); TraceLog(DEBUG, "[%s] Font texture scale: %ix%i", fileName, texWidth, texHeight); fgets(buffer, MAX_BUFFER_SIZE, fntFile); searchPoint = strstr(buffer, "file"); sscanf(searchPoint, "file=\"%128[^\"]\"", texFileName); TraceLog(DEBUG, "[%s] Font texture filename: %s", fileName, texFileName); fgets(buffer, MAX_BUFFER_SIZE, fntFile); searchPoint = strstr(buffer, "count"); sscanf(searchPoint, "count=%i", &numChars); TraceLog(DEBUG, "[%s] Font num chars: %i", fileName, numChars); // Compose correct path using route of .fnt file (fileName) and texFileName char *texPath = NULL; char *lastSlash = NULL; lastSlash = strrchr(fileName, '/'); // NOTE: We need some extra space to avoid memory corruption on next allocations! texPath = malloc(strlen(fileName) - strlen(lastSlash) + strlen(texFileName) + 4); // NOTE: strcat() and strncat() required a '\0' terminated string to work! *texPath = '\0'; strncat(texPath, fileName, strlen(fileName) - strlen(lastSlash) + 1); strncat(texPath, texFileName, strlen(texFileName)); TraceLog(DEBUG, "[%s] Font texture loading path: %s", fileName, texPath); Image imFont = LoadImage(texPath); if (imFont.format == UNCOMPRESSED_GRAYSCALE) { Image imCopy = ImageCopy(imFont); for (int i = 0; i < imCopy.width*imCopy.height; i++) ((unsigned char *)imCopy.data)[i] = 0xff; // WHITE pixel ImageAlphaMask(&imCopy, imFont); font.texture = LoadTextureFromImage(imCopy); UnloadImage(imCopy); } else font.texture = LoadTextureFromImage(imFont); font.size = fontSize; font.numChars = numChars; font.charValues = (int *)malloc(numChars*sizeof(int)); font.charRecs = (Rectangle *)malloc(numChars*sizeof(Rectangle)); font.charOffsets = (Vector2 *)malloc(numChars*sizeof(Vector2)); font.charAdvanceX = (int *)malloc(numChars*sizeof(int)); UnloadImage(imFont); free(texPath); int charId, charX, charY, charWidth, charHeight, charOffsetX, charOffsetY, charAdvanceX; for (int i = 0; i < numChars; i++) { fgets(buffer, MAX_BUFFER_SIZE, fntFile); sscanf(buffer, "char id=%i x=%i y=%i width=%i height=%i xoffset=%i yoffset=%i xadvance=%i", &charId, &charX, &charY, &charWidth, &charHeight, &charOffsetX, &charOffsetY, &charAdvanceX); // Save data properly in sprite font font.charValues[i] = charId; font.charRecs[i] = (Rectangle){ charX, charY, charWidth, charHeight }; font.charOffsets[i] = (Vector2){ (float)charOffsetX, (float)charOffsetY }; font.charAdvanceX[i] = charAdvanceX; } fclose(fntFile); if (font.texture.id == 0) { UnloadSpriteFont(font); font = GetDefaultFont(); } else TraceLog(INFO, "[%s] SpriteFont loaded successfully", fileName); return font; }