Magic Lantern Forum

Developing Magic Lantern => Modules Development => Topic started by: petabyte on May 26, 2021, 02:46:14 AM

Title: ML Tetris (mltetris.mo)
Post by: petabyte on May 26, 2021, 02:46:14 AM
Source code: https://github.com/petabyt/mltetris
Download: https://github.com/petabyt/mltetris/releases/download/0.1.0/mltetris.mo

Of course, I was too lazy to actually write the game myself, so I ported somebody
else's code. (http://spritesmods.com/?art=zx3hack, GPL3)

Demonstration:

https://www.youtube.com/watch?v=F0wOXCJyLEw
Title: Re: ML Tetris
Post by: theBilalFakhouri on May 26, 2021, 08:02:34 AM
Cool, thanks for sharing
Title: Re: ML Tetris (mltetris.mo)
Post by: petabyte on November 02, 2022, 11:25:43 PM
Update:
Will eventually be merged into magiclantern_simplified. https://github.com/petabyt/magiclantern_simplified/tree/tetris
Some notes:
- menu_redraw_blocked is set to 1 to prevent flickering as menu is being drawn.
- task_create is called to keep the ML menus in place after the game is quit.
- Code is based on my project, ptetris (https://github.com/petabyt/ptetris/), which can be compiled and run with X11/rawdraw
Title: Re: ML Tetris (mltetris.mo)
Post by: dpjpandone on November 19, 2022, 01:26:24 AM
Does not work on EOSM. The game starts but none of the buttons work.
Title: Re: ML Tetris (mltetris.mo)
Post by: petabyte on November 19, 2022, 03:13:37 AM
Should work if you compile it yourself. MODULE_KEY_PRESS macros might be different.
Title: Re: ML Tetris (mltetris.mo)
Post by: dpjpandone on November 25, 2022, 05:21:17 PM
I did compile myself, Where to change MODULE_KEY_PRESS macros? you use same format as arkanoid (working) what else could be the problem? Is it because EOSM has "Q" "Set" combined? so game does not start?


switch(key)
    {
    case MODULE_KEY_Q:
        running = 0;
        return 1;


game does not start until "Q" ?
The blocks fall, just cannot move or flip them and cannot exit until level fills up and Game Over
Title: Re: ML Tetris (mltetris.mo)
Post by: petabyte on November 25, 2022, 07:16:30 PM
Quote from: dpjpandone on November 25, 2022, 05:21:17 PM
Is it because EOSM has "Q" "Set" combined? so game does not start?
Maybe? I don't know, I've never used an EOS M and I'm not familiar with the button macros.
Are you compiling https://github.com/petabyt/magiclantern_simplified/tree/tetris/modules/tetris or https://github.com/petabyt/mltetris?
Wouldn't make sense if none of the buttons work, I assume it must be some kind of major bug. Maybe try in Qemu?
Title: Re: ML Tetris (mltetris.mo)
Post by: dpjpandone on December 02, 2022, 07:57:21 PM
compiled source from: https://github.com/petabyt/mltetris
Title: Re: ML Tetris (mltetris.mo)
Post by: dpjpandone on December 28, 2022, 04:28:38 AM
OK!

I picked up a 5D3 last week and the game works on this camera. I would like to suggest some small improvements:

-I think the speed should start off slower and increase over time
-pressing a direction and holding it should be read as multiple button presses in that direction. This would improve playability and reduce wear and tear on the hardware
- The game should be the highest level priority for drawing graphics, as it stands the audio meters conflict with the top of the screen.

I will do some homework on my end to try to implement some of these proposals and see if you like them.. In the meantime if any of these ideas appeal to you and you have suggestions I would love to discuss further!

Thanks for such a neat module!
Title: Re: ML Tetris (mltetris.mo)
Post by: petabyte on December 28, 2022, 04:55:13 AM
QuoteI think the speed should start off slower and increase over time
Good idea! I'll implement this when I have the time.

Currently I haven't touched the tetris code since August, so I'll have to find the time to re-read the source code and fix a few things.
Eventually, it should end up in the magiclantern_simplified repository or other forks as it has a compatible license.
Title: Re: ML Tetris (mltetris.mo)
Post by: dpjpandone on December 28, 2022, 06:05:28 AM
I found myself failing to align the blocks perfectly on the tiny screen and one down press makes it permanent. This small change makes it more playable (IMO):

case MODULE_KEY_PRESS_DOWN:
    testfield.currBlockY++;
if (fieldIsPossible(&testfield))
        {
            fieldDup(&field, &testfield);
        }


        //mustFixBlock = 1; //This stobs the block on the current row (not needed if we don't want block to drop instantly
        break;
    }
Title: Re: ML Tetris (mltetris.mo)
Post by: dpjpandone on December 28, 2022, 06:26:25 AM
Quote from: petabyte on December 28, 2022, 04:55:13 AM
Good idea! I'll implement this when I have the time.


this might be helpful (from Pong lua script)

game_speed = 3
    counter = 0

    ball_dx = game_speed
    ball_dy = math.random(-game_speed, game_speed)

    AI_maxspeed = game_speed

    while menu.visible do
        --gradually increase speed
        counter = counter + 1
        if counter == 1000 then
            counter = 0
            game_speed = game_speed + 1
            AI_maxspeed = game_speed
        end


so in the case of tetris a higher (speed) number slows the game down since MSLEEP uses this variable, so maybe start with a speed of 300 and decrement by 5 each time a line is cleared?
Title: Re: ML Tetris (mltetris.mo)
Post by: petabyte on December 28, 2022, 11:55:46 PM
I've abandoned the archived tetris module (https://github.com/petabyt/mltetris) but the last one I've worked on is https://github.com/petabyt/magiclantern_simplified/tree/tetris/modules/tetris (complete rewrite)
It's been a while since I've touched the two, but the more recent one is much better at rendering, but has slight game logic issues. Can't remember exactly what.