def __init__(self): # 飞机拥有自己的坐标 self.__points = [ DisplayMode.Point(39, 18), DisplayMode.Point(39, 19), DisplayMode.Point(38, 19), DisplayMode.Point(39, 20) ]
def end(self): center_point = self.__points[0] BoomAnimation.AnimationManager.manager().play( DisplayMode.Point(center_point.x + 2, center_point.y + 2)) Option.Functions.fenshu() self.active = False self.set_point(DisplayMode.Point(-20, -20))
def create_bullet(self): for i in self.__bullet_list: if not i.active: i.active = True # 将飞机头的位置设置为子弹的初始位置 point = self.__jet.get_point_list()[-2] i.set_point(DisplayMode.Point(point.x - 5, point.y)) return
def __init__(self): self.__enemy_list = [] # 通过列表管理所有敌人 self.__n = 0 # 记录激活状态的敌人数量 # 总共创建8个敌人,根据激活状态,反复使用 for i in range(8): alien = Alien(DisplayMode.Point(-20, -20)) alien.active = False self.__enemy_list.append(alien)
def check_injury(bullet_manager: AirPlay.BulletManager, enemys: Enemys.EnemyManager): # 检测激活状态的子弹和敌人的坐标是否重合 for i in bullet_manager.get_bullet_list(): # 获得所有子弹的列表 if not i.active: continue for j in enemys.get_enemys_list(): # 获取所有敌人的列表 if not j.active: continue if Injury_Check.__check_interation(i.get_point_list(), j.get_point_list()): i.active = False i.set_point(DisplayMode.Point(-8, -8)) j.end()
def __init__(self, master, monitor): super().__init__(master) # Capture focus so that the program # will get the keypresses immediately self.focus_set() self.add_hotkeys() self.wm_attributes("-topmost", 1) curr_mode = DisplayMode.get_mode() self.overrideredirect(1) width = int(monitor.width / 2) height = int(monitor.height / 2) x = int(monitor.x + width / 2) y = int(monitor.y + height / 2) geometry = '{:d}x{:d}+{:d}+{:d}'.format(width, height, x, y) self.geometry(geometry) self._create_widgets(curr_mode)
def create_enemy(self): for i in self.__enemy_list: if not i.active: i.set_point(DisplayMode.Point(-8, random.randint(0, 35))) i.active = True return
def __init__(self, start_point): self.active = True # 激活状态 self.__points = [ start_point, DisplayMode.Point(start_point.x, start_point.y + 1), DisplayMode.Point(start_point.x, start_point.y + 2), DisplayMode.Point(start_point.x, start_point.y + 3), DisplayMode.Point(start_point.x, start_point.y + 4), DisplayMode.Point(start_point.x + 1, start_point.y), DisplayMode.Point(start_point.x + 1, start_point.y + 1), DisplayMode.Point(start_point.x + 1, start_point.y + 3), DisplayMode.Point(start_point.x + 1, start_point.y + 4), DisplayMode.Point(start_point.x + 2, start_point.y + 1), DisplayMode.Point(start_point.x + 2, start_point.y + 2), DisplayMode.Point(start_point.x + 2, start_point.y + 3), DisplayMode.Point(start_point.x + 3, start_point.y), DisplayMode.Point(start_point.x + 3, start_point.y + 2), DisplayMode.Point(start_point.x + 3, start_point.y + 4), DisplayMode.Point(start_point.x + 4, start_point.y), DisplayMode.Point(start_point.x + 4, start_point.y + 2), DisplayMode.Point(start_point.x + 4, start_point.y + 4) ]
def set_point(self, start_point): self.__points = [ start_point, DisplayMode.Point(start_point.x, start_point.y + 1), DisplayMode.Point(start_point.x, start_point.y + 2), DisplayMode.Point(start_point.x, start_point.y + 3), DisplayMode.Point(start_point.x, start_point.y + 4), DisplayMode.Point(start_point.x + 1, start_point.y), DisplayMode.Point(start_point.x + 1, start_point.y + 1), DisplayMode.Point(start_point.x + 1, start_point.y + 3), DisplayMode.Point(start_point.x + 1, start_point.y + 4), DisplayMode.Point(start_point.x + 2, start_point.y + 1), DisplayMode.Point(start_point.x + 2, start_point.y + 2), DisplayMode.Point(start_point.x + 2, start_point.y + 3), DisplayMode.Point(start_point.x + 3, start_point.y), DisplayMode.Point(start_point.x + 3, start_point.y + 2), DisplayMode.Point(start_point.x + 3, start_point.y + 4), DisplayMode.Point(start_point.x + 4, start_point.y), DisplayMode.Point(start_point.x + 4, start_point.y + 2), DisplayMode.Point(start_point.x + 4, start_point.y + 4) ]
def set_right_screen(self): DisplayMode.set_mode(RightTV) self.exit()
def set_left_screen(self): DisplayMode.set_mode(LeftTV) self.exit()
def set_extended(self): DisplayMode.set_mode(Mode.Extend) self.exit()
def set_duplicated(self): DisplayMode.set_mode(Mode.Duplicate) self.exit()
c = str(msvcrt.getch()) # 输入函数,不需要敲回车,但是值为: b'x' if c == "b'a'": # 不输入的话,就会卡在这里等,但是不影响主线程 jet.move_left() elif c == "b'd'": jet.move_right() if c == "b'j'": # 开火 bullet_manager.create_bullet() elif c == "b'q'": global running running = False exit(0) # 退出当前线程 # 创建显示器 display = DisplayMode.Displayer() # 创建飞机 jet = AirPlay.airplay() # 创建敌人 enemys = Enemys.EnemyManager() # 创建子弹 bullet_manager = AirPlay.BulletManager(jet) # 把飞机添加到显示器 display.add_item(jet) # 把所有敌人添加到显示器 display.add_item(enemys) # 把所有子弹添加到显示器 display.add_item(bullet_manager) # 把图案添加到显示器
def set_point(self, start_point): self.__point = [ start_point, DisplayMode.Point(start_point.x + 1, start_point.y), DisplayMode.Point(start_point.x + 2, start_point.y) ]
def set_point(self, center_point): self.__first = [ DisplayMode.Point(center_point.x - 2, center_point.y - 2), DisplayMode.Point(center_point.x - 2, center_point.y + 2), DisplayMode.Point(center_point.x + 2, center_point.y - 2), DisplayMode.Point(center_point.x + 2, center_point.y + 2), DisplayMode.Point(center_point.x - 1, center_point.y - 1), DisplayMode.Point(center_point.x - 1, center_point.y + 1), DisplayMode.Point(center_point.x + 1, center_point.y - 1), DisplayMode.Point(center_point.x + 1, center_point.y + 1) ] self.__second = [ DisplayMode.Point(center_point.x - 2, center_point.y - 2), DisplayMode.Point(center_point.x - 2, center_point.y + 2), DisplayMode.Point(center_point.x + 2, center_point.y - 2), DisplayMode.Point(center_point.x + 2, center_point.y + 2), DisplayMode.Point(center_point.x - 1, center_point.y - 1), DisplayMode.Point(center_point.x - 1, center_point.y + 1), DisplayMode.Point(center_point.x + 1, center_point.y - 1), DisplayMode.Point(center_point.x + 1, center_point.y + 1), center_point, DisplayMode.Point(center_point.x - 2, center_point.y - 1), DisplayMode.Point(center_point.x - 1, center_point.y + 2), DisplayMode.Point(center_point.x + 1, center_point.y - 2), DisplayMode.Point(center_point.x + 2, center_point.y + 1) ]