若无特殊说明,默认是在script.rpy文件中进行编写

参考资料

Ren’py官方文档相关链接:

  1. 音乐空间
  2. 画廊

视频教程

前提条件

之前编写的init python代码,基本不用修改。

音乐空间相关

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

#音乐空间背景
image music_background:
"music_background.png"
size (1920, 1080)

#音乐列表
init python:
#淡入淡出
mr = MusicRoom(fadein = 1.0 , fadeout = 1.0)
#音乐列表,第一个用于主界面bgm,设为默认解锁
mr.add("bgm01.ogg",always_unlocked = True)
mr.add("bgm02.ogg")
mr.add("bgm03.ogg")
mr.add("bgm04.ogg")

#更多音乐请自行添加


#时长参数
init python:
def get_audio_duration(channel="music"):
duration = renpy.music.get_duration(channel)
return convert_format(int(duration))


def get_audio_position(channel="music"):
music_pos = renpy.music.get_pos(channel)

if music_pos:
return convert_format(int(music_pos))
return "00:00"
#时间转换
def convert_format(second):
minute = second // 60
second = second % 60
result = ""

#可用于59分59秒内音乐
if minute:

if minute < 10:
result = '0' + str(minute) + ":" + str(second)
if second < 10:
result ='0' + str(minute) + ":" '0' + str(second)
else:
result = str(minute) + ":" + str(second)
if second < 10:
result = str(minute) + '0' + str(second)

else:

if second < 10:
result = '00:0' + str(second)
else:
result = '00:' + str(second)

return result

画廊相关

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

#画廊/CG鉴赏

#背景图片
image gallery_background:
"gallery_background.png"
size (1920, 1080)


#前提条件
init python:

g = Gallery()

g.button("bg")#类似于标签
g.image("bg01.png")#真正的图片
g.unlock_image("bg03.png")#差分

g.button("cg")
g.condition("persistent.unlock_1")#解锁限制
g.image("cg01.png")

#未解锁
g.button("unlock")


#更多图像请自行添加

# 图像切换使用的转场。
g.transition = dissolve

界面编写

由于空间有限,我们舍弃掉画廊的快速定位功能,同时为避免产生歧义,CG鉴赏采取翻页效果,音乐鉴赏采取滚动条效果,具体代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

#音乐列表顶部底部按钮定位
default extra_music_pos = ui.adjustment()

#鉴赏空间界面
screen extra(cg_page=0):
tag menu
add "extra_bg.jpg"
text "EXTRA" size 80 color "#000000" align (0.05, 0.1) #调整大小,颜色,位置

#######画廊部分

#CG列表
viewport:

xysize (1044, 690)
align (0.1, 0.5)

vbox:
#间距
spacing 60

#页数判断
if (cg_page == 0):
grid 3 3:
spacing 60
#解锁判断,后续判断请自行添加
if renpy.seen_image("bg03"):
add g.make_button("bg", "smbg03.png")
else:
add g.make_button("unlock", "unknow.png")
if renpy.seen_image("bg03"):
add g.make_button("bg", "smbg03.png")
else:
add g.make_button("unlock", "unknow.png")
if renpy.seen_image("bg03"):
add g.make_button("bg", "smbg03.png")
else:
add g.make_button("unlock", "unknow.png")

add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")

add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")

if (cg_page == 1):
grid 3 3:
spacing 60
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("cg", "smcg01.png")

add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("cg", "smcg01.png")


add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("cg", "smcg01.png")

if (cg_page == 2):
grid 3 3:
spacing 60
add g.make_button("cg", "smcg01.png")
add g.make_button("cg", "smcg01.png")
add g.make_button("cg", "smcg01.png")

add g.make_button("cg", "smcg01.png")
add g.make_button("cg", "smcg01.png")
add g.make_button("cg", "smcg01.png")

add g.make_button("cg", "smcg01.png")
add g.make_button("cg", "smcg01.png")
add g.make_button("cg", "smcg01.png")
#翻页按钮
hbox:
xalign 0.2 yalign 0.85
spacing 60
if cg_page < 2:
textbutton "下一页" action Show("extra",cg_page=(cg_page+1))
else:
textbutton "下一页" action NullAction()

textbutton "1" action Show("extra",cg_page=0)
textbutton "2" action Show("extra",cg_page=1)
textbutton "3" action Show("extra",cg_page=2)

if cg_page > 0:
textbutton "上一页" action Show("extra",cg_page=(cg_page-1))
else:
textbutton "上一页" action NullAction()


######音乐部分


#更新renpy.music.get_position()和get_music_duration()
timer 0.1:
action [SetVariable('duration',get_audio_duration()),SetVariable('music_pos',get_audio_position())]
repeat True

#音乐列表
viewport id "MUSIC_list":
mousewheel True #垂直滚动
xysize (500, 600)
align (0.9, 0.4)
draggable True #鼠标拖动可滚动视口
yadjustment extra_music_pos #快速定位

vbox:

spacing 50

textbutton "bgm01" action mr.Play("bgm01.ogg")

#解锁判断
if mr.is_unlocked("bgm02.ogg"):
textbutton "bgm02" action mr.Play("bgm02.ogg")
else:
textbutton "???" action NullAction()

if mr.is_unlocked("bgm03.ogg"):
textbutton "bgm03" action mr.Play("bgm03.ogg")
else:
textbutton "???" action NullAction()

if mr.is_unlocked("bgm04.ogg"):
textbutton "bgm04" action mr.Play("bgm04.ogg")
else:
textbutton "???" action NullAction()
if mr.is_unlocked("bgm04.ogg"):
textbutton "bgm04" action mr.Play("bgm04.ogg")
else:
textbutton "???" action NullAction()
if mr.is_unlocked("bgm04.ogg"):
textbutton "bgm04" action mr.Play("bgm04.ogg")
else:
textbutton "???" action NullAction()
if mr.is_unlocked("bgm04.ogg"):
textbutton "bgm04" action mr.Play("bgm04.ogg")
else:
textbutton "???" action NullAction()
if mr.is_unlocked("bgm04.ogg"):
textbutton "bgm04" action mr.Play("bgm04.ogg")
else:
textbutton "???" action NullAction()
if mr.is_unlocked("bgm04.ogg"):
textbutton "bgm04" action mr.Play("bgm04.ogg")
else:
textbutton "???" action NullAction()
if mr.is_unlocked("bgm04.ogg"):
textbutton "bgm04" action mr.Play("bgm04.ogg")
else:
textbutton "???" action NullAction()

#顶部底部按钮
vbox:
align (0.95, 0.4)
textbutton "顶部" action Function(extra_music_pos.change,0)
vbar:
xysize (10, 500)
align (0.5, 0.5)
value YScrollValue("MUSIC_list")
#如果不想算,只需保证该值足够大
textbutton "底部" action Function(extra_music_pos.change,500000)

#功能按钮
hbox:

align (0.85, 0.85)
spacing 40
textbutton "下一首" action mr.Next()
imagebutton:

idle "pause.png"
hover "pause.png"
selected_idle "continue.png"
selected_hover "continue.png"
if not renpy.music.is_playing() and not renpy.music.get_pause():
action mr.Play("bgm01.ogg")
else:
action PauseAudio(channel="music",value="toggle")

textbutton "上一首" action mr.Previous()
textbutton "随机播放" action mr.RandomPlay()

vbox:
xpos 0.5
ypos 0.2
python:
duration = get_audio_duration()
music_pos = get_audio_position()

#音量调节,可有可无
hbox:
text "音量"
align (0.85, 0.12)
bar:
value Preference("music volume")
thumb "dot.png"
thumb_offset 3
xysize (400, 5)
align (0.5, 0.5)

#进度条,时长显示
hbox:
align (0.9, 0.8)

bar:
value AudioPositionValue(channel='music', update_interval=0.1)
xysize (400,5)
align (0.5, 0.5)
thumb "dot.png"
thumb_offset 3

hbox:
spacing 10
text music_pos
text "/"
text duration

#返回按钮
textbutton "返回":
align (0.05, 0.95)
text_color "#000"
text_size 50
action [Return(), Play("music", "bgm01.ogg")]

周目解锁

添加如下代码:

1
2
3
4
init python:
if persistent.unlock_1 == None:
persistent.unlock_1 ==False
#更多条件限制请自行添加

在某一结局内添加如下代码:

1
2
3
#解锁条件1
$ persistent.unlock_1 = True
#更多周目请自行添加

添加入口

完成上述操作后,我们还需要添加主界面进入按钮,打开screens.rpy,找到screen navigation()(287行左右),在合适位置添加下面的代码

1
textbutton "EXTRA" action ShowMenu("extra")

现在运行游戏,即可在主界面看到鉴赏空间进入按钮,请检查各功能是否可用。