Return select grid selection back to calling function

Hi Jakub,

sorry for the late answer! Find some time to work on the project again.
First I removed the "Select Level" menu entry from the game's play screen because it made no sense there either. Replace it with a save game entry.

playdate-20240826-113408

Next I added the "Select Level" entry to the games Start/Menu screen, where it is actually has more sense, UI wise.

Oxydian 2024-08-26 11.12.27

In the game's menu screen, I'm using now something called as a "SceneManager", which lets me switch between different screens.

function Menu:update()
    if self.active then
        if pd.buttonJustPressed(pd.kButtonLeft) then
            self.gridview:selectPreviousColumn(true)
        elseif pd.buttonJustPressed(pd.kButtonRight) then
            self.gridview:selectNextColumn(true)
        end

        if pd.buttonJustPressed(pd.kButtonA) then
            local _, _, selectedColumn = self.gridview:getSelection()
            if #self.elements == 3 then
                if selectedColumn == 1 then
                    SCENE_MANAGER:switchScene(GameScene, CUR_LEVEL, CUR_X, CUR_Y, STONES, LEVELS)
                elseif selectedColumn == 2 then
                    SCENE_MANAGER:switchScene(GameScene, nil)
                else
                    SCENE_MANAGER:switchScene(LevelSelectView)
                end
            else
                if selectedColumn == 1 then
                    SCENE_MANAGER:switchScene(GameScene, nil)
                else    
                    SCENE_MANAGER:switchScene(LevelSelectView)
                end    
            end
        end        

        -- if pd.buttonJustPressed(pd.kButtonA) then
        --     GameScene()
        -- end
    end

Using the SceneManger code module, I can now simply passing the select level from the "Select Level screen" back to the Game Scene as a parameter.

Oxydian 2024-08-26 12.21.07

Oxydian 2024-08-26 12.22.33

Everything now working fine and the game is mostly in a playable state. Also thanks for the advice for optimizing the code. Before adding new level(s) and other features, I will do the optimizing first. But I have to say that I not really completely understand some of code yet.
I might create a repo for you, maybe you just have look at it, if you have some time. Anyway thanks for the great help....

1 Like