5: Flies, Lady frogs, scoring & sound

So, big update this time round. Flies, timer bars, lady frogs and sound, A supporting video is available below:

As mentioned in the video that added sound I’m not writing up pages for small updates but rather collecting a few together. If you want the full code and have built your hardware and have been following this series then all you need is the updated code below (less the sound). To implement the sound  you will need to add the sound hardware which consists of

PAM8403 Audio Amplifier board (other amplifiers will probably be fine)
10K Resistor
1K Resistor
4 or 8Ohm speaker (rated 3Watts or larger)
10K Logarithmic potentiometer (Usually sold as 10K Log Pot)

The full circuit for the project is further down in the article.

The Code
Here is the complete project code, note that you need additional libraries to support the graphics and sound. These are mentioned in previous articles but for ease I’ve re-listed them after the code.

Frogger V5

Essential libraries

XTronical ST7735 LCD Driver : Based on Adafruit version, has extra functionality to make screen updates faster and smoother (essential for games)

Adafruit graphics library : Useful routines for various graphics operations (install using arduino library manager)

DACAudio : Audio library for playing digitised sound and other effects.

If your new to this and you want to try this project for yourself then these articles will get you up and running first;

Useful articles for beginners
Connecting a colour LCD to ESP32
DacAudio Introduction
1st Frogger article

Important : Ensure the buffer option of the 7735 driver is turned on
If you don’t then you will get an error when you compile the code. Frogger (or any game) requires fast screen updates, the buffer option is essential for this. The error you will get if you don’t is shown below.

error: ‘class Adafruit_ST7735’ has no member named ‘displayBuffer’

This is because by default the screen buffer is turned off so that as standard compatibility is maintained from previous versions so that existing program code with small memory MCU’s is not broken. You need to purposely enable the screen buffer. To do this open up the file “XTronical_ST7735.h” in a text editor of your choice (I use the excellent NotePad++). This file will be within the “XTronical-ST7735-Library” folder which is within the Arduino Library folder (see this guide to locate it if your not sure). Un-comment the line that reads //#define SCREEN_BUFFER so it just reads #define SCREEN_BUFFER. Save and close this file.

Important 2 : Ensure sound buffer is set high enough, default will make sound play too slowly

In the XT_DacAudio.h file you will need to alter the line that says

#define BUFFER_SIZE 600

to

#define BUFFER_SIZE 1600

otherwise the sound will play too slowly and not be correct. This is because the Frogger display code takes a reasonable amount of time to execute.

Prerequisites out of the way lets move on.

What has been added?
Four main game elements have been added in this build, scoring, flies, lady frogs and sound. In addition the timer bar at the bottom that just rapidly went down and then restarted has been altered to correctly progress down at the same rate as the arcade version of the game (around 32 seconds) and if it runs out before you get your frog home you lose a life.

Fly’s
Flies appear randomly in a frog home at the top of the screen, if you land on a fly when you jump home then you gain 200 points.

Lady Frogs
These appear randomly (less chance than a fly appearing as far as I can determine watching the arcade version) on the first row of logs that you come across going up the screen. Note that most sites talking about Frogger just state that they appear randomly on logs, however, after playing the game it would appear they can only appear on this first row of logs and no-where else. If you land on a Lady Frog then she will hitch a ride on your back as you continue the game. If you get to a “home” with her on your back then you score an additional 200 points when you make that home jump successfully.

Scoring
All critical scoring elements have been added, as mentioned the additional points for the lady frogs and flies above, but also you score 10pts for every “game beat” left on the clock. There are 60 game beats on the timer at the start of each new frog. I know that I stated above that the timer bar takes 32 seconds to end, which doesn’t make sense from a 60 game decrements for the actual timer bar. And it doesn’t, a 30 second countdown seems to make most sense when used with 60 game beats. i.e. 0.5s per game beat. However I timed the time it took for the bar to go down several times and 32 seconds seems to be the time it takes. So in the code this time is converted to 60 changes in the timer bar by a simple calculation. I find it hard to believe that the original coder (can’t find out who, but developed originally by the company Konami) would do this calculation back in the day (as easy in modern language but pain and time consuming in assembly). So presuming that MAME is correct (the arcade emulator I’m using) and for these older arcade machines it is very very accurate, then I presume that there as some hardware on the board that help in this 32 seconds to 60 beats conversion. Possibly just a simply 555 timer circuit that they tweaked with different settings to give a good game-play timer countdown but would always countdown from 60 beats.

Also you are awarded 10 points for every “new forward” position you jump to. That is to say when you do your first jump from your home position you will get 10 points, but if you then go backward and then forward again you will not get another 10 points as you have not gained any new ground from your last farthest position up the game board.

Sound
All game sounds apart from music are present for the first level and are digitised versions of the actual arcade sounds. The music and any later sounds on other levels have not yet been added.

What’s missing from the level 1 game play?
There is only one omission from the level 1 game-play as far as I know and that is the part of the game that speeds up certain lanes if you take too long getting all your frogs home. I need to re-jig some of the classes to implement this in a way I would like, so held off on this till next time. Apart from that I l think level 1 is complete, please comment if you know of something I’ve missed for the start level.

Upgraded circuit
As there is now sound there have been some additions to the basic circuit to enable this. Mainly the introduction of a PAM8403 Audio Amplifier board, a couple of resistors and a variable resistor. See this article for the full list of components and a basic test build. See also the pages that go through and install the DACAudio library, which is a requirement to play the sound. See the menu option “Basics->Audio->Dacs for Sound” as a starting point to the articles. The full Frogger circuit is now below (click to enlarge):

 

 

And here is the breadboard diagram equivalent (click to enlarge)

and finally what it looks like in real life (click to enlarge)

 

 

That’s it for this article, hopefully you’ve found it enjoyable, if you have please consider subscribing (if you’ve not already done so) to the associated Youtube channel and also this website, where if you do you will receive emails when new articles are posted. In the next Frogger article we will add in the background music and implement at least level 2 of the game, perhaps more.

1 Comment

Comments are closed.