Tuesday, September 29, 2020

Bmax - buttonDash 02

As an easy way to show the user what button has to press in each moment, we are going to use the SDL and the screen.c file we created before (don't worry if you don't remember, we are going to practically explain it again).

[Mind you, this entry is made after we adapted screen.c to load a bmp file. That means we can load the pictures in the cmake lists before the code explained here. Nevertheless, we have to make that modular]

Adding pictures to the CMakeLists.txt


With the previous part clear, we can start our road to load the bmp file in the psVita screen.

Note: images will be in BMP because the PNGs require another package to SDL (SDL_image). Although this package works equaly to the one we are using, there's not enough of it defined for the psVita and it won't run without a lot of extra effort.

The First thing to do is define the functions in the headers file (common.h). We are going to need four:
 - One for initializing the library. This also creates the window where the image is load.
 - One for loading the image file.
 - One for cleaning and closing the SDL
 - One (dummy) that calls the other three and print a image on screen (this will be our goodBye img for the app).

Defining the new functions in common.c

With those defined, we can proceed to make the code for them (in screen.c):

initialise SDL

Load bmp image

Clean memory and close SDL + goodBye dummy

Now it's time to focus on the buttonDash code. A good start point is to print the rules (image) on screen using SDL.

Function to load rules image in buttonDash.c


Warning: When all of this is done, it loads the rules image on screen, but it fails to load a second image (specifically fails at creating a new window). Solving this is currently our next step. [It has to be something with the sdl and the memory management]

Sunday, September 27, 2020

Bmax - buttonDash 01

 
Having a selection menu means you can call differents apps or modules, now we need modules to launch.
We have decided to start with a simple and easy minigame.
[The minigame will be named buttonDash, a description is comming later]

First we need to create a new btnDash.c file to work on, and add it to the CMakeLists.txt
[Reminder : This is an specific module or game inside the main app (BMAX)]

updated CMakeLists.txt


The following is to create a function in btnDash.c, we will name it btnDashGame().
This is the function we are going to launch from common.c.

With this, we update the common.c file, in the selectedApp to launch the buttonDash:
[This line goes inside selectedApp function]

if ( !strcmp(selApp,"buttonDash") ) btnDashGame ();

----

[Normally, you know what kind of modules or games you want to do before starting the project. And you do a specific menu for them. However with a launcher this part is sticked to each module. The launcher just call them, that is why we did not mention any of this before.]

We got the code ready to call our new module, it is time to decide what module is going to be.
[This part comes with idea brainstorming, but here we will go just directly to the picked idea.]

Here is a briefly explanation of what are we trying to achieve in this module:

- A minigame with highscore, and current score. Highscore will be saved in a file, for future replays.

- A game flow guided by the speed of pressing buttons correctly. A failure reset the current score.

- The button to press will be showed on screen. One button appears at a time. If no button is pressed in a specific time interval, the game will count this as a failure and, it will pass to the next button.

- An increasing difficulty based in the current score. The difficulty will have 3 stages:
   - Button image shown highlighted, 60 sec before next button appears.
   - Button will not be highlighted, 60 sec before next button appears.
   - Button will not be highlighted, 30 sec before next button appears.
[Higher difficulties with less time may be added later. Another difficuly could be show wrong button to confuse.]

- A pause menu. This screen is to be determinated.

Having the bases of the module, the next step is to draw the flowchart.
[Pseudocode could be used too, but the flowchart makes the big picture clearer. In addition, both can be done together or, done one after another.]

Warning: There are some "steps" that can be omitted, if the knowledge of the rendering were farther (which won't be done in this module).


Button dash flowchart

Tuesday, September 22, 2020

Bmax part 3.2

This entry is about making the main loop to follow the flowchart. The code will be on the main.c file, and it will (most probably) be the last one done in this file. After this, the code will be done particularly to each module, and a few lines in common.c to launch each module.
[Remember that, we are using this flowchart]

We will want to add a confirmation screen, when the user wants to exit. Right now, we have done a dummy function for that.

dummy to know if the user wants to exit


To create the flow in code, we are using a do while loop. The reasons of this are:
 - The app should, at least, show the menu at the begining.
 - We want to show this menu every time the user close any inside module (app).

To control the loop, we will need a variable which changes when the user ask to exit.
Everything else is just directly follow the flowchart.

Note: the chooseLang must be asked before the loop once, if we don't want to ask the user constantly.

main loop in main.c file

With this, it comes the first official release, go to https://homebrew-psvita.blogspot.com/2020/08/main-projects-plan-000.html and check it out.

Bmax part 3.1

In this entry we are making the functions of the main loop.

First, we declare the functions in common.h:

declare new functions in common.h

Now to code the appSelect() function, we are using the same idea of chooseLang() explained here. However, the options offered have changed. Options now:
 - help (default answer in bracket)
 - chooseLang
 - button_dash
 - exit

After doing that, we should check everything is ok, and we don't have made any typo or something. This is made by doing the main just launch it, and printing the answer (launching nothing afterwards).

main.c to check appSelect()

With this assured, we can go to implement selectedApp():

This function is basically a column of ifs with string comparison, where each option launch a function.
It will also receive two arguments, the selected app and the language to use.


selectedApp()


If everything is correct (which it is), now we have our selection menu up and running. We can do a test with:

main.c with code to check our main menu


The only thing left now is to make the loops to keep the game running, until the user wants to exit.

Monday, September 21, 2020

Bmax part 3

Up to now, we have some basic required funtions for the app. It is time to give it another essential feature, we will implement the main flowchart. To do that, we will use the one we did here.

To implement the flowchart, we need to decide a few things:

 - How are we going to get the user input?
   The user will write what he wants to do.

 - Where will the main menu go? after or before chooseLang?
   Better chooseLang right away the app init, and then main menu with option to changeLang again.

 - Which text are going to show on the selections screen?

 - Some flow decissions, that are made on the flowchart, will be explain directly on the code.
   [This should be writen in the draft with the flowchart on more official documents.]



Note 1: To make things easier, the selection menus will only have the default english ime. However we will try to make the sentences short and globally known.

Note 2: After making these selection menus, we can delete previous functions on main, and leave only these two new ones. With this, in theory, we won't have to modify main.c file again.

Note 3: To implement this, we will use one loop in each decission triangle. This will be BMAX's main loop, from there it executes other modules, or it just wait the user input.


Sunday, September 13, 2020

Bmax part 2.6

 

 This is the third entry of the Bmax help, here we are going to explain two new functions (help and echoFile). Besides we have done a few fixes here and there to improve the code and the understanding of the project files.

First of all, we need the txt files on the vpk package, so we are adding those to the project, in the CMakeLists.txt

adding txt files to the project in CMakeLists.txt


Next, we have change the name of main.h to common.h because it is a more adecuate name. After that, we have added declarations for the new functions we are going to create and use this time.

new functions in common.h

Now to the coding part: for the help function we need the language (which we have previously got), and the help printing, but the printing will be used with more texts so we will better have an specific function for that.

We have name the printing funcion, echoFile, as it is going to echo the file on screen.
Any specific explanation of the code is in its comments as a good programming practice.

echoFile function

 Note: In the future should be desirable to upgrade it, and make here the font size bigger to make the text easier to read (this is because, on the contrary with the debug log and other normal prints it is specific for user in-app reading).

Note 2: there is a known bug in japanese text files, caused by the codification. This bug affects to other languages too.


Having done the echoFile function, we need the help function to choose the right txt file (remember that we have one with each language).

Last but not least, we want the help to print the file, it is time to use the echoFile function with the datapath obtained for the language.

help function


Moving forward. We have the basics of an app, it is time to create a github to upload all the code and files of this project. In addition, a re-read and update of some of the previous entries with some fixes will be made. When this is done, we will add the github link on https://homebrew-psvita.blogspot.com/2020/08/bmax-part-0.html to have a quick access to it.

Clarification: this is not the end of the project, it is "only" the point when it goes fully public, and maybe collaborative (if people on github make pushes to the code).

Saturday, September 12, 2020

Bmax part 2.5

 This is the 2nd entry of the BMAX help function. After thinking about that, we have decided that is easier to choose the language with the IME as it lets you write the language directly with the ps vita api.

As we are using the ime and the ime will be used again, we have decided to make another file to have the ime variables and functions easy to find and modify (using the ime sample code).
We will call it (keyboard display -> ) kbDisplay.h


kbDisplay.h


To do the function ChooseLang, we are going to ask the user to introduce the language with the initials (e.g. ENG for english), using the ime to get the input. After that we are returning it as a result, to have it outside. Currently, we have 3 languages included, but we can add any simply repeating the if statements with each lang.

Note: more info about the initials here https://iso639-3.sil.org/code_tables/639/data

Note: as a base code we have used the ime sample.


chooseLang function

Wednesday, September 9, 2020

Bmax part 2

 In this next 2 entries we are going to make the function to call the help, in order to make it able to read different files depending on the language chosen by the user. [This will be divided in 2 functions, one to chose the language and another to trigger the help]

First we need to define (in main.h) and create the function (in common.c).

With that done, we have to make it read the buttons to know the user election.

We make that using the sceCtrl functions. as an entry point we write a function
that prints a text to let the user know how to stop it. And then keeps checking in loop
until the user stop it. Code below:

function definition


function code


* Note: we have made a new file (screen.c) to have everything related to the rendering (currently with sdl) and functions in common.c separated.

adding screen.c to the CMakeLists.txt


After that we have to put a way to give the different options for him to choose. This should be a visual option (graphics rendered on screen or ime dialog) which will see in the next entry.