Page 1 of 1

Game loop within renpy for playing mini-games?

Posted: Mon Dec 19, 2016 10:01 pm
by bats
Generally a game follows this pattern:

Code: Select all

while notQuit:
    game.update()
    userInput.process()
Where the game gets updated and the user inputs gets processed at each iteration. With renpy, it handles the main game loop and inputs. If I want to add some super mario-like gameplay in between the visual novel stuff, how should it be handled? The mario world needs a constant loop to update the screen and to read user input, but renpy also needs to render blit the images to the screen.

I was playing with @nyaatrap's tilegenerator: https://github.com/nyaatrap/renpy-utili ... ilemap.rpy

He builds the initial map with

Code: Select all

 tilemap = Tilemap(map1, tileset, 32,32)
which is a custom displayable and then constructs the image to be rendered with:

Code: Select all

image map = tilemap
I can then call this from renpy:

Code: Select all

label start:
    show screen map
But this renders once and does not handle any keyboard/mouse input. Should the game loop for the world be handled in the init python block like this:

Code: Select all

init python:
    tilemap = TileMap(...)
    
    while notQuit:
        tilemap.update()
        userInput.process()

image map = tilemap
and then I can still call it with show screen map? Or does renpy have a preferred way of handling this?

Re: Game loop within renpy for playing mini-games?

Posted: Tue Dec 20, 2016 10:54 am
by nyaatrap
Ren'Py is not designed for real time event handling.
Basically Ren'Py wait to player's input then do next function (restart main loop), so turn-based game is only option. If you want to make real-time action games, it's better to look for a different game engine.
If you really want, you could do it by writings all events in screens. But performance is terrible - that the reason I was saying blur blur things at this post viewtopic.php?f=51&t=35608#p412003 (It can be better than outdated pygame though).

BTW, tilemap can be updated by given time. Its example is written on viewtopic.php?f=51&t=35608#p393503 (but again, performance is bad)

Re: Game loop within renpy for playing mini-games?

Posted: Tue Dec 20, 2016 4:49 pm
by bats
Hm, even with turn-based games, how is the game supposed to update itself? Do I create a label and then jump to it over and over again?

Like this possibly?

Code: Select all

label doit:
    show screen map
    $ map.update(...)
    if notQuit: 
        jump doit
But this seems really slow.

Re: Game loop within renpy for playing mini-games?

Posted: Tue Dec 20, 2016 5:25 pm
by PyTom
You probably want to check out the creator-defined displaybale odcumentaiton:

https://www.renpy.org/doc/html/udd.html

You can handle events in the event method, and then call renpy.redraw(self, 0) to trigger the render method.