找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 448|回复: 0

[教程] 简单的点击收集物品\物品栏\随机任务的任务栏\全局使用两种字体

[复制链接]
发表于 2023-9-4 17:37:29 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖最后由 程序过于烧脑 于 2023-9-8 20:24 编辑

可收集物品的物品栏
道理很简单define定义一个值,用screen做物品栏、可捡起的物品和物品栏里的物品,if 判断值 use显示收集的物品 、Hide让物品消失,SetVariable("wp",wp + 1)使用定义的值并让定义的值加1、if判断 值=1让use显示物品

指令测试过,可以食用


[RenPy] 纯文本查看 复制代码
# 定义物品的值,用来检测
define wp1 = 0
define wp2 = 
define wp3 = 0
define wp4 = 0
define wp5 = 0

# 物品栏
screen wpl():
    
    frame:
        ypos 300

        vbox:
            spacing 10 #间距
            add "gzi.png"  #添加物品栏的图片
            add "gzi.png"
            add "gzi.png"
            add "gzi.png"
            add "gzi.png"


    # 如果不想要加没有捡起时的界面elif == 0:的use换成pass
    if wp1 == 1: # 判断捡起后,物品到物品栏
        use wp1
    elif wp1 == 0: #没有捡起时
        use wp1_

    if wp2 == 1:
        use wp2
    elif wp2 == 0:
        use wp2_

    if wp3 == 1:
        use wp3
    elif wp3 == 0:
        use wp3_

    if wp4 == 1:
        use wp4
    elif wp4 == 0:
        use wp4_

    if wp5 == 1:
        use wp5
    elif wp5 == 0:
        use wp5_

    


# 需要捡起来(点击)的物品
# x,y的pos按需自行更改
screen wp_1:
    imagebutton:
        xpos 555
        ypos 502
        idle "gzi.png"
        hover "gzi.png"
        action Hide("wp_1"),SetVariable("wp1",wp1 + 1)

screen wp_2:
    imagebutton:
        xpos 250
        ypos 505
        idle "gzi.png"
        hover "gzi.png"
        action Hide("wp_2"),SetVariable("wp2",wp2 + 1)

screen wp_3:
    imagebutton:
        xpos 37
        ypos 50
        idle "gzi.png"
        hover "gzi.png"
        action Hide("wp_3"),SetVariable("wp3",wp3 + 1)

screen wp_4:
    imagebutton:
        xpos 58
        ypos 12
        idle "gzi.png"
        hover "gzi.png"
        action Hide("wp_4"),SetVariable("wp4",wp4 + 1)

screen wp_5:
    imagebutton:
        xpos 986
        ypos 20
        idle "gzi.png"
        hover "gzi.png"
        action Hide("wp_5"),SetVariable("wp5",wp5 + 1)

# 在物品栏里的物品,按照自己的需要自行更改为imagebutton

# screen wp1():
#     imagebutton:
#         idle "wp1l@4.png" 如果图片大可以在图片命名@来缩小
#         yalign 0.3
#         xalign 0.002

screen wp1():
    textbutton"物品":
        yalign 0.3
        xalign 0.002
        text_color "#000"
        text_size 20

screen wp2():
    textbutton"物品":
        yalign 0.36
        xalign 0.002
        text_color "#000"
        text_size 20
screen wp3():
    textbutton"物品":
        yalign 0.412
        xalign 0.002
        text_color "#000"
        text_size 20
screen wp4():
    textbutton"物品":
        yalign 0.47
        xalign 0.002
        text_color "#000"
        text_size 20
screen wp5():
    textbutton"物品":
        yalign 0.53
        xalign 0.002
        text_color "#000"
        text_size 20



# 没有物品时的界面 上面pass的就无视这个
screen wp1_:
    textbutton"无":
        yalign 0.3
        xalign 0.002
        text_color "#000"
        text_size 20
screen wp2_:
    textbutton"无":
        yalign 0.36
        xalign 0.002
        text_color "#000"
        text_size 20
screen wp3_:
    textbutton"无":
        yalign 0.412
        xalign 0.002
        text_color "#000"
        text_size 20
screen wp4_:
    textbutton"无":
        yalign 0.47
        xalign 0.002
        text_color "#000"
        text_size 20
screen wp5_:
    textbutton"无":
        yalign 0.53
        xalign 0.002
        text_color "#000"
        text_size 20




最后进行测试

[RenPy] 纯文本查看 复制代码
label start:
    #显示物品栏
    show screen wpl
    "测试"
    #显示点击收集的物品
    show screen wp_1
    show screen wp_2
    show screen wp_3
    show screen wp_4
    show screen wp_5
    # 按钮只是用来停住画面,自己用无需添加
    menu:
        "..":
            $ x =1
    if x = 1:
        pass



    return


随机任务的任务栏
定义一个值用给SetVariable来显示或者收起任务界面
screen任务界面+随机任务界面+任务栏


[RenPy] 纯文本查看 复制代码
define rwz = 0 #任务值
screen rw: #任务界面
    vbox:
        xalign 1.0
        yalign 0.0
        add "rwlx.png"
    use sjrw
    
screen sjrw:  #随机任务
    text "任务"color "fff" size 40 xpos 1700
    vbox:
        spacing 10
        xpos 1700
        ypos 80
        if rw == 1:
            text "任务1"color"fff"
            text "任务2"color"fff"
            text "任务1"color"fff"
            text "任务2"color"fff"
        elif rw ==2:
            text "任务2"color"fff"
            text "任务2"color"fff"
            text "任务1"color"fff"
            text "任务2"color"fff"
        elif rw ==3:
            text "任务3"color"fff"
            text "任务2"color"fff"
            text "任务1"color"fff"
            text "任务2"color"fff"
        elif rw ==4:
            text "任务3"color"fff"
            text "任务4"color"fff"
            text "任务1"color"fff"
            text "任务2"color"fff"
        elif rw ==5:
            text "任务5"color"fff"
            text "任务2"color"fff"
            text "任务1"color"fff"
            text "任务2"color"fff"

screen rwl: #任务栏
    if rwz ==0:
        imagebutton:
            xalign 1.0
            yalign 0.0
            idle "rwl.png"
            action Show("rw"),SetVariable("rwz",rwz + 1)
        text "点\n击\n查\n看\n任\n务" xalign 1.0 yalign 0.0
    elif rwz == 1:
        imagebutton:
            xalign 1.0
            yalign 0.0
            idle "rwl.png"
            action Hide("rw"),SetVariable("rwz",rwz - 1)
        text "点\n击\n收\n起\n任\n务"xalign 1.0 yalign 0.0


以上写好后,将下面的放进游戏出现任务的地方
[RenPy] 纯文本查看 复制代码
$ rw = random.randint(0,5)#(0,5)表示随机0-5的数值,可以自行增大
show screen rwl



或许能帮助到大家,其实能看懂的话,还能干别的,按逻辑去写还是蛮有趣的或许因为太简单,也没见到相关教程(或许有类似的但是我找不到?)……所以我出了一个,没准我以后忘了还能复习一下呢


让全局同时使用两种字体(中、英)

gui.rpy里改,大概是FontGroup.add()来增加它的字体,前面字体(英)应该是选择"A" "Z"的英文字母替换掉,后面是字体(中文)用None,也就是都用,除非有其他替换的比如A-Z的英文字母就不会使用该字体。
[RenPy] 纯文本查看 复制代码
define gui.name_text_font = FontGroup().add("CARBON-DROID.ttf", "A", "Z").add("SourceHanSansLite.ttf", None, None)



如果想比如说除了大写A-Z还有小写a-z就再复制一样的.add改成"a","z"就行了,符号同理
[RenPy] 纯文本查看 复制代码
define gui.name_text_font = FontGroup().add("CARBON-DROID.ttf", "A", "Z").add("CARBON-DROID.ttf", "a", "z").add("SourceHanSansLite.ttf", None, None)























没有物品栏可以用用这个

没有物品栏可以用用这个

评分

参与人数 1活力 +120 干货 +1 收起 理由
被诅咒的章鱼 + 120 + 1 感谢分享!

查看全部评分

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|RenPy中文空间 ( 苏ICP备17067825号|苏公网安备 32092302000068号 )

GMT+8, 2024-4-28 15:58 , Processed in 0.065070 second(s), 17 queries , File On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表