Code: Select all
#hf - HiddenFolks (Hidden Objects)
# used in conjunction with the 7dots.rpy module
# usage example:
init1:
# define the game background, game time in seconds
# and set game parameters - sprites and position for collected items
$hf_init("bg room", 5,
("beer", 1013, 705),
("elf", 111, 560),
("flowers", 700, 615),
("skull", 1813, 161),
("sprite", 355, 240),
# OPTIONAL PARAMETERS:
# enable cursor change on hover
mouse=True,
# turn on the inventory with the removal of found items from it
inventory=False,
# turn on the highlight of the object on hover
hover=brightness(.05),
# reduce the size of inventory cells so that they do not interfere with collecting items
w=200,
h=200
)
# then the game will be called:
# $hf_start()
# number of uncollected items will be in hf_return
init python:
# automatic declaration of sprites (including webp)
images_auto()
# cursors
config.mouse = {"default": [("images/c/default.png", 1, 1)],
"hand": [("images/c/hand1.png", 2, 10),
("images/c/hand1.png", 2, 10), ("images/c/hand1.png", 2, 10),
("images/c/hand1.png", 2, 10), ("images/c/hand2.png", 2, 10),
("images/c/hand2.png", 2, 10), ("images/c/hand3.png", 2, 10),
("images/c/hand3.png", 2, 10), ("images/c/hand2.png", 2, 10),
("images/c/hand2.png", 2, 10)],
"finger": [("images/c/finger.png", 2, 10)]}
# SETTINGS
# whether to change the cursor on hover
hf_mouse = False
# True - found items are added to inventory
# False - found items disappear from inventory
# None - inventory is not displayed
hf_inventory = None
# transform to highlight on hover
# could be, for example, brightness(.05)
hf_hover = None
# the name of the folder with the sprites of the game in the images directory, plus a space
hf_dir="game"
# sizes of items in inventory
hf_w, hf_h = 300, 300
# timebar sizes
hf_t_w, hf_t_h = 1040, 32
# padding items from inventory edges
hf_xpadding = 20
hf_ypadding = 40
# inventory window position
hf_xalign = .5
hf_yalign = .05
# timebar position
hf_t_xalign = .5
hf_t_yalign = .01
# INTERNAL VARIABLES
# time to collect items
hf_time = 5
# time to reset for animation
hf_bar = 100
# game mode (False - background mode)
hf_game_mode = False
# items to find
hf_needed = []
# items already found
hf_picked = []
# game background
hf_back="black"
# whether to repaint the timebar (a quarter of the time left)
hf_warning = False
# number of uncollected items
hf_return = 0
# initial number of items
hf_max_count = 0
# game initialization
def hf_init(bg, time, *args, **kwargs):
global hf_needed, hf_picked, hf_back, hf_time, hf_bar, hf_max_count
# reset lists and variables
hf_needed = []
hf_picked = []
hf_back=bg
hf_time = time
hf_bar = 100
# add to the list of items to be found
for item, x, y in args:
hf_needed.append((item, x, y))
hf_max_count = len(hf_needed)
# apply optional game parameters
# essentially change the values of similar variables,
# but only they must start with hf_
for k, v in kwargs.items():
kk = "hf_" + k
if kk in globals().keys():
globals()[kk] = kwargs.get(k)
# show game as background on master layer
def hf_bg():
store.hf_game_mode = False
show_s("Hidden Folks")
# hide game-background
# but first show if game screen is hidden
def hf_hide():
hf_bg()
renpy.with_statement(None)
hide_s("Hidden Folks")
# start the game
# if some effect is set, then first show the game with it
def hf_start(effect=None):
store.hf_game_mode = False
store.hf_warning = False
hf_bg()
renpy.with_statement(effect)
store.hf_game_mode = True
store.hf_return = len(hf_needed)
renpy.call_screen("Hidden Folks")
hf_bg()
# click on an item (move it to inventory or remove it from there)
def hf_click(item, x, y):
store.hf_picked.append(store.hf_needed.pop(hf_needed.index((item, x, y))))
splay("click")
renpy.restart_interaction()
# left to collect
store.hf_return = len(hf_needed)
hfclick = renpy.curry(hf_click)
# change the color of the timer
# or start the time reduction animation
def hf_go(warning=False):
if warning:
# change color
store.hf_warning = True
else:
# start animation
store.hf_bar = 0
renpy.restart_interaction()
HFGo = renpy.curry(hf_go)
# get inventory sprite
def hf_isprite(item):
# if there is an item in the inventory folder,
# then we take it, otherwise - what is on the screen
i = hf_dir + " inventory " + item
if has_image(i):
item = i
# get item sprite size
w, h = get_size(item)
# coefficients for zoom
zoom=1
# if the item is larger than the cell, calculate the new zoom
if w > hf_w or h > hf_h:
# on the larger side
if w > h:
zoom=hf_w/w
else:
zoom=hf_h/h
# return the sprite inscribed in the dimensions of the inventory cell
return Transform(item, zoom=zoom)
screen HiddenFolks():
# game background
add hf_back
# all items on the screen
for i, x, y in hf_needed:
$ item = hf_dir + " " + i
# button item
imagebutton:
style "empty"
# item sprite
idle item
# item position (coordinates of its center)
pos(x, y)
# all actions only in game mode
if hf_game_mode:
# change cursor if necessary
if hf_mouse:
mouse "hand"
# if highlight on hover is enabled
if not hf_hover is None:
# if there is a picture for the selected object, then display it
if has_image(item + "hover"):
hover item + "hover"
# otherwise highlight the transform specified in the settings
else:
hover At(item, hf_hover)
# handle click
action HFCclick(i, x, y)
# timer animation
if hf_game_mode and hf_time > 0:
# activate the timer
timer .01 action HFGo()
# timer for repainting the bar (one third of the total time)
timer hf_time * .6666 action HFGo(True)
# visualization of the timer as a bar
bar:
# position and size of the timebar
align(hf_t_xalign, hf_t_yalign)
xysize(hf_t_w, hf_t_h)
value AnimatedValue(hf_bar, 100, hf_time)
# repainting and flickering of the left strip of the bar,
# when less than a third of the time is left
if hf_warning:
left_bar Frame(At("gui/bar/left.png", paint2("#e02", "#e028", .2)), gui.bar_borders, tile=gui.bar_tile)
# timer loss
timer hf_time repeat True action SPlay("gameover"), Return()
# collected everything, leave (Return()() from def does not work anymore)
if hf_return < 1:
timer .01 repeat True action SPlay("gamewin"), Return()
# inventory
if not hf_inventory is None:
# inventory frame
frame:
style "empty"
xysize(hf_max_count * hf_w + hf_xpadding * 2, hf_h + hf_ypadding * 2)
# inventory position
align(hf_xalign, hf_yalign)
background Frame("framei", 48, 48)
# item container
hbox:
align(.5, .5)
# display collected items
if hf_inventory:
for item, x, y in hf_picked:
button style "empty" xysize(hf_w, hf_h):
add hf_isprite(item) align(.5, .5)
# either display the items left to collect
else:
for item, x, y in hf_needed:
button style "empty" xysize(hf_w, hf_h):
add hf_isprite(item) align(.5, .5)