戦闘画面(敵3体)
入力箇所が2つあります。
パスとモンスターの名前です。
ここをクリックしてください
Zキーで決定です。
方向キーでカーソルを動かします。
import pygame
from pygame import *
import sys
import time
import random
import numpy as np
width, height = 640, 480
pygame.init()
screen=pygame.display.set_mode((width, height))
pygame.display.set_caption('battle')
# 初期ステータス
Max_HP = 53
player_HP = 53
Max_MP = 0
player_MP = 0
power = 23
quick = 1
arms = 0
attack_power = power + arms
deffence = 0
Gold = 200
Level = 1
Exp = 0
# ここにフォントのパスを貼り付ける
font = pygame.font.Font(, 18)
# ここにカーソル画像のパスを貼り付ける
cursor = pygame.image.load()
# ここにモンスター画像のパスを貼り付ける
slyme_image = pygame.image.load()
# ここにモンスター画像のパスを貼り付ける
wolf_image = pygame.image.load()
# ここにモンスター画像のパスを貼り付ける
chikin_image = pygame.image.load()
# SE
# ここにボタン音のパスを貼り付ける
sound = pygame.mixer.Sound()
# ここにダメージ音のパスを貼り付ける
sound2 = pygame.mixer.Sound()
# ここにレベルアップのパスを貼り付ける
sound3 = pygame.mixer.Sound()
# BGM
# ここに戦闘のBGMのパスを貼り付ける
battle_bgm =
# ここに勝ったときのBGMのパスを貼り付ける
win_bgm =
# ここに負けたときのBGMのパスを貼り付ける
lose_bgm =
# テキストを改行して描画する関数
def draw_text(surface, message, pos, font, color=(255, 255, 255)):
lines = message.split('\n')
x, y = pos
for line in lines:
text_surface = font.render(line, True, color)
surface.blit(text_surface, (x, y))
y += text_surface.get_height()
# カーソル
cursor_x = 30
cursor_y = 368
alpha = 220
delta = 5
clock = pygame.time.Clock()
battle_message = True
command = False
select = False
effect = 0
monster_attack = 0
motion = 0
attack = 0
encount = 0
sub_motion = 0# monster2以降の攻撃のため
defeat1 = 0
defeat2 = 0
defeat3 = 0
defense_cmd = 0
# モンスター
# モンスターのグループ
# 全角スペースで区切ります
# ex) "スライム ウルフ"
# ひとグループ3体までです
groupA = ""
groupB = ""
groupC = ""
# クォーテーションの中にモンスターの名前を入れてください
nameA = ""
nameB = ""
nameC = ""
monster_list = [groupA,groupB,groupC]
monster_dict = {nameA: monsterA_image,nameB: monsterB_image,nameC: monsterC_image}
mon_HP_dict = {nameA: 4,nameB: 6,nameC: 8}
mon_power_dict = {nameA: 6,nameB: 10,nameC: 6}
mon_deffence_dict = {nameA: 4,nameB: 4,nameC: 8}
mon_EXP_dict = {nameA: 1,nameB: 2,nameC: 4}
mon_Gold_dict = {nameA: 4,nameB: 5,nameC: 10}
mon = random.choice(monster_list)
mon_group_list = mon.split()
mon_group_list2 = mon_group_list.copy()
monster_num = len(mon_group_list2)
if len(mon_group_list2) == 1:
mon_index_list = [0]
mon_index = 0
elif len(mon_group_list2) == 2:
mon_index_list = [0,1]
mon_index = 0
elif len(mon_group_list2) == 3:
mon_index_list = [1,0,2]
mon_index = 0
elif len(mon_group_list2) == 4:
mon_index_list = [2,0,1,3]
mon_index = 0
elif len(mon_group_list2) == 5:
mon_index_list = [3,1,0,2,4]
mon_index = 0
num = 0
select_mon = mon_index_list[0]
# 部分一致で値を取得する関数
def get_value_by_partial_key(dictionary, partial_key):
for key in dictionary:
if key in partial_key:
return dictionary[key]
return None
if len(mon_group_list) >= 1:
monster_image1 = get_value_by_partial_key(monster_dict,mon_group_list[0])
if len(mon_group_list) >= 2:
monster_image2 = get_value_by_partial_key(monster_dict,mon_group_list[1])
if len(mon_group_list) >= 3:
monster_image3 = get_value_by_partial_key(monster_dict,mon_group_list[2])
if len(mon_group_list) >= 4:
monster_image4 = get_value_by_partial_key(monster_dict,mon_group_list[3])
if len(mon_group_list) >= 5:
monster_image5 = get_value_by_partial_key(monster_dict,mon_group_list[4])
message = "モンスターが あらわれた!"
if len(mon_group_list) >= 1:
monster1_name = mon_group_list[0]
monster1_HP = get_value_by_partial_key(mon_HP_dict,mon_group_list[0])
monster1_power = get_value_by_partial_key(mon_power_dict,mon_group_list[0])
monster1_deffence = get_value_by_partial_key(mon_deffence_dict,mon_group_list[0])
if len(mon_group_list) >= 2:
monster2_name = mon_group_list[1]
monster2_HP = get_value_by_partial_key(mon_HP_dict,mon_group_list[1])
monster2_power = get_value_by_partial_key(mon_power_dict,mon_group_list[1])
monster2_deffence = get_value_by_partial_key(mon_deffence_dict,mon_group_list[1])
if len(mon_group_list) >= 3:
monster3_name = mon_group_list[2]
monster3_HP = get_value_by_partial_key(mon_HP_dict,mon_group_list[2])
monster3_power = get_value_by_partial_key(mon_power_dict,mon_group_list[2])
monster3_deffence = get_value_by_partial_key(mon_deffence_dict,mon_group_list[2])
if len(mon_group_list) >= 4:
monster4_name = mon_group_list[3]
monster4_HP = get_value_by_partial_key(mon_HP_dict,mon_group_list[3])
monster4_power = get_value_by_partial_key(mon_power_dict,mon_group_list[3])
monster4_deffence = get_value_by_partial_key(mon_deffence_dict,mon_group_list[3])
if len(mon_group_list) >= 5:
monster5_name = mon_group_list[4]
monster5_HP = get_value_by_partial_key(mon_HP_dict,mon_group_list[4])
monster5_power = get_value_by_partial_key(mon_power_dict,mon_group_list[4])
monster5_deffence = get_value_by_partial_key(mon_deffence_dict,mon_group_list[4])
# ここのpathはそのままにしておく(パスを貼り付けるところではない)
def bgm(path):
pygame.mixer.music.load(path)
pygame.mixer.music.play(1)
bgm(battle_bgm)
def bright_image(image):
# 画像をnumpy配列に変換
image_array = pygame.surfarray.array3d(image)
# 明るさを調整する関数
def adjust_brightness(img_array, brightness_factor):
img_array = img_array * brightness_factor
img_array = np.clip(img_array, 0, 255) # 値を0-255に制限
return img_array
# 明るさを上げる(例:1.2倍にする)
brightness_factor = 1.6
bright_image_array = adjust_brightness(image_array, brightness_factor)
# 調整後の画像をサーフェスに戻す
bright_image_surface = pygame.surfarray.make_surface(bright_image_array)
return bright_image_surface
if len(mon_group_list) >= 1:
bright_image1 = bright_image(monster_image1)
if len(mon_group_list) >= 2:
bright_image2 = bright_image(monster_image2)
if len(mon_group_list) >= 3:
bright_image3 = bright_image(monster_image3)
if len(mon_group_list) >= 4:
bright_image4 = bright_image(monster_image4)
if len(mon_group_list) >= 5:
bright_image5 = bright_image(monster_image5)
# 黒い画像
m_width, m_height = monster_image1.get_size()
black_image = pygame.Surface((m_width, m_height))#106,107
# 奇数
if len(mon_group_list) == 1 or len(mon_group_list) == 3 or len(mon_group_list) == 5:
if len(mon_group_list) >= 1:
monster_rect1 = monster_image1.get_rect(center = (width * 0.5, height * 0.5))
if len(mon_group_list) >= 2:
monster_rect2 = monster_image2.get_rect(center = (width * 0.3, height * 0.5))
if len(mon_group_list) >= 3:
monster_rect3 = monster_image3.get_rect(center = (width * 0.7, height * 0.5))
if len(mon_group_list) >= 4:
monster_rect4 = monster_image4.get_rect(center = (width * 0.1, height * 0.5))
if len(mon_group_list) >= 5:
monster_rect5 = monster_image5.get_rect(center = (width * 0.9, height * 0.5))
# 偶数
if len(mon_group_list) == 2 or len(mon_group_list) == 4:
if len(mon_group_list) >= 1:
monster_rect10 = monster_image1.get_rect(center = (width * 0.4, height * 0.5))
if len(mon_group_list) >= 2:
monster_rect11 = monster_image2.get_rect(center = (width * 0.6, height * 0.5))
if len(mon_group_list) >= 3:
monster_rect12 = monster_image3.get_rect(center = (width * 0.2, height * 0.5))
if len(mon_group_list) >= 4:
monster_rect13 = monster_image4.get_rect(center = (width * 0.8, height * 0.5))
# ダメージエフェクト(奇数)
def damage_effect1():
screen.blit(bright_image1, (monster_rect1.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image1, (monster_rect1.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(black_image, (monster_rect1.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image1, (monster_rect1.topleft))
pygame.display.update()
sound2.play()
def damage_effect2():
screen.blit(bright_image2, (monster_rect2.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image2, (monster_rect2.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(black_image, (monster_rect2.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image2, (monster_rect2.topleft))
pygame.display.update()
sound2.play()
def damage_effect3():
screen.blit(bright_image3, (monster_rect3.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image3, (monster_rect3.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(black_image, (monster_rect3.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image3, (monster_rect3.topleft))
pygame.display.update()
sound2.play()
def damage_effect4():
screen.blit(bright_image4, (monster_rect4.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image4, (monster_rect4.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(black_image, (monster_rect4.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image4, (monster_rect4.topleft))
pygame.display.update()
sound2.play()
def damage_effect5():
screen.blit(bright_image5, (monster_rect5.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image5, (monster_rect5.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(black_image, (monster_rect5.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image5, (monster_rect5.topleft))
pygame.display.update()
sound2.play()
# ダメージエフェクト(偶数)
def damage_effect10():
screen.blit(bright_image1, (monster_rect10.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image1, (monster_rect10.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(black_image, (monster_rect10.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image1, (monster_rect10.topleft))
pygame.display.update()
sound2.play()
def damage_effect11():
screen.blit(bright_image2, (monster_rect11.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image2, (monster_rect11.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(black_image, (monster_rect11.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image2, (monster_rect11.topleft))
pygame.display.update()
sound2.play()
def damage_effect12():
screen.blit(bright_image3, (monster_rect12.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image3, (monster_rect12.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(black_image, (monster_rect12.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image3, (monster_rect12.topleft))
pygame.display.update()
sound2.play()
def damage_effect13():
screen.blit(bright_image4, (monster_rect13.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image4, (monster_rect13.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(black_image, (monster_rect13.topleft))
pygame.display.update()
time.sleep(0.1)
screen.blit(monster_image4, (monster_rect13.topleft))
pygame.display.update()
sound2.play()
# 枠点滅
damage_flash = True
flash = 0
# 色
white = (255, 255, 255)
action_number = 0
player_damage = 0
damage = 0
running = True
while running:
clock.tick(60)
# 画面を黒色に塗りつぶし
screen.fill((0, 0, 0))
# モンスターの画像表示
if len(mon_group_list2) == 1 or len(mon_group_list2) == 3 or len(mon_group_list2) == 5:
if len(mon_group_list2) == 1:
if monster1_HP > 0:
screen.blit(monster_image1, (monster_rect1.topleft))
if len(mon_group_list2) == 3:
if monster1_HP > 0:
screen.blit(monster_image1, (monster_rect2.topleft))
if monster2_HP > 0:
screen.blit(monster_image2, (monster_rect1.topleft))
if monster3_HP > 0:
screen.blit(monster_image3, (monster_rect3.topleft))
if len(mon_group_list2) == 5:
if monster1_HP > 0:
screen.blit(monster_image1, (monster_rect4.topleft))
if monster2_HP > 0:
screen.blit(monster_image2, (monster_rect2.topleft))
if monster3_HP > 0:
screen.blit(monster_image3, (monster_rect1.topleft))
if monster4_HP > 0:
screen.blit(monster_image4, (monster_rect3.topleft))
if monster5_HP > 0:
screen.blit(monster_image5, (monster_rect5.topleft))
if len(mon_group_list2) == 2 or len(mon_group_list2) == 4:
if len(mon_group_list2) >= 1:
if monster1_HP > 0:
screen.blit(monster_image1, (monster_rect10.topleft))
if len(mon_group_list2) >= 2:
if monster2_HP > 0:
screen.blit(monster_image2, (monster_rect11.topleft))
if len(mon_group_list2) >= 3:
if monster3_HP > 0:
screen.blit(monster_image3, (monster_rect12.topleft))
if len(mon_group_list2) >= 4:
if monster4_HP > 0:
screen.blit(monster_image4, (monster_rect13.topleft))
# メッセージウィンドゥ
if battle_message:
pygame.draw.rect(screen, white, Rect(20, 320, 600, 140), 3)
# バトルメッセージ
draw_text(screen,message,(40,350),font)
# ステータスウィンドゥ
if damage_flash == True:
pygame.draw.line(screen, white, (20, 58),(118, 58))
pygame.draw.rect(screen, white, (20, 20, 102, 134), 3)
text = font.render("ゆうしゃ", True, white)
screen.blit(text,(35, 35))
text = font.render("H", True, white)
screen.blit(text,(35, 65))
text = font.render(str(player_HP), True, white)
screen.blit(text,(85, 65))
text = font.render("M", True, white)
screen.blit(text,(35, 95))
text = font.render(str(player_MP), True, white)
screen.blit(text,(85, 95))
text = font.render("ゆ: ", True, white)
screen.blit(text,(35, 125))
text = font.render(str(Level), True, white)
screen.blit(text,(85, 125))
# コマンドウィンドゥ
if command:
pygame.draw.line(screen, white, (20, 358),(236, 358))
pygame.draw.rect(screen, white, (20, 320, 220, 140), 3)
text = font.render("ゆうしゃ", True, white)
screen.blit(text,(80, 335))
text = font.render("こうげき", True, white)
screen.blit(text,(50, 370))
text = font.render("まほう", True, white)
screen.blit(text,(50, 400))
text = font.render("ふせぐ", True, white)
screen.blit(text,(50, 430))
text = font.render("アイテム", True, white)
screen.blit(text,(160, 370))
text = font.render("そうび", True, white)
screen.blit(text,(160, 400))
text = font.render("にげる", True, white)
screen.blit(text,(160, 430))
# カーソル
screen.blit(cursor, (cursor_x, cursor_y))
cursor.set_alpha(alpha)
alpha += delta
if alpha <= 120 or alpha >= 255:
delta = -delta
# セレクトウィンドゥ
if select:
pygame.draw.rect(screen, white, (260, 320, 220, 140), 3)
if len(mon_group_list) >= 1:
text = font.render(mon_group_list[0], True, white)
screen.blit(text,(290, 330))
if len(mon_group_list) >= 2:
text = font.render(mon_group_list[1], True, white)
screen.blit(text,(290, 355))
if len(mon_group_list) >= 3:
text = font.render(mon_group_list[2], True, white)
screen.blit(text,(290, 380))
if len(mon_group_list) >= 4:
text = font.render(mon_group_list[3], True, white)
screen.blit(text,(290, 405))
if len(mon_group_list) >= 5:
text = font.render(mon_group_list[4], True, white)
screen.blit(text,(290, 430))
# ターン終了したら、コマンドウィンドゥをひらく
if motion == 12:
message = ""
battle_message = False
command = True
motion = 1
defense_cmd = 0
mon_index = 0
select_mon = mon_index_list[0]
if monster1_HP <= 0 and monster2_HP > 0:
num = 1
elif monster1_HP > 0:
num = 0
elif monster1_HP <= 0 and monster2_HP <= 0:
num = 2
# player_HPがゼロになったら閉じる
if player_HP == 0 and motion == 14:
pygame.display.update()# player_HPがゼロのときにテキスト表示するのに必要
time.sleep(2)
pygame.quit()
sys.exit()
if motion == 13:
message = "そのあと\nゆうしゃのすがたをみたものはいない"
motion = 14
pygame.display.update()
# プレイヤーのダメージエフェクト
if flash > 0:
damage_flash = not damage_flash
flash -= 1
time.sleep(0.15)
if flash == 1:
sound2.play()
if monster_num == 1:
motion = 4
elif monster_num == 2:
if monster2_HP <= 0:
motion = 4
elif sub_motion == 0:
sub_motion = 1
motion = 2
elif sub_motion == 1:
motion = 4
elif monster_num == 3:
if monster2_HP <= 0 and monster3_HP <= 0:
motion = 4
elif sub_motion == 0:
if monster2_HP > 0:
sub_motion = 1
elif monster2_HP <= 0:
sub_motion = 2
motion = 2
elif sub_motion == 1:
sub_motion = 2
motion = 2
if monster3_HP <= 0:
motion = 4
elif sub_motion == 2:
motion = 4
# モンスターのダメージエフェクト
elif action_number == 0 and motion == 2 and attack == 1 and effect == 1:
if len(mon_group_list2) == 1 or len(mon_group_list2) == 3 or len(mon_group_list2) == 5:
if select_mon == 0:
damage_effect1()
elif select_mon == 1:
damage_effect2()
elif select_mon == 2:
damage_effect3()
elif select_mon == 3:
damage_effect4()
elif select_mon == 4:
damage_effect5()
elif len(mon_group_list2) == 2 or len(mon_group_list2) == 4:
if select_mon == 0:
damage_effect10()
elif select_mon == 1:
damage_effect11()
elif select_mon == 2:
damage_effect12()
elif select_mon == 3:
damage_effect13()
effect = 0
if monster1_HP <= 0 and defeat1 == 0 or monster2_HP <= 0 and defeat2 == 0 or monster3_HP <= 0 and defeat3 == 0:
motion = 15
# モンスターを一匹たおした時の処理
elif motion == 11:
if monster_num == 1 and defeat1 == 0:
message = monster1_name + "をたおした!"
elif monster_num == 2:
if monster1_HP <= 0 and defeat1 == 0:
message = monster1_name + "をたおした!"
motion = 2
defeat1 = 1
if sub_motion == 0:
sub_motion = 1
motion = 2
del mon_group_list[0]
del mon_index_list[0]
elif monster2_HP <= 0 and defeat2 == 0:
message = monster2_name + "をたおした!"
motion = 2
defeat2 = 1
if monster1_HP > 0:
del mon_group_list[1]
del mon_index_list[1]
elif monster1_HP <= 0:
del mon_group_list[0]
del mon_index_list[0]
elif monster_num == 3:
if monster1_HP <= 0 and defeat1 == 0:
message = monster1_name + "をたおした!"
motion = 2
defeat1 = 1
if sub_motion == 0:
if monster2_HP > 0:
sub_motion = 1
elif monster2_HP <= 0:
sub_motion = 2
motion = 2
del mon_group_list[0]
del mon_index_list[0]
elif monster2_HP <= 0 and defeat2 == 0:
message = monster2_name + "をたおした!"
motion = 2
defeat2 = 1
if sub_motion == 1:
sub_motion = 2
motion = 2
if monster1_HP > 0:
del mon_group_list[1]
del mon_index_list[1]
elif monster1_HP <= 0:
del mon_group_list[0]
del mon_index_list[0]
elif monster3_HP <= 0 and defeat3 == 0:
message = monster3_name + "をたおした!"
motion = 2
defeat3 = 1
if monster1_HP <= 0 or monster2_HP <= 0:
del mon_group_list[1]
del mon_index_list[1]
elif monster1_HP > 0:
del mon_group_list[2]
del mon_index_list[2]
elif monster1_HP <= 0 and monster2_HP <= 0:
del mon_group_list[0]
del mon_index_list[0]
# モンスターをすべてたおした時の処理
if monster_num == 1:
if monster1_HP <= 0:
bgm(win_bgm)
motion = 5
elif monster_num == 2:
if monster1_HP <= 0 and monster2_HP <= 0:
bgm(win_bgm)
motion = 5
elif monster_num == 3:
if monster1_HP <= 0 and monster2_HP <= 0 and monster3_HP <= 0:
bgm(win_bgm)
motion = 5
# キーハンドラー
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_z:
#「にげる」
if action_number == 5:
sound.play()
pygame.quit()
sys.exit()
#「ふせぐ」
elif action_number == 2 and attack != 1:
sound.play()
defense_cmd = 1
motion = 2
attack = 1
command = False
battle_message = True
message = "プレイヤーは ぼうぎょした"
# ダメージ計算(モンスターに与えるダメージ)
elif motion == 2 and attack != 1:
sound.play()
if len(mon_group_list2) >= 1:
if monster1_HP > 0 and num == 0:
damage = attack_power // 2 - monster1_deffence // 4
if damage <= 0:
damage = 1
monster1_HP -= damage
message = monster1_name + "に " + str(damage) + "の ダメージ"
time.sleep(0.5)
if len(mon_group_list2) >= 2:
if monster2_HP > 0 and num == 1:
damage = attack_power // 2 - monster2_deffence // 4
if damage <= 0:
damage = 1
monster2_HP -= damage
message = monster2_name + "に " + str(damage) + "の ダメージ"
time.sleep(0.5)
if len(mon_group_list2) >= 3:
if monster3_HP > 0 and num == 2:
damage = attack_power // 2 - monster3_deffence // 4
if damage <= 0:
damage = 1
monster3_HP -= damage
message = monster3_name + "に " + str(damage) + "の ダメージ"
time.sleep(0.5)
if len(mon_group_list2) >= 4:
if monster4_HP > 0 and select_mon == mon_index_list[3]:
damage = attack_power // 2 - monster4_deffence // 4
if damage <= 0:
damage = 1
monster4_HP -= damage
message = monster4_name + "に " + str(damage) + "の ダメージ"
time.sleep(0.5)
if len(mon_group_list2) >= 5:
if monster5_HP > 0 and select_mon == mon_index_list[4]:
damage = attack_power // 2 - monster5_deffence // 4
if damage <= 0:
damage = 1
monster5_HP -= damage
message = monster5_name + "に " + str(damage) + "の ダメージ"
time.sleep(0.5)
attack = 1
effect = 1
# セレクトウィンドゥをひらく
elif motion == 1 and action_number == 0 and select == False:
select = True
sound.play()
cursor_x = 270
cursor_y = 328
#「たたかう」
elif motion == 1 and action_number == 0:
sound.play()
command = False
battle_message = True
select = False
cursor_x = 30
cursor_y = 368
message = "プレイヤーのこうげき"
motion = 2
# あらわれた!を消してコマンドウィンドゥをひらく
elif motion == 0:
sound.play()
motion = 1
message = ""
battle_message = False
command = True
# モンスター1の攻撃(プレイヤーに与えるダメージ)
elif attack == 1 and motion == 2 and sub_motion == 0:
if monster1_HP > 0:
sound.play()
message = monster1_name + "のこうげき"
motion = 3
elif attack == 1 and motion == 3 and sub_motion == 0:
player_damage = monster1_power // 2 - deffence // 4
if defense_cmd == 1:
player_damage = int(player_damage * 0.6)
if player_damage <= 0:
player_damage = 1
player_HP -= player_damage
message = "プレイヤーに " +str(player_damage) + "のダメージ"
damage_flash = False
flash = 3
time.sleep(0.5)
if player_HP <= 0:
player_HP = 0
# モンスター2の攻撃(プレイヤーに与えるダメージ)
elif attack == 1 and motion == 2 and sub_motion == 1:
if monster2_HP > 0:
sound.play()
message = monster2_name + "のこうげき"
motion = 3
elif attack == 1 and motion == 3 and sub_motion == 1:
if monster2_HP > 0:
player_damage = monster2_power // 2 - deffence // 4
if defense_cmd == 1:
player_damage = int(player_damage * 0.6)
if player_damage <= 0:
player_damage = 1
player_HP -= player_damage
message = "プレイヤーに " +str(player_damage) + "のダメージ"
damage_flash = False
flash = 3
time.sleep(0.5)
if player_HP <= 0:
player_HP = 0
# モンスター3の攻撃(プレイヤーに与えるダメージ)
elif attack == 1 and motion == 2 and sub_motion == 2:
if monster3_HP > 0:
sound.play()
message = monster3_name + "のこうげき"
motion = 3
elif attack == 1 and motion == 3 and sub_motion == 2:
if monster3_HP > 0:
player_damage = monster3_power // 2 - deffence // 4
if defense_cmd == 1:
player_damage = int(player_damage * 0.6)
if player_damage <= 0:
player_damage = 1
player_HP -= player_damage
message = "プレイヤーに " +str(player_damage) + "のダメージ"
motion = 4
damage_flash = False
flash = 3
time.sleep(0.5)
if player_HP <= 0:
player_HP = 0
elif attack == 1 and motion == 4:
sound.play()
if player_HP <= 0:
bgm(lose_bgm)
motion = 13
else:
attack = 0
motion = 12
if monster1_HP > 0:
sub_motion = 0
else:
sub_motion = 1
# 経験値とお金
elif motion == 5:
sound.play()
if monster_num == 1:
mon_EXP = get_value_by_partial_key(mon_EXP_dict,mon_group_list2[0])
mon_Gold = get_value_by_partial_key(mon_Gold_dict,mon_group_list2[0])
message = f"けいけんち {mon_EXP}かくとく\n{mon_Gold}ゴールドを てにいれた"
Exp += mon_EXP
Gold += mon_Gold
elif monster_num == 2:
mon_EXP = get_value_by_partial_key(mon_EXP_dict,mon_group_list2[0]) + get_value_by_partial_key(mon_EXP_dict,mon_group_list2[1])
mon_Gold = get_value_by_partial_key(mon_Gold_dict,mon_group_list2[0]) + get_value_by_partial_key(mon_Gold_dict,mon_group_list2[1])
message = f"けいけんち {mon_EXP}かくとく\n{mon_Gold}ゴールドを てにいれた"
Exp += mon_EXP
Gold += mon_Gold
elif monster_num == 3:
mon_EXP = get_value_by_partial_key(mon_EXP_dict,mon_group_list2[0]) + get_value_by_partial_key(mon_EXP_dict,mon_group_list2[1]) + get_value_by_partial_key(mon_EXP_dict,mon_group_list2[2])
mon_Gold = get_value_by_partial_key(mon_Gold_dict,mon_group_list2[0]) + get_value_by_partial_key(mon_Gold_dict,mon_group_list2[1]) + get_value_by_partial_key(mon_Gold_dict,mon_group_list2[2])
message = f"けいけんち {mon_EXP}かくとく\n{mon_Gold}ゴールドを てにいれた"
Exp += mon_EXP
Gold += mon_Gold
elif monster_num == 4:
mon_EXP = get_value_by_partial_key(mon_EXP_dict,mon_group_list2[0]) + get_value_by_partial_key(mon_EXP_dict,mon_group_list2[1]) + get_value_by_partial_key(mon_EXP_dict,mon_group_list2[2]) + get_value_by_partial_key(mon_EXP_dict,mon_group_list2[3])
mon_Gold = get_value_by_partial_key(mon_Gold_dict,mon_group_list2[0]) + get_value_by_partial_key(mon_Gold_dict,mon_group_list2[1]) + get_value_by_partial_key(mon_Gold_dict,mon_group_list2[2]) + get_value_by_partial_key(mon_Gold_dict,mon_group_list2[3])
message = f"けいけんち {mon_EXP}かくとく\n{mon_Gold}ゴールドを てにいれた"
Exp += mon_EXP
Gold += mon_Gold
elif monster_num == 5:
mon_EXP = get_value_by_partial_key(mon_EXP_dict,mon_group_list2[0]) + get_value_by_partial_key(mon_EXP_dict,mon_group_list2[1]) + get_value_by_partial_key(mon_EXP_dict,mon_group_list2[2]) + get_value_by_partial_key(mon_EXP_dict,mon_group_list2[3]) + get_value_by_partial_key(mon_EXP_dict,mon_group_list2[4])
mon_Gold = get_value_by_partial_key(mon_Gold_dict,mon_group_list2[0]) + get_value_by_partial_key(mon_Gold_dict,mon_group_list2[1]) + get_value_by_partial_key(mon_Gold_dict,mon_group_list2[2]) + get_value_by_partial_key(mon_Gold_dict,mon_group_list2[3]) + get_value_by_partial_key(mon_Gold_dict,mon_group_list2[4])
message = f"けいけんち {mon_EXP}かくとく\n{mon_Gold}ゴールドを てにいれた"
Exp += mon_EXP
Gold += mon_Gold
if Level == 1 and Exp >= 4 or Level == 2 and Exp >= 8:
motion = 8
else:
motion = 6
# 戦闘に勝利したら画面を閉じる
elif motion == 6:
sound.play()
motion = 7
pygame.quit()
sys.exit()
# レベルアップ
elif motion == 8:
pygame.mixer.music.pause()
sound3.play()
message = "レベルが上がった"
if Level == 1:
motion = 9
elif Level == 2:
motion = 10
elif motion == 9:
time.sleep(1)
pygame.mixer.music.unpause()
sound.play()
message = "さいだいHPが 4ポイント上がった!\nちからが 3ポイント 上がった!\nすばやさが 2ポイント 上がった!"
Max_HP += 4
power += 3
quick += 2
Level += 1
motion = 6
attack_power = power + arms
elif motion == 10:
time.sleep(1)
pygame.mixer.music.unpause()
sound.play()
message = "さいだいHPが 6ポイント上がった!\nさいだいMPが 5ポイント上がった!\nちからが 1ポイント上がった!\nすばやさが 1ポイント上がった!\nホイムンをおぼえた"
Max_HP += 4
power += 3
quick += 2
Level += 1
motion = 6
attack_power = power + arms
# モンスターをたおした時(ワンテンポずらす)
elif motion == 15:
sound.play()
motion = 11
#キーハンドラー(矢印)
if event.key == K_DOWN:
if cursor_y != 428 and select == False:
cursor_y += 30
action_number += 1
sound.play()
elif len(mon_group_list2) - 1 != num and select == True:
cursor_y += 25
sound.play()
if monster2_HP > 0:
num += 1
if monster2_HP <= 0:
num += 2
mon_index += 1
select_mon = mon_index_list[mon_index]
elif event.key == K_UP:
if cursor_y != 368 and select == False:
cursor_y -= 30
action_number -= 1
sound.play()
elif cursor_y != 328 and select == True:
cursor_y -= 25
sound.play()
if monster2_HP > 0:
num -= 1
if monster2_HP <= 0:
num -= 2
mon_index -= 1
select_mon = mon_index_list[mon_index]
elif event.key == K_LEFT:
if cursor_x != 30 and select == False:
cursor_x -= 110
action_number -= 3
sound.play()
elif event.key == K_RIGHT:
if cursor_x != 140 and select == False:
cursor_x += 110
action_number += 3
sound.play()