概要
・敵生成を追加
・攻撃メッセージを追加
ダメージの計算式は
/ 調整係数1 - 敵の防御力 / 調整係数2
{int(self.status.infact_status['ATK'] / 4) - int(self.enemy.mob_info['DEF']/3)}
敵生成
以前にkivyで作ったものを流用
import random, os, re
from data_config import Config
from glob import glob
class EntryEnemy():
def __init__(self) -> None:
self.enemy_setting_path ='./enemy/info'
def generate_random_enemy(self):
file_paths = glob(os.path.join(os.getcwd(), self.enemy_setting_path, '*.json'))
file_names = [os.path.basename(path) for path in file_paths]
choice = random.choice(file_names)
id = re.search(r'\d+', choice).group()
# print(id)
config = Config(id)
return config.get_json_info()
if __name__ == '__main__':
instance = EntryEnemy()
print(instance.generate_random_enemy())
Enemyクラス
生成したものは、Enemyクラスをそのまま引き渡す
import pygame as pg
class Enemy(pg.sprite.Sprite):
def __init__(self, pos, mob_info, mob_pos, *groups):
super().__init__(*groups)
self.base_path = './enemy/img/'
self.mob_img_path = self.base_path + mob_info['IMG']
self.mob_info = mob_info
# 論理配置
self.mob_pos = mob_pos
# name
self.name = self.mob_info['name']
self.original = pg.image.load(self.mob_img_path).convert_alpha()
self.battle_surface = pg.transform.scale(self.original, (128, 128))
self.surface = pg.transform.scale(self.original, (64, 64))
# 画面での位置
self.pos = pos
# rect
self.rect = self.surface.get_frect(topleft=pos)
self.enemy_sprites_type = True