Room navigation and free movement

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
Daert
Newbie
Posts: 5
Joined: Mon Feb 13, 2017 7:45 am
Contact:

Room navigation and free movement

#1 Post by Daert »

Hi, I'm working on a simple game which is also a way for me to learn coding. Recently I've decided to try to make some sort of free movement. It was challenging but I was moving slowly. However I feel like I've hit a wall and also I'm pretty sure I've got it somehow all wrong. So after a while of bashing my head against the wall I decided it would be best to ask someone who knows what he's doing.

Alright so here's how I've done it. I've made separate .rpy file for each room. Each room is basically a screen with imagemap with clickable buttons with "Jump" actions directed to labels. Now I know it's probably all wrong and messed up but so far it kinda worked. Here's a little example:

Code: Select all

label room:
    hide screen hallway
    window hide
    show screen bedroom
    show screen minimap
    $ renpy.pause(hard=True)

screen bedroom:
    
    add "bedroom empty.png"
    imagebutton auto "bedroom/pc_%s.png" xpos 905 ypos 328 focus_mask True action Jump("pc")
    imagebutton auto "bedroom/window_%s.png" xpos 000 ypos 062 focus_mask True action Jump("windov")
    imagebutton auto "bedroom/board_%s.png" xpos 525 ypos 142 focus_mask True action Jump("board")
    imagebutton auto "bedroom/exit_%s.png" xpos 609 ypos 592 focus_mask True action Jump("upstairs")
    imagebutton auto "bedroom/bed_%s.png" xpos 000 ypos 427 focus_mask True action Jump("bed")
    imagebutton auto "bedroom/closet_%s.png" xpos 1061 ypos 000 focus_mask True action Jump("closet")
    


label bed:
    hide screen bedroom
    show bedroom_empty
    "Oh I wish I could stay in bed forever...."
    jump room
Now here are some thing I either don't understand or some problems I've stumbled upon:
-hiding stuff
Is there a way to hide everything and just show one thing? As I understand it, every time the player moves from one location to other I have to hide everything that was shown but that doesn't seems right. As I would add more and more locations, the hiding would become ridiculous. Or am I doing it completely wrong?
-minimap on top
I've also started to mess a bit with map. I've made a minimap icon but I'm not sure how to keep it on top all the time. It's an imagemap that jumps to label with map screen.
And of course my biggest and most important question is, is it a viable code or is it a complete nonsense? Oh and please try to keep it as simple as possible, I'm really a beginner. Thanks! :)

MaximeChaos
Newbie
Posts: 9
Joined: Sat Feb 11, 2017 9:21 pm
Contact:

Re: Room navigation and free movement

#2 Post by MaximeChaos »

Code: Select all

label room:
    scene "bedroom empty.png"
    window hide
    show screen minimap
    call screen bedroom

    $ result = _return

    if result == "bed":
        hide screen bedroom
        "Oh I wish I could stay in bed forever...."

    
    elif result == "pc":
        etc.

    jump room

screen bedroom:
    
    imagebutton auto "bedroom/pc_%s.png" xpos 905 ypos 328 focus_mask True action Return("pc")
    imagebutton auto "bedroom/window_%s.png" xpos 000 ypos 062 focus_mask True action Return("windov")
    imagebutton auto "bedroom/board_%s.png" xpos 525 ypos 142 focus_mask True action Return("board")
    imagebutton auto "bedroom/exit_%s.png" xpos 609 ypos 592 focus_mask True action Return("upstairs")
    imagebutton auto "bedroom/bed_%s.png" xpos 000 ypos 427 focus_mask True action Return("bed")
    imagebutton auto "bedroom/closet_%s.png" xpos 1061 ypos 000 focus_mask True action Return("closet")
Sorry I have to go :'(

User avatar
TheKiwi
Regular
Posts: 56
Joined: Sun Feb 03, 2013 4:09 am
Projects: The Waters Above, Heart of the Woods
Organization: Studio Élan
Tumblr: minutekiwi
Contact:

Re: Room navigation and free movement

#3 Post by TheKiwi »

Hi!
Here's what I would do. I added a variable, "area", so we can remember where we are. Then, instead of making a screen for each room, we simply change what's shown depending on where we are. This way, we don't have to hide everything.

Code: Select all

screen movement:
    style_prefix "choice"
    modal True
    vbox:
        if area == "bedroom":
            add "bedroom empty.png" ##This will show your background for the room you are in.
            textbutton "My PC": ##You can change this to be your image button code! This is just for testing purposes.
                action [SetVariable("area", "pc"),Jump("room")] ##I'll explain the Jump later on.
            textbutton "Hallway":
                add "hallway empty.png"
                action [SetVariable("area", "hallway"),Jump("room")]
        elif area == "pc":
            add "pc empty.png" 
            textbutton "Bedroom":
                action [SetVariable("area", "bedroom"),Jump("room")]
        elif area == "hallway":
            textbutton "Bedroom":
                action [SetVariable("area", "bedroom"), Jump("room")]
            textbutton "Kitchen":
                action [SetVariable("area", "kitchen"),Jump("room")] ##blah blah blah etc.
        else:
            pass
Now, I set the Variable (area) to change when we click the button its on. After, we jump to a place called "room".

Code: Select all

label room:
    show screen movement
    show screen minimap
    $ renpy.pause(hard=True)
Here's the empty room. It will have the background change based on the "area" variable. This is good for just testing movement, because there's no way to really add story. For a navigation system though, this is all you'll need.

When you have all the rooms you want coded in, you can add story bits depending on where you are if you want!

The way you can do this is change the

Code: Select all

Jump("room")
to make it jump to scenes. Here's an example of how to show the first scene of the game by going to the PC.

First, we will set a variable to tell the game that we haven't seen the first scene yet. Once you're more comfortable with Ren'py, you could set this based on something like if you've visited a certain area three or more times or something, but this is the simplest example.

Code: Select all

label start:
    $ scene1 = False
    $ area = bedroom
label bedroom:
    scene bedroom
Pretty easy. When the game begins, we know that we haven't seen the first scene yet, and that we started out in the bedroom.
Now, we'll change the Jumps so they all correspond correctly.

Code: Select all

screen movement:
    style_prefix "choice"
    modal True
    vbox:
        if area == "bedroom":
            textbutton "My PC":
                action [SetVariable("area", "pc"),Jump("pc")
            textbutton "Hallway":
                action [SetVariable("area", "hallway"),Jump("hallway")]
        elif area == "pc":
            textbutton "Bedroom":
                action [SetVariable("area", "bedroom"),Jump("bedroom")]
        elif area == "hallway":
            textbutton "Bedroom":
                action [SetVariable("area", "bedroom"), Jump("bedroom")]
            textbutton "Kitchen":
                action [SetVariable("area", "kitchen"),Jump("kitchen")]
        else:
            pass
Notice I took out the "add bedroom_empty.png" lines. That's because we'll jump to scenes now.
For the first scene, we'll start with the MC in his bedroom. To get the story, we must go to the pc.

Code: Select all

label pc:
     scene pc_empty
     if scene1 == False: ##Or, "if we haven't seen this yet..."
         "This is the first scene of the game."
         "Now, I'll show the minimap and movement screens."
          $scene1 = True ##This will remember that we saw the first now, and when we return to the bedroom by navigation, it won't play again.
    else: ##Or, "If we've already seen this...
           pass ##Do nothing.
     jump room_movement
The room_movement label will just show the screens we want. This way, during story, we can't accidentally click and leave the room.

Code: Select all

label room_movement:
    show screen movement
    show screen minimap
    $ renpy.pause(hard=True)
And then you can continue this way by making scenes correspond to the areas and creating flags. Scene1, scene2, etc are hard variables to remember if you have branching, so it might be best to name them something easier to remember.

I hope this helped and it wasn't too confusing! I'm sorry I can't help out with the minimap, but you should be able to just "show screen minimap" and it should stay unless you tagged it or something.

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Room navigation and free movement

#4 Post by philat »

If you call the screen and return from it, the screen is hidden automatically. All you have to worry about is showing what's in each label jumped to.

Daert
Newbie
Posts: 5
Joined: Mon Feb 13, 2017 7:45 am
Contact:

Re: Room navigation and free movement

#5 Post by Daert »

Thank you for your answer Kiwi, I really apreciate it! I'll be honest, I'm not sure I understand it correctly. I'll try to use it in a simple example. Let's say I've got 3 locations, Bedroom, Hallway and Bathroom. Hallway connects Bathroom and Bedroom so that you can't go directly from Bedroom to Bathroom. Now each location has it's own background and buttons used for movement are part of the background (clickable doors). Let's foget everything else for now. Here's my try:

Code: Select all

/label start:
    show random_image
    "Bla blah blah introduction."
    jump bedroom                              

/label bedroom:
    "I'm standing in my room, thinking of hot shower."
    show screen movement 
    $ renpy.pause(hard=True)
/label hallway:
    "I'm standing in the hallway."
    show screen movement 
    $ renpy.pause(hard=True)
/label bathroom:
    "I'm standing in the bathroom."
    show screen movement 
    $ renpy.pause(hard=True)
So far so good (I hope). Now the movement screen:

Code: Select all

screen movement:
    style_prefix "choice"           #What does this do?
    modal True                        # This means the player can interact only with this screen, right?
    vbox:                               #What does this do?
        if area == "bedroom":
            add "bedroom.png" 
            imagebutton auto "bedroom/exit_%s.png" xpos 609 ypos 592 focus_mask True action [SetVariable("area", "hallway"),Jump("hallway")]
        elif area == "hallway":
            add "hallway.png" 
            imagebutton auto "hallway/bedroom_door_%s.png" xpos 609 ypos 592 focus_mask True action [SetVariable("area", "bedroom"),Jump("hallway")]
            imagebutton auto "hallway/bathroom_door_%s.png" xpos 609 ypos 592 focus_mask True action [SetVariable("area", "bathroom"),Jump("bathroom")].
        elif area == "bathroom":
            add "bathroom.png" 
            imagebutton auto "bathroom/exit_%s.png" xpos 609 ypos 592 focus_mask True action [SetVariable("area", "hallway"),Jump("hallway")]
        else:
            pass

Am I going in right direction? I think I understand how this works. Basically all I have to do is setup every location in this single screen and then just show that, instead of setting up individual screen for each location. Now let's say I want more imagebuttons in bedroom. For example a noticeboard that would show an image when I click on it. What I would do, is add another imagebutton to bedroom in movement screen with Jump action. Should I still keep it as an area Variable or would this work:

Code: Select all

imagebutton auto "bedroom/noticeboard_%s.png" xpos 609 ypos 592 focus_mask True action Jump("noticebard")

label noticeboard:     #This would be in bedroom.rpy, a separate file with similar labels that are mostly not story-related 
    show poster
    "Omg I love this band!"
    jump bedroom
Let me know what you think :)

*EDIT
This is a dumb question but.....how exactly do I setup the area Variable?

User avatar
TheKiwi
Regular
Posts: 56
Joined: Sun Feb 03, 2013 4:09 am
Projects: The Waters Above, Heart of the Woods
Organization: Studio Élan
Tumblr: minutekiwi
Contact:

Re: Room navigation and free movement

#6 Post by TheKiwi »

Hi! Sorry to leave you hanging, hopefully I can clear up some info.

style_prefix "choice" was JUST for the textbuttons. I just used it so if you wanted to plug it directly into a game, it would show up correctly.
vbox creates a vertical box to align the choices in. Once again, only necessary with textbuttons or imagebuttons. It only is used for positioning and spacing of the items. Your imagemaps won't need this.

The rest of that first code looks great!

As for your second question, that is definitely a way to do it and would probably the cleanest way to do it, so I say go for it! You can continue this method to do a lot of things, like triggering an event if you look at the noticeboard three times or something. I hope I was of help!

Daert
Newbie
Posts: 5
Joined: Mon Feb 13, 2017 7:45 am
Contact:

Re: Room navigation and free movement

#7 Post by Daert »

Thanks for your reply Kiwi!
style_prefix "choice" was JUST for the textbuttons. I just used it so if you wanted to plug it directly into a game, it would show up correctly.
vbox creates a vertical box to align the choices in. Once again, only necessary with textbuttons or imagebuttons. It only is used for positioning and spacing of the items. Your imagemaps won't need this.
Alright so that means I don't need to use it in my case?
The rest of that first code looks great!
Wooohooo!
As for your second question, that is definitely a way to do it and would probably the cleanest way to do it, so I say go for it! You can continue this method to do a lot of things, like triggering an event if you look at the noticeboard three times or something. I hope I was of help!
Thanks for confirming my thoughts and yes, you've been a great help! My last question would be how do I setup the are Variable? I know it's kinda basic stuff but I'd like to be absolutely sure I'm doing it the right way :)

Daert
Newbie
Posts: 5
Joined: Mon Feb 13, 2017 7:45 am
Contact:

Re: Room navigation and free movement

#8 Post by Daert »

Alright I'm totally stuck with the area variable. I understand the variable tells the game where the player is. But when I use $ area = bedroom in start label, the game tells me that the "name 'bedroom' is not defined". What am I doing wrong? Is the variable tied to some label? Also why is the word "area" showing blue?

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Room navigation and free movement

#9 Post by xavimat »

Don't forget the quotes...

Code: Select all

$ area = "bedroom"
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

Daert
Newbie
Posts: 5
Joined: Mon Feb 13, 2017 7:45 am
Contact:

Re: Room navigation and free movement

#10 Post by Daert »

xavimat wrote:Don't forget the quotes...

Code: Select all

$ area = "bedroom"
Yes that was it! Thank you! Besides that I also had to make some small changes but it appears to be working good now, I'll post the final code later in case anyone has the same problem.

Post Reply

Who is online

Users browsing this forum: henne, Ocelot