如何添加新剧情?
2026-08-23 08:13:01
发布于:广东
如何添加新剧情
第一步:新建剧情文件
在 game/stories/data/ 下新建一个 .py 文件,比如 chapter3.py:
vn_final/game/stories/data/
├── __init__.py
├── ch1.py ← 已有参考
├── ch2.py ← 已有参考
└── chapter3.py ← 你新建这个
第二步:写节点字典
打开 chapter3.py,按这个模板写:
chapter3.py 完整模板
from game.story_api import register_story
NODES = {
# ---- 起始节点 ----
"start": {
"bg": "rooftop", # 背景图 key(在 config.py BACKGROUNDS 登记)
"bgm": "calm", # BGM key(在 config.py MUSIC 登记)
"show": {"alice": "center"}, # 立绘:角色名: 位置(left/center/right)
"say": ("艾莉丝", "欢迎来到第三章。"),
"next": "ask_help", # 指向下一个节点
},
# ---- 选项节点 ----
"ask_help": {
"say": ("艾莉丝", "你需要我的帮助吗?"),
"options": [
{"text": "是的,拜托了", "next": "help_yes", "add": {"affection": 1}},
{"text": "不用了", "next": "help_no", "add": {"affection": -1}},
],
},
# ---- 分支节点 ----
"help_yes": {
"say": ("艾莉丝", "好,跟我来。"),
"next": "ending",
},
"help_no": {
"say": ("艾莉丝", "……好吧。"),
"next": "ending",
},
# ---- 结束节点 ----
"ending": {
"say": ("", "(第三章·完)"),
"save_page": True, # 显示存档页(保存/下一章/回到标题)
"end": True, # 标记本章结束
},
}
注册到系统
register_story("ch3", NODES, title="第三章·迷雾")
第三步:注册到章节列表
打开 game/config.py,找到 CHAPTERS 列表,在末尾追加:
CHAPTERS = [
{"id": "ch1", "title": "第一章·初遇", "start_node": "start", "ending_node": "ending", "next_chapter": "ch2"},
{"id": "ch2", "title": "第二章·抉择", "start_node": "start", "ending_node": "ending", "next_chapter": None},
#加这行
{"id": "ch3", "title": "第三章·迷雾", "start_node": "start", "ending_node": "ending", "next_chapter": None},
]
然后打开 game/stories/init.py,加一行导入:
from .data.ch1 import *
from .data.ch2 import *
from .data.chapter3 import * #加这行
True标记本章结束
快速示例:一个最简单的三节点剧情
from game.story_api import register_story
NODES = {
"start": {
"say": ("", "故事开始了。"),
"next": "middle",
},
"middle": {
"say": (" narrator", "这是中间部分。"),
"options": [
{"text": "向左走", "next": "end_a"},
{"text": "向右走", "next": "end_b"},
],
},
"end_a": {
"say": ("", "你选择了左边。结局 A。"),
"save_page": True,
"end": True,
},
"end_b": {
"say": ("", "你选择了右边。结局 B。"),
"save_page": True,
"end": True,
},
}
register_story("mini", NODES, title="迷你示例"
)
然后在 config.py 的 CHAPTERS 加一行 {"id": "mini", ...} 就能玩了。
如果要加新角色/新背景/新 BGM
打开 game/config.py,在对应字典里加一行:
新角色
CHARACTERS = {
"alice": {"color": (255,200,210), "image": "alice.png"},
"bob": {"color": (180,220,255), "image": "bob.png"},
"eve": {"color": (200,255,200), "image": "eve.png"}, # ← 加这行
}
新背景
BACKGROUNDS = {
"rooftop": {"file": "rooftop.png", "caption": "天台"},
"forest": {"file": "forest.png", "caption": "森林"},
"cave": {"file": "cave.png", "caption": "洞穴"}, # ← 加这行
}
新 BGM
MUSIC = {
"calm": {"file": "calm.ogg"},
"night": {"file": "night.ogg"},
"tense": {"file": "tense.ogg"}, # 加这行
}
然后把对应的图片文件放进 game/images/,BGM 文件放进 game/audio/
附:节点字段表

全部评论 3
- 置顶
请勿发布wyy评论
2天前 来自 广东
0 太可怕了,我不会写,能不能直接把剧情逻辑发给你,你写(
昨天 来自 天津
0我 ,。,。 我 。我是是。,是。 啥啥子ziiii,,、。,我我我不会写写 谢。作文文。。。。
昨天 来自 广东
0你只要把剧情写给我就行了
昨天 来自 广东
0主要剧情在我的帖子上你去看吧
昨天 来自 广东
0
这玩意写出来不就是雷霆大模拟吗 /yiw
2天前 来自 湖北
0这个只是剧情文件
2天前 来自 广东
0我自己搞了个模块化的方便后续加剧情
2天前 来自 广东
0其实一大坨分支结构会把人写死的(
2天前 来自 湖北
0


























有帮助,赞一个