How to conditionally display an ATL and update game logic for mini-game?

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
newbiemate
Regular
Posts: 85
Joined: Tue Dec 19, 2017 1:36 pm
Contact:

How to conditionally display an ATL and update game logic for mini-game?

#1 Post by newbiemate » Tue Oct 30, 2018 11:46 am

I don't quite understand how to render another screen temporarily, and also have it run some logic needed to update the state of the mini-game world. For example, I want a ball to fly across the screen from point A to point B for 0.5 seconds, if I click on an image button.

Code: Select all

init -1:
    
    transform throw_ball():
        subpixel True
        xpos 960
        ypos 1080
        rotate -360
        linear 0.5 xpos 0 ypos 0

init -1 python:
    # Set up some objects to track the game state.
    ball = Ball("baseball")
    user = Player("Sam", baseball=ball)
    game_world = World(ball, user)


screen doit():
                    
    imagebutton:
        action Return(user.name)
        idle "images/player.png"
        xpos 400
        ypos 0

screen render_ball():
    
    add "images/ball.png" at throw_ball()
       
label start():

    scene bg background
    
    while True:  
    
        call screen doit()
        $ res = _return
        
        if res == user.name:
                show screen render_ball()
                $ game_world.updateScore()
                $ ball.checkAndUpdate()
                $ renpy.pause(0.5)
                hide screen render_ball
    
    return
The basic flow is this:

- Player clicks on the player's icon (the imagebutton). The action is returned, and the result is checked.
- If result is the player's name, render the ball ATL, update the mini game logic, wait for the ATL to finish (0.5s), then hide the ball because we've thrown it.
- Game while loops back and begins the interaction again, waiting for the player to click on his icon.

There are two problems I'm seeing here:

1) When the ball screen renders, everything else on the screen disappears, and after the ball screen is hidden, the displayables in the main screen returns again. @rames44 mentioned in another thread that it's because when action Returns back to the label, it hides the default screen, which is why I see them disappear. If I put the ball screen in the doit() screen, how can I conditionally render throwing my ball there?

2) I have to also update the game world logic. How do I also conditionally update the game logic if I move the ball screen code into the doit() screen?

I guess I don't understand how to handle the overall user interaction with the screen. Can someone help?

DannX
Regular
Posts: 99
Joined: Mon Mar 12, 2018 11:15 am
Contact:

Re: How to conditionally display an ATL and update game logic for mini-game?

#2 Post by DannX » Wed Oct 31, 2018 8:55 am

I think what you need is screen actions.

Bear in mind these are just suggestions as I am not able to test it out right now to see if this properly works:

1) Instead of Return, you can try using Show('render_ball') in doit() screen, so clicking the button shows the screen automatically, and in render_ball screen, add a timer so it hides itself after the animation ends.

2) As with 1), try using Function() screen actions to trigger your objects methods from doit(). You can set more than one action to a button by providing it a list of actions.

Roughly, this is what I mean:

Code: Select all

screen doit():
                    
    imagebutton:
        action [Show('render_ball'),
                Function(game_world.updateScore),
                Function(ball.checkAndUpdate)]

screen render_ball():
    
    add "images/ball.png" at throw_ball()
    
    timer .51 action Hide('render_ball') #set the time a few miliseconds after the animation ends
Moving the ball screen code to the doit screen should also be possible, you would probably have to use some some if else logic and extra variables.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], _ticlock_