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?

Pygameを使って RPGを作る(17. 戦闘画面(その5))

Posted at

概要

・敵生成を追加
・攻撃メッセージを追加
ダメージの計算式は
 / 調整係数1 - 敵の防御力 / 調整係数2

{int(self.status.infact_status['ATK'] / 4) - int(self.enemy.mob_info['DEF']/3)}

image.png

敵生成

以前に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
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?