Esempio n. 1
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;
    }
}
Esempio n. 2
0
bool CheckPlayerTrianglesCollision()
{
    for (int i=0; i<maxTriangles; i++)
    {
        if (triangles[i].isActive) // If triangle is in the screen
        {
           for (int j=0; j<MAX_TRIANGLE_COLLIDING_POINTS; j++)
            {
                if (CheckCollisionPointRec(triangles[i].collidingPoints[j], player.collider)) 
                {
                    return TRUE;
                }
            } 
        }
    }
    return FALSE;
}
Esempio n. 3
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++;
}
Esempio n. 4
0
// Update game (one frame)
void UpdateGame(void)
{
    if (!gameOver)
    {
        if (IsKeyPressed('P')) pause = !pause;

        if (!pause)
        {
            framesCounter++;

            static 
            float distance;

            // Interceptors update
            for (int i = 0; i < MAX_INTERCEPTORS; i++)
            {
                if (interceptor[i].active)
                {
                    // Update position
                    interceptor[i].position.x += interceptor[i].speed.x;
                    interceptor[i].position.y += interceptor[i].speed.y;

                    // Distance to objective
                    distance = sqrt( pow(interceptor[i].position.x - interceptor[i].objective.x, 2) +
                                     pow(interceptor[i].position.y - interceptor[i].objective.y, 2));

                    if (distance < INTERCEPTOR_SPEED)
                    {
                        // Interceptor dissapears
                        interceptor[i].active = false;

                        // Explosion
                        explosion[explosionIndex].position = interceptor[i].position;
                        explosion[explosionIndex].active = true;
                        explosion[explosionIndex].frame = 0;
                        explosionIndex++;
                        if (explosionIndex == MAX_EXPLOSIONS) explosionIndex = 0;

                        break;
                    }
                }
            }

            // Missiles update
            for (int i = 0; i < MAX_MISSILES; i++)
            {
                if (missile[i].active)
                {
                    // Update position
                    missile[i].position.x += missile[i].speed.x;
                    missile[i].position.y += missile[i].speed.y;

                    // Collision and missile out of bounds
                    if (missile[i].position.y > screenHeight) missile[i].active = false;
                    else
                    {
                        // CHeck collision with launchers
                        for (int j = 0; j < LAUNCHERS_AMOUNT; j++)
                        {
                            if (launcher[j].active)
                            {
                                if (CheckCollisionPointRec(missile[i].position,  (Rectangle){ launcher[j].position.x - LAUNCHER_SIZE/2, launcher[j].position.y - LAUNCHER_SIZE/2,
                                                                                            LAUNCHER_SIZE, LAUNCHER_SIZE }))
                                {
                                    // Missile dissapears
                                    missile[i].active = false;

                                    // Explosion and destroy building
                                    launcher[j].active = false;

                                    explosion[explosionIndex].position = missile[i].position;
                                    explosion[explosionIndex].active = true;
                                    explosion[explosionIndex].frame = 0;
                                    explosionIndex++;
                                    if (explosionIndex == MAX_EXPLOSIONS) explosionIndex = 0;

                                    break;
                                }
                            }
                        }

                        // CHeck collision with buildings
                        for (int j = 0; j < BUILDINGS_AMOUNT; j++)
                        {
                            if (building[j].active)
                            {
                                if (CheckCollisionPointRec(missile[i].position,  (Rectangle){ building[j].position.x - BUILDING_SIZE/2, building[j].position.y - BUILDING_SIZE/2,
                                                                                            BUILDING_SIZE, BUILDING_SIZE }))
                                {
                                    // Missile dissapears
                                    missile[i].active = false;

                                    // Explosion and destroy building
                                    building[j].active = false;

                                    explosion[explosionIndex].position = missile[i].position;
                                    explosion[explosionIndex].active = true;
                                    explosion[explosionIndex].frame = 0;
                                    explosionIndex++;
                                    if (explosionIndex == MAX_EXPLOSIONS) explosionIndex = 0;

                                    break;
                                }
                            }
                        }

                        // CHeck collision with explosions
                        for (int j = 0; j < MAX_EXPLOSIONS; j++)
                        {
                            if (explosion[j].active)
                            {
                                if (CheckCollisionPointCircle(missile[i].position, explosion[j].position, EXPLOSION_RADIUS*explosion[j].radiusMultiplier))
                                {
                                    // Missile dissapears and we earn 100 points
                                    missile[i].active = false;
                                    score += 100;

                                    explosion[explosionIndex].position = missile[i].position;
                                    explosion[explosionIndex].active = true;
                                    explosion[explosionIndex].frame = 0;
                                    explosionIndex++;
                                    if (explosionIndex == MAX_EXPLOSIONS) explosionIndex = 0;

                                    break;
                                }
                            }
                        }
                    }
                }
            }

            // Explosions update
            for (int i = 0; i < MAX_EXPLOSIONS; i++)
            {
                if (explosion[i].active)
                {
                    explosion[i].frame++;

                    if (explosion[i].frame <= EXPLOSION_INCREASE_TIME) explosion[i].radiusMultiplier = explosion[i].frame/(float)EXPLOSION_INCREASE_TIME;
                    else if (explosion[i].frame <= EXPLOSION_TOTAL_TIME) explosion[i].radiusMultiplier = 1 - (explosion[i].frame - (float)EXPLOSION_INCREASE_TIME)/(float)EXPLOSION_TOTAL_TIME;
                    else
                    {
                        explosion[i].frame = 0;
                        explosion[i].active = false;
                    }
                }
            }

            // Fire logic
            UpdateOutgoingFire();
            UpdateIncomingFire();

            // Game over logic
            int checker = 0;

            for (int i = 0; i < LAUNCHERS_AMOUNT; i++)
            {
                if (!launcher[i].active) checker++;
                if (checker == LAUNCHERS_AMOUNT) gameOver = true;
            }

            checker = 0;
            for (int i = 0; i < BUILDINGS_AMOUNT; i++)
            {
                if (!building[i].active) checker++;
                if (checker == BUILDINGS_AMOUNT) gameOver = true;
            }
        }
    }
    else
    {
        if (IsKeyPressed(KEY_ENTER))
        {
            InitGame();
            gameOver = false;
        }
    }
}
Esempio n. 5
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;
    }
}
Esempio n. 6
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;
}
Esempio n. 7
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;
    }
}
Esempio n. 8
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
}