class Frostbeam(PlayerMove): """Class for representing the player's frostbeam move.""" def __init__(self): super().__init__(30) self.icon = Image("player/frostbeam_move_icon_solid.png") self.icon_faded = Image("player/frostbeam_move_icon_faded.png") self.info = Image("player/frostbeam_move_info.png") self.sound = Audio("player/frostbeam_move.ogg", 0.2) self.frostbeam_start = Image("player/frostbeam_start.png", (215, 381)) self.frostbeam_middle = Image("player/frostbeam_middle.png") self.frostbeam_end = Image("player/frostbeam_end.png") self.duration = 0 self.total_duration = 2 * self.game.fps def run(self): self.opponent.display() self.user.character_frostbeam_stance.display() if self.duration < self.total_duration: if self.duration == 0: self.play_sound() elif self.duration == self.total_duration // 2: self.opponent.damage(random.randint(15, 30)) self.frostbeam_start.display() for x in range(14): self.frostbeam_middle.display(265 + 50 * x, 383 + 2 * x) self.duration += 1 else: # Resetting variables for next time self.duration = 0 self.opponent.next_move()
def main(gfile, args=None): start = datetime.now() name = gfile if isinstance(gfile,str) else gfile.name puts(colored.blue('Visualizing the file: %s\n Started: %s'%(name,datetime.now()))) # Read in the gcode gcode = GCode(gfile, limit=None) gcode.parse() # parse the code into an array of tool moves tool = Tool(gcode) tool.uniq() box = tool.boundBox() # proces and save image ext = args.ext if args is not None else '.pdf' outfile = os.path.splitext(gfile.name)[0] + FILEENDING + ext print box print box[0:2] image = Image(outfile, gridsize=box[0:2]) image.process(tool) image.save() # how long did this take? puts(colored.green('Time to completion: %s'%(deltaTime(start)))) print
def initialise(cls): cls.MAIN_MENU = Image("main_menu.png", (0, 0)) cls.PLAY_BUTTON_FLARED = Image("menu_play_flared.png", (79, 0)) cls.LOAD_BUTTON_FLARED = Image("menu_load_flared.png", (82, 106)) cls.OPTIONS_BUTTON_FLARED = Image("menu_options_flared.png", (82, 212)) cls.EXIT_BUTTON_FLARED = Image("menu_exit_flared.png", (166, 476)) cls.MUSIC = Audio("title_screen_music.ogg", 0.1)
def initialise(cls): super().initialise() cls.ENTER_CHARACTER_NAME = Image("enter_character_name.png", (0, 0)) cls.CONTINUE_BUTTON_FLARED = Image("continue_button_flared.png", (0, 0)) cls.ARE_YOU_SURE = Image("are_you_sure.png", (0, 0)) cls.SURE_YES_FLARED = Image("sure_yes_flared.png", (0, 0)) cls.SURE_NO_FLARED = Image("sure_no_flared.png", (0, 0))
def __init__(self, game, max_hp=180, max_mana=300): super().__init__(game, "Evil Cloud", max_hp, max_mana) self.x = 930 self.y = 400 self.normal = Image("evil_cloud/evil_cloud_normal.png", (self.x, self.y)) Moves = namedtuple("Moves", "heal") self.moves = Moves(OpponentHeal(1005, 230, 410))
def __init__(self): super().__init__(20) self.icon = Image("player/headbutt_move_icon_solid.png") self.icon_faded = Image("player/headbutt_move_icon_faded.png") self.info = Image("player/headbutt_move_info.png") self.sound = Audio("player/character_attack1.ogg") self.advancing = True self.start_x = 150 self.sound_x = 750 self.end_x = 870 self.forward_step = 24 self.backward_step = 36
def query(sourceFrame = None): global match # Convert frame into gray scale # To improve perfomance frame = cv2.cvtColor(sourceFrame, cv2.COLOR_BGR2GRAY) image = Image.create('Frame', fileBuffer = frame, usePath = False, useColor = True) # Query Image in the dictionaries # If the result is None, then we don't mutate # lastMatch, somehow it is useful someday. result = Image.find(image) if (match != result): match = result
class KanyeSnake(Opponent): """Class representing the Kanye Snake opponent.""" def __init__(self, game, max_hp=120, max_mana=120): super().__init__(game, "Kanye Snake", max_hp, max_mana) self.x = 930 self.y = 440 self.snake_normal = Image("kanye_snake/snake_normal.png", (self.x, self.y)) self.snake_dead = Image("kanye_snake/snake_dead.png", (self.x, self.y)) self.snake_backwards = Image("kanye_snake/snake_backwards.png") self.snake_moving = Image("kanye_snake/snake_moving.png") self.snake_venom_stance = Image("kanye_snake/snake_venom_stance.png", (self.x, self.y)) self.snake_laser_stance = Image("kanye_snake/snake_laser_stance.png", (self.x, self.y)) Moves = namedtuple("Moves", "heal confuse venom laser") self.moves = Moves(OpponentHeal(1005, 230, 410), Confuse(), Venom(), Laser()) def choose_move(self): """Return the move that the snake decides to use.""" if self.current_mana < 10: # Only usable move return self.moves.confuse if self.game.player.current_hp < 20: return random.choice(self.attack_options(favour_damage=True)) if self.current_hp < self.max_hp / 5: if random.randint(1, 10) == 1: return random.choice(self.attack_options()) return self.moves.heal options = self.attack_options() if self.current_hp <= 3 * (self.max_hp / 4): options.append(self.moves.heal) return random.choice(options) def attack_options(self, *, favour_damage=False): # pylint: disable=arguments-differ """Return the options the snake can/would choose from for attacking based on his mana.""" moves = super().attack_options() if len(moves) > 1 and favour_damage: moves.remove(self.moves.confuse) return moves def _idle_display(self): self.snake_normal.display() def _dead_display(self): self.snake_dead.display()
def __init__(self, heart_x, start_y, end_y): super().__init__(10) self.icon = Image("player/heal_move_icon_solid.png") self.icon_faded = Image("player/heal_move_icon_faded.png") self.info = Image("player/heal_move_info.png") self.sound = Audio("player/heal_move.ogg", 0.1) self.heart = Image("player/heal_heart.png") self.heart_x = heart_x self.start_y = start_y self.end_y = end_y self.heart_y = self.start_y self.delay_duration = 0
def render_frame(self, frame_index): angle = 2 * math.pi * frame_index / self._frames self._camera.set_position(self._dist * math.cos(angle), self._dist * math.sin(angle), 0.0) self._camera.set_direction(_rad(180.0) + angle, 0.0) get_points = self._camera.compiled_get_points() image = Image(self._W, self._H, background_color = (0.1, 0.1, 0.1)) for line in self._osm_cart: image.draw_polygon( *[self._camera.get_point(*point) for point in line], line_color = (0.7, 0.7, 0.7), line_width = 0.3, ) get_points(self._usgs_cart, self._usgs_cart_2d) for index in range(self._usgs_cart_2d.shape[1]): image.draw_filledcircle( *self._usgs_cart_2d[:, index], r = 1.0, fill_color = (1.0, 0.0, 0.0), ) image.save(os.path.join('frames', f'frame_{frame_index:05d}.png'))
def __init__(self, game, max_hp=200, max_mana=150): super().__init__(game, "Spook Dog", max_hp, max_mana) self.x = 930 self.y = 440 self.num_idle_frames = 20 self.idle_fps = 20 self.idle_frames = [ Image(f"spook_dog/ghost_dog_normal{n}.png") for n in range(self.num_idle_frames) ] self.ghost_dog_dead = Image("spook_dog/ghost_dog_dead.png", (self.x, self.y)) Moves = namedtuple("Moves", "heal teleport glide claw") self.moves = Moves(OpponentHeal(1005, 230, 410), Teleport(), Glide(), Claw())
def initialise(cls): cls.RETURN_TO_GAME_BUTTON = Image("return_to_game_button.png") cls.RETURN_TO_TITLE_BUTTON = Image("return_to_title_button.png") cls.VOLUME_MINUS_BUTTON = Image("volume_minus_button.png") cls.VOLUME_PLUS_BUTTON = Image("volume_plus_button.png") cls.VOLUME_MUTE_BUTTON = Image("volume_mute_button.png") cls.WINDOWED_BUTTON = Image("windowed_button.png") cls.FULLSCREEN_BUTTON = Image("fullscreen_button.png") cls.BLANK_OVERLAY = Image("blank_overlay.png")
def __init__(self): super().__init__(30) self.icon = Image("player/frostbeam_move_icon_solid.png") self.icon_faded = Image("player/frostbeam_move_icon_faded.png") self.info = Image("player/frostbeam_move_info.png") self.sound = Audio("player/frostbeam_move.ogg", 0.2) self.frostbeam_start = Image("player/frostbeam_start.png", (215, 381)) self.frostbeam_middle = Image("player/frostbeam_middle.png") self.frostbeam_end = Image("player/frostbeam_end.png") self.duration = 0 self.total_duration = 2 * self.game.fps
def initialise(cls): cls.WELCOME_L1 = Text("Welcome to Sunni!", Font.OPENING, Color.BLACK) cls.WELCOME_L2 = Text( "This is coded entirely with Python and the pygame module!", Font.OPENING, Color.BLACK) cls.WELCOME_L3 = Text("created by Andrew and co.", Font.OPENING, Color.BLACK) cls.WELCOME_L4 = Text("Enjoy!", Font.OPENING, Color.BLACK) cls.TITLE_SCREEN = Image("title_screen.png", (0, 0)) cls.GAME_TITLE = Text("SUNNI", Font.TITLE, Color.MURKY_YELLOW)
def _init_res(self): super()._init_res() self.key_sound = Sound(os.path.join(self.sound_dir, 'pew.wav')) self.bg_image = Image( os.path.join(self.image_dir, 'blackboard_1024_768.png')).image self.right_image = Image( os.path.join(self.image_dir, 'right_140_147.png')).image self.wrong_image = Image( os.path.join(self.image_dir, 'wrong_140_177.png')).image ball_path = os.path.join(self.image_dir, 'basketball_50_50.png') speed = 13 rand = ((0.1 * (random.randint(5, 8)))) vector = (0.47, speed) basketball = BasketBall(path=ball_path, vector=vector) self.basketball = pygame.sprite.RenderPlain(basketball) # self._init_db() self.voicer_name = 'ada' self.voice_path = os.path.join(self.sound_dir, self.voicer_name) self.voicer = Voicer(path=self.voice_path)
def __init__(self): super().__init__(-10) self.sound = Audio("spook_dog/ghost_dog_teleport.ogg") self.duration = 0 self.damage_time = 2 * self.game.fps self.total_duration = 2.5 * self.game.fps self.glows = [ Image(f"spook_dog/ghost_dog_glow{n}.png", (830, 290)) for n in range(5) ]
def initialise(cls): cls.OPTIONS_BUTTON = Image("options_button.png", (10, 665)) cls.VICTORY_OVERLAY = Image("victory_overlay.png", (0, 0)) cls.DEFEAT_OVERLAY = Image("defeat_overlay.png", (0, 0)) cls.CONTINUE_BUTTON = Image("continue_button.png", (1000, 600)) cls.TRY_AGAIN_BUTTON = Image("try_again_button.png", (1000, 600)) cls.RETURN_TO_TITLE_BUTTON = Image("return_to_title_button.png", (80, 600))
def main(gfile, args=None): start = datetime.now() name = gfile if isinstance(gfile, str) else gfile.name puts( colored.blue('Visualizing the file: %s\n Started: %s' % (name, datetime.now()))) # Read in the gcode gcode = GCode(gfile, limit=None) gcode.parse() # parse the code into an array of tool moves tool = Tool(gcode) tool.uniq() box = tool.boundBox() # proces and save image ext = args.ext if args is not None else '.pdf' outfile = os.path.splitext(gfile.name)[0] + FILEENDING + ext print box print box[0:2] image = Image(outfile, gridsize=box[0:2]) image.process(tool) image.save() # how long did this take? puts(colored.green('Time to completion: %s' % (deltaTime(start)))) print
class MemeDog(Opponent): """Class representing the Meme Dog opponent.""" def __init__(self, game, max_hp=100, max_mana=100): super().__init__(game, "Meme Dog", max_hp, max_mana) self.x = 930 self.y = 440 self.dog_normal = Image("meme_dog/dog_normal.png", (self.x, self.y)) self.dog_dead = Image("meme_dog/dog_dead.png", (self.x, self.y)) self.dog_backwards = Image("meme_dog/dog_backwards.png") self.dog_bark_stance = Image("meme_dog/dog_bark_stance.png", (self.x, self.y)) Moves = namedtuple("Moves", "heal bark bite spin") self.moves = Moves(OpponentHeal(1005, 230, 410), Bark(), Bite(), Spin()) def choose_move(self): """Return the name of the next move that the dog decides to use.""" if self.current_mana < 10: # Only usable move return self.moves.bark if self.game.player.current_hp < 15: # Try to finish the player off return random.choice(self.attack_options()) if self.current_hp < self.max_hp / 4: # Low - prefer to heal but chance of attacking if random.randint(1, 10) == 1: return random.choice(self.attack_options()) return self.moves.heal options = self.attack_options() if self.current_hp <= 3 * (self.max_hp / 4): options.append(self.moves.heal) return random.choice(options) def _idle_display(self): self.dog_normal.display() def _dead_display(self): self.dog_dead.display()
class EvilCloud(Opponent): """Class representing the Evil Cloud opponent.""" def __init__(self, game, max_hp=180, max_mana=300): super().__init__(game, "Evil Cloud", max_hp, max_mana) self.x = 930 self.y = 400 self.normal = Image("evil_cloud/evil_cloud_normal.png", (self.x, self.y)) Moves = namedtuple("Moves", "heal") self.moves = Moves(OpponentHeal(1005, 230, 410)) def choose_move(self): """Return the move that the spook cloud decides to use.""" return self.moves.heal def _idle_display(self): self.normal.display() def _dead_display(self): pass
def __init__(self, **kwargs): self.logger = kwargs.get('logger') self.name = kwargs.get('name') if not self.name: raise Exception self.gitlab = GitlabConfig(**kwargs.get('gitlab', {})) self.registry = RegistryConfig(**kwargs.get('registry', {})) self.images = [ Image(**image, registry_client=self.registry._client, logger=self.logger) for image in kwargs.get('images', []) ]
def loadImages(self): images = [] dir_images = "_Data/Radiographs/" files = glob.glob(dir_images + "*.tif") for file in files: img_matrix = cv2.imread(file) name = str(file).replace('_Data/Radiographs\\', '') image = Image(name, img_matrix) images.append(image) self.images = images
class Heal(PlayerMove): """Class for representing the player's heal move.""" def __init__(self, heart_x, start_y, end_y): super().__init__(10) self.icon = Image("player/heal_move_icon_solid.png") self.icon_faded = Image("player/heal_move_icon_faded.png") self.info = Image("player/heal_move_info.png") self.sound = Audio("player/heal_move.ogg", 0.1) self.heart = Image("player/heal_heart.png") self.heart_x = heart_x self.start_y = start_y self.end_y = end_y self.heart_y = self.start_y self.delay_duration = 0 @property def total_delay_duration(self): return self.user.display_stat_change_duration def run(self): self.user.display() self.opponent.display() if self.heart_y < self.end_y: if self.heart_y == self.start_y: self.play_sound() self.heart.display(self.heart_x, self.heart_y) self.heart_y += 5 elif self.delay_duration < self.total_delay_duration: # Allow time for stat change to show if self.delay_duration == 0: self.user.restore_hp(random.randint(5, 15)) self.delay_duration += 1 else: self.delay_duration = 0 self.heart_y = self.start_y self.opponent.next_move()
async def add(): # Adds image to the database def add_image(): inverse = 1 / factor mgr.add(path, [(round(p[0] * inverse), round(p[1] * inverse)) for p in points]) points.clear() for path in paths: img = Image(path) factor = img.scale_bounded(X_MAX, Y_MAX) scaled = copy(img) win.show(img) while True: while len(points) < 4: x, y = await win.click() points.append((x, y)) if len(points) == 4: p1 = points[-1] p2 = points[0] img.draw_line(p1, p2) if len(points) > 1: p1 = points[-2] p2 = points[-1] img.draw_line(p1, p2) img.draw_point(x, y) win.show(img) k = await win.keypress() if k == KEY_ENTER: add_image() break # Reset points.clear() img = copy(scaled) win.show(img)
def __init__(self, game, max_hp=120, max_mana=120): super().__init__(game, "Kanye Snake", max_hp, max_mana) self.x = 930 self.y = 440 self.snake_normal = Image("kanye_snake/snake_normal.png", (self.x, self.y)) self.snake_dead = Image("kanye_snake/snake_dead.png", (self.x, self.y)) self.snake_backwards = Image("kanye_snake/snake_backwards.png") self.snake_moving = Image("kanye_snake/snake_moving.png") self.snake_venom_stance = Image("kanye_snake/snake_venom_stance.png", (self.x, self.y)) self.snake_laser_stance = Image("kanye_snake/snake_laser_stance.png", (self.x, self.y)) Moves = namedtuple("Moves", "heal confuse venom laser") self.moves = Moves(OpponentHeal(1005, 230, 410), Confuse(), Venom(), Laser())
def __init__(self): pygame.init() self.options = Options(self) self.screen = pygame.display.set_mode(self.options.window_size) self.icon = Image("game_icon.png") self.caption = "Sunni (Alpha 3.0.0)" self.keys = Keys(self) self.page = None self.file_directory = os.getcwd()[:-3] self.mouse = Mouse() self.clock = pygame.time.Clock() self.fps = 30 self.start_time = time.time() self.current_time = 0 # The amount of time the program as been running self.music = Music(self) self.saves = [Save(n) for n in range(4)] self.selected_save = None self.is_running = True self.next_battle = None self.main_menu = MainMenu(self) self.opening_sequence = OpeningSequence(self) self.opening_sequence.visit() self.new_game_page = NewGamePage(self) self.load_game_page = LoadGamePage(self) self.player = None self.opponent = None self.initialise() OpeningSequence.initialise() NewGamePage.initialise() LoadGamePage.initialise() Surface.initialise(self) Options.initialise() Move.initialise(self) Character.initialise() Player.initialise() MainMenu.initialise() MemeDog.initialise() Battle.initialise() self.opponents = OrderedDict() self.opponents["Meme Dog"] = MemeDog self.opponents["Kanye Snake"] = KanyeSnake self.opponents["Spook Dog"] = SpookDog self.opponents["Evil Cloud"] = EvilCloud
def view(args: Namespace): mgr = get_asset_mgr() (path, points) = mgr.get(args.n) img = Image(path) img.perspective_transform(points) img.scale_bounded(X_MAX, Y_MAX) win = get_window() win.show(img) win.run_until_quit()
def make_train_data(classes): print(classes) ret = {} for c in classes: ret[c["name"]] = [] img_file_pathes = fs.list_entries(c["path"]) class_dir_path = os.path.join(train_data_dir_path, c["name"]) os.makedirs(class_dir_path, exist_ok=True) for filepath in img_file_pathes: try: image = Image() image.load_image_from_filepath(filepath) image.transform_image_for_predict_with(config["image_size_px"]) dst_filepath = os.path.join(class_dir_path, fs.get_filename(filepath)) image.write_to(dst_filepath) print(dst_filepath) ret[c["name"]].append(dst_filepath) except Exception as e: print(e) return ret
def __init__(self, game, max_hp=100, max_mana=100): super().__init__(game, "Meme Dog", max_hp, max_mana) self.x = 930 self.y = 440 self.dog_normal = Image("meme_dog/dog_normal.png", (self.x, self.y)) self.dog_dead = Image("meme_dog/dog_dead.png", (self.x, self.y)) self.dog_backwards = Image("meme_dog/dog_backwards.png") self.dog_bark_stance = Image("meme_dog/dog_bark_stance.png", (self.x, self.y)) Moves = namedtuple("Moves", "heal bark bite spin") self.moves = Moves(OpponentHeal(1005, 230, 410), Bark(), Bite(), Spin())
def __init__(self, number): self.number = number self.file_name = f"../saves/save{self.number+1}.txt" y_offset = 119*self.number self._display_x = 450 self._display_y = 230 + y_offset self.button_flared = Image(f"load{self.number+1}_flared.png", (0, 0)) self.button_boundaries = (355, 225+y_offset, 925, 338+y_offset) with open(self.file_name, "r") as save_file: save_lines = save_file.read().splitlines() self.player_name = save_lines[0] self.player_level = None self.opponent_name = None self.player_character = None if self.player_name != self.EMPTY_SAVE_NAME: self.player_level = float(save_lines[1]) self.opponent_name = save_lines[2] self.player_character = save_lines[3]
def __init__(self): super().__init__(50) self.sound = Audio("spook_dog/ghost_dog_claw.ogg") self.fade_overlays = [ Image(f"fade_overlay{10*(n+1)}.png", (0, 0)) for n in range(10) ] self.opacity = 0 top_claw_swipes = [ Image(f"spook_dog/ghost_dog_top_claw_swipe{n}.png", (145, 365)) for n in range(5) ] top_claw_sizes = [ Image(f"spook_dog/ghost_dog_top_claw_size{n}.png", (145, 365)) for n in range(8) ] top_claw_fades = [ Image(f"spook_dog/ghost_dog_top_claw_fade{20*(n+1)}.png", (145, 365)) for n in range(4) ] self.top_claw_frames = top_claw_swipes + top_claw_sizes + list( reversed(top_claw_fades)) side_claw_swipes = [ Image(f"spook_dog/ghost_dog_side_claw_swipe{n}.png", (130, 420)) for n in range(5) ] side_claw_sizes = [ Image(f"spook_dog/ghost_dog_side_claw_size{n}.png", (130, 420)) for n in range(8) ] side_claw_fades = [ Image(f"spook_dog/ghost_dog_side_claw_fade{20*(n+1)}.png", (130, 420)) for n in range(4) ] self.side_claw_frames = side_claw_swipes + side_claw_sizes + list( reversed(side_claw_fades)) self.duration = 0 self.total_duration = 2 * self.game.fps