[Game]Pokittobloids

Do not remember any more. Some positive value.

1 Like

Right. Got some ditties for the menu and the in-game, though I’m considering doing a 2nd tune for the in-game experience so you have a choice of a happy tune or a much more subtle-in-the-background tune…
In any case, is there a way I can place the audio files into a subfolder on the SD card and point to it? I tried with ./folder/filename.wave and also without the dot, like /foldername/filename.wav but neither works.

PS. I also find on the hardware that when the wav loops, there’s a loud click. Is that something anyone else is experiencing? I guess if i wanted to loop songs, it might be best to fade them at the start and ends instead, but that makes it a little less loopy :slight_smile:

try “foldername/filename.wav” or “/sd/foldername/filename.wav`”.

1 Like

Thanks @Hanski - your first suggestion worked a treat!

2 Likes

Aaargh. How do you stop playing a song when you play it using the play_from_sd() method?

I cant’ seem to get play or pause to work.

I tried:

… Top of my code…

g_sound = pygame.mixer.Sound()

… then when trying to stop/pause:

g_sound.pause # or g_sound.play

Neither works. When I try declare say a pause sound using pauseMusic = pygame.mixer.pause it gives me an error the method doesn’t exist.

For now I’ve made a silent wav file to play but it sounds terrible due to the 8-bit quality, whereas if you don’t have music playing, it’s proper silent.

g_sound.pause should pause the audio. If you call play_sfx or other play command, it should start playing again.

Weird, because it ain’t working for me…

This is my code:

(top of source):

# Init audio
g_sound = pygame.mixer.Sound()

Then a class with these methods:

def stopMusic(self):
        global isThisRealHardware
        
        if (isThisRealHardware == True):
            g_sound.sound.reset()
            #g_sound.play_from_sd(pauseSong)    # Silent wav file - terrible!
            g_sound.pause
        
def playMenuMusic(self):
        global isThisRealHardware
        
        if (isThisRealHardware == True):
            g_sound.play_from_sd(menuSong)

Then in my while true statement:

if eventtype.type == pygame.KEYDOWN:
            if (gameState == 0):
                if (eventtype.key == pygame.K_RIGHT):
                    musicEnabled = False
                    if (musicIsPlaying == True):
                        interface.stopMusic()
                        musicIsPlaying = False
                    
                if (eventtype.key == pygame.K_LEFT):
                    musicEnabled = True
                    if (musicIsPlaying == False):
                        interface.playMenuMusic()
                        musicIsPlaying = True

With the reset() method commented out, the menu song just keeps playing, ie. not pausing/stopping.
When I uncomment it so I reset and pause, the song goes into an infinite loop of playing the wave’s first half second over and over…

I looked at your Matti’s nightmare code and how you reset the sound and I’m doing it the same way as you can see…

Ok nevermind. In the end, what finally worked was to point to a fake file g_sound.play_from_sd("dummy.raw") # This file does not exist in my stop method.

It works a treat!

I updated the first post with the release bin and updated screenshot and instructions.

Instead of
g_sound.sound.reset()
use
g_sound.reset()

Instead of
g_sound.pause
use
g_sound.pause()

It won’t fix your problem but I’d like to point out this is redundant.
Just if (isThisRealHardware) should work fine and is generally preferred.

Similarly instead of doing if (something != True) or if (something == False) you can just do if (not something).
(And for C++ and most other languages you use ! instead of not.)

The reason it’s redundant is because isThisRealHardware will be a boolean value of either True or False, so essentially in writing isThisRealHardware == True you’re actually writing True == True or False == True, which then evaluates to either True or False, and the result will be equivalent to the value of isThisRealHardware.

So essentially == True is the boolean equivalent of doing + 0 on an integer.

Thanks @Pharap, I am aware of shorthand boolean use, I just wasn’t sure if it works in Python :slight_smile:

I’ll use shorthand for my future games!

@Hanski - Thanks for clarifying that! I will again use that in the future…

I’ve updated the code in my github account and uploaded the zip file which has the bin, readme and wav files for the music.

Now I can move onto getting this game to run on my Gameshell! :slight_smile:

3 Likes

Hey @jonne - I saw @Hanski release his Matti’s nightmare with a Pokitto emulator. Is there a chance I can do this? What are your requirements to do so? I’d like to make it a self-standing Windows game so my mates can try it without having to buy Pokittos (as much as I try to convince them to)

As a rule of thumb, if == true works then omitting it works too.
If it doesn’t then the language in question must be doing something really weird because that would completely break with convention.

== true only works in the first place because not having it works.

It’s not really shorthand, it’s the ‘proper’ way.

As I say, == true is redundant in the same sense that doing + 0 on an integer is redundant - it’s an extra operation that doesn’t change the result of the expression.
If you add zero to an integer, you get the same integer.
If you compare a boolean to true, you get the same boolean.

Sorry if it seems like I’m overstressing this, but understanding why it’s redundant is important for having a deeper understanding of programming languages in general.

This is touching the surface of an important concept known as ‘evaluation of expressions’,
which underpins how a lot of programming languages function,
so understanding it can greatly help with learning new languages and understanding the intricacies of the ones you already use.

I need to do the same for Pysconian! I will check it out myself and advice here

2 Likes

The easiest chance is to use the Pokitto (standalone) emulator for Windows and rename your game as file.bin. Then you can run the binary by just starting the emulator.

A bit more work is needed if you want to build the game under the simulator (with CodeBlocks).

You can use the existing “micropython” target and put your files under the “PokittoLib \ Pokitto \ POKITTO_LIBS \ MicroPython \ src_py \” folder. Replace the content with your own project files and rebuild “MicroPython” project. If you have changed some environment settings in the Python Editor tabs, like the font, you have to set the font in the main cpp file (in the parent folder of src_py). As a bonus, with the simulator, you can hear the audio also :slight_smile: Simulator simulates the SD card also.

With the simulator distribution, you have to include the executable and some dll:s also. Look at the zip in the Matti project in Itch.io.

1 Like

Thanks @Hanski - much appreciated.

2 Likes

@Hanski - Hi mate. Thanks for your help. I got it up and running easily thanks. However, as you said, the font isn’t right, so some of my text is wrapping. I don’t know what you mean by replacing the font in the main.cpp file - there is no main.cpp file and I see no Micropython classes or method to change the font progammatically. The online IDE seems to just do it for you in the background when you build.

1 Like

The file is located here:

SetFont() is there also.

Sorry but that didn’t work for me. I copied the .cpp file into the MicroPython folder and changed the font and the source file, and it still doesn’t work. ( I took out the license text below so it won’t truncate this code)

#include "Pokitto.h"

#ifndef POK_SIM
#include "USBSerial.h"
#ifdef USE_SEGGER_SERIAL_PRINT
#include "SEGGER_RTT.h"
#endif
#endif

#include "PythonBindings.h"
#include "PokittoFonts.h"

#ifdef POK_SIM
#define PYTHON_SOURCE_FILE_PATH "..\\..\\..\\POKITTO_LIBS\\MicroPython\\src_py\\"
#else
#define PYTHON_SOURCE_FILE_PATH
#endif

Pokitto::Core game;

extern "C" int PythonMain(int argc, char **argv);

int main () {

    game.begin();

    game.display.persistence = 0;

    game.display.setFont(fontTiny);

    if (game.isRunning()) {

        #if PROJ_PYTHON_REPL

        PythonMain(0, NULL);

        #else // Run python script

        // Load the python script and start running it.
        #pragma GCC diagnostic push
        #pragma GCC diagnostic ignored "-Wwrite-strings" // The strings below will not be changed in the function called
        char* argv[] = {
            "",
            PYTHON_SOURCE_FILE_PATH"main.py"
        };
        #pragma GCC diagnostic pop

        PythonMain(2, argv);

        #endif  // PROJ_PYTHON_REPL

   }

    return 1;
}

Keep in mind, as in Mattie’s nightmare, there were no .cpp files anywhere to be seen so I’m unsure how this is helping/not helping.

At the end of the day, why won’t the emulator just run with Pokitto_sim.exe file.bin ? It has the SDL2.dll in there and EEP.ROM, so I’m not sure why you need the source.py files when you said yourself you shoudl just be able to run the emulator with the file.bin by default?

I’m sorry about this, but this is a bit over my head, hence why I’m trying to find a simple working solution. This is not turning out to be simple at all. You’d think the emulator calling a .bin file would work…