Create a mini game

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
Gianserpe
Newbie
Posts: 21
Joined: Mon May 27, 2019 4:20 pm
Contact:

Create a mini game

#1 Post by Gianserpe »

Hello, in the meantime, I apologize for my English. I wanted to create a small game in which I have to do a certain action in a room (in this case break objects in a box), but in doing so I don't have to be discovered by the person who is facing away from me. Randomly the person in front should turn around; if I am breaking objects while the person is watching me I lose. Would anyone have any idea how I could set it up? Or if something already exists in the cookbook. Thanks in advance

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Create a mini game

#2 Post by Per K Grok »

Gianserpe wrote: Sat Oct 24, 2020 2:59 pm Hello, in the meantime, I apologize for my English. I wanted to create a small game in which I have to do a certain action in a room (in this case break objects in a box), but in doing so I don't have to be discovered by the person who is facing away from me. Randomly the person in front should turn around; if I am breaking objects while the person is watching me I lose. Would anyone have any idea how I could set it up? Or if something already exists in the cookbook. Thanks in advance
You could use screens and screen language to do something like that.

Each object that can be broken would be a button, that when clicked on will result in an action.

You will need a variable representing in what direction the other person is looking. You will want to have different images for the direction the other person is looking. Which image is shown depends on the variable.

You will need a timer that randomly changes the value of the variable, making the other person randomly looking in different directions.

When the player clicks one of the buttons the action will depend on the value of the variable that decides in what direction the other person is looking. If the other person looks at the player the action will be something like Jump("youLose"), else the action will be what ever you want breaking the object should result in.

You might want to start by reading a bit about screens and screen language.
https://www.renpy.org/doc/html/screens.html

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Create a mini game

#3 Post by hell_oh_world »

This is how I thought of it...

Code: Select all

screen minigame(number_of_boxes=5, chance=25, look_time_window=1.0):
  # variables that you can modify, when calling the screen. not specifying them leaves them in their default values above.
  # look_time_window >>> the time spent when looking in seconds by the one watching, a tuple can also be passed (min_possible_time, max_possible_time) making the look_time_window random
  # chance >>> the chance of the watcher looking, in this case its 50%
  # number_of_boxes >>> number of boxes that we can break
  
  # variables used by the minigame only
  default chance_change_interval = 0.5
  default current_chance = 0 # 
  default boxes_broken = []
  default looking = False
  
  # set look_time_window randomly if we called screen with something like look_time_window=(1, 10)
  # this makes the time window varies from 1 up to 10 seconds
  $ random_look_time_window = isinstance(look_time_window, (tuple, set, list))
  $ _look_time_window = renpy.random.randint(look_time_window[0], look_time_window[1]) if random_look_time_window else look_time_window
  
  if not looking:
    timer chance_chance_interval:
      repeat True
      action (
        SetScreenVariable("current_chance", renpy.random.randint(1, 100)),
        SetScreenVariable("looking", current_chance <= chance)
      )

  else:
    timer _look_time_window:
      action SetScreenVariable("looking", False)

  text "Looking: {}".format(looking):
    align (0.5, 0.25)

  hbox:
    align (0.5, 0.5)

    for i in range(number_of_boxes):
      python:
        broken = i in boxes_broken
        if broken:
          text = "BROKEN"

        else:
          text = "BREAK"
          
        if looking:
          action = Return(False)

        else:
          action = Function(boxes_broken.append, i)

      textbutton text:
        action action
        sensitive (i not in boxes_broken)

  if len(boxes_broken) == number_of_boxes:
    timer 0.01 action Return(True) # we won if we broke all the boxes

# The game starts here.
label start:
    call screen minigame(chance=100) # chance is 100, look_time_window is 1.0 sec, number_of_boxes is 5
    if _return: # we check if we won the game, _return handles what we passed in the Return() action
      "YOU BROKE ALL OF THEM!!!"

    else:
      "NOT ON MY WATCH!!!"

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Silac