[Solved] Does anyone know if there's a code/tutorial like this? Mini-game idea?

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
User avatar
Nanahs
Veteran
Posts: 297
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

[Solved] Does anyone know if there's a code/tutorial like this? Mini-game idea?

#1 Post by Nanahs » Sat Feb 09, 2019 3:55 pm

I was thinking of adding a cooking mini-game on my game.

The idea is having a kitchen as a background (kind of abvious hah), and there would be different recipes.

A background like this:

Image

To cook these recipes you'd need 3,5 ingredients. For eg., let's say it's a sandwich. Then the ingredients would be: bread, cheese, tomato and lettuce.

There would be "tomato.png", "lettuce.png", "chocolate.png", etc. And they would be displayed like this (animated):

Image

You would have to click the image(ingredient) you need when it shows up inside the circle frame.
Then it would go to one of the square boxes, so the person would know that one of the ingredients was already picked.

If it's not an ingredient you need, it simply would go to the box, or maybe an "X" could appear when clicked.

Image

And then when the person have all the ingredients they win the game (kind of obvious haha).

I know how to make this in a simple way. Like a "questions and answers" game. But that wouldn't be fun at all.
I was thinking of making it animated like this.

I'm not asking anyone to make this for me :oops: :lol:
I just want to know if someone have any idea how it could work.

If the code works nice, I think it can help other people too.

Thanks.
Last edited by Nanahs on Sun Feb 10, 2019 5:05 pm, edited 1 time in total.

Human Bolt Diary
Regular
Posts: 99
Joined: Fri Oct 11, 2013 12:46 am
Contact:

Re: Does anyone know if there's a code/tutorial like this? Mini-game idea?

#2 Post by Human Bolt Diary » Sat Feb 09, 2019 4:37 pm

You can define each recipe as an object that takes a list of ingredient names. Each ingredient is then placed into a dictionary so you can track if it's been added or not:

Code: Select all

class Recipe(store.object):
    def __init__(self, ingredients):
        self.ingredients = {i: False for i in ingredients}

    def add_ingredient(self, name):
    	"""If an ingredient is part of the recipe, add it.
    	Returns:
    	    bool: True if added, else False
    	"""
        if self.ingredients.get(name) is not None:
            self.ingredients[name] = True
            return True
        return False

default apple_pie = Recipe(['apples', 'flour', 'sugar'])
Then each ingredient as an object:

Code: Select all

class Ingredient(store.object):
    def __init__(name, image):
        self.name = name
        self.image = image
        
default apples = Ingredient('apples', 'apples.png')
default flour = Ingredient('apples', 'flour.png')
default sugar = Ingredient('apples', 'sugar.png')
Then write a function to try and add the ingredient, and show a screen with a red X if not:

Code: Select all

def try_to_add_ingredient(recipe, ingredient):
    result = recipe.add_ingredient(ingredient)
    if not result:
        renpy.show_screen('red_x_screen')
You can then create an screen action like:

Code: Select all

imagebutton idle apples.image action Function(try_to_add_ingredient, apple_pie, apples.name)

User avatar
Nanahs
Veteran
Posts: 297
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: Does anyone know if there's a code/tutorial like this? Mini-game idea?

#3 Post by Nanahs » Sat Feb 09, 2019 7:02 pm

Human Bolt Diary wrote:
Sat Feb 09, 2019 4:37 pm
You can define each recipe as an object that takes a list of ingredient names. Each ingredient is then placed into a dictionary so you can track if it's been added or not:

Code: Select all

class Recipe(store.object):
    def __init__(self, ingredients):
        self.ingredients = {i: False for i in ingredients}

    def add_ingredient(self, name):
    	"""If an ingredient is part of the recipe, add it.
    	Returns:
    	    bool: True if added, else False
    	"""
        if self.ingredients.get(name) is not None:
            self.ingredients[name] = True
            return True
        return False

default apple_pie = Recipe(['apples', 'flour', 'sugar'])
Then each ingredient as an object:

Code: Select all

class Ingredient(store.object):
    def __init__(name, image):
        self.name = name
        self.image = image
        
default apples = Ingredient('apples', 'apples.png')
default flour = Ingredient('apples', 'flour.png')
default sugar = Ingredient('apples', 'sugar.png')
Then write a function to try and add the ingredient, and show a screen with a red X if not:

Code: Select all

def try_to_add_ingredient(recipe, ingredient):
    result = recipe.add_ingredient(ingredient)
    if not result:
        renpy.show_screen('red_x_screen')
You can then create an screen action like:

Code: Select all

imagebutton idle apples.image action Function(try_to_add_ingredient, apple_pie, apples.name)
Thank you so much! I'll try that :)

Post Reply

Who is online

Users browsing this forum: Bing [Bot]