Our RenPy Game Part 3 - Beginning

by IoFAdmin at

renpy | python | programming

Last Post

Last time we created a rough outline for our game's story.

Let's Install RenPy

I'm not going to cover installing and setting up RenPy in detail because the Quickstart official documentation does that very well. Follow the instructions and then come back here. Go on! I'll wait.

Getting Started

Create a new project as detailed in the Quickstart and name it "Pirates" with a resolution of 1280 x 720. Then just take the defaults. Select "Launch Project" and Pirates should start. Close the game and then we can start with our game.

Time For Some Code

RenPy is built on the Python programming language but simple tasks don't really require programming in the traditional sense. Since we're just starting out, we don't need anything complex so we aren't going to write any custom Python code... the "normal" RenPy scripting tags will cover us for now.

From the main "Projects" screen of RenPy, make sure "Pirates" is selected and click script.rpy under "Edit File". Assuming you've set up your text editor correctly, script.rpy will open for editing. I recommend Atom for writing RenPy scripts but you can use whatever you want.

Copy/Paste Time (or Ctrl + C / Ctrl + V for the cool kids)

Copy and paste the code below into your script.rpy and save it. I'll explain what it all does in minute.

define p = Character("Player")
define s = Character("Squid")
define f = Character("Miss Fluffybottom")

label start:
    scene bg insidehouse
    show pirate happy

    p "No Miss Fluffybottom! Wait!"
    "Your cat, the adventurous (and naughty) Miss Fluffybottom runs out the front door of your house. That bad kitty's chasing a bird again! You should probably go after her right meow."

    menu:
        "Go after her.":
            jump house_outside
        "She'll be fine.":
            jump house_inside

    return

label house_inside:
    scene bg insidehouse
    show pirate happy
    p "Just your normal run-of-the-mill house. It's not much but it's home. Mom doesn't seem to be home right now."
    p "Maybe I should go check on Miss Fluffybottom."

    menu:
        "Check on Ms Fluffybottom.":
            jump house_outside

label house_outside:
    scene bg outsidehouse
    show pirate happy

    p "There she is down on the beach chasing the seagulls again. Crazy cat! I should probably bring her back in the house before she gets lost or drowns."
    "The door slams shut and you're locked out of the house!"

    menu:
        "Knock on the door.":
            jump door_knock
        "Go after Ms Fluffybottom.":
            jump beach_squid

label door_knock:
    scene bg outsidehouse
    show pirate happy

    "Knock, knock, knock!"
    p "I guess Mom's not home."

    return

label beach_squid:
    scene bg beach
    show squid

    "As you reach for your cat, a sea creature rises out of the sea."
    s "Boo! Sorry... I mean Roar!"
    "The squid, who definitely doesn't speak English, roars and grabs poor Miss Fluffybottom! Today would've been a good day for a catnap but too late for that."

    show pirate happy at right

    p "Let my cat go you under-cooked calamari!"
    f "Meow!!!"
    "The squid, holding your terrified feline, wipes tears from her eyes. (That calamari insult hurt.) She dives under the waves."

    hide squid

    p "Wow! Mom's gonna be mad."

    show squid

    "The giant squid pops her head above the water and wiggles her tentacles in disgust."
    s "Roar! Gurgle. (Yuck! I guess cousin Johnny is right... cats really are nasty.)"
    "The squid spits out the water-logged Miss Fluffybottom who flies through the air and lands on..."
    "a docked pirate ship!"

    p "Ok... correction. Mom's gonna be SUPER mad. Somehow I have to get on that pirate ship and rescue the cat."
    p "I can start at the pier or those palm trees further down the beach."

Code Explanation

define p = Character("Player")
define s = Character("Squid")
define f = Character("Miss Fluffybottom")

We define three Character objects with names and assign them to short variable names for ease of use. Why type player when we can type p?

label start:
    scene bg insidehouse
    show pirate happy

    p "No Miss Fluffybottom! Wait!"
    "Your cat, the adventurous (and naughty) Miss Fluffybottom runs out the front door of your house. That bad kitty's chasing a bird again! You should probably go after her right meow."

    menu:
        "Go after her.":
            jump house_outside
        "She'll be fine.":
            jump house_inside

    return

label start is a special label where RenPy always starts your game. scene bg insidehouse loads a file named "bg insidehouse" as the background image and show pirate happy loads a file named "show pirate happy" as a Character image.

p "No Miss Fluffybottom! Wait!" has Player (referenced by p) say the text in the quotes. "Your cat, the adventurous (and naughty) Miss Fluffybottom runs out the front door of your house. That bad kitty's chasing a bird again! You should probably go after her right meow." has the Narrator say the text in the quotes.

menu: creates two options: Go after her. and She'll be fine. The jump statements link the menu options to other labels. If someone playing your game selects "Go after her", the game will jump to the code section labeled "house_outside".

label beach_squid:
    scene bg beach
    show squid

    "As you reach for your cat, a sea creature rises out of the sea."
    s "Boo! Sorry... I mean Roar!"
    "The squid, who definitely doesn't speak English, roars and grabs poor Miss Fluffybottom! Today would've been a good day for a catnap but too late for that."

    show pirate happy at right

    p "Let my cat go you under-cooked calamari!"
    f "Meow!!!"
    "The squid, holding your terrified feline, wipes tears from her eyes. (That calamari insult hurt.) She dives under the waves."

    hide squid

    p "Wow! Mom's gonna be mad."

    show squid

    "The giant squid pops her head above the water and wiggles her tentacles in disgust."
    s "Roar! Gurgle. (Yuck! I guess cousin Johnny is right... cats really are nasty.)"
    "The squid spits out the water-logged Miss Fluffybottom who flies through the air and lands on..."
    "a docked pirate ship!"

    p "Ok... correction. Mom's gonna be SUPER mad. Somehow I have to get on that pirate ship and rescue the cat."
    p "I can start at the pier or those palm trees further down the beach."

show pirate happy at right loads the file named "pirate happy" and displays it a the right hand side of the screen. hide squid unsurprisingly hides the image from view.

The labels start and door_knock both end with the return statement which ends the program.

Game Images

The beginning version of our Untitled Pirate Game (UPG) is almost complete but we're missing something... Arrrhg piratey images. Feel free to use any images you want as long as your name them correctly or you can use mine. My images are just placeholders right now so that we can get the game functioning.

Image Downloads:

Note: if you use my images, you will have to rename them by replacing the underscores with spaces in the filenames.

Where Do I Put My Images?

Assuming you named your project "Pirates" like I did, RenPy loads images from "Pirates/game/images/" so you'll need to place your images there.

Update (Apr 25, 2021) - Git Repo Link

If you want to download the files, get them here.

Screenshots

I captured these from RenPy running on Ubuntu. If you followed the tutorial correctly, you should have something similar.

kitchen front door octopus on the beach confronting the octopus

Wrapping Up

If everything went well, you should have a very simple working RenPy game that allows you to reach a "good" and "bad" ending. The bad conclusion ends with you locked out of the house and the good conclusion ends with you on the beach.

We've learned a lot this post: how to set up a RenPy project, how to create Character objects, load image assets, create scenes, create menus and label jumps, and edit the script.rpy file. Pour yourself a piratey drink and take a break because you've earned it!

In our next post, we'll set up our Git repository.

Comments