import json import random import os import pygame from game.algo import aStar from game.const import color as C from game.const import game as G from game.frame import bomb, item from game.level import level from game.sound import sound_player from game.effect.effect_instance import EffectState, EffectInstance from game.sprite.bomb_instance import BombInstance from game.sprite.ghost import Ghost from game.sprite.hero import Hero from game.sprite.item_instance import ItemInstance from game.sprite.player import Player, PlayerState from game.sprite.throwable import Throwable from game.skill.skill import AngelBeats from game.file_loader.fileLoader import load_json, load_png import logging from datetime import datetime class Angel(Player, Throwable): def __init__(self, npc_name, xy, color=C.CHARACTER_RED): super(Angel, self).__init__(npc_name, xy, color) self.npc_json = None self.chs_name = None # Npc中文名 self.stats_name = npc_name self.idx_motion = {0: "R", 1: "U", 2: "L", 3: "D"} self.contact = -100000 # Npc接触伤害 self.resent_dist = None # Npc仇恨范围(几格以内) self.resentful = False # Npc玩家仇恨 self.mocking = False # Npc受到嘲笑药水的作用暂时仇恨 self.friendly = False # Npc受到玫瑰药水的作用暂时解除仇恨 self.refresh = 0 self.is_ghost = True # 幽灵模式 self.fake_blood = 0 self.energy_amount = 0 # 充能格数 self.max_energy_amount = 0 self.has_energy = False self.wall_walking = True # 穿墙 self.flying = True # 飞行(免疫墙体减速) self.sliding = False # 踩技能滑行中 self.sliding_direction = None # 踩技能后滑的方向 self.witch_protected_remove = False # 巫师无防护状态 self.fire_load_time = 0 self.slime = False self.last_in_water = 0 self.slime_time = 0 self.free_chasing = False self.chasing_point = (1,1) self.imitating = False self.combo_num = 1 self.is_combo_target = False self.bomb_shield_num = 0 # 防糖泡电磁护盾 self.bomb_shield_protect = False self.is_target = False self.light = 0 # 鬼屋模式发光大小 0不发光,1发光20像素,2发光40像素 最大9 self.sharing_damage = False self.obstacle_can_push = False self.npc_time_init = None # Npc初始化时刻 self.wander_random = 10 # Npc在无仇恨时的闲逛时间 self.district_locked = True self.chase_path = None # Npc追踪路径 self.npc_skill_time = pygame.time.get_ticks() # npc施放技能时的时刻 设为成员变量是为了统一多个技能的时间 self.blood_bar = None self.blood_bar_pos = 0 self.angel_state = 0 self.target_npc = None self.angel_launch = False self.target = (self.x, self.y) self.true_direction = (0, 0) self.last_collide = pygame.time.get_ticks() self.bomb_skin = bomb.get_bomb("bomb1") self.gifts = None # 爆装备 self.death = None # 死亡状态 self.last_motion = 0 self.energy_num = None self.load_npc() def load_npc(self): self.chs_name = "angel" self.blood = 10000000000000000 self.light = 5 self.speed = (8 * G.GAME_SQUARE) / 1000 self.contact = -10000 self.defense = 100000000000000 self.remain_blood = self.blood self.chase_path = dict() self.character = self.load_character("Angel", C.CHARACTER_RED, dict()) self.npc_time_init = pygame.time.get_ticks() def update(self): super().update() self.find_target() self.chase_target() self.fly() # self.try_using_skills() def find_target(self): if self.target_npc is None or self.target_npc.remain_blood <= 0: # 无目标 self.target_npc = None if not self.angel_launch: # 未初始化, 随机找一个 for npc in level.current_level.npcs: if not npc.isTreasure: self.target_npc = npc if self.target_npc is None: # 如果都没有 self.target_npc = level.current_level.me def chase_target(self): if self.target_npc is not None: self.target = (self.target_npc.x, self.target_npc.y) now = (self.x, self.y) self.true_direction = (self.target[0] - now[0], self.target[1] - now[1]) if self.true_direction != (0, 0): tx, ty = self.true_direction[0], self.true_direction[1] if ty <= -abs(tx): self.orientation = "U" elif ty >= abs(tx): self.orientation = "D" elif tx >= 0: self.orientation = "R" else: self.orientation = "L" else: self.collide() def fly(self): if self.target_npc is not None and self.true_direction != (0, 0): length = (self.true_direction[0]**2 + self.true_direction[1]**2)**(1/2) if length != 0: self.x_pos += self.speed * max(1, length/3) * self.true_direction[0]/length self.y_pos += self.speed * max(1, length/3) * self.true_direction[1]/length def collide(self): if self.remain_blood <= 0: return if pygame.time.get_ticks() - self.last_collide < 600: return self.last_collide = pygame.time.get_ticks() me = level.current_level.me if self.target_npc != me: AngelBeats(self, self.skill_instances) if self.target_npc is not None and self.target_npc.remain_blood > 0: self.angel_state = 2 else: me.heal(int(level.current_level.me.blood/100)) EffectInstance("revival_card", me, True, me.effects_front) self.die() def half_body_damage(self, point, cl, current_time): self.try_damage(cl.grid_damage_blood[point]) def die(self): super().die() self.remain_blood = 0 def try_using_skills(self): pass def use_skill(self, idx: int): cl = level.current_level if self.npc_skill_time < self.skill_init_times[idx] or self.skill_remains[idx] == 0: # 未到初始时间 或技能冷却中 或次数已用完(-1则可以无限使用) return def set_restoration(self, to_x, to_y): self.x = to_x self.y = to_y def draw(self, screen: pygame.Surface): super().draw(screen)