I've found, in the cookbook section, a free to use search items mini-game, and I wanted to use the base code to create a mini game when you can take care of your pets by simply clicking on some part of the screen (clicking on a fork clean the place, clicking on a manger feed them, etc.)
So, I thought I would use variables for that : when you click on a certain spot, it changes the variable's value.
The thing is, I know almost nothing in python, and I just can't seem to make it work. That's why I'm asking here for your help today.
Here's what the script.rpy file looks like :
Code: Select all
image bg locker = "locker_empty.png"
init python:
locker_items = []
locker_items.append(Item("Food", 240,454,56,101))
locker_items.append(Item("Clean",189,112,167,63))
locker_items.append(Item("Pet 1",528,73,91,129))
locker_items.append(Item("Pet 2",515,296,98,99))
##
# The game starts here.
label start:
$ foodg = 0
$ start = renpy.time.time()
# this sets all the items back to not found
$ resetItems(locker_items)
# which image set to use
$ hidden_files = "locker_%s.png"
# randomize the list and pick 5 items
$ hidden_items = renpy.random.sample(locker_items,4)
# set number of hints
$ num_hints = 3
# set number of extra clicks
$ num_clicks = 0
scene bg locker
"Test" "test"
$ showitems = True
call screen hidden_object
label result:
if foodg == 1:
"test" "animals fed"
else:
"test" "animals not fed"
return
Code: Select all
init python:
class registerClick(Action):
def __call__(self):
global num_clicks
num_clicks += 1
renpy.restart_interaction()
class getHint(Action):
def __call__(self):
global num_hints
num_hints -= 1
for index,i in enumerate(hidden_items):
if i.found == False and i.hint == False:
i.hint = True
break
renpy.restart_interaction()
def get_sensitive(self):
global num_hints
return num_hints > 0
class SetItem(Action):
def __init__(self, object, field, value):
self.object = object
self.field = field
self.value = value
def __call__(self):
setattr(self.object, self.field, self.value)
renpy.restart_interaction()
def get_selected(self):
return getattr(self.object, "hint") == True
class Item:
def __init__(self, name, x,y,w,h,hint=False):
self.name = name
self.x = x
self.y = y
self.w = w
self.h = h
self.found = False
self.hint = hint
showitems = False
def is_all_found():
for i in hidden_items:
if i.found == False:
return False
return True
def resetItems(in_items):
for i in in_items:
i.found = False
screen hidden_object:
tag hidden
imagemap:
auto hidden_files
cache False
imagebutton auto "empty_%s.png" action registerClick()
for index, item in enumerate(hidden_items):
hotspot (item.x,item.y,item.w,item.h) action If(hidden_items[index].found==False, SetItem(hidden_items[index],"found",True), None)
if locker_items[1]==True:
$ foodg = 1
textbutton "Done" xalign 1.0 yalign 0.1 action Jump("result")
Code: Select all
if locker_items[1]==True:
$ foodg = 1
Thank you for taking the time to read it all, and thank you in advance if you decide to help me!
(and sorry for the broken english, it's not my native language, I'm trying my best!)