v1.2 Updates


So firstly, it should be noted that this is v1.2, which is a jump away from the originally uploaded 1.0. There never really was a v1.1, but I did play around with many additions, and built a test version before this one...so, here we are. What might have started as a typo has thusly been explained rationally...ish.

Let's get to the fun nerdy stuff:

As promised in the previous devLog, I have added extra lives! Quite proud of how I managed to do this, primarily because I did it entirely on my own. To date, this is probably the most I've worked towards adding features to a game without the aid of tutorials. I am absolutely certain there are better ways to perform a similar end result, or even a superior end result. However, this solution works, and I am happy enough with that.

To spawn extra lives, I added the following code to the Player class:

public int lifeSpawnRate = 0;
private int spawnChance;      
private bool hasSpawnedLife; 
     
void Update()     
{         
    SpawnLife();     
}      
private void CheckLevelStarted()     
{         
    if(levelStarting == true)         
    {             
        lifeSpawnRate++;
    }
}
void SpawnLife()     
{         
    if (lifeSpawnRate == 1)         
    {             
        spawnChance = Random.Range(1, 100);              
        
        if (spawnChance <= 25)             
        {                 
            GameObject extraLife = (GameObject)Instantiate(Resources.Load("Prefabs/frogger_life"));
            extraLife.GetComponent<spriterenderer>().enabled = false;
            hasSpawnedLife = true;             
        }
    }          
    
    if (hasSpawnedLife && levelStarted && lifeSpawnRate > 1)         
    {             
        GameObject extraLife = GameObject.Find("frogger_life(Clone)");             
        extraLife.GetComponent<spriterenderer>().enabled = true;         
    }     
}      
public void SpawnLifeOnDeath()     
{         
    if (!hasSpawnedLife)         
    {             
        spawnChance = Random.Range(1, 100);              
        if (spawnChance <= 25)             
        {                 
            GameObject extraLife = (GameObject)Instantiate(Resources.Load("Prefabs/frogger_life")); 
            hasSpawnedLife = true;             
        }         
    }     
}

I utilized a float titled lifeSpawnRate that would increment as long as the level is starting (while the level music is playing), because this is when I first wanted the lives to spawn. Furthermore, I wanted to place the object during the song, but wait until it was over to show it to the player. This was to prevent an overlap with the "GET READY!" text that appears during the level break. 

So, I use the lifeSpawnRate to set up my desired result. The number increments constantly while the song plays, but because of the If Statement in the SpawnLife() function, the object spawns only once. Then, at the conclusion of the song, the <SpriteRenderer> component is enabled and the life is shown to the player. In the GameReset() and ResetLevel() functions, the lifeSpawnRate is reset to 0, and the process can start again.

As I said, there's more than likely more efficient ways to implement the functionality I was going for, but this works. In regards to having the player collide with the extra life, I was able to use the same method that was being used for every other collidable object in the game:

if (collidableObject.isExtraLife)                     
{                         
    if (health < 4)                         
    {                             
        health += 1;                             
        PlayExtraLifeSound();                             
        collidableObject.DestroyExtraLife();                             
        hud.UpdatePlayerLivesHUD(health);                             
        hasSpawnedLife = false;                         
    }                         
    else                         
    {                             
        PlayExtraLifeSound();                             
        collidableObject.DestroyExtraLife();                             
        hud.UpdatePlayerScore(150);                             
        hasSpawnedLife = false;                         
    }                     
}

As you'll see above, I went for different interactions with the extra life, based on the number of lives the player has. My first concern was hoarding lives. I did not want players to exceed the original max number of lives they had been given. As such, if the extra life were to act as health, I wanted to ensure the player had less than the starting 4 lives. If so, Frogger is granted another shot at life (provided the player makes it past the road). 

If the player still has (or has gained back and kept) all their allotted lives, I wanted to ensure the extra life was still of some value. As such, the game awards Frogger 150 points outright. While the rest of the scoring in the game is dynamically affected by the level, I did not wish for the extra lives to share this feature. My fear stemmed from the random method which instantiates the extra life. It would be possible for the player to fill all their lives during a high level, successfully move to the next level, and be granted yet another life. Then, provided they crossed the road, their score would be vastly increased. All the while, another player may reach the same spot and not obtain such an advantage. It didn't seem fair for such a difference in score to come from a totally random source. So, the point value of the extra lives remains static.

You'll also notice, it is when the player interacts with the extra life, that we destroy the life and reset the hasSpawnedLife bool to false. This allows all the extra life spawning functions to...well...function. I'll spare you a wall of code to explain how the lives are removed in the case of player death. It's pretty simple. Basically, if the player dies, we destroy the gameObject, and reset the hasSpawnedLife boolean. 

Finally, I also added an indication to the player for movement controls. There was text explaining controls for the pause and quit functionality, but until now I have been relying on instincts to tell the player to use the arrow keys to move. This is all well and good, unless playing with someone not used to the classic gaming keyboard layout. No matter how seemingly obvious, I always try to ensure the player is fully told of the game controls. It's only fair. 

So, I created a sprite. The first time I've ever done so, aside from the extra life sprite for this same game. In that case, I traced the frogger_up graphic with a pixel pen tool in Microsoft Paint to turn it white. In the case of the move icon, I again utilized Microsoft Paint to create a simple icon that resembled the arrow keys. Then I placed it in the world and used the same method to flicker text I have been using since Tone-tris.

Again, I'll spare you the wall of code, but suffice to say my solution is two functions that invoke each other at a given rate. While using this in Pac-Man to make the indicator icon on the Game Menu flash, I discovered a curious thing. If I set the flicker rate to lower than one-tenth of a second, it mimicked a rolling shutter effect. I used this idea for the move icon in Frogger, setting the flicker rate to 0.02f and lowering the alpha setting to around 70. 

Finally, using a boolean, another method to hide the image altogether, and a few calls to everything I set up the icon. It will appear when the game is first launched during the opening of Level 1. Once the level music is finished, movement is allowed for the player and the HUD clears all the text and updates the countdown timer in the lower right. However, the move icon will still remain on screen until the player actually moves Frogger. Then, the icon disappears and remains hidden until after a Game Over and the player restarts from the beginning. 

All this took very little effort, and it works. For this I am happy. I hope these additions enhance gameplay and enjoyment.

-T


P.S. I also made a custom icon for the start file. Learned how to do that. Simple. Fun. 

Files

Frogger v1.2.zip 26 MB
Apr 23, 2022

Get Frogger

Leave a comment

Log in with itch.io to leave a comment.