[Tutorial] Making a Mad Libs game. [Sample Game]

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
OokamiKasumi
Eileen-Class Veteran
Posts: 1775
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

[Tutorial] Making a Mad Libs game. [Sample Game]

#1 Post by OokamiKasumi » Thu Oct 17, 2013 5:22 pm

"...I was wondering in particular about how to create a Mad Lib game. I noted that this was one of your first projects using Ren'Py, and I was curious how you approached the project."
My very first project was indeed a Mad Libs game, Yaoi Story (R18!). However, you're the very first person to ask me how I did it.

The key to the whole thing is renpy.input.

In script.rpy, somewhere after label start:

Code: Select all

label MadLibs:
    $ m1 = renpy.input("Name your hero: \n{i}Backspace to erase this name and type in your choice. \nHit ENTER to go to the next choice.{/i}", "Hero", length=20)
    $ m1 = m1.strip() 

    $ ff = renpy.input("Name a Female Friend for the Hero:", "Female Friend", length=20)
    $ ff = ff.strip()

    $ home = renpy.input("Name a type of Home:\n{i}Examples: dorm, mansion, house...{/i}:", "apartment", length=20)
    $ home = home.strip()

    $ dinner = renpy.input("Name a Dinner Course:\n{i}Examples: pizza, roast beef, spagetti & meatballs, lasagne...{/i}", "dinner", length=20)
    $ dinner = dinner.strip()
"Name your Hero." is the text that appears.
"Hero" is the default name that will appear if nothing is typed in.
length = 20 is how many characters are allowed for that name.
$ m1 = m1.strip() takes off any empty spaces after their input.

It looks like this:
ML_01.png
This is the adjusted Input code:

In screens.rpy:

Code: Select all

##############################################################################
# Input

screen input:
    window:
        xalign 0.5
        yalign 0.5
        has vbox
 
        text prompt:
            yoffset 5
            style "say_dialogue"
            xoffset 50
       
        input:
            id "input"
            style "say_dialogue"
            color "#cc9933"
            yoffset 5
            xoffset 70
   
init -2 python:
    style.input_text.size = 20
    style.input_window.background = Frame("textbox1.png", 0, 0)
    style.input_window.left_padding = 80
    style.input_window.right_padding = 100
    style.input_window.bottom_padding = 20
This is for a 1024x768 game.
-- You may need to adjust these numbers to suit your game.


After that, all you need to do is include [m1] in any line, and that word will appear.

Code: Select all

label gamestart: 
    play nature "sfx/Cityscape.wav" fadeout 1.0
    
    scene bg_street with fade
    show Arthur at left with easeinleft
    
    "\n\n\n\nFull night had fallen by the time [m1] headed for [ff]'s [home] for dinner and a movie. She was cooking [dinner], his favorite."

    n2 "The End."
    hide Arthur with moveoutleft
    with Pause (1.0)
    
    return
I did this in Nvl mode, and used a half-page rather than a whole page, for the NVL text. This was so I wouldn't block out the characters and background images.
ML_02.jpg
To do this, start with a 1/2 page graphic with a transparent background that is the Same Size as your game. This one is 1024x768.
textbox2.png
The Narrator Definition looks like this:

in script.rpy:

Code: Select all

init:
# Declare characters used by this game.
    # ---------- CTC blinking arrow -----------------------
    image ctc_blink:
        xpos 1020 ypos 763
        alpha 1.0
        "arrow.png"
        0.75
        alpha 0
        0.75
        repeat
    
    define narrator = Character(None, 
        ctc="ctc_blink", 
        kind=nvl,) 
    
    define n2 = Character(None, 
        ctc="ctc_blink") 
The Textbox definitions look like this:

in options.rpy

Code: Select all

    #########################################
    ## TEXT

    ## The default font:
    style.default.font = "DejaVuSans.ttf"

    ## The default size of text:
    style.default.size = 22

    ## -------Text Alignment ---------------
    ## text Justified 
    style.create("justify_style", "default", u"(text) Justify Style")
    style.default.justify = True

    #########################################
    ## These settings let you customize the window containing the
    ## dialogue and narration, by replacing it with an image.

    ## The background of the window. In a Frame, the two numbers
    ## are the size of the left/right and top/bottom borders,
    ## respectively.
    
        ###############################################
    ##-------------- Textbox ----------------------

    # style.say_window.font = "bluecabin.ttf"
    # style.say_label.size =30

    ## Frame ------------------------
    style.window.background = Frame("ui/textbox1.png", 0, 0)
    
    ## No Frame --------------------
    # style.window.background = "ui/textbox.png"

    ## Margin is space surrounding the window, where the background
    ## is not drawn.

    style.window.left_margin = 50
    style.window.right_margin = 50 
    style.window.top_margin = 0
    style.window.bottom_margin = 50

    ## Padding is space inside the window, where the background is
    ## drawn.

    style.window.left_padding = 70
    style.window.right_padding = 70
    style.window.top_padding = 30
    style.window.bottom_padding = 30

    ## This is the minimum height of the window, including the margins
    ## and padding.

    style.window.yminimum = 201 

    # --------------NVL Box ----------------------------  

    # If you want a different Font for your NVL text. 
    # style.nvl_dialogue.font = "LIBSA1.TTF"
    
    # If you want a different Color for your NVL text. 
    # style.nvl_dialogue.color = "#ffffcc"
    
    # If you want a different Size for your NVL text. 
    # style.nvl_dialogue.size =30
    
    style.nvl_dialogue.justify = True

    ## Interblock spacing: ------------------
    style.nvl_vbox.box_spacing = 3

    ## ----------- Framed NVL box ------------------------
    style.nvl_window.background = Frame("ui/textbox2.png", 0, 0)  
     
    ## ---------- No Frame Nvl Box--------------------
    # style.nvl_window.background = "ui/NVLbox02.png"    
     
    # margins ---------------------------------
    style.nvl_window.top_margin = 0
    style.nvl_window.bottom_margin = 0
    style.nvl_window.left_margin = 0
    style.nvl_window.right_margin = 0
     
    # padding ---------------------------------
    style.nvl_window.top_padding = 30
    style.nvl_window.bottom_padding = 0
    style.nvl_window.left_padding = 550
    style.nvl_window.right_padding = 30
     
    # menu = nvl_menu 

    config.window_hide_transition = dissolve
    config.window_show_transition = dissolve

    # config.empty_window = nvl_show_core
    config.nvl_paged_rollback = True
    style.nvl_vbox.box_spacing = 10
These codes are for a 1024x768 game.
-- You may need to adjust these numbers to suit your game.


The rest is up to you and your creativity. :)

Sample game:
MadLibs-1.0-all.zip
(30 MiB) Downloaded 187 times
None of the files are archived, so feel free to pick it apart and make with it what you like.
Last edited by OokamiKasumi on Sun Dec 15, 2013 1:36 pm, edited 2 times in total.
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

User avatar
Tooz
Newbie
Posts: 2
Joined: Sun Oct 13, 2013 6:07 pm
Contact:

Re: [Tutorial] Making a Mad Libs game. [Sample Game]

#2 Post by Tooz » Fri Oct 18, 2013 1:40 am

Oh my, this is perfect! Thank you so much for sharing. Seeing how you set everything up, down to the little details for customizing the font or textbox, helps tremendously. I can't wait to try it out~! ^^ Thank you!!

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1775
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: [Tutorial] Making a Mad Libs game. [Sample Game]

#3 Post by OokamiKasumi » Fri Oct 18, 2013 4:01 am

Tooz wrote:Oh my, this is perfect! Thank you so much for sharing. Seeing how you set everything up, down to the little details for customizing the font or textbox, helps tremendously. I can't wait to try it out~! ^^ Thank you!!
I'm glad you like the tutorial.
-- I can't wait to see what you do with it. :)
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

User avatar
ComputerArt.Club
Veteran
Posts: 417
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

Re: [Tutorial] Making a Mad Libs game. [Sample Game]

#4 Post by ComputerArt.Club » Sun Dec 17, 2017 4:56 am

This looks interesting! I love doing Madlibs with my students. I must give thisl a go. Thanks!

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1775
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: [Tutorial] Making a Mad Libs game. [Sample Game]

#5 Post by OokamiKasumi » Tue Dec 19, 2017 5:28 am

ComputerArt.Club wrote:
Sun Dec 17, 2017 4:56 am
This looks interesting! I love doing Madlibs with my students. I must give thisl a go. Thanks!
MadLibs games can be hysterically funny if you do them right. Have a go! This type was actually the very first game I made. However, I would not suggest showing my game to your students -- Yaoi Story is R18 for a reason!
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

Post Reply

Who is online

Users browsing this forum: No registered users