I have been practicing about lists. However, I have this problem.
The list, at the beginning, shows the cards face down.
Code: Select all
$ items_list = [
{"name":"uno", "child":"images/d.png", "default_x_pos":197, "default_y_pos":202, "x_pos":197, "y_pos":202},
{"name":"dos", "child":"images/d.png", "default_x_pos":197, "default_y_pos":202, "x_pos":197, "y_pos":202},
{"name":"tres", "child":"images/d.png", "default_x_pos":197, "default_y_pos":202, "x_pos":197, "y_pos":202},
]
For example,
Code: Select all
# pseudocode
$ item_list[0] = # Suppose you change the first row (change name, appearance, and location).
{"name":"Decisión", "child":"images/01.png", "default_x_pos":197, "default_y_pos":202, "x_pos":197, "y_pos":202},
#to:
$ slots_list[0] = [
{"name":"1", "child":"images/d1.png", "x_pos":750, "y_pos":202, "var_name":"itemone"},
#### card 1 [in deck] -> a slot -> any card (random) [shows content of the card].
Code: Select all
default interaccion = False
default itemUno = False
default itemDos = False
default itemTres = False
image esperanza = "images/01.png"
image logica = "images/02.png"
init python:
def my_dragged (drags, drop):
####
# If dragged item wasn't dropped over droppable item.
#
if not drop:
# Let's find dragged item in items_list,
# set its x_pos and y_pos to default values
# and move it to its default position.
for i in items_list:
if i["name"] == drags[0].drag_name:
ind = items_list.index(i)
items_list[ind]["x_pos"] = i["default_x_pos"]
items_list[ind]["y_pos"] = i["default_y_pos"]
drags[0].snap(i["default_x_pos"], i["default_y_pos"], 0.1)
# (in case of item been dragged out of the slot)
# If dragged item was already placed in one of the slots,
# the corresponding variable was set to the name of this item.
# Let's find this variable and delete it.
for s in slots_list:
if hasattr(store, s["var_name"]):
if getattr(store, s["var_name"]) == drags[0].drag_name:
delattr(store, s["var_name"])
renpy.restart_interaction() # This command used to refresh variables values shown onscreen (delete it if no need to show values)
return
####
# If dragged item was dropped onto droppable item.
#
# Let's find the dragged item index in items_list.
for i in items_list:
if i["name"] == drags[0].drag_name:
ind = items_list.index(i)
# Default value for variable dropped_over_slot
# (we don't know yet if item was dropped over slot or not).
dropped_over_slot = False
# Let's check if one of variables has value of dragged item name.
# If so - delete this variable.
for s in slots_list:
if hasattr(store, s["var_name"]):
if getattr(store, s["var_name"]) == drags[0].drag_name:
delattr(store, s["var_name"])
# Also, let's check if the position of an item
# we dropped our dragged item onto match the
# position of one of the slots.
# If so - set dragged items x_pos and y_pos to the values of (x,y)
# of item dropped onto,
# set the corresponding variable value to the name of dragged item,
# and set the variable dropped_over_slot to True.
if s["x_pos"] == drop.x and s["y_pos"] == drop.y:
items_list[ind]["x_pos"] = drop.x
items_list[ind]["y_pos"] = drop.y
setattr(store, s["var_name"], drags[0].drag_name)
dropped_over_slot = True
# If dragged item was dropped onto another item (not onto the slot)
# let's move dragged item to its default position.
if not dropped_over_slot:
drags[0].snap(items_list[ind]["default_x_pos"], items_list[ind]["default_y_pos"], 0.1)
return
# Let's place dragged item over item it was dropped onto.
drags[0].snap(drop.x, drop.y, 0.1)
# Let's check if another item was already placed over this slot
# and if so - move this another item to its default position.
for j in items_list:
if j["name"] == drop.drag_name:
ind = items_list.index(j)
items_list[ind]["x_pos"] = j["default_x_pos"]
items_list[ind]["y_pos"] = j["default_y_pos"]
drop.snap(j["default_x_pos"], j["default_y_pos"], 0.1)
renpy.restart_interaction() # This command used to refresh variables values shown onscreen (delete it if no need to show values)
return
screen shop_screen:
# An image as background.
add "bg.jpg"
####
# This part shows variables values (just delete this lines if not needed).
#
vbox:
align (0.95, 0.05)
if hasattr(store, "itemone"):
text "Primera carta: [itemone]"
$ itemUno = True
if hasattr(store, "itemtwo"):
text "Segunda carta: [itemtwo]"
$ itemDos = True
if hasattr(store, "itemthree"):
text "Tercera carta: [itemthree]"
$ itemTres = True
#
####
# A drag group ensures that items can be dragged to BUY
draggroup:
# At first create slots from their description.
for each_slot in slots_list:
drag:
drag_name each_slot["name"]
draggable False
child each_slot["child"]
xpos each_slot["x_pos"] ypos each_slot["y_pos"]
# And then - items from their descriptions.
for each_item in items_list:
drag:
drag_name each_item["name"]
child each_item["child"]
droppable True
dragged my_dragged
xpos each_item["x_pos"] ypos each_item["y_pos"]
if itemUno:
$ persistent.items_list[0,"child"]= "images/01.png"
# The game starts here.
label start:
# The descriptions of items and slots (one easily can add more items or slots).
# We need them to create items and slots automaticaly
# and also to be able to properly store the game state
# if it will be saved during the interactions with the screen.
$ items_list = [
{"name":"uno", "child":"images/d.png", "default_x_pos":197, "default_y_pos":202, "x_pos":197, "y_pos":202},
{"name":"dos", "child":"images/d.png", "default_x_pos":197, "default_y_pos":202, "x_pos":197, "y_pos":202},
{"name":"tres", "child":"images/d.png", "default_x_pos":197, "default_y_pos":202, "x_pos":197, "y_pos":202},
{"name":"cuatro", "child":"images/d.png", "default_x_pos":197, "default_y_pos":202, "x_pos":197, "y_pos":202},
# {"name":"Decisión", "child":"images/01.png", "default_x_pos":100, "default_y_pos":100, "x_pos":100, "y_pos":100},
# {"name":"Imaginación", "child":"images/02.png", "default_x_pos":150, "default_y_pos":100, "x_pos":150, "y_pos":100},
# {"name":"Naturaleza", "child":"images/03.png", "default_x_pos":170, "default_y_pos":100, "x_pos":150, "y_pos":100},
# {"name":"Fortaleza", "child":"images/04.png", "default_x_pos":170, "default_y_pos":100, "x_pos":150, "y_pos":100},
# {"name":"Esperanza", "child":"images/05.png", "default_x_pos":170, "default_y_pos":100, "x_pos":150, "y_pos":100},
# {"name":"Inicio", "child":"images/06.png", "default_x_pos":170, "default_y_pos":100, "x_pos":150, "y_pos":100},
# {"name":"Certeza", "child":"images/07.png", "default_x_pos":150, "default_y_pos":100, "x_pos":150, "y_pos":100},
# {"name":"Emoción", "child":"images/08.png", "default_x_pos":170, "default_y_pos":100, "x_pos":150, "y_pos":100},
# {"name":"Cooperación", "child":"images/09.png", "default_x_pos":170, "default_y_pos":100, "x_pos":150, "y_pos":100},
]
$ slots_list = [
{"name":"1", "child":"images/d1.png", "x_pos":750, "y_pos":202, "var_name":"itemone"},
{"name":"2", "child":"images/d2.png", "x_pos":549, "y_pos":202, "var_name":"itemtwo"},
{"name":"3", "child":"images/d3.png", "x_pos":950, "y_pos":202, "var_name":"itemthree"},
]
# Another line that is neccessary for proper storing the game state
# while interacting with the screen.
$ renpy.retain_after_load()
while True:
$ interaccion = True
call screen shop_screen
if _return == "UnO":
$ renpy.pause(0.001, hard=True) #<-- obligatorio para que no salte el primer diálogo.
$ interaccion = False
show screen shop_screen
# --> I don't know if the code I need goes here or somewhere else (and that I write there)