Beispiel #1
0
// Level07 Screen Update logic
void UpdateLevel07Screen(void)
{
    // Update Level07 screen variables here!
    framesCounter++;
    
    if (!done)
    {
        if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
        {
            if (CheckCollisionPointCircle(GetMousePosition(), leftBtnPos, btnRadius)) leftCircleActive = !leftCircleActive;
            else if (CheckCollisionPointCircle(GetMousePosition(), middleBtnPos, btnRadius)) middleCircleActive = !middleCircleActive;
            else if (CheckCollisionPointCircle(GetMousePosition(), rightBtnPos, btnRadius)) rightCircleActive = !rightCircleActive;
            
            if (rightCircleActive && CheckCollisionPointCircle(GetMousePosition(), leftCirclePos, circleRadius))
            {
                if (CheckColor(leftCircleColor, GRAY)) leftCircleColor = LIGHTGRAY;
                else leftCircleColor = GRAY;
            }
            
            if (middleCircleActive && CheckCollisionPointCircle(GetMousePosition(), middleCirclePos, circleRadius))
            {
                if (CheckColor(middleCircleColor, GRAY)) middleCircleColor = LIGHTGRAY;
                else middleCircleColor = GRAY;
            }
            
            if (rightCircleActive && leftCircleActive && CheckCollisionPointCircle(GetMousePosition(), rightCirclePos, circleRadius))
            {
                if (CheckColor(rightCircleColor, GRAY)) rightCircleColor = LIGHTGRAY;
                else rightCircleColor = GRAY;
            }
        }
    
        // Check all cicles done
        if (CheckColor(leftCircleColor, LIGHTGRAY) && CheckColor(middleCircleColor, LIGHTGRAY) && CheckColor(rightCircleColor, LIGHTGRAY) &&
            !leftCircleActive && !middleCircleActive && !rightCircleActive)
        {
            done = true;
            PlaySound(levelWin);
        }
    }
    
    if (done && !levelFinished)
    {
        levelTimeSec = framesCounter/60;
        levelFinished = true;
        framesCounter = 0;
    }
    
    if (levelFinished)
    {
        framesCounter++;
        
        if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true;
    }
}
Beispiel #2
0
// Level06 Screen Update logic
void UpdateLevel06Screen(void)
{
    // Update Level06 screen variables here!
    framesCounter++;

    if (!done)
    {
        for (int i = 0; i < 4; i++)
        {
            if (!stoppedRec[i]) movingRecs[i].x += speedRecs[i];
            
            if (movingRecs[i].x >= GetScreenWidth()) movingRecs[i].x = -movingRecs[i].width;
            
            if (CheckCollisionPointRec(GetMousePosition(), movingRecs[i]))
            {
                mouseOverNum = i;
                
                if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
                {
                    if (i == 0) stoppedRec[3] = !stoppedRec[3];
                    else if (i == 1) stoppedRec[2] = !stoppedRec[2];
                    else if (i == 2) stoppedRec[0] = !stoppedRec[0];
                    else if (i == 3) stoppedRec[1] = !stoppedRec[1];
                }
            }
        }

        // Check if all boxes are aligned
        if (((movingRecs[0].x > centerRec.x) && ((movingRecs[0].x + movingRecs[0].width) < (centerRec.x + centerRec.width))) &&
            ((movingRecs[1].x > centerRec.x) && ((movingRecs[1].x + movingRecs[1].width) < (centerRec.x + centerRec.width))) &&
            ((movingRecs[2].x > centerRec.x) && ((movingRecs[2].x + movingRecs[2].width) < (centerRec.x + centerRec.width))) &&
            ((movingRecs[3].x > centerRec.x) && ((movingRecs[3].x + movingRecs[3].width) < (centerRec.x + centerRec.width))))
        {
            done = true;
            PlaySound(levelWin);
        }
    }

    
    if (done && !levelFinished)
    {
        levelTimeSec = framesCounter/60;
        levelFinished = true;
        framesCounter = 0;
    }
    
    if (levelFinished)
    {
        framesCounter++;
        
        if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true;
    }
}
Beispiel #3
0
int main(void)
{
    // Initialization
    //--------------------------------------------------------------------------------------
    const int screenWidth = 800;
    const int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input");

    Vector2 ballPosition = { -100.0f, -100.0f };
    Color ballColor = DARKBLUE;

    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
        //----------------------------------------------------------------------------------
        ballPosition = GetMousePosition();

        if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) ballColor = MAROON;
        else if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) ballColor = LIME;
        else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE;
        //----------------------------------------------------------------------------------

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

            ClearBackground(RAYWHITE);

            DrawCircleV(ballPosition, 40, ballColor);

            DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);

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

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

    return 0;
}
Beispiel #4
0
//--------------------------------------------------------------------------------------
// Additional module functions
//--------------------------------------------------------------------------------------
static void UpdateOutgoingFire()
{
    static int interceptorNumber = 0;
    int launcherShooting = 0;

    if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) launcherShooting = 1;
    if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) launcherShooting = 2;
    if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) launcherShooting = 3;

    if (launcherShooting > 0 && launcher[launcherShooting - 1].active)
    {
        float module;
        float sideX;
        float sideY;

        // Activate the interceptor
        interceptor[interceptorNumber].active = true;

        // Assign start position
        interceptor[interceptorNumber].origin = launcher[launcherShooting - 1].position;
        interceptor[interceptorNumber].position = interceptor[interceptorNumber].origin;
        interceptor[interceptorNumber].objective = GetMousePosition();

        // Calculate speed
        module = sqrt( pow(interceptor[interceptorNumber].objective.x - interceptor[interceptorNumber].origin.x, 2) +
                       pow(interceptor[interceptorNumber].objective.y - interceptor[interceptorNumber].origin.y, 2));

        sideX = (interceptor[interceptorNumber].objective.x - interceptor[interceptorNumber].origin.x)*INTERCEPTOR_SPEED/module;
        sideY = (interceptor[interceptorNumber].objective.y - interceptor[interceptorNumber].origin.y)*INTERCEPTOR_SPEED/module;

        interceptor[interceptorNumber].speed = (Vector2){ sideX, sideY };

        // Update
        interceptorNumber++;
        if (interceptorNumber == MAX_INTERCEPTORS) interceptorNumber = 0;
    }
}
Beispiel #5
0
int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    int screenWidth = 800;
    int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input");

    int mouseX, mouseY;
    Vector2 ballPosition = { -100.0, -100.0 };
    //---------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
        {
            mouseX = GetMouseX();
            mouseY = GetMouseY();

            ballPosition.x = (float)mouseX;
            ballPosition.y = (float)mouseY;
        }
        //----------------------------------------------------------------------------------

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

            ClearBackground(RAYWHITE);

            DrawCircleV(ballPosition, 40, GOLD);

            DrawText("mouse click to draw the ball", 10, 10, 20, DARKGRAY);

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

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

    return 0;
}
Beispiel #6
0
// Ending Screen Update logic
void UpdateEndingScreen(void)
{
    // TODO: Update ENDING screen variables here!
    framesCounter++;
    
    alpha += 0.005f;
    
    if (alpha >= 1.0f) alpha = 1.0f;

    // Press enter to change to ATTIC screen
    if ((IsKeyPressed(KEY_ENTER)) || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)))
    {
        finishScreen = 1;
    }
}
Beispiel #7
0
bool InputManager::GetMouseButtonUp( eInputCode button )
{
	bool found = false;
	bool isUp = false;

	for( unsigned int i = 0; i < keys.Size() && !found; i++ )
	{
		if( keys[i].key == button )
		{
			found = true;
			isUp = keys[i].wasPushed && !IsMouseButtonPressed( button ); 
		}	
	}
	
	return isUp;	
}
Beispiel #8
0
// Gameplay Screen Update logic
void UpdateAisle01Screen(void)
{
    // Update doors bounds
    doorLeft.bound.x = doorLeft.position.x - scroll;
    doorCenter.bound.x = doorCenter.position.x - scroll;
    doorRight.bound.x = doorRight.position.x - scroll;

    if (player.key)
    {       
        // Door: left
        if ((CheckCollisionPointRec(GetMousePosition(), doorLeft.bound)) || 
            (CheckCollisionRecs(player.bounds, doorLeft.bound))) doorLeft.selected = true; 
        else doorLeft.selected = false;
        
        if ((doorLeft.selected) && (CheckCollisionRecs(player.bounds, doorLeft.bound)))
        {
            if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorLeft.bound)) || (IsKeyPressed(KEY_SPACE)))
            {
                if (doorLeft.locked)
                {
                    doorLeft.frameRec.y = 0;
                    doorLeft.locked = false;
                    PlaySound(sndDoor);
                }
                else finishScreen = 1;
            }
        }
        
        // Door: center
        if ((CheckCollisionPointRec(GetMousePosition(), doorCenter.bound)) || 
            (CheckCollisionRecs(player.bounds, doorCenter.bound))) doorCenter.selected = true; 
        else doorCenter.selected = false;
        
        if ((doorCenter.selected) && (CheckCollisionRecs(player.bounds, doorCenter.bound)))
        {
            if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorCenter.bound)) || (IsKeyPressed(KEY_SPACE)))
            {
                if (doorCenter.locked)
                {
                    doorCenter.frameRec.y = 0;
                    doorCenter.locked = false;
                    PlaySound(sndDoor);
                }
                else finishScreen = 2;
            }
        }
        
        // Door: right
        if ((CheckCollisionPointRec(GetMousePosition(), doorRight.bound)) || 
            (CheckCollisionRecs(player.bounds, doorRight.bound))) doorRight.selected = true; 
        else doorRight.selected = false;
        
        if ((doorRight.selected) && (CheckCollisionRecs(player.bounds, doorRight.bound)))
        {
            if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorRight.bound)) || (IsKeyPressed(KEY_SPACE)))
            {
                if (doorRight.locked)
                {
                    doorRight.frameRec.y = 0;
                    doorRight.locked = false;
                    PlaySound(sndDoor);
                }
                else finishScreen = 3;
            }
        }
    }
    
    if (msgState > 2)
    {
        UpdatePlayer();
	
		// Monsters logic
        UpdateMonster(&lamp);
        UpdateMonster(&picture);
    }
    
    // Update monster bounds
    lamp.bounds.x = lamp.position.x + 20 - scroll;
    picture.bounds.x = picture.position.x + 44 - scroll;
	
    // Check player hover monsters to interact
    if (((CheckCollisionRecs(player.bounds, lamp.bounds)) && !lamp.active) ||
        ((CheckCollisionRecs(player.bounds, picture.bounds)) && !picture.active)) monsterHover = true;
    else monsterHover = false;
    
    // Monters logic: lamp
    if ((CheckCollisionRecs(player.bounds, lamp.bounds)) && !lamp.active)
    {
        lamp.selected = true;
        
        if ((IsKeyPressed(KEY_SPACE)) || 
            ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), lamp.bounds))))
        {
            SearchKeyPlayer();
            searching = true;
            framesCounter = 0;
            
            monsterCheck = 1;
        }
    }
    else lamp.selected = false;
    
    // Monters logic: picture
    if ((CheckCollisionRecs(player.bounds, picture.bounds)) && !picture.active)
    {
        picture.selected = true;
        
        if ((IsKeyPressed(KEY_SPACE)) || 
            ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), picture.bounds))))
        {
            SearchKeyPlayer();
            searching = true;
            framesCounter = 0;
            
            monsterCheck = 2;
        }
    }
    else picture.selected = false;
    
    if (searching)
    {
        framesCounter++;
        
        if (framesCounter > 180)
        {
            if (monsterCheck == 1)
            {
                if (lamp.spooky)
                {
                    ScarePlayer();
                    PlaySound(sndScream);
                }
                else FindKeyPlayer();
                
                lamp.active = true;
                lamp.selected = false;
            }
            else if (monsterCheck == 2)
            {
                if (picture.spooky)
                {
                    ScarePlayer();
                    PlaySound(sndScream);
                }
                else FindKeyPlayer();
                
                picture.active = true;
                picture.selected = false;
            }
  
            searching = false;
            framesCounter = 0;
        }
    }
    
    // Text animation
    framesCounter++;
    
    if ((framesCounter%2) == 0) lettersCounter++;

    if (msgState == 0)
    {
        if (lettersCounter <= (int)strlen(message)) strncpy(msgBuffer, message, lettersCounter);
        else
        {
            for (int i = 0; i < (int)strlen(msgBuffer); i++) msgBuffer[i] = '\0';

            lettersCounter = 0;
            msgState = 1;
        }
        
        if (IsKeyPressed(KEY_ENTER)) msgState = 1;
    }
    else if (msgState == 1)
    {
        msgCounter++;
        
        if ((IsKeyPressed(KEY_ENTER)) || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)))
        {
            msgState = 2;
            msgCounter = 0;
        }
    }
    else if (msgState == 2)
    {
        msgCounter++;
        
        if (msgCounter > 180) msgState = 3;
    }
    else msgCounter++;
    
    if (player.position.x > 200)
    {
        scroll = player.position.x - 200;
        
        if (scroll > 620) scroll = 620;
    }
}
Beispiel #9
0
bool InputManager::IsMouseButtonReleased(const gd::String& button) const {
  return oldButtonsPressed.find(button) != oldButtonsPressed.end() &&
         oldButtonsPressed.find(button)->second &&
         !IsMouseButtonPressed(button);
}
Beispiel #10
0
int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    int screenWidth = 800;
    int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [physac] example - forces");
    InitPhysics((Vector2){ 0.0f, -9.81f/2 });      // Initialize physics module
    
    // Global variables
    Vector2 mousePosition;
    bool isDebug = false;
    
    // Create rectangle physic objects
    PhysicBody rectangles[3];
    for (int i = 0; i < 3; i++)
    {
        rectangles[i] = CreatePhysicBody((Vector2){ screenWidth/4*(i+1), (((i % 2) == 0) ? (screenHeight/3) : (screenHeight/1.5f)) }, 0.0f, (Vector2){ 50, 50 });
        rectangles[i]->rigidbody.enabled = true;       // Enable physic object rigidbody behaviour
        rectangles[i]->rigidbody.friction = 0.1f;
    }
    
    // Create circles physic objects
    // NOTE: when creating circle physic objects, transform.scale must be { 0, 0 } and object radius must be defined in collider.radius and use this value to draw the circle.
    PhysicBody circles[3];
    for (int i = 0; i < 3; i++)
    {
        circles[i] = CreatePhysicBody((Vector2){ screenWidth/4*(i+1), (((i % 2) == 0) ? (screenHeight/1.5f) : (screenHeight/4)) }, 0.0f, (Vector2){ 0, 0 });
        circles[i]->rigidbody.enabled = true;       // Enable physic object rigidbody behaviour
        circles[i]->rigidbody.friction = 0.1f;
        circles[i]->collider.type = COLLIDER_CIRCLE;
        circles[i]->collider.radius = 25;
    }
    
    // Create walls physic objects
    PhysicBody leftWall = CreatePhysicBody((Vector2){ -25, screenHeight/2 }, 0.0f, (Vector2){ 50, screenHeight });
    PhysicBody rightWall = CreatePhysicBody((Vector2){ screenWidth + 25, screenHeight/2 }, 0.0f, (Vector2){ 50, screenHeight });
    PhysicBody topWall = CreatePhysicBody((Vector2){ screenWidth/2, -25 }, 0.0f, (Vector2){ screenWidth, 50 });
    PhysicBody bottomWall = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight + 25 }, 0.0f, (Vector2){ screenWidth, 50 });
    
    SetTargetFPS(60);
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        
        // Update mouse position value
        mousePosition = GetMousePosition();
        
        // Check force input
        if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) ApplyForceAtPosition(mousePosition, FORCE_AMOUNT, FORCE_RADIUS);
        
        // Check reset input
        if (IsKeyPressed('R'))
        {
            // Reset rectangle physic objects positions
            for (int i = 0; i < 3; i++)
            {
                rectangles[i]->transform.position = (Vector2){ screenWidth/4*(i+1) - rectangles[i]->transform.scale.x/2, (((i % 2) == 0) ? (screenHeight/3) : (screenHeight/1.5f)) - rectangles[i]->transform.scale.y/2 };
                rectangles[i]->rigidbody.velocity =(Vector2){ 0.0f, 0.0f };
            }
            
            // Reset circles physic objects positions
            for (int i = 0; i < 3; i++)
            {
                circles[i]->transform.position = (Vector2){ screenWidth/4*(i+1), (((i % 2) == 0) ? (screenHeight/1.5f) : (screenHeight/4)) };
                circles[i]->rigidbody.velocity =(Vector2){ 0.0f, 0.0f };
            }
        }
        
        // Check debug switch input
        if (IsKeyPressed('P')) isDebug = !isDebug;
        //----------------------------------------------------------------------------------

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

            ClearBackground(RAYWHITE);

            // Draw rectangles
            for (int i = 0; i < 3; i++)
            {
                // Convert transform values to rectangle data type variable
                DrawRectangleRec(TransformToRectangle(rectangles[i]->transform), RED);
                if (isDebug) DrawRectangleLines(rectangles[i]->collider.bounds.x, rectangles[i]->collider.bounds.y, rectangles[i]->collider.bounds.width, rectangles[i]->collider.bounds.height, GREEN);

                // Draw force radius
                DrawCircleLines(mousePosition.x, mousePosition.y, FORCE_RADIUS, BLACK);
                
                // Draw direction lines
                if (CheckCollisionPointCircle((Vector2){ rectangles[i]->transform.position.x + rectangles[i]->transform.scale.x/2, rectangles[i]->transform.position.y + rectangles[i]->transform.scale.y/2 }, mousePosition, FORCE_RADIUS))
                {
                    Vector2 direction = { rectangles[i]->transform.position.x + rectangles[i]->transform.scale.x/2 - mousePosition.x, rectangles[i]->transform.position.y + rectangles[i]->transform.scale.y/2 - mousePosition.y };
                    float angle = atan2l(direction.y, direction.x);
                    
                    // Calculate arrow start and end positions
                    Vector2 startPosition = { rectangles[i]->transform.position.x + rectangles[i]->transform.scale.x/2, rectangles[i]->transform.position.y + rectangles[i]->transform.scale.y/2 };
                    Vector2 endPosition = { rectangles[i]->transform.position.x + rectangles[i]->transform.scale.x/2 + (cos(angle)*LINE_LENGTH), rectangles[i]->transform.position.y + rectangles[i]->transform.scale.y/2 + (sin(angle)*LINE_LENGTH) };
                    
                    // Draw arrow line
                    DrawLineV(startPosition, endPosition, BLACK);
                    
                    // Draw arrow triangle
                    DrawTriangleLines((Vector2){ endPosition.x - cos(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH, endPosition.y - sin(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH },
                                      (Vector2){ endPosition.x + cos(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH, endPosition.y + sin(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH },
                                      (Vector2){ endPosition.x + cos(angle)*LINE_LENGTH/TRIANGLE_LENGTH*2, endPosition.y + sin(angle)*LINE_LENGTH/TRIANGLE_LENGTH*2 }, BLACK);
                }
            }
            
            // Draw circles
            for (int i = 0; i < 3; i++)
            {
                DrawCircleV(circles[i]->transform.position, circles[i]->collider.radius, BLUE);
                if (isDebug) DrawCircleLines(circles[i]->transform.position.x, circles[i]->transform.position.y, circles[i]->collider.radius, GREEN);

                // Draw force radius
                DrawCircleLines(mousePosition.x, mousePosition.y, FORCE_RADIUS, BLACK);
                
                // Draw direction lines
                if (CheckCollisionPointCircle((Vector2){ circles[i]->transform.position.x, circles[i]->transform.position.y }, mousePosition, FORCE_RADIUS))
                {
                    Vector2 direction = { circles[i]->transform.position.x - mousePosition.x, circles[i]->transform.position.y - mousePosition.y };
                    float angle = atan2l(direction.y, direction.x);
                    
                    // Calculate arrow start and end positions
                    Vector2 startPosition = { circles[i]->transform.position.x, circles[i]->transform.position.y };
                    Vector2 endPosition = { circles[i]->transform.position.x + (cos(angle)*LINE_LENGTH), circles[i]->transform.position.y + (sin(angle)*LINE_LENGTH) };
                    
                    // Draw arrow line
                    DrawLineV(startPosition, endPosition, BLACK);
                    
                    // Draw arrow triangle
                    DrawTriangleLines((Vector2){ endPosition.x - cos(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH, endPosition.y - sin(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH },
                                      (Vector2){ endPosition.x + cos(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH, endPosition.y + sin(angle + 90*DEG2RAD)*LINE_LENGTH/TRIANGLE_LENGTH },
                                      (Vector2){ endPosition.x + cos(angle)*LINE_LENGTH/TRIANGLE_LENGTH*2, endPosition.y + sin(angle)*LINE_LENGTH/TRIANGLE_LENGTH*2 }, BLACK);
                }
            }
            
            // Draw help messages
            DrawText("Use LEFT MOUSE BUTTON to apply a force", screenWidth/2 - MeasureText("Use LEFT MOUSE BUTTON to apply a force", 20)/2, screenHeight*0.075f, 20, LIGHTGRAY);
            DrawText("Use R to reset objects position", screenWidth/2 - MeasureText("Use R to reset objects position", 20)/2, screenHeight*0.875f, 20, GRAY);
            
            DrawFPS(10, 10);

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

    // De-Initialization
    //--------------------------------------------------------------------------------------
    ClosePhysics();       // Unitialize physics module
    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
Beispiel #11
0
int main(void)
{
    // Initialization
    //--------------------------------------------------------------------------------------
    const int screenWidth = 800;
    const int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib example - obj viewer");

    // Define the camera to look into our 3d world
    Camera camera = { { 30.0f, 30.0f, 30.0f }, { 0.0f, 10.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };

    Model model = LoadModel("resources/models/turret.obj");                     // Load default model obj
    Texture2D texture = LoadTexture("resources/models/turret_diffuse.png");     // Load default model texture
    model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Bind texture to model

    Vector3 position = { 0.0, 0.0, 0.0 };                   // Set model position
    BoundingBox bounds = MeshBoundingBox(model.meshes[0]);  // Set model bounds
    bool selected = false;                                  // Selected object flag

    SetCameraMode(camera, CAMERA_FREE);     // Set a free camera mode

    char objFilename[64] = "turret.obj";

    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
        //----------------------------------------------------------------------------------
        if (IsFileDropped())
        {
            int count = 0;
            char **droppedFiles = GetDroppedFiles(&count);

            if (count == 1)
            {
                if (IsFileExtension(droppedFiles[0], ".obj"))
                {
                    for (int i = 0; i < model.meshCount; i++) UnloadMesh(&model.meshes[i]);
                    model.meshes = LoadMeshes(droppedFiles[0], &model.meshCount);
                    bounds = MeshBoundingBox(model.meshes[0]);
                }
                else if (IsFileExtension(droppedFiles[0], ".png"))
                {
                    UnloadTexture(texture);
                    texture = LoadTexture(droppedFiles[0]);
                    model.materials[0].maps[MAP_DIFFUSE].texture = texture;
                }

                strcpy(objFilename, GetFileName(droppedFiles[0]));
            }

            ClearDroppedFiles();    // Clear internal buffers
        }

        UpdateCamera(&camera);

        // Select model on mouse click
        if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
        {
            // Check collision between ray and box
            if (CheckCollisionRayBox(GetMouseRay(GetMousePosition(), camera), bounds)) selected = !selected;
            else selected = false;
        }
        //----------------------------------------------------------------------------------

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

            ClearBackground(RAYWHITE);

            BeginMode3D(camera);

                DrawModel(model, position, 1.0f, WHITE);   // Draw 3d model with texture

                DrawGrid(20.0, 10.0);        // Draw a grid

                if (selected) DrawBoundingBox(bounds, GREEN);

            EndMode3D();

            DrawText("Free camera default controls:", 10, 20, 10, DARKGRAY);
            DrawText("- Mouse Wheel to Zoom in-out", 20, 40, 10, GRAY);
            DrawText("- Mouse Wheel Pressed to Pan", 20, 60, 10, GRAY);
            DrawText("- Alt + Mouse Wheel Pressed to Rotate", 20, 80, 10, GRAY);
            DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 20, 100, 10, GRAY);

            DrawText("Drag & drop .obj/.png to load mesh/texture.", 10, GetScreenHeight() - 20, 10, DARKGRAY);
            DrawText(FormatText("Current file: %s", objFilename), 250, GetScreenHeight() - 20, 10, GRAY);
            if (selected) DrawText("MODEL SELECTED", GetScreenWidth() - 110, 10, 10, GREEN);

            DrawText("(c) Turret 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);

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

    // De-Initialization
    //--------------------------------------------------------------------------------------
    UnloadModel(model);         // Unload model

    ClearDroppedFiles();        // Clear internal buffers

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

    return 0;
}
Beispiel #12
0
int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    int screenWidth = 800;
    int screenHeight = 400;
    
    Color colors[21] = { DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN,
                         GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW,
                         GREEN, SKYBLUE, PURPLE, BEIGE };
    
    Rectangle recs[21];             // Rectangles array
    
    // Fills recs data (for every rectangle)
    for (int i = 0; i < 21; i++)
    {
        recs[i].x = 20 + 100*(i%7) + 10*(i%7);
        recs[i].y = 40 + 100*(i/7) + 10*(i/7);
        recs[i].width = 100;
        recs[i].height = 100;
    }
    
    bool selected[21] = { false };   // Selected rectangles indicator
    
    Vector2 mousePoint;
    
    InitWindowEx(screenWidth, screenHeight, "raylib example 06a - color selection", false, "resources/mouse.png");
    
    SetTargetFPS(60);
    //--------------------------------------------------------------------------------------
    
    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        mousePoint = GetMousePosition();
        
        for (int i = 0; i < 21; i++)    // Iterate along all the rectangles
        {
            if (CheckCollisionPointRec(mousePoint, recs[i]))
            {   
                colors[i].a = 120;
                
                if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selected[i] = !selected[i];
            }
            else colors[i].a = 255;
        }
        //----------------------------------------------------------------------------------
        
        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();
        
            ClearBackground(RAYWHITE);
            
            for (int i = 0; i < 21; i++)    // Draw all rectangles
            {
                DrawRectangleRec(recs[i], colors[i]);
                
                // Draw four rectangles around selected rectangle
                if (selected[i])
                {
                    DrawRectangle(recs[i].x, recs[i].y, 100, 10, RAYWHITE);        // Square top rectangle
                    DrawRectangle(recs[i].x, recs[i].y, 10, 100, RAYWHITE);        // Square left rectangle
                    DrawRectangle(recs[i].x + 90, recs[i].y, 10, 100, RAYWHITE);   // Square right rectangle
                    DrawRectangle(recs[i].x, recs[i].y + 90, 100, 10, RAYWHITE);   // Square bottom rectangle
                }
            }
       
        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------  
    CloseWindow();                // Close window and OpenGL context
    //--------------------------------------------------------------------------------------
    
    return 0;
}
Beispiel #13
0
// Función de actualización, actualización de estados entre frames
void InputManager::Update()
{

	for( unsigned int i = 0; i < virtualButtons.Size(); i++ )
	{
		if( virtualButtons[i].buttonsAssigned > Mouse_Right && virtualButtons[i].buttonsAssigned < Button_Up )
		{
			virtualButtons[i].isDown = !virtualButtons[i].pressed && IsKeyPressed( virtualButtons[i].buttonsAssigned );
			virtualButtons[i].isUp = virtualButtons[i].pressed && !IsKeyPressed( virtualButtons[i].buttonsAssigned );
			virtualButtons[i].pressed = IsKeyPressed( virtualButtons[i].buttonsAssigned );
		}
		else if( virtualButtons[i].buttonsAssigned <= Mouse_Right ) 
		{
			virtualButtons[i].isDown = !virtualButtons[i].pressed && IsMouseButtonPressed( virtualButtons[i].buttonsAssigned );
			virtualButtons[i].isUp = virtualButtons[i].pressed && !IsMouseButtonPressed( virtualButtons[i].buttonsAssigned );
			virtualButtons[i].pressed = IsMouseButtonPressed( virtualButtons[i].buttonsAssigned );
		}
		else
		{
			virtualButtons[i].isDown = !virtualButtons[i].pressed && IsXboxDown( virtualButtons[i].buttonsAssigned );
			virtualButtons[i].isUp = virtualButtons[i].pressed && !IsXboxPressed( virtualButtons[i].buttonsAssigned );
			virtualButtons[i].pressed = IsXboxPressed( virtualButtons[i].buttonsAssigned );
		}
	}

	for( unsigned int i = 0; i < virtualAxis.Size(); i++ )
	{
	
		if( virtualAxis[i].positiveAxis > Mouse_Right && virtualAxis[i].positiveAxis < Button_Up )
		{
			IsKeyPressed( virtualAxis[i].positiveAxis ) ? 	virtualAxis[i].movement = 1.0 : virtualAxis[i].movement = 0;
		}
		else if( virtualAxis[i].positiveAxis <= Mouse_Right )
		{
			IsMouseButtonPressed( virtualAxis[i].positiveAxis ) ? 	virtualAxis[i].movement = 1.0 : virtualAxis[i].movement = 0;
		}
		else
		{
			IsXboxPressed( virtualAxis[i].positiveAxis ) ? 	virtualAxis[i].movement = 1.0 : virtualAxis[i].movement = 0;
		}

		if( virtualAxis[i].negativeAxis > Mouse_Right && virtualAxis[i].negativeAxis < Button_Up )
		{
			IsKeyPressed( virtualAxis[i].negativeAxis ) ? 	virtualAxis[i].movement += -1.0 : virtualAxis[i].movement += 0;
		}
		else if( virtualAxis[i].negativeAxis <= Mouse_Right )
		{
			IsMouseButtonPressed( virtualAxis[i].negativeAxis ) ? 	virtualAxis[i].movement += -1.0 : virtualAxis[i].movement += 0;
		}
		else
		{
			IsXboxPressed( virtualAxis[i].negativeAxis ) ? 	virtualAxis[i].movement += -1.0 : virtualAxis[i].movement += 0;
		}
	}


	for( unsigned int i = 0; i < keys.Size(); i++ )
	{
		if( keys[i].device == Keyboard )
		{
			keys[i].wasPushed = IsKeyPressed( keys[i].key );
		}
		else if( keys[i].key == Mouse )
		{
			keys[i].wasPushed = IsMouseButtonPressed( keys[i].key );		
		}
		else if( keys[i].key == XboxPad )
		{
			keys[i].wasPushed = IsXboxPressed( keys[i].key );
		}
	}

	xMouse = Screen::Instance().GetMouseX();
	yMouse = Screen::Instance().GetMouseY();
}
Beispiel #14
0
// Gameplay Screen Update logic
void UpdateAtticScreen(void)
{
    if (player.key)
    {
        // Door: right
        if ((CheckCollisionPointRec(GetMousePosition(), doorRight.bound)) || 
            (CheckCollisionRecs(player.bounds, doorRight.bound))) doorRight.selected = true; 
        else doorRight.selected = false;
        
        if ((doorRight.selected) && (CheckCollisionRecs(player.bounds, doorRight.bound)))
        {
            if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorRight.bound)) || (IsKeyPressed(KEY_SPACE)))
            {
                if (doorRight.locked)
                {
                    doorRight.frameRec.y = 0;
                    doorRight.locked = false;
                    PlaySound(sndDoor);
                }
                else finishScreen = 1;
            }
        }
    }
        
    if (msgState > 2)
    {
        UpdatePlayer();
	
		// Monsters logic
        UpdateMonster(&lamp);
        UpdateMonster(&arc);
    }
	
    // Check player hover monsters to interact
    if (((CheckCollisionRecs(player.bounds, lamp.bounds)) && !lamp.active) ||
        ((CheckCollisionRecs(player.bounds, arc.bounds)) && !arc.active)) monsterHover = true;
    else monsterHover = false;
    
    // Monters logic: lamp
    if ((CheckCollisionRecs(player.bounds, lamp.bounds)) && !lamp.active)
    {
        lamp.selected = true;
        
        if ((IsKeyPressed(KEY_SPACE)) || 
            ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), lamp.bounds))))
        {
            SearchKeyPlayer();
            searching = true;
            framesCounter = 0;
            
            monsterCheck = 1;
        }
    }
    else lamp.selected = false;
    
    // Monters logic: arc
    if ((CheckCollisionRecs(player.bounds, arc.bounds)) && !arc.active)
    {
        arc.selected = true;
        
        if ((IsKeyPressed(KEY_SPACE)) || 
            ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), arc.bounds))))
        {
            SearchKeyPlayer();
            searching = true;
            framesCounter = 0;
            
            monsterCheck = 2;
        }
    }
    else arc.selected = false;
    
    if (searching)
    {
        framesCounter++;
        
        if (framesCounter > 180)
        {
            if (monsterCheck == 1)
            {
                if (lamp.spooky)
                {
                    ScarePlayer();
                    PlaySound(sndScream);
                }
                else FindKeyPlayer();
                
                lamp.active = true;
                lamp.selected = false;
            }
            else if (monsterCheck == 2)
            {
                if (arc.spooky) 
                {
                    ScarePlayer();
                    PlaySound(sndScream);
                }
                else FindKeyPlayer();
                
                arc.active = true;
                arc.selected = false;
            }
  
            searching = false;
            framesCounter = 0;
        }
    }
    
    // Text animation
    framesCounter++;
    
    if ((framesCounter%2) == 0) lettersCounter++;

    if (msgState == 0)
    {
        if (lettersCounter <= (int)strlen(message)) strncpy(msgBuffer, message, lettersCounter);
        else
        {
            for (int i = 0; i < (int)strlen(msgBuffer); i++) msgBuffer[i] = '\0';

            lettersCounter = 0;
            msgState = 1;
        }
        
        if (IsKeyPressed(KEY_ENTER)) msgState = 1;
    }
    else if (msgState == 1)
    {
        msgCounter++;
        
        if ((IsKeyPressed(KEY_ENTER)) || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)))
        {
            msgState = 2;
            msgCounter = 0;
        }
    }
    else if (msgState == 2)
    {
        msgCounter++;
        
        if (msgCounter > 180) msgState = 3;
    }
    else msgCounter++;
    
    if (IsKeyPressed('M'))
    {
        finishScreen = 1;
    }
}
Beispiel #15
0
int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    int screenWidth = 800;
    int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking");

    // Define the camera to look into our 3d world
    Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};

    Vector3 cubePosition = { 0.0, 1.0, 0.0 };
    
    Ray ray;        // Picking line ray
    
    SetCameraMode(CAMERA_FREE);         // Set a free camera mode
    SetCameraPosition(camera.position); // Set internal camera position to match our camera position

    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
        //----------------------------------------------------------------------------------
        UpdateCamera(&camera);          // Update internal camera and our camera
        
        if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
        {
            // NOTE: This function is NOT WORKING properly!
            ray = GetMouseRay(GetMousePosition(), camera);
            
            // TODO: Check collision between ray and box
        }
        //----------------------------------------------------------------------------------

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

            ClearBackground(RAYWHITE);

            Begin3dMode(camera);

                DrawCube(cubePosition, 2, 2, 2, GRAY);
                DrawCubeWires(cubePosition, 2, 2, 2, DARKGRAY);

                DrawGrid(10.0, 1.0);
                
                DrawRay(ray, MAROON);

            End3dMode();
            
            DrawText("Try selecting the box with mouse!", 240, 10, 20, GRAY);

            DrawFPS(10, 10);

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

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

    return 0;
}
Beispiel #16
0
// Gameplay Screen Update logic
void UpdateLivingroomScreen(void)
{
    if (player.key)
    {       
        // Door: left
        if ((CheckCollisionPointRec(GetMousePosition(), doorLeft.bound)) || 
            (CheckCollisionRecs(player.bounds, doorLeft.bound))) doorLeft.selected = true; 
        else doorLeft.selected = false;
        
        if ((doorLeft.selected) && (CheckCollisionRecs(player.bounds, doorLeft.bound)))
        {
            if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorLeft.bound)) || (IsKeyPressed(KEY_SPACE)))
            {
                if (doorLeft.locked)
                {
                    doorLeft.frameRec.y = 0;
                    doorLeft.locked = false;
                    PlaySound(sndDoor);
                }
                else finishScreen = 1;
            }
        }
        
        // Door: center
        if ((CheckCollisionPointRec(GetMousePosition(), doorCenter.bound)) || 
            (CheckCollisionRecs(player.bounds, doorCenter.bound))) doorCenter.selected = true; 
        else doorCenter.selected = false;
        
        if ((doorCenter.selected) && (CheckCollisionRecs(player.bounds, doorCenter.bound)))
        {
            if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorCenter.bound)) || (IsKeyPressed(KEY_SPACE)))
            {
                if (doorCenter.locked)
                {
                    doorCenter.frameRec.y = 0;
                    doorCenter.locked = false;
                    PlaySound(sndDoor);
                }
                else finishScreen = 2;
            }
        }
    }
        
    if (msgState > 2)
    {
        UpdatePlayer();
	
		// Monsters logic
        UpdateMonster(&candle);
        UpdateMonster(&picture);
        UpdateMonster(&phone);
    }
	
    // Check player hover monsters to interact
    if (((CheckCollisionRecs(player.bounds, candle.bounds)) && !candle.active) ||
        ((CheckCollisionRecs(player.bounds, picture.bounds)) && !picture.active) ||
        ((CheckCollisionRecs(player.bounds, phone.bounds)) && !phone.active)) monsterHover = true;
    else monsterHover = false;
    
    // Monters logic: candle
    if ((CheckCollisionRecs(player.bounds, candle.bounds)) && !candle.active)
    {
        candle.selected = true;
        
        if ((IsKeyPressed(KEY_SPACE)) || 
            ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), candle.bounds))))
        {
            SearchKeyPlayer();
            searching = true;
            framesCounter = 0;
            
            monsterCheck = 1;
        }
    }
    else candle.selected = false;
    
    // Monters logic: picture
    if ((CheckCollisionRecs(player.bounds, picture.bounds)) && !picture.active)
    {
        picture.selected = true;
        
        if ((IsKeyPressed(KEY_SPACE)) || 
            ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), picture.bounds))))
        {
            SearchKeyPlayer();
            searching = true;
            framesCounter = 0;
            
            monsterCheck = 2;
        }
    }
    else picture.selected = false;
    
    // Monters logic: phone
    if ((CheckCollisionRecs(player.bounds, phone.bounds)) && !phone.active)
    {
        phone.selected = true;
        
        if ((IsKeyPressed(KEY_SPACE)) || 
            ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), phone.bounds))))
        {
            SearchKeyPlayer();
            searching = true;
            framesCounter = 0;
            
            monsterCheck = 3;
        }
    }
    else phone.selected = false;
    
    if (searching)
    {
        framesCounter++;
        
        if (framesCounter > 180)
        {
            if (monsterCheck == 1)
            {
                if (candle.spooky)
                {
                    ScarePlayer();
                    PlaySound(sndScream);
                }
                else FindKeyPlayer();
                
                candle.active = true;
                candle.selected = false;
            }
            else if (monsterCheck == 2)
            {
                if (picture.spooky)
                {
                    ScarePlayer();
                    PlaySound(sndScream);
                }
                else FindKeyPlayer();
                
                picture.active = true;
                picture.selected = false;
            }
            else if (monsterCheck == 3)
            {
                if (phone.spooky)
                {
                    ScarePlayer();
                    PlaySound(sndScream);
                }
                else FindKeyPlayer();
                
                phone.active = true;
                phone.selected = false;
            }
  
            searching = false;
            framesCounter = 0;
        }
    }
    
    // Text animation
    framesCounter++;
    
    if ((framesCounter%2) == 0) lettersCounter++;

    if (msgState == 0)
    {
        if (lettersCounter <= (int)strlen(message)) strncpy(msgBuffer, message, lettersCounter);
        else
        {
            for (int i = 0; i < (int)strlen(msgBuffer); i++) msgBuffer[i] = '\0';

            lettersCounter = 0;
            msgState = 1;
        }
        
        if (IsKeyPressed(KEY_ENTER)) msgState = 1;
    }
    else if (msgState == 1)
    {
        msgCounter++;
        
        if ((IsKeyPressed(KEY_ENTER)) || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)))
        {
            msgState = 2;
            msgCounter = 0;
        }
    }
    else if (msgState == 2)
    {
        msgCounter++;
        
        if (msgCounter > 180) msgState = 3;
    }
    else msgCounter++;
}
Beispiel #17
0
// Ending Screen Update logic
void UpdateEndingScreen(void)
{
    framesCounter += 1*TIME_FACTOR;
  
    switch (endingCounter)
    {
        case DELAY:
        {
            if(framesCounter >= 10)
            {
                endingCounter = SEASONS;
                framesCounter = 0;
            }
            
        } break;
        case SEASONS:
        {
            if (seasons > 0)
            {
                seasonsCounter = (int)LinearEaseIn((float)framesCounter, 0.0f, (float)(seasons), 90.0f);
                clockRotation = LinearEaseIn((float)framesCounter, (float)initRotation, (float)-(finalRotation - initRotation), 90.0f);
                
                if (framesCounter >= 90)
                {
                    endingCounter = LEAVES;
                    framesCounter = 0;
                }
            }
            else endingCounter = LEAVES;
            
#if (defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB))
            if (IsGestureDetected(GESTURE_TAP))
            {
                seasonsCounter = seasons;
                clockRotation = finalRotation;
                framesCounter = 0;
                endingCounter = LEAVES;
            }
#elif (defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB))
            if (IsKeyPressed(KEY_ENTER))
            {
                seasonsCounter = seasons;
                clockRotation = finalRotation;
                framesCounter = 0;
                endingCounter = LEAVES;
            }
#endif
        } break;
        case LEAVES: 
        {
            if (currentLeaves > 0)
            {
                if (currentLeavesEnding == currentLeaves)
                {
                    endingCounter = KILLS;
                    framesCounter = 0;
                }
                else if (currentLeavesEnding < currentLeaves)
                {
                    if (framesCounter >= 4)
                    {
                        currentLeavesEnding += 1;
                        framesCounter = 0;
                    }
                    
                    for (int i = 0; i < 20; i++)
                    {
                        if (!leafParticles[i].active)
                        {
                            leafParticles[i].position = (Vector2){ GetScreenWidth()*0.46, GetScreenHeight()*0.32};
                            leafParticles[i].alpha = 1.0f;
                            leafParticles[i].active = true;
                        }
                    }
                }
            }
            else endingCounter = KILLS;       

#if (defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB))
            if (IsGestureDetected(GESTURE_TAP))
            {
                currentLeavesEnding = currentLeaves;
                framesCounter = 0;
                endingCounter = KILLS;
            }
#elif (defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB))
            if (IsKeyPressed(KEY_ENTER))
            {
                currentLeavesEnding = currentLeaves;
                framesCounter = 0;
                endingCounter = KILLS;
            }  
#endif
        } break;
        case KILLS:
        {
            if (score > 0)
            {
                if (framesCounter <= 90 && !replaying)
                {
                    currentScore = (int)LinearEaseIn((float)framesCounter, 0.0f, (float)(score), 90.0f);
                }
                
                framesKillsCounter += 1*TIME_FACTOR;
                
                for (int i = 0; i < MAX_KILLS; i++)
                {
                    if (framesKillsCounter >= drawTimer && active[i] == false)
                    {
                        active[i] = true;
                        framesKillsCounter = 0;
                    }
                }
                
                if (framesCounter >= 90)
                {
                    endingCounter = REPLAY;
                    framesCounter = 0;
                }
            }
            else endingCounter = REPLAY;   
            
#if (defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB))
            if (IsGestureDetected(GESTURE_TAP))
            {
               currentScore = score;
               framesCounter = 0;
               for (int i = 0; i < MAX_KILLS; i++) active[i] = true;
               endingCounter = REPLAY;
            }
#elif (defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB))
            if (IsKeyPressed(KEY_ENTER))
            {
               currentScore = score;
               framesCounter = 0;
               for (int i = 0; i < MAX_KILLS; i++) active[i] = true;
               endingCounter = REPLAY;
            }
#endif
        } break;
        case REPLAY:
        {
#if (defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB))
            if (IsGestureDetected(GESTURE_TAP)) replaying = true;
#elif (defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB))
            if (IsKeyPressed(KEY_ENTER)) replaying = true;
#endif
            if (replaying)
            {
                replayTimer += 1*TIME_FACTOR;
                
                if (replayTimer >= 30)
                {
                    finishScreen = 1;
                    initSeason = GetRandomValue(0, 3);
                }
                
                buttonPlayColor = GOLD;
            }
        } break;
    }
    
    for (int i = 0; i < 20; i++)
    {
        if (leafParticles[i].active == true)
        {
            leafParticles[i].position.x +=  leafParticles[i].speed.x;
            leafParticles[i].position.y +=  leafParticles[i].speed.y;
            leafParticles[i].rotation += 6;
            leafParticles[i].alpha -= 0.03f;
            leafParticles[i].size -= 0.004;

            if (leafParticles[i].size <= 0) leafParticles[i].size = 0.0f;

            if (leafParticles[i].alpha <= 0)
            {
                leafParticles[i].alpha = 0.0f;
                leafParticles[i].active = false;
            }               
        }
    }

    // Buttons logic
#if (defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB))
    if ((IsGestureDetected(GESTURE_TAP)) && CheckCollisionPointRec(GetTouchPosition(0), playButton))
    {
        endingCounter = REPLAY;
        replaying = true;
    }
    
#elif (defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB))
    if (CheckCollisionPointRec(GetMousePosition(), playButton)) 
    {
        buttonPlayColor = GOLD;  
        if (IsMouseButtonPressed(0)) 
        {
            endingCounter = REPLAY;
            replaying = true;
        }
    }       
    else buttonPlayColor = WHITE;

    if (CheckCollisionPointRec(GetMousePosition(), shopButton)) buttonShopColor = GOLD;
    else buttonShopColor = WHITE;
    
    if (CheckCollisionPointRec(GetMousePosition(), trophyButton)) buttonTrophyColor = GOLD;
    else buttonTrophyColor = WHITE;
    
    if (CheckCollisionPointRec(GetMousePosition(), shareButton)) buttonShareColor = GOLD;
    else buttonShareColor = WHITE;
#endif
}