Exemple #1
0
// Gameplay Screen Update logic
void UpdateGameplayScreen(void)
{
    
    if (IsKeyPressed('P')) 
    {
        pause = !pause;
        if (!pause) ResumeMusicStream();
        else PauseMusicStream();
    }
    
    if (!pause)
    {     
        if (!startGame && IsKeyPressed(KEY_SPACE)) 
        {
            startGame = TRUE;
            ResumeMusicStream();
        }
        // TODO: Update GAMEPLAY screen variables here!
        if (startGame)
        {
            UpdateMainCamera(&mainCamera);
            
            UpdateTrianglesPosition(mainCamera.position);
            UpdateTrianglesState();
            UpdatePlatformsPosition(mainCamera.position);
            UpdatePlatformsState();
            
            UpdatePlayer(&player);
        }
    }
    // Press enter to change to ENDING screen
    
    /*
    if (IsKeyPressed(KEY_ENTER) || !player.isAlive || mainCamera.position.x/CELL_SIZE>GRID_WIDTH+10)
    {
        finishScreen = 1;
    }
    */
    
    // WIN / LOSE Conditions
    if (!player.isAlive) GameplayEnd(1); // If player dies, reset gameplay screen
    else if (mainCamera.position.x/CELL_SIZE>GRID_WIDTH+20) GameplayEnd(2); // If player reaches the end level (+20 cells) game ends.   
    
    // MusicIsPlaying
    UpdateMusicStream();
}
Exemple #2
0
void GameplayEnd(int next)
{
    PauseMusicStream();
    finishScreen = next;
}
Exemple #3
0
// Gameplay Screen Initialization logic
void InitGameplayScreen(void)
{
    // TODO: Initialize GAMEPLAY screen variables here!
    framesCounter = 0;
    finishScreen = 0;
    
    // MAP LAODING
        // TODO: Read .bmp file propierly in order to get image width & height
    Color *mapPixels = malloc(GRID_WIDTH*GRID_HEIGHT * sizeof(Color));
    mapPixels = GetImageData(LoadImage("assets/gameplay_screen/maps/map.bmp"));
    
    maxTriangles = 0;
    maxPlatforms = 0;
    
    for (int i=0; i<GRID_WIDTH*GRID_HEIGHT; i++)
    {
        /*
        printf("r: %i\n", mapPixels[i].r);
        printf("g: %i\n", mapPixels[i].g);
        printf("b: %i\n\n", mapPixels[i].b);
        */
        if (mapPixels[i].r == 255 && mapPixels[i].g == 0 && mapPixels[i].b == 0) maxTriangles++;
        else if (mapPixels[i].r == 0 && mapPixels[i].g == 255 && mapPixels[i].b == 0) maxPlatforms++;
    }
    
    triangles = malloc(maxTriangles * sizeof(TriangleObject));
    platforms = malloc(maxPlatforms * sizeof(SquareObject));
    
    int trianglesCounter=0;
    int platformsCounter=0;
    
    
    for (int y=0; y<GRID_HEIGHT; y++)
    {
        for (int x=0; x<GRID_WIDTH; x++)
        {
            if (mapPixels[y*GRID_WIDTH+x].r == 255 && mapPixels[y*GRID_WIDTH+x].g == 0 && mapPixels[y*GRID_WIDTH+x].b == 0) 
            {
                InitializeTriangle(&triangles[trianglesCounter], (Vector2){x, y});
                trianglesCounter++;
            }
            else if (mapPixels[y*GRID_WIDTH+x].r == 0 && mapPixels[y*GRID_WIDTH+x].g == 255 && mapPixels[y*GRID_WIDTH+x].b == 0) 
            {
                InitializePlatform(&platforms[platformsCounter], (Vector2){x, y});
                platformsCounter++;
            }
        }
    }
    
    free(mapPixels);
    
    //DEBUGGING && TESTING variables
    pause = FALSE;
    srand(time(NULL)); 
    
    // Textures loading
    player.texture = LoadTexture("assets/gameplay_screen/cube_main.png");
    triangleTexture = LoadTexture("assets/gameplay_screen/triangle_main.png");
    platformTexture = LoadTexture("assets/gameplay_screen/platform_main.png");
    player.pEmitter.texture = LoadTexture("assets/gameplay_screen/particle_main.png");
    
    bg = LoadTexture("assets/gameplay_screen/bg_main.png");
    
    // Sound loading
    InitAudioDevice();
    PlayMusicStream("assets/gameplay_screen/music/Flash_Funk_MarshmelloRemix.ogg");
    PauseMusicStream();
    SetMusicVolume(0.5f);
    
    // Did player win?
    startGame = FALSE;
    
    /*
    player.texture = LoadTexture("assets/gameplay_screen/debug.png");
    triangleTexture = LoadTexture("assets/gameplay_screen/debug.png");
    platformTexture = LoadTexture("assets/gameplay_screen/debug.png");
    player.pEmitter.texture = LoadTexture("assets/gameplay_screen/particle_main.png");
    */
    
    // Camera initialization
    mainCamera = (Camera2D){Vector2Right(), (Vector2){6.5f, 6.5f}, Vector2Zero(), TRUE};
    
    // Gravity initialization
    gravity = (GravityForce){Vector2Up(), 1.5f};
    
    // Ground position and coordinate
    groundCoordinadeY = GetScreenHeight()/CELL_SIZE-1;
    groundPositionY = GetOnGridPosition((Vector2){0, groundCoordinadeY}).y;
    
    // Player initialization
    InitializePlayer(&player, (Vector2){4, groundCoordinadeY-1}, (Vector2){0, 15}, 0.35f*GAME_SPEED);
    
    /*
    // Triangles initialization
    InitializeTriangle(&triangles[0], (Vector2){40, groundCoordinadeY-1});
    InitializeTriangle(&triangles[1], (Vector2){50, groundCoordinadeY-1});
    InitializeTriangle(&triangles[2], (Vector2){85, groundCoordinadeY-1});
    
    // Platforms initialization
    InitializePlatform(&platforms[0], (Vector2){20, groundCoordinadeY-1});
    InitializePlatform(&platforms[1], (Vector2){21, groundCoordinadeY-1});
    InitializePlatform(&platforms[2], (Vector2){22, groundCoordinadeY-1});
    InitializePlatform(&platforms[3], (Vector2){23, groundCoordinadeY-2});
    InitializePlatform(&platforms[4], (Vector2){24, groundCoordinadeY-2});
    */
}
Exemple #4
0
int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    int screenWidth = 800;
    int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)");

    InitAudioDevice();              // Initialize audio device

    PlayMusicStream("resources/audio/guitar_noodling.ogg");         // Play music stream

    int framesCounter = 0;
    float timePlayed = 0.0f;
    //float volume = 1.0;

    SetTargetFPS(60);               // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        framesCounter++;

        // Testing music fading from one file to another
/*
        if (framesCounter > 600)    // Wait for 10 seconds (600 frames)
        {
            volume -= 0.01;         // Decrement music volume level

            // When music volume level equal or lower than 0,
            // restore volume level and init another music file
            if (volume <= 0)
            {
                volume = 1.0;
                framesCounter = 0;
                PlayMusicStream("resources/audio/another_file.ogg");
            }

            SetMusicVolume(volume);
        }
*/
        if (IsWindowMinimized()) PauseMusicStream();
        else ResumeMusicStream();

        timePlayed = GetMusicTimePlayed()/GetMusicTimeLength()*100*4; // We scale by 4 to fit 400 pixels
        
        UpdateMusicStream();        // Update music buffer with new stream data
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(RAYWHITE);

            DrawText("MUSIC SHOULD BE PLAYING!", 255, 200, 20, LIGHTGRAY);

            DrawRectangle(200, 250, 400, 12, LIGHTGRAY);
            DrawRectangle(200, 250, (int)timePlayed, 12, MAROON);

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    CloseAudioDevice();     // Close audio device (music streaming is automatically stopped)

    CloseWindow();          // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}