Skip to content

Commit 4988618

Browse files
feat(examples): add drag and drop
1 parent 3207f22 commit 4988618

File tree

6 files changed

+143
-0
lines changed

6 files changed

+143
-0
lines changed

game/examples/drag_and_drop.rpy

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# https://www.renpy.org/doc/html/drag_drop.html
2+
label drag_and_drop:
3+
4+
# https://github.com/VimislikArt/dragdropcode/blob/main/dragdrop.rpy
5+
init python:
6+
def drag_placed(drags, drop):
7+
if not drop:
8+
return
9+
10+
store.draggable = drags[0].drag_name
11+
store.droppable = drop.drag_name
12+
13+
return True
14+
15+
show screen drag_sample1
16+
call screen drag_sample2
17+
show screen drag_sample3
18+
19+
if droppable == "The Left Circle":
20+
$ xpos_var = 150
21+
elif droppable == "The Right Circle":
22+
$ xpos_var = 790
23+
else:
24+
$ xpos_var = 640
25+
26+
if draggable == "circle":
27+
show circle:
28+
xpos xpos_var ypos 460
29+
elif draggable == "triangle":
30+
show triangle:
31+
xpos xpos_var ypos 460
32+
elif draggable == "square":
33+
show square:
34+
xpos xpos_var ypos 460
35+
36+
"The [draggable] was put in [droppable]"
37+
38+
hide screen drag_sample1
39+
hide screen drag_sample2
40+
hide screen drag_sample3
41+
42+
jump start
43+
44+
screen drag_sample1:
45+
draggroup:
46+
drag:
47+
xpos 0.25
48+
ypos 0.25
49+
draggable True
50+
drag_raise True
51+
frame:
52+
xpadding 20
53+
ypadding 20
54+
text "Draggable"
55+
56+
drag:
57+
xpos 0.5
58+
ypos 0.25
59+
draggable True
60+
drag_raise True
61+
frame:
62+
xpadding 20
63+
ypadding 20
64+
text "Draggable"
65+
66+
drag:
67+
xpos 0.75
68+
ypos 0.25
69+
draggable True
70+
drag_raise True
71+
frame:
72+
xpadding 20
73+
ypadding 20
74+
text "Draggable"
75+
76+
screen drag_sample2:
77+
draggroup:
78+
drag:
79+
drag_name "circle"
80+
child "drag_and_drop/circle.png"
81+
xpos 100
82+
ypos 100
83+
draggable True
84+
droppable False
85+
dragged drag_placed
86+
drag_raise True
87+
88+
drag:
89+
drag_name "triangle"
90+
child "drag_and_drop/triangle.png"
91+
xpos 400
92+
ypos 100
93+
draggable True
94+
droppable False
95+
dragged drag_placed
96+
drag_raise True
97+
98+
drag:
99+
drag_name "square"
100+
child "drag_and_drop/square.png"
101+
xpos 700
102+
ypos 100
103+
draggable True
104+
droppable True
105+
dragged drag_placed
106+
drag_raise True
107+
108+
drag:
109+
drag_name "The Left Circle"
110+
xpos 0.1
111+
ypos 0.6
112+
child "drag_and_drop/spot.png"
113+
draggable False
114+
droppable True
115+
116+
drag:
117+
drag_name "The Right Circle"
118+
xpos 0.6
119+
ypos 0.6
120+
child "drag_and_drop/spot.png"
121+
draggable False
122+
droppable True
123+
124+
screen drag_sample3:
125+
draggroup:
126+
drag:
127+
drag_name "The Left Circle"
128+
xpos 0.1
129+
ypos 0.6
130+
child "drag_and_drop/spot.png"
131+
draggable False
132+
droppable False
133+
134+
drag:
135+
drag_name "The Right Circle"
136+
xpos 0.6
137+
ypos 0.6
138+
child "drag_and_drop/spot.png"
139+
draggable False
140+
droppable False

game/examples/start.rpy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ label start:
1414
"Dialogue":
1515
jump dialogue
1616

17+
"Drag and Drop":
18+
jump drag_and_drop
19+
1720
"Text":
1821
jump text
1922

game/images/drag_and_drop/circle.png

1.55 KB
Loading

game/images/drag_and_drop/spot.png

3.04 KB
Loading

game/images/drag_and_drop/square.png

3.17 KB
Loading
1.64 KB
Loading

0 commit comments

Comments
 (0)