Game loop within renpy for playing mini-games?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
bats
Newbie
Posts: 6
Joined: Sun Dec 18, 2016 4:29 am
Contact:

Game loop within renpy for playing mini-games?

#1 Post by bats » Mon Dec 19, 2016 10:01 pm

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?

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

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

#2 Post by nyaatrap » Tue Dec 20, 2016 10:54 am

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)

bats
Newbie
Posts: 6
Joined: Sun Dec 18, 2016 4:29 am
Contact:

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

#3 Post by bats » Tue Dec 20, 2016 4:49 pm

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.

User avatar
PyTom
Ren'Py Creator
Posts: 15447
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

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

#4 Post by PyTom » Tue Dec 20, 2016 5:25 pm

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.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]