Basic Interactive Grid Map

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Basic Interactive Grid Map

#1 Post by noeinan »

I've been working on this for one of my games and figured I would release it in case anyone else was interested. This is a grid map, and each "square" is hidden until the player visits that area. You can see the map from the in game menu (press escape).

You can also click the individual map squares to be taken to the "label" corresponding to that location. Right now, I just have each of the squares going back to the "start" label, but you can change this to suit your needs.

To add this code to *your* game, you need to copy the following files into your "game" folder:
-mapscreen.rpy
-mapcomp.rpy
-copy the entire "map" folder, which contains my default images

In addition, you need this code at the start of your script file:

Code: Select all

init python hide:
    for file in renpy.list_files():
        if file.startswith('map/') and file.endswith('.png'):
            name = file.replace('map/', '').replace('.png','')
            renpy.image(name, Image(file))
It just defines all the images without you having to do it manually.

You need this block of code also at the start of your script file:

Code: Select all

init -2 python:
    map_a1 = "hidden"
    map_a2 = "hidden"
    map_a3 = "hidden"
    map_a4 = "hidden"
    map_a5 = "hidden"
    map_a6 = "hidden"
    map_a7 = "hidden"

    map_b1 = "hidden"
    map_b2 = "hidden"
    map_b3 = "hidden"
    map_b4 = "hidden"
    map_b5 = "hidden"
    map_b6 = "hidden"
    map_b7 = "hidden"

    map_c1 = "hidden"
    map_c2 = "hidden"
    map_c3 = "hidden"
    map_c4 = "hidden"
    map_c5 = "hidden"
    map_c6 = "hidden"
    map_c7 = "hidden"

    map_d1 = "hidden"
    map_d2 = "hidden"
    map_d3 = "hidden"
    map_d4 = "hidden"
    map_d5 = "hidden"
    map_d6 = "hidden"
    map_d7 = "hidden"

    map_e1 = "hidden"
    map_e2 = "hidden"
    map_e3 = "hidden"
    map_e4 = "hidden"
    map_e5 = "hidden"
    map_e6 = "hidden"
    map_e7 = "hidden"
Which just sets the parts of the map as hidden. If you want a "home" square or something to be shown from the beginning of the game, just set that square to "found" instead of "hidden".

If your game is not already set up with a Quick Menu, you will need to add one.

Add this code to the bottom of your screens.rpy file:

Code: Select all

##############################################################################
# Game Menu
#
# Screen that appears when the player presses the escape button.

image logo = "logo.jpg"

screen game_menu:
    tag menu
    
    add "logo"
    
    frame: 
        xalign .5
        yalign .33
        
        has vbox spacing 5
   
        textbutton _("Continue") action Return()
        textbutton _("Save Game") action ShowMenu("save")
        textbutton _("Load Game") action ShowMenu("load")
        textbutton _("Map") action ShowMenu("map")
        textbutton _("Preferences") action ShowMenu("preferences")
        textbutton _("Main Menu") action MainMenu()
        textbutton _("Help") action Help()
        textbutton _("Quit") action Quit()
Then add this code *after* the start label.

Code: Select all

    $ _game_menu_screen = "game_menu" # This code activates the "pause menu" in screens.rpy
After that you should be good to go! This is under a Creative Commons license, so you may use it however you like.
Attachments
Hidden Map.png
Revealed Map.png
15.02.05 Interactive Map.rar
(1.58 MiB) Downloaded 651 times
Image

Image
Image

User avatar
Hazel-Bun
Eileen-Class Veteran
Posts: 1010
Joined: Sun Oct 28, 2012 6:03 pm
Completed: Sunrise: A Dieselpunk Fantasy & Ultramarine: A Seapunk Adventure
Projects: Thrall: A Dark Otome Visual Novel
Organization: AURELIA LEO, LLC
Tumblr: authorzknight
itch: authorzknight
Contact:

Re: Basic Interactive Grid Map

#2 Post by Hazel-Bun »

Nice! Thanks for sharing :)
Black bookstore owner. Diverse fiction reviewer. Bestselling romance author. Award-winning fiction editor. Quite possibly a werewolf, ask me during the next full moon.

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Basic Interactive Grid Map

#3 Post by noeinan »

You're welcome. :) Hope folks fine it useful!
Image

Image
Image

User avatar
LimeLord
Newbie
Posts: 3
Joined: Sun Jun 05, 2016 3:50 pm
Tumblr: limelord
Contact:

Re: Basic Interactive Grid Map

#4 Post by LimeLord »

Holy cr--- I think this is what I was looking for!! Thanks so much!

DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: Basic Interactive Grid Map

#5 Post by DragoonHP »

This a great idea daikiraikimi.

A few tips though:
-> Use a dict instead of multiple variables (to reduce the number of defines) and since your tile image befines follow a pattern, you can reduce it into a simple loop. Something like:

Code: Select all

init -2 python:
    
    # These three lines create a dict with keys "a1" to "e7" and assign the value of "hidden" to all of them.
    kv = [[x+str(y), "hidden"] for x in ["a", "b", "c", "d", "e"] for y in range(1, 8)]
    map = {key: value for (key, value) in kv}
    del kv
    
    # This function creates the tile_* images.
    def generate_displayable():
        for i in map:
            name = "tile_" + i
            d = ConditionSwitch(
                "map['{}'] == 'found'".format(i), Image("map/tile {} found.png".format(i)),
                "map['{}'] == 'hidden'".format(i), Image("map/tile {} hidden.png".format(i)),
                "True", Image("map/tile {} found.png".format(i)),
                )
            
            renpy.image(name, d)
            
    generate_displayable()
-> In the same spirit, you can loop-ify the hotpsots creation.

Code: Select all

screen map:
    
    # Starting posotion of first tile and spacing b/w tiles
    default bx = 232
    default by = 68
    default s = 116
    
    tag menu
    modal True
    
    imagemap:
        xalign 0.5 yalign 0.5
        
        ground "map base"
        
        for i, y in enumerate(["a", "b", "c", "d", "e"]):
            for x in range(1, 8):
                $ cx = bx + s*(x-1)
                $ cy = by + s*(i)
                $ n = y + str(x)
                
                hotspot (cx, cy, 117, 117) action [SetDict(map, n, "found"), Hide("menu"), Jump("start")]
Doing it this way, you won't need mapcomp.rpy and you will reduce the amount of manual labour required.

PS: Doing it via buttons will probably be a bit more effecient.
Attachments
script.rpy
(1.67 KiB) Downloaded 145 times
mapscreen.rpy
(1.45 KiB) Downloaded 146 times

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Basic Interactive Grid Map

#6 Post by noeinan »

DragoonHP wrote:This a great idea daikiraikimi.

A few tips though:
-> Use a dict instead of multiple variables (to reduce the number of defines) and since your tile image befines follow a pattern, you can reduce it into a simple loop. Something like:

Doing it this way, you won't need mapcomp.rpy and you will reduce the amount of manual labour required.

PS: Doing it via buttons will probably be a bit more effecient.
Thank you very much for the tips! It's been a long time since my programming courses in college, and I really need to brush up again. I've used a simple loop like this one by leon before, but would definitely like to expand that knowledge. Typing the same thing over and over gets tedious, haha!

Code: Select all

init python hide:
    for file in renpy.list_files():
        if file.startswith('bg') and file.endswith('.jpg'):
            name = file.replace('BG/','').replace('/', ' ').replace('.jpg','')
            renpy.image(name, Image(file))
Image

Image
Image

User avatar
Trafagal
Regular
Posts: 100
Joined: Mon Apr 29, 2019 9:32 am
Contact:

Re: Basic Interactive Grid Map

#7 Post by Trafagal »

noeinan wrote: Thu Feb 05, 2015 2:21 pm
To add this code to *your* game, you need to copy the following files into your "game" folder:
-mapscreen.rpy
-mapcomp.rpy
-copy the entire "map" folder, which contains my default images
Hi ,

I would like to find out where are the files mapscreen.rpy and mapcomp.rpy that you refers to?

Thank you.
Check out some of my stuffs here:https://linktr.ee/theartofjoshlab

Art Portfolio: https://www.instagram.com/theartofjoshlab/

Working on a personal Visual Novel~

User avatar
Trafagal
Regular
Posts: 100
Joined: Mon Apr 29, 2019 9:32 am
Contact:

Re: Basic Interactive Grid Map

#8 Post by Trafagal »

Oh nvm, I just found it!
Check out some of my stuffs here:https://linktr.ee/theartofjoshlab

Art Portfolio: https://www.instagram.com/theartofjoshlab/

Working on a personal Visual Novel~

Post Reply

Who is online

Users browsing this forum: No registered users