0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

_

Last updated at Posted at 2025-06-25

新RPGの目次

# セットアップ


# そうびウィンドウを開くためのフラグ
equip_select = False

# ミス、強烈な一撃
# 通常攻撃、ミス、強烈な一撃を判定するのに使う変数
# random.randomで0.00以上1.00未満が代入される予定
# 飾り(ここになくても動く)
random_value= 0
# 通常攻撃なら1,強烈な一撃なら1.5
# 飾り(ここになくても動く)
critical = 1

# 全体攻撃
# 左から攻撃するために、一回だけmon_select_indexnを0にするためのフラグ。
is_all_attack = False


# 武具データ
weapon_data = {"なし": 0, "きのぼう": 5, "つるぎ": 7, "オノ": 9, "ブーメラン": 23}
helmet_data = {"なし": 0, "ぼうし": 2}
shield_data = {"なし": 0, "きのたて": 2, "てつのたて": 5}
armor_data = {"なし": 0, "ぬののふく": 3, "たびのふく": 5, "よろい": 7}

# 武具効果のデータ
equip_effect_data = {"ブーメラン": "全体攻撃"}
# 武具効果を管理する変数
# いまは、0と"全体攻撃"だけ
equip_effect = 0

# アイテム種別に応じた処理
equip_categories = {
    "weapon": weapon_data,
    "helmet": helmet_data,
    "shield": shield_data,
    "armor": armor_data,
}
# そうびウィンドウでカーソルがある、そうびアイテムが代入される
# 飾り(ここになくても動く)
current_item = item_list[item_index]

# 各キャラの武具名の辞書のリスト
equip_data = [{},{},{},{}]

# キャラのまもりのデータ
player_tough_dict = {player_nameA:2,player_nameB:6,player_nameC:3,player_nameD:2}

# 各キャラが持っているそうび可能アイテム
player_equip_dict = {player_nameA:[" きのぼう", " ブーメラン", " たびのふく"],
                    player_nameB:[" きのぼう", " オノ", " よろい"],
                    player_nameC:[" きのぼう", " ぼうし", " ぬののふく"],
                    player_nameD:[" きのぼう",  " ぬののふく"]}

# そうびアイテムの左にEを描画するための、値がリストの辞書
player_E_dict = {player_nameA:["", "E", "E"],
                    player_nameB:["E", "", "E"],
                    player_nameC:["E", "E", "E"],
                    player_nameD:["E",  "E"]}

# player_E_dictでそうびアイテム名を取得、
# 各キャラの初期そうびをequip_dataに格納
for i in range(len(chara_group_list)):
    # 全ての値を"なし"に設定
    equip_data[i].update({
        "weapon_name": "なし",
        "helmet_name": "なし",
        "shield_name": "なし",
        "armor_name": "なし"
    })
    # player_E_dictとインデックスが一致する、武具名をリストequip_dataに入れる、辞書の値に設定
    for j, E in enumerate(player_E_dict[chara_group_list[i]]):
        if E == "E":
            for category, data_dict in equip_categories.items():
                if player_equip_dict[chara_group_list[i]][j][1:] in data_dict:
                    # 装備する
                    if category == "weapon":
                        equip_data[i].update({
                        "weapon_name": player_equip_dict[chara_group_list[i]][j][1:]
                            })
                    elif category == "helmet":
                        equip_data[i].update({
                        "helmet_name": player_equip_dict[chara_group_list[i]][j][1:]
                            })
                    elif category == "shield":
                        equip_data[i].update({
                        "shield_name": player_equip_dict[chara_group_list[i]][j][1:]
                            })
                    elif category == "armor":
                        equip_data[i].update({
                        "armor_name": player_equip_dict[chara_group_list[i]][j][1:]
                            })

# player_dataのなかにある、そうびとパラメーター関連のデータ
# equip_dataを反映させえたプレイヤーのパラメーター
"strength": player_strength_dict[chara_group_list[i]],
"power": calc_power(player_strength_dict[chara_group_list[i]], equip_data[i]["weapon_name"]),
"tough": player_tough_dict[chara_group_list[i]],
"defence": calc_defence(player_tough_dict[chara_group_list[i]], equip_data[i]["helmet_name"], equip_data[i]["shield_name"], equip_data[i]["armor_name"]),
"E_list":player_E_dict[chara_group_list[i]],
"equip_effect":0,

# メインループ


# 全体攻撃
# 装備している武器で効果を判定
# いまは、0か"全体攻撃"
# 武器が"全体攻撃"の場合、こうげきを選んだ時に、魔物選択ウィンドゥを開かないため
player_data[cmd_chara_index]["equip_index"] = equip_index
player_data[cmd_chara_index]["equip_effect"] = equip_effect
none_key = equip_effect_data.get(equip_data[cmd_chara_index]["weapon_name"])  # 存在しない場合は None
if none_key is not None:
    equip_effect = equip_effect_data[equip_data[cmd_chara_index]["weapon_name"]]
elif none_key == None:
    equip_effect = 0


# キャラが持っているそうび可能アイテム名の描画
if equip_select:
    # 装備品がある場合のみ描画
    pygame.draw.rect(screen,white,select_rect,3,5)
    if player_data[cmd_chara_index]["equip_list"]:
        for i, item in enumerate(player_data[cmd_chara_index]["equip_list"]):
            text = font.render(item, True, (255, 255, 255))
            screen.blit(text, ((select_rectx + 14) + 30, (select_recty + 14) + 24 * i))
        for i, item in enumerate(player_data[cmd_chara_index]["E_list"]):
            text = font.render(item, True, (255, 255, 255))
            screen.blit(text, ((select_rectx + 14) + 22, (select_recty + 14) + 24 * i))
        screen.blit(cursor, ((select_rectx + 14), (select_recty + 11) + 24 * equip_index))  # カーソル描画

# キーハンドラー


# コマンドウィンドゥを開いたまま、そうび選択ウィンドゥをひらく
# 「そうび」
# 装備したり、外したりする
elif phase == 1 and cmd_index == 4:
    sound.play()                        
    if equip_select:
        # カーソルが示すそうび可能なアイテム
        current_item =  player_data[cmd_chara_index]["equip_list"][equip_index][1:]
        # カーソルが示すそうび可能なアイテムと同じインデックスの、"E_list"の値
        current_E =  player_data[cmd_chara_index]["E_list"][equip_index]
        # equip_categoriesのキーと値
        for category, data_dict in equip_categories.items():
            # 
            if current_item in data_dict:
                # 空文字なら装備する
                if current_E == "":                   
                    if category == "weapon":
                        equip_data[cmd_chara_index]["weapon_name"] = current_item
                    elif category == "helmet":
                        equip_data[cmd_chara_index]["helmet_name"] = current_item
                    elif category == "shield":
                        equip_data[cmd_chara_index]["shield_name"] = current_item
                    elif category == "armor":
                        equip_data[cmd_chara_index]["armor_name"] = current_item
                    # categoryに当てはまるアイテムのインデックスなら、"E_list"の値をすべて空文字にする
                    for i, item in enumerate(player_data[cmd_chara_index]["equip_list"]):
                        if item[1:] in equip_categories[category]:
                            player_data[cmd_chara_index]["E_list"][i] = ""
                    # カーソルが示すそうび可能なアイテムと同じインデックスの、"E_list"の値を"E"にする
                    player_data[cmd_chara_index]["E_list"][equip_index] = "E"
                # Eなら外す
                elif current_E == "E":                    
                    if category == "weapon":
                        equip_data[cmd_chara_index]["weapon_name"] = "なし"
                    elif category == "helmet":
                        equip_data[cmd_chara_index]["helmet_name"] = "なし"
                    elif category == "shield":
                        equip_data[cmd_chara_index]["shield_name"] = "なし"
                    elif category == "armor":
                        equip_data[cmd_chara_index]["armor_name"] = "なし"
                    player_data[cmd_chara_index]["E_list"][equip_index] = ""
                break  # 該当するカテゴリを処理したら終了
        # ステータス再計算
        player_data[cmd_chara_index]["power"] = calc_power(player_data[cmd_chara_index]["strength"], equip_data[cmd_chara_index]["weapon_name"])
        player_data[cmd_chara_index]["defence"] = calc_defence(player_data[cmd_chara_index]["tough"], equip_data[cmd_chara_index]["helmet_name"], equip_data[cmd_chara_index]["shield_name"], equip_data[cmd_chara_index]["armor_name"])
    # そうびウィンドウを開いただけではそうびを変更しないように、ここにある。
    equip_select = True
    cmd_cursor = False


# 全体攻撃
# is_all_attackがFalseならmon_select_indexを0にする
# is_all_attackがTrueならmon_select_indexをふやす
if current_actor["equip_effect"] != 0 and equip_effect_data[equip_data[current_actor["num"]]["weapon_name"]] == "全体攻撃":
    if not is_all_attack:
        current_actor["mon_select_index"] = 0
    else:
        current_actor["mon_select_index"] += 1
    is_all_attack = True                            

# "通常攻撃" or その他の行動ならactor_indexふやす
# "全体攻撃"ならすべてのモンスターに攻撃したらactor_indexをふやす
if current_actor["cmd_index"] == 0:
    if current_actor["equip_effect"] == 0:
        actor_index += 1
    elif equip_effect_data[equip_data[current_actor["num"]]["weapon_name"]] == "全体攻撃":
        if current_actor["mon_select_index"] == len(mon_group_list) - 1: 
            actor_index += 1
else:
    actor_index += 1

# 全体攻撃でモンスターを倒したら、mon_select_indexを減らす
if current_actor["equip_effect"] != 0 and equip_effect_data[equip_data[current_actor["num"]]["weapon_name"]] == "全体攻撃":
    current_actor["mon_select_index"] = current_actor["mon_select_index"] - 1                    

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?